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