]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetHostByDns/GetHostByDns.c
Add Socket Library applications.
[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
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
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
12\r
13**/\r
14\r
15#include <errno.h>\r
16#include <netdb.h>\r
17#include <string.h>\r
18#include <Uefi.h>\r
19#include <unistd.h>\r
20\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiLib.h>\r
23\r
24#include <sys/socket.h>\r
25\r
26struct hostent * _gethostbydnsname(const char *, int);\r
27\r
28char mBuffer [65536];\r
29\r
30\r
31/**\r
32 Translate the host name into an IP address\r
33\r
34 @param [in] Argc The number of arguments\r
35 @param [in] Argv The argument value array\r
36\r
37 @retval 0 The application exited normally.\r
38 @retval Other An error occurred.\r
39**/\r
40int\r
41main (\r
42 IN int Argc,\r
43 IN char **Argv\r
44 )\r
45{\r
46 int AppStatus;\r
47 UINT8 * pIpAddress;\r
48 struct hostent * pHost;\r
49\r
50 DEBUG (( DEBUG_INFO,\r
51 "%a starting\r\n",\r
52 Argv[0]));\r
53\r
54 //\r
55 // Determine if the host name is specified\r
56 //\r
57 AppStatus = 0;\r
58 if ( 1 == Argc ) {\r
59 Print ( L"%a <host name>\r\n", Argv[0]);\r
60 }\r
61 else {\r
62 //\r
63 // Translate the host name\r
64 //\r
65 pHost = _gethostbydnsname ( Argv[1], AF_INET );\r
66 if ( NULL == pHost ) {\r
67 Print ( L"ERROR - host not found, errno: %d\r\n", errno );\r
68 }\r
69 else {\r
70 pIpAddress = (UINT8 *)pHost->h_addr;\r
71 Print ( L"%a: Type %d, %d.%d.%d.%d\r\n",\r
72 pHost->h_name,\r
73 pHost->h_addrtype,\r
74 pIpAddress[0],\r
75 pIpAddress[1],\r
76 pIpAddress[2],\r
77 pIpAddress[3]);\r
78 }\r
79 }\r
80\r
81 //\r
82 // All done\r
83 //\r
84 return errno;\r
85}\r