]>
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 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
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.
20 #include <arpa/nameser.h>
21 #include <arpa/nameser_compat.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiLib.h>
26 #include <sys/socket.h>
29 Translate the IP address into a host name
31 @param[in] Argc The number of arguments
32 @param[in] Argv The argument value array
34 @retval 0 The application exited normally.
35 @retval Other An error occurred.
45 struct hostent
* pHost
;
48 UINT32 RemoteAddress
[4];
51 // Determine if the IPv4 address is specified
54 || ( 4 != sscanf ( Argv
[1],
60 || ( 255 < RemoteAddress
[0])
61 || ( 255 < RemoteAddress
[1])
62 || ( 255 < RemoteAddress
[2])
63 || ( 255 < RemoteAddress
[3])) {
64 Print ( L
"%a <IPv4 Address>\r\n", Argv
[0]);
68 // Translate the address into a host name
70 IpAddress
[0] = (UINT8
)RemoteAddress
[0];
71 IpAddress
[1] = (UINT8
)RemoteAddress
[1];
72 IpAddress
[2] = (UINT8
)RemoteAddress
[2];
73 IpAddress
[3] = (UINT8
)RemoteAddress
[3];
74 pHost
= gethostbyaddr ( (const char *)&IpAddress
[0], INADDRSZ
, AF_INET
);
75 if ( NULL
== pHost
) {
76 Print ( L
"ERROR - host not found, h_errno: %d\r\n", h_errno
);
79 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[ 0 ];
80 Print ( L
"%d.%d.%d.%d, %a\r\n",
88 // Display the other addresses
90 for ( Index
= 1; NULL
!= pHost
->h_addr_list
[Index
]; Index
++ ) {
91 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[Index
];
92 Print ( L
"%d.%d.%d.%d\r\n",
100 // Display the list of aliases
102 ppName
= pHost
->h_aliases
;
103 if (( NULL
== ppName
) || ( NULL
== *ppName
)) {
104 Print ( L
"No aliases\r\n" );
107 Print ( L
"Aliases: " );
108 while ( NULL
!= *ppName
) {
112 Print ( L
"%a", *ppName
);
115 // Set the next alias
118 if ( NULL
!= *ppName
) {