]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the host name into an IP address\r | |
3 | \r | |
b81cc7d6 | 4 | Copyright (c) 2011 - 2014, 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 <string.h>\r | |
10 | #include <Uefi.h>\r | |
11 | #include <unistd.h>\r | |
12 | \r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/UefiLib.h>\r | |
15 | \r | |
16 | #include <sys/socket.h>\r | |
17 | \r | |
59bc0593 | 18 | char mBuffer[65536];\r |
4684b66f | 19 | \r |
20 | \r | |
b81cc7d6 | 21 | /** Translate the host name into an IP address\r |
4684b66f | 22 | \r |
b81cc7d6 OM |
23 | @param[in] Argc The number of arguments\r |
24 | @param[in] Argv The argument value array\r | |
4684b66f | 25 | \r |
26 | @retval 0 The application exited normally.\r | |
27 | @retval Other An error occurred.\r | |
28 | **/\r | |
29 | int\r | |
30 | main (\r | |
31 | IN int Argc,\r | |
32 | IN char **Argv\r | |
33 | )\r | |
34 | {\r | |
4684b66f | 35 | UINTN Index;\r |
36 | struct hostent * pHost;\r | |
37 | UINT8 * pIpAddress;\r | |
38 | char ** ppName;\r | |
39 | \r | |
40 | DEBUG (( DEBUG_INFO,\r | |
41 | "%a starting\r\n",\r | |
42 | Argv[0]));\r | |
43 | \r | |
4684b66f | 44 | // Determine if the host name is specified\r |
4684b66f | 45 | if ( 1 == Argc ) {\r |
46 | Print ( L"%a <host name>\r\n", Argv[0]);\r | |
47 | }\r | |
48 | else {\r | |
4684b66f | 49 | // Translate the host name\r |
4684b66f | 50 | pHost = gethostbyname ( Argv[1]);\r |
51 | if ( NULL == pHost ) {\r | |
f32df6f6 | 52 | Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );\r |
4684b66f | 53 | }\r |
54 | else {\r | |
55 | pIpAddress = (UINT8 *)pHost->h_addr;\r | |
56 | Print ( L"%d.%d.%d.%d, Type %d, %a\r\n",\r | |
57 | pIpAddress[0],\r | |
58 | pIpAddress[1],\r | |
59 | pIpAddress[2],\r | |
60 | pIpAddress[3],\r | |
61 | pHost->h_addrtype,\r | |
62 | pHost->h_name );\r | |
63 | \r | |
4684b66f | 64 | // Display the other addresses\r |
4684b66f | 65 | for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {\r |
66 | pIpAddress = (UINT8 *)pHost->h_addr_list[Index];\r | |
67 | Print ( L"%d.%d.%d.%d\r\n",\r | |
68 | pIpAddress[0],\r | |
69 | pIpAddress[1],\r | |
70 | pIpAddress[2],\r | |
71 | pIpAddress[3]);\r | |
72 | }\r | |
73 | \r | |
4684b66f | 74 | // Display the list of aliases\r |
4684b66f | 75 | ppName = pHost->h_aliases;\r |
76 | if (( NULL == ppName ) || ( NULL == *ppName )) {\r | |
77 | Print ( L"No aliases\r\n" );\r | |
78 | }\r | |
79 | else {\r | |
80 | Print ( L"Aliases: " );\r | |
81 | while ( NULL != *ppName ) {\r | |
82 | //\r | |
83 | // Display the alias\r | |
84 | //\r | |
85 | Print ( L"%a", *ppName );\r | |
86 | \r | |
87 | //\r | |
88 | // Set the next alias\r | |
89 | //\r | |
90 | ppName += 1;\r | |
91 | if ( NULL != *ppName ) {\r | |
92 | Print ( L", " );\r | |
93 | }\r | |
94 | }\r | |
95 | Print ( L"\r\n" );\r | |
96 | }\r | |
97 | }\r | |
98 | }\r | |
4684b66f | 99 | // All done\r |
4684b66f | 100 | return errno;\r |
101 | }\r |