]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetAddrInfo/GetAddrInfo.c
3db71ba3dcf7c4b1a5185733a80051042d19993a
2 Test the getaddrinfo API
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 <netinet/in.h>
24 #include <sys/socket.h>
30 Test the getaddrinfo API
32 @param [in] Argc The number of arguments
33 @param [in] Argv The argument value array
35 @retval 0 The application exited normally.
36 @retval Other An error occurred.
47 struct addrinfo
* pAddrInfo
;
49 struct addrinfo
* pInfo
;
53 // Determine if the host name is specified
57 printf ( "%s <host name> <server name>\r\n", Argv
[0]);
61 // Translate the host name
66 pServerName
= Argv
[2];
68 AppStatus
= getaddrinfo ( pHostName
,
72 if ( 0 != AppStatus
) {
73 printf ( "ERROR - address info not found, errno: %d\r\n", AppStatus
);
75 if ( NULL
== pAddrInfo
) {
76 printf ( "ERROR - No address info structure allocated\r\n" );
80 // Walk the list of addresses
83 while ( NULL
!= pInfo
) {
87 printf ( "0x%08x: ai_flags\r\n", pInfo
->ai_flags
);
88 printf ( "0x%08x: ai_family\r\n", pInfo
->ai_family
);
89 printf ( "0x%08x: ai_socktype\r\n", pInfo
->ai_socktype
);
90 printf ( "0x%08x: ai_protocol\r\n", pInfo
->ai_protocol
);
91 printf ( "0x%08x: ai_addrlen\r\n", pInfo
->ai_addrlen
);
92 printf ( "%s: ai_canonname\r\n", pInfo
->ai_canonname
);
93 printf ( " 0x%02x: ai_addr->sa_len\r\n", (UINT8
)pInfo
->ai_addr
->sa_len
);
94 printf ( " 0x%02x: ai_addr->sa_family\r\n", (UINT8
)pInfo
->ai_addr
->sa_family
);
95 MaxLen
= pInfo
->ai_addr
->sa_len
;
96 if ( sizeof ( struct sockaddr_in6
) < MaxLen
) {
97 MaxLen
= sizeof ( struct sockaddr_in6
);
99 for ( Index
= 0; ( MaxLen
- 2 ) > Index
; Index
++ ) {
100 printf ( " 0x%02x: ai_addr->sa_data[%02d]\r\n", (UINT8
)pInfo
->ai_addr
->sa_data
[ Index
], Index
);
104 // Set the next entry
106 pInfo
= pInfo
->ai_next
;
110 // Done with this structures
112 freeaddrinfo ( pAddrInfo
);