]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetHostByName/GetHostByName.c
2 Translate the host name into an IP address
4 Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
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.
19 #include <Library/DebugLib.h>
20 #include <Library/UefiLib.h>
22 #include <sys/socket.h>
27 /** Translate the host name into an IP address
29 @param[in] Argc The number of arguments
30 @param[in] Argv The argument value array
32 @retval 0 The application exited normally.
33 @retval Other An error occurred.
42 struct hostent
* pHost
;
50 // Determine if the host name is specified
52 Print ( L
"%a <host name>\r\n", Argv
[0]);
55 // Translate the host name
56 pHost
= gethostbyname ( Argv
[1]);
57 if ( NULL
== pHost
) {
58 Print ( L
"ERROR - host not found, h_errno: %d\r\n", h_errno
);
61 pIpAddress
= (UINT8
*)pHost
->h_addr
;
62 Print ( L
"%d.%d.%d.%d, Type %d, %a\r\n",
70 // Display the other addresses
71 for ( Index
= 1; NULL
!= pHost
->h_addr_list
[Index
]; Index
++ ) {
72 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[Index
];
73 Print ( L
"%d.%d.%d.%d\r\n",
80 // Display the list of aliases
81 ppName
= pHost
->h_aliases
;
82 if (( NULL
== ppName
) || ( NULL
== *ppName
)) {
83 Print ( L
"No aliases\r\n" );
86 Print ( L
"Aliases: " );
87 while ( NULL
!= *ppName
) {
91 Print ( L
"%a", *ppName
);
97 if ( NULL
!= *ppName
) {