]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetHostByDns/GetHostByDns.c
AppPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetHostByDns / GetHostByDns.c
CommitLineData
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 18struct hostent * _gethostbydnsname (const char *, int);\r
4684b66f 19\r
59bc0593 20char mBuffer[65536];\r
4684b66f 21\r
22\r
b81cc7d6 23/** Translate the host name into an IP address\r
4684b66f 24\r
25 @param [in] Argc The number of arguments\r
26 @param [in] Argv The argument value array\r
27\r
28 @retval 0 The application exited normally.\r
29 @retval Other An error occurred.\r
30**/\r
31int\r
32main (\r
33 IN int Argc,\r
34 IN char **Argv\r
35 )\r
36{\r
4684b66f 37 UINT8 * pIpAddress;\r
38 struct hostent * pHost;\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 = _gethostbydnsname ( Argv[1], AF_INET );\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"%a: Type %d, %d.%d.%d.%d\r\n",\r
57 pHost->h_name,\r
58 pHost->h_addrtype,\r
59 pIpAddress[0],\r
60 pIpAddress[1],\r
61 pIpAddress[2],\r
62 pIpAddress[3]);\r
63 }\r
64 }\r
4684b66f 65 // All done\r
4684b66f 66 return errno;\r
67}\r