]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c
Add Socket Library applications.
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetHostByName / GetHostByName.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
26char mBuffer [65536];\r
27\r
28\r
29/**\r
30 Translate the host name into an IP address\r
31\r
32 @param [in] Argc The number of arguments\r
33 @param [in] Argv The argument value array\r
34\r
35 @retval 0 The application exited normally.\r
36 @retval Other An error occurred.\r
37**/\r
38int\r
39main (\r
40 IN int Argc,\r
41 IN char **Argv\r
42 )\r
43{\r
44 int AppStatus;\r
45 UINTN Index;\r
46 struct hostent * pHost;\r
47 UINT8 * pIpAddress;\r
48 char ** ppName;\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 = gethostbyname ( Argv[1]);\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"%d.%d.%d.%d, Type %d, %a\r\n",\r
72 pIpAddress[0],\r
73 pIpAddress[1],\r
74 pIpAddress[2],\r
75 pIpAddress[3],\r
76 pHost->h_addrtype,\r
77 pHost->h_name );\r
78\r
79 //\r
80 // Display the other addresses\r
81 //\r
82 for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {\r
83 pIpAddress = (UINT8 *)pHost->h_addr_list[Index];\r
84 Print ( L"%d.%d.%d.%d\r\n",\r
85 pIpAddress[0],\r
86 pIpAddress[1],\r
87 pIpAddress[2],\r
88 pIpAddress[3]);\r
89 }\r
90\r
91 //\r
92 // Display the list of aliases\r
93 //\r
94 ppName = pHost->h_aliases;\r
95 if (( NULL == ppName ) || ( NULL == *ppName )) {\r
96 Print ( L"No aliases\r\n" );\r
97 }\r
98 else {\r
99 Print ( L"Aliases: " );\r
100 while ( NULL != *ppName ) {\r
101 //\r
102 // Display the alias\r
103 //\r
104 Print ( L"%a", *ppName );\r
105\r
106 //\r
107 // Set the next alias\r
108 //\r
109 ppName += 1;\r
110 if ( NULL != *ppName ) {\r
111 Print ( L", " );\r
112 }\r
113 }\r
114 Print ( L"\r\n" );\r
115 }\r
116 }\r
117 }\r
118\r
119 //\r
120 // All done\r
121 //\r
122 return errno;\r
123}\r