]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c
Update the license dates
[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-2012, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <errno.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <Uefi.h>
19 #include <unistd.h>
20
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23
24 #include <sys/socket.h>
25
26 char mBuffer[65536];
27
28
29 /**
30 Translate the host name into an IP address
31
32 @param [in] Argc The number of arguments
33 @param [in] Argv The argument value array
34
35 @retval 0 The application exited normally.
36 @retval Other An error occurred.
37 **/
38 int
39 main (
40 IN int Argc,
41 IN char **Argv
42 )
43 {
44 int AppStatus;
45 UINTN Index;
46 struct hostent * pHost;
47 UINT8 * pIpAddress;
48 char ** ppName;
49
50 DEBUG (( DEBUG_INFO,
51 "%a starting\r\n",
52 Argv[0]));
53
54 //
55 // Determine if the host name is specified
56 //
57 AppStatus = 0;
58 if ( 1 == Argc ) {
59 Print ( L"%a <host name>\r\n", Argv[0]);
60 }
61 else {
62 //
63 // Translate the host name
64 //
65 pHost = gethostbyname ( Argv[1]);
66 if ( NULL == pHost ) {
67 Print ( L"ERROR - host not found, h_errno: %d\r\n", h_errno );
68 }
69 else {
70 pIpAddress = (UINT8 *)pHost->h_addr;
71 Print ( L"%d.%d.%d.%d, Type %d, %a\r\n",
72 pIpAddress[0],
73 pIpAddress[1],
74 pIpAddress[2],
75 pIpAddress[3],
76 pHost->h_addrtype,
77 pHost->h_name );
78
79 //
80 // Display the other addresses
81 //
82 for ( Index = 1; NULL != pHost->h_addr_list[Index]; Index++ ) {
83 pIpAddress = (UINT8 *)pHost->h_addr_list[Index];
84 Print ( L"%d.%d.%d.%d\r\n",
85 pIpAddress[0],
86 pIpAddress[1],
87 pIpAddress[2],
88 pIpAddress[3]);
89 }
90
91 //
92 // Display the list of aliases
93 //
94 ppName = pHost->h_aliases;
95 if (( NULL == ppName ) || ( NULL == *ppName )) {
96 Print ( L"No aliases\r\n" );
97 }
98 else {
99 Print ( L"Aliases: " );
100 while ( NULL != *ppName ) {
101 //
102 // Display the alias
103 //
104 Print ( L"%a", *ppName );
105
106 //
107 // Set the next alias
108 //
109 ppName += 1;
110 if ( NULL != *ppName ) {
111 Print ( L", " );
112 }
113 }
114 Print ( L"\r\n" );
115 }
116 }
117 }
118
119 //
120 // All done
121 //
122 return errno;
123 }