]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetHostByAddr/GetHostByAddr.c
2 Translate the port number into a service name
4 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <arpa/nameser.h>
15 #include <arpa/nameser_compat.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiLib.h>
20 #include <sys/socket.h>
23 Translate the IP address into a host name
25 @param[in] Argc The number of arguments
26 @param[in] Argv The argument value array
28 @retval 0 The application exited normally.
29 @retval Other An error occurred.
39 struct hostent
* pHost
;
42 UINT32 RemoteAddress
[4];
45 // Determine if the IPv4 address is specified
48 || ( 4 != sscanf ( Argv
[1],
54 || ( 255 < RemoteAddress
[0])
55 || ( 255 < RemoteAddress
[1])
56 || ( 255 < RemoteAddress
[2])
57 || ( 255 < RemoteAddress
[3])) {
58 Print ( L
"%a <IPv4 Address>\r\n", Argv
[0]);
62 // Translate the address into a host name
64 IpAddress
[0] = (UINT8
)RemoteAddress
[0];
65 IpAddress
[1] = (UINT8
)RemoteAddress
[1];
66 IpAddress
[2] = (UINT8
)RemoteAddress
[2];
67 IpAddress
[3] = (UINT8
)RemoteAddress
[3];
68 pHost
= gethostbyaddr ( (const char *)&IpAddress
[0], INADDRSZ
, AF_INET
);
69 if ( NULL
== pHost
) {
70 Print ( L
"ERROR - host not found, h_errno: %d\r\n", h_errno
);
73 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[ 0 ];
74 Print ( L
"%d.%d.%d.%d, %a\r\n",
82 // Display the other addresses
84 for ( Index
= 1; NULL
!= pHost
->h_addr_list
[Index
]; Index
++ ) {
85 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[Index
];
86 Print ( L
"%d.%d.%d.%d\r\n",
94 // Display the list of aliases
96 ppName
= pHost
->h_aliases
;
97 if (( NULL
== ppName
) || ( NULL
== *ppName
)) {
98 Print ( L
"No aliases\r\n" );
101 Print ( L
"Aliases: " );
102 while ( NULL
!= *ppName
) {
106 Print ( L
"%a", *ppName
);
109 // Set the next alias
112 if ( NULL
!= *ppName
) {