]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the port number into a service name\r | |
3 | \r | |
6dbd32ca | 4 | Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
4684b66f | 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 | |
4684b66f | 12 | **/\r |
4684b66f | 13 | #include <errno.h>\r |
14 | #include <netdb.h>\r | |
15 | #include <stdio.h>\r | |
16 | #include <string.h>\r | |
17 | #include <Uefi.h>\r | |
18 | #include <unistd.h>\r | |
19 | \r | |
6dbd32ca | 20 | #include <arpa/nameser.h>\r |
21 | #include <arpa/nameser_compat.h>\r | |
4684b66f | 22 | \r |
23 | #include <Library/DebugLib.h>\r | |
24 | #include <Library/UefiLib.h>\r | |
25 | \r | |
26 | #include <sys/socket.h>\r | |
27 | \r | |
28 | /**\r | |
29 | Translate the IP address into a host name\r | |
30 | \r | |
6dbd32ca | 31 | @param[in] Argc The number of arguments\r |
32 | @param[in] Argv The argument value array\r | |
4684b66f | 33 | \r |
34 | @retval 0 The application exited normally.\r | |
35 | @retval Other An error occurred.\r | |
36 | **/\r | |
37 | int\r | |
38 | main (\r | |
39 | IN int Argc,\r | |
40 | IN char **Argv\r | |
41 | )\r | |
42 | {\r | |
43 | UINTN Index;\r | |
44 | UINT8 IpAddress[4];\r | |
45 | struct hostent * pHost;\r | |
46 | UINT8 * pIpAddress;\r | |
47 | char ** ppName;\r | |
48 | UINT32 RemoteAddress[4];\r | |
49 | \r | |
50 | //\r | |
51 | // Determine if the IPv4 address is specified\r | |
52 | //\r | |
53 | if (( 2 != Argc )\r | |
54 | || ( 4 != sscanf ( Argv[1],\r | |
55 | "%d.%d.%d.%d",\r | |
56 | &RemoteAddress[0],\r | |
57 | &RemoteAddress[1],\r | |
58 | &RemoteAddress[2],\r | |
59 | &RemoteAddress[3]))\r | |
59bc0593 | 60 | || ( 255 < RemoteAddress[0])\r |
61 | || ( 255 < RemoteAddress[1])\r | |
62 | || ( 255 < RemoteAddress[2])\r | |
63 | || ( 255 < RemoteAddress[3])) {\r | |
4684b66f | 64 | Print ( L"%a <IPv4 Address>\r\n", Argv[0]);\r |
65 | }\r | |
66 | else {\r | |
67 | //\r | |
68 | // Translate the address into a host name\r | |
69 | //\r | |
70 | IpAddress[0] = (UINT8)RemoteAddress[0];\r | |
71 | IpAddress[1] = (UINT8)RemoteAddress[1];\r | |
72 | IpAddress[2] = (UINT8)RemoteAddress[2];\r | |
73 | IpAddress[3] = (UINT8)RemoteAddress[3];\r | |
d3a595ce | 74 | pHost = gethostbyaddr ( (const char *)&IpAddress[0], INADDRSZ, AF_INET );\r |
4684b66f | 75 | if ( NULL == pHost ) {\r |
f32df6f6 | 76 | Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );\r |
4684b66f | 77 | }\r |
78 | else {\r | |
59bc0593 | 79 | pIpAddress = (UINT8 *)pHost->h_addr_list[ 0 ];\r |
4684b66f | 80 | Print ( L"%d.%d.%d.%d, %a\r\n",\r |
81 | pIpAddress[0],\r | |
82 | pIpAddress[1],\r | |
83 | pIpAddress[2],\r | |
84 | pIpAddress[3],\r | |
85 | pHost->h_name );\r | |
86 | \r | |
87 | //\r | |
88 | // Display the other addresses\r | |
89 | //\r | |
90 | for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {\r | |
91 | pIpAddress = (UINT8 *)pHost->h_addr_list[Index];\r | |
92 | Print ( L"%d.%d.%d.%d\r\n",\r | |
93 | pIpAddress[0],\r | |
94 | pIpAddress[1],\r | |
95 | pIpAddress[2],\r | |
96 | pIpAddress[3]);\r | |
97 | }\r | |
98 | \r | |
99 | //\r | |
100 | // Display the list of aliases\r | |
101 | //\r | |
102 | ppName = pHost->h_aliases;\r | |
103 | if (( NULL == ppName ) || ( NULL == *ppName )) {\r | |
104 | Print ( L"No aliases\r\n" );\r | |
105 | }\r | |
106 | else {\r | |
107 | Print ( L"Aliases: " );\r | |
108 | while ( NULL != *ppName ) {\r | |
109 | //\r | |
110 | // Display the alias\r | |
111 | //\r | |
112 | Print ( L"%a", *ppName );\r | |
113 | \r | |
114 | //\r | |
115 | // Set the next alias\r | |
116 | //\r | |
117 | ppName += 1;\r | |
118 | if ( NULL != *ppName ) {\r | |
119 | Print ( L", " );\r | |
120 | }\r | |
121 | }\r | |
122 | Print ( L"\r\n" );\r | |
123 | }\r | |
124 | }\r | |
125 | }\r | |
126 | \r | |
127 | //\r | |
128 | // All done\r | |
129 | //\r | |
130 | return errno;\r | |
131 | }\r |