]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetHostByName / GetHostByName.c
1 /** @file
2 Translate the host name into an IP address
3
4 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7 #include <errno.h>
8 #include <netdb.h>
9 #include <string.h>
10 #include <Uefi.h>
11 #include <unistd.h>
12
13 #include <Library/DebugLib.h>
14 #include <Library/UefiLib.h>
15
16 #include <sys/socket.h>
17
18 char mBuffer[65536];
19
20
21 /** Translate the host name into an IP address
22
23 @param[in] Argc The number of arguments
24 @param[in] Argv The argument value array
25
26 @retval 0 The application exited normally.
27 @retval Other An error occurred.
28 **/
29 int
30 main (
31 IN int Argc,
32 IN char **Argv
33 )
34 {
35 UINTN Index;
36 struct hostent * pHost;
37 UINT8 * pIpAddress;
38 char ** ppName;
39
40 DEBUG (( DEBUG_INFO,
41 "%a starting\r\n",
42 Argv[0]));
43
44 // Determine if the host name is specified
45 if ( 1 == Argc ) {
46 Print ( L"%a <host name>\r\n", Argv[0]);
47 }
48 else {
49 // Translate the host name
50 pHost = gethostbyname ( Argv[1]);
51 if ( NULL == pHost ) {
52 Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );
53 }
54 else {
55 pIpAddress = (UINT8 *)pHost->h_addr;
56 Print ( L"%d.%d.%d.%d, Type %d, %a\r\n",
57 pIpAddress[0],
58 pIpAddress[1],
59 pIpAddress[2],
60 pIpAddress[3],
61 pHost->h_addrtype,
62 pHost->h_name );
63
64 // Display the other addresses
65 for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {
66 pIpAddress = (UINT8 *)pHost->h_addr_list[Index];
67 Print ( L"%d.%d.%d.%d\r\n",
68 pIpAddress[0],
69 pIpAddress[1],
70 pIpAddress[2],
71 pIpAddress[3]);
72 }
73
74 // Display the list of aliases
75 ppName = pHost->h_aliases;
76 if (( NULL == ppName ) || ( NULL == *ppName )) {
77 Print ( L"No aliases\r\n" );
78 }
79 else {
80 Print ( L"Aliases: " );
81 while ( NULL != *ppName ) {
82 //
83 // Display the alias
84 //
85 Print ( L"%a", *ppName );
86
87 //
88 // Set the next alias
89 //
90 ppName += 1;
91 if ( NULL != *ppName ) {
92 Print ( L", " );
93 }
94 }
95 Print ( L"\r\n" );
96 }
97 }
98 }
99 // All done
100 return errno;
101 }