]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the IPv4 address into a network name\r | |
3 | \r | |
bcb96695 MK |
4 | Copyright (c) 2011-2012, Intel Corporation. All rights reserved.\r |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
4684b66f | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <errno.h>\r | |
10 | #include <netdb.h>\r | |
11 | #include <stdio.h>\r | |
12 | #include <string.h>\r | |
13 | #include <Uefi.h>\r | |
14 | #include <unistd.h>\r | |
15 | \r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/UefiLib.h>\r | |
18 | \r | |
19 | #include <sys/socket.h>\r | |
20 | \r | |
21 | /**\r | |
22 | Translate the IPv4 address into a network name\r | |
23 | \r | |
24 | @param [in] Argc The number of arguments\r | |
25 | @param [in] Argv The argument value array\r | |
26 | \r | |
27 | @retval 0 The application exited normally.\r | |
28 | @retval Other An error occurred.\r | |
29 | **/\r | |
30 | int\r | |
31 | main (\r | |
32 | IN int Argc,\r | |
33 | IN char **Argv\r | |
34 | )\r | |
35 | {\r | |
36 | UINT32 RemoteAddress[4];\r | |
37 | UINT8 IpAddress[4];\r | |
38 | struct netent * pNetwork;\r | |
39 | \r | |
40 | //\r | |
41 | // Determine if the IPv4 address is specified\r | |
42 | //\r | |
43 | if (( 2 != Argc )\r | |
44 | || ( 4 != sscanf ( Argv[1],\r | |
45 | "%d.%d.%d.%d",\r | |
46 | &RemoteAddress[0],\r | |
47 | &RemoteAddress[1],\r | |
48 | &RemoteAddress[2],\r | |
49 | &RemoteAddress[3]))\r | |
59bc0593 | 50 | || ( 255 < RemoteAddress[0])\r |
51 | || ( 255 < RemoteAddress[1])\r | |
52 | || ( 255 < RemoteAddress[2])\r | |
53 | || ( 255 < RemoteAddress[3])) {\r | |
4684b66f | 54 | Print ( L"%a <IPv4 Address>\r\n", Argv[0]);\r |
55 | }\r | |
56 | else {\r | |
57 | //\r | |
58 | // Translate the address into a network name\r | |
59 | //\r | |
60 | IpAddress[0] = (UINT8)RemoteAddress[0];\r | |
61 | IpAddress[1] = (UINT8)RemoteAddress[1];\r | |
62 | IpAddress[2] = (UINT8)RemoteAddress[2];\r | |
63 | IpAddress[3] = (UINT8)RemoteAddress[3];\r | |
64 | pNetwork = getnetbyaddr ( *(uint32_t *)&IpAddress[0], AF_INET );\r | |
65 | if ( NULL == pNetwork ) {\r | |
66 | Print ( L"ERROR - network not found, errno: %d\r\n", errno );\r | |
67 | }\r | |
68 | else {\r | |
69 | Print ( L"%a: %d.%d.%d.%d, 0x%08x\r\n",\r | |
70 | pNetwork->n_name,\r | |
71 | IpAddress[0],\r | |
72 | IpAddress[1],\r | |
73 | IpAddress[2],\r | |
74 | IpAddress[3],\r | |
75 | pNetwork->n_net );\r | |
76 | }\r | |
77 | }\r | |
78 | \r | |
79 | //\r | |
80 | // All done\r | |
81 | //\r | |
82 | return errno;\r | |
83 | }\r |