2 Translate the port number into a service name
4 Copyright (c) 2011, 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
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.
22 #include <arpa\nameser.h>
23 #include <arpa\nameser_compat.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiLib.h>
28 #include <sys/socket.h>
31 Translate the IP address into a host name
33 @param [in] Argc The number of arguments
34 @param [in] Argv The argument value array
36 @retval 0 The application exited normally.
37 @retval Other An error occurred.
47 struct hostent
* pHost
;
50 UINT32 RemoteAddress
[4];
53 // Determine if the IPv4 address is specified
56 || ( 4 != sscanf ( Argv
[1],
62 || ( 255 < RemoteAddress
[0])
63 || ( 255 < RemoteAddress
[1])
64 || ( 255 < RemoteAddress
[2])
65 || ( 255 < RemoteAddress
[3])) {
66 Print ( L
"%a <IPv4 Address>\r\n", Argv
[0]);
70 // Translate the address into a host name
72 IpAddress
[0] = (UINT8
)RemoteAddress
[0];
73 IpAddress
[1] = (UINT8
)RemoteAddress
[1];
74 IpAddress
[2] = (UINT8
)RemoteAddress
[2];
75 IpAddress
[3] = (UINT8
)RemoteAddress
[3];
76 pHost
= gethostbyaddr ( &IpAddress
[0], INADDRSZ
, AF_INET
);
77 if ( NULL
== pHost
) {
78 Print ( L
"ERROR - host not found, h_errno: %d\r\n", h_errno
);
81 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[ 0 ];
82 Print ( L
"%d.%d.%d.%d, %a\r\n",
90 // Display the other addresses
92 for ( Index
= 1; NULL
!= pHost
->h_addr_list
[Index
]; Index
++ ) {
93 pIpAddress
= (UINT8
*)pHost
->h_addr_list
[Index
];
94 Print ( L
"%d.%d.%d.%d\r\n",
102 // Display the list of aliases
104 ppName
= pHost
->h_aliases
;
105 if (( NULL
== ppName
) || ( NULL
== *ppName
)) {
106 Print ( L
"No aliases\r\n" );
109 Print ( L
"Aliases: " );
110 while ( NULL
!= *ppName
) {
114 Print ( L
"%a", *ppName
);
117 // Set the next alias
120 if ( NULL
!= *ppName
) {