]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c
StdLib: Fix more GCC warnings/errors caused by variables being set but not used.
[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
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 24char mBuffer[65536];\r
4684b66f 25\r
26\r
b81cc7d6 27/** Translate the host name into an IP address\r
4684b66f 28\r
b81cc7d6
OM
29 @param[in] Argc The number of arguments\r
30 @param[in] Argv The argument value array\r
4684b66f 31\r
32 @retval 0 The application exited normally.\r
33 @retval Other An error occurred.\r
34**/\r
35int\r
36main (\r
37 IN int Argc,\r
38 IN char **Argv\r
39 )\r
40{\r
4684b66f 41 UINTN Index;\r
42 struct hostent * pHost;\r
43 UINT8 * pIpAddress;\r
44 char ** ppName;\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 = gethostbyname ( Argv[1]);\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"%d.%d.%d.%d, Type %d, %a\r\n",\r
63 pIpAddress[0],\r
64 pIpAddress[1],\r
65 pIpAddress[2],\r
66 pIpAddress[3],\r
67 pHost->h_addrtype,\r
68 pHost->h_name );\r
69\r
4684b66f 70 // Display the other addresses\r
4684b66f 71 for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {\r
72 pIpAddress = (UINT8 *)pHost->h_addr_list[Index];\r
73 Print ( L"%d.%d.%d.%d\r\n",\r
74 pIpAddress[0],\r
75 pIpAddress[1],\r
76 pIpAddress[2],\r
77 pIpAddress[3]);\r
78 }\r
79\r
4684b66f 80 // Display the list of aliases\r
4684b66f 81 ppName = pHost->h_aliases;\r
82 if (( NULL == ppName ) || ( NULL == *ppName )) {\r
83 Print ( L"No aliases\r\n" );\r
84 }\r
85 else {\r
86 Print ( L"Aliases: " );\r
87 while ( NULL != *ppName ) {\r
88 //\r
89 // Display the alias\r
90 //\r
91 Print ( L"%a", *ppName );\r
92\r
93 //\r
94 // Set the next alias\r
95 //\r
96 ppName += 1;\r
97 if ( NULL != *ppName ) {\r
98 Print ( L", " );\r
99 }\r
100 }\r
101 Print ( L"\r\n" );\r
102 }\r
103 }\r
104 }\r
4684b66f 105 // All done\r
4684b66f 106 return errno;\r
107}\r