]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetNameInfo/GetNameInfo.c
2 Test the getnameinfo API
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
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 <netinet/in.h>
24 #include <sys/socket.h>
28 char mServiceName
[256];
31 Test the getnameinfo API
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.
46 struct addrinfo
* pAddrInfo
;
48 struct addrinfo
* pInfo
;
52 // Determine if the host name is specified
56 printf ( "%s <host address> <server name>\r\n", Argv
[0]);
60 // Translate the host name
65 pServerName
= Argv
[2];
67 AppStatus
= getaddrinfo ( pHostName
,
71 if ( 0 != AppStatus
) {
72 printf ( "ERROR - address info not found, errno: %d\r\n", AppStatus
);
74 if ( NULL
== pAddrInfo
) {
75 printf ( "ERROR - No address info structure allocated\r\n" );
79 // Walk the list of names
82 while ( NULL
!= pInfo
) {
86 AppStatus
= getnameinfo ((struct sockaddr
*)pInfo
->ai_addr
,
91 sizeof ( mServiceName
),
93 if ( 0 != AppStatus
) {
100 printf ( "%s: HostName\r\n", &mHostName
[0]);
101 printf ( "%s: Service Name\r\n", &mServiceName
[0]);
104 // Set the next entry
106 pInfo
= pInfo
->ai_next
;
110 // Done with this structures
112 freeaddrinfo ( pAddrInfo
);