]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /** @file\r |
2 | Translate the host name into an IP address\r | |
3 | \r | |
b81cc7d6 OM |
4 | Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials are licensed and made available under\r | |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
4684b66f | 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 <string.h>\r | |
16 | #include <Uefi.h>\r | |
17 | #include <unistd.h>\r | |
18 | \r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/UefiLib.h>\r | |
21 | \r | |
22 | #include <sys/socket.h>\r | |
23 | \r | |
59bc0593 | 24 | struct hostent * _gethostbydnsname (const char *, int);\r |
4684b66f | 25 | \r |
59bc0593 | 26 | char mBuffer[65536];\r |
4684b66f | 27 | \r |
28 | \r | |
b81cc7d6 | 29 | /** Translate the host name into an IP address\r |
4684b66f | 30 | \r |
31 | @param [in] Argc The number of arguments\r | |
32 | @param [in] Argv The argument value array\r | |
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 | |
4684b66f | 43 | UINT8 * pIpAddress;\r |
44 | struct hostent * pHost;\r | |
45 | \r | |
46 | DEBUG (( DEBUG_INFO,\r | |
47 | "%a starting\r\n",\r | |
48 | Argv[0]));\r | |
49 | \r | |
4684b66f | 50 | // Determine if the host name is specified\r |
4684b66f | 51 | if ( 1 == Argc ) {\r |
52 | Print ( L"%a <host name>\r\n", Argv[0]);\r | |
53 | }\r | |
54 | else {\r | |
4684b66f | 55 | // Translate the host name\r |
4684b66f | 56 | pHost = _gethostbydnsname ( Argv[1], AF_INET );\r |
57 | if ( NULL == pHost ) {\r | |
f32df6f6 | 58 | Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );\r |
4684b66f | 59 | }\r |
60 | else {\r | |
61 | pIpAddress = (UINT8 *)pHost->h_addr;\r | |
62 | Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",\r | |
63 | pHost->h_name,\r | |
64 | pHost->h_addrtype,\r | |
65 | pIpAddress[0],\r | |
66 | pIpAddress[1],\r | |
67 | pIpAddress[2],\r | |
68 | pIpAddress[3]);\r | |
69 | }\r | |
70 | }\r | |
4684b66f | 71 | // All done\r |
4684b66f | 72 | return errno;\r |
73 | }\r |