]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the IPv4 address into a network name\r | |
3 | \r | |
9f7f5161 | 4 | Copyright (c) 2011-2012, Intel Corporation\r |
4684b66f | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <errno.h>\r | |
16 | #include <netdb.h>\r | |
17 | #include <stdio.h>\r | |
18 | #include <string.h>\r | |
19 | #include <Uefi.h>\r | |
20 | #include <unistd.h>\r | |
21 | \r | |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/UefiLib.h>\r | |
24 | \r | |
25 | #include <sys/socket.h>\r | |
26 | \r | |
27 | /**\r | |
28 | Translate the IPv4 address into a network name\r | |
29 | \r | |
30 | @param [in] Argc The number of arguments\r | |
31 | @param [in] Argv The argument value array\r | |
32 | \r | |
33 | @retval 0 The application exited normally.\r | |
34 | @retval Other An error occurred.\r | |
35 | **/\r | |
36 | int\r | |
37 | main (\r | |
38 | IN int Argc,\r | |
39 | IN char **Argv\r | |
40 | )\r | |
41 | {\r | |
42 | UINT32 RemoteAddress[4];\r | |
43 | UINT8 IpAddress[4];\r | |
44 | struct netent * pNetwork;\r | |
45 | \r | |
46 | //\r | |
47 | // Determine if the IPv4 address is specified\r | |
48 | //\r | |
49 | if (( 2 != Argc )\r | |
50 | || ( 4 != sscanf ( Argv[1],\r | |
51 | "%d.%d.%d.%d",\r | |
52 | &RemoteAddress[0],\r | |
53 | &RemoteAddress[1],\r | |
54 | &RemoteAddress[2],\r | |
55 | &RemoteAddress[3]))\r | |
59bc0593 | 56 | || ( 255 < RemoteAddress[0])\r |
57 | || ( 255 < RemoteAddress[1])\r | |
58 | || ( 255 < RemoteAddress[2])\r | |
59 | || ( 255 < RemoteAddress[3])) {\r | |
4684b66f | 60 | Print ( L"%a <IPv4 Address>\r\n", Argv[0]);\r |
61 | }\r | |
62 | else {\r | |
63 | //\r | |
64 | // Translate the address into a network name\r | |
65 | //\r | |
66 | IpAddress[0] = (UINT8)RemoteAddress[0];\r | |
67 | IpAddress[1] = (UINT8)RemoteAddress[1];\r | |
68 | IpAddress[2] = (UINT8)RemoteAddress[2];\r | |
69 | IpAddress[3] = (UINT8)RemoteAddress[3];\r | |
70 | pNetwork = getnetbyaddr ( *(uint32_t *)&IpAddress[0], AF_INET );\r | |
71 | if ( NULL == pNetwork ) {\r | |
72 | Print ( L"ERROR - network not found, errno: %d\r\n", errno );\r | |
73 | }\r | |
74 | else {\r | |
75 | Print ( L"%a: %d.%d.%d.%d, 0x%08x\r\n",\r | |
76 | pNetwork->n_name,\r | |
77 | IpAddress[0],\r | |
78 | IpAddress[1],\r | |
79 | IpAddress[2],\r | |
80 | IpAddress[3],\r | |
81 | pNetwork->n_net );\r | |
82 | }\r | |
83 | }\r | |
84 | \r | |
85 | //\r | |
86 | // All done\r | |
87 | //\r | |
88 | return errno;\r | |
89 | }\r |