]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/GetAddrInfo/GetAddrInfo.c
4a25f6be6db5156c0bc94e77e6cfa9b37c3a02cf
2 Test the getaddrinfo API
4 Copyright (c) 2011-2012, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <netinet/in.h>
18 #include <sys/socket.h>
24 Test the getaddrinfo API
26 @param [in] Argc The number of arguments
27 @param [in] Argv The argument value array
29 @retval 0 The application exited normally.
30 @retval Other An error occurred.
41 struct addrinfo
* pAddrInfo
;
43 struct addrinfo
* pInfo
;
47 // Determine if the host name is specified
51 printf ( "%s <host name> <server name>\r\n", Argv
[0]);
55 // Translate the host name
60 pServerName
= Argv
[2];
62 AppStatus
= getaddrinfo ( pHostName
,
66 if ( 0 != AppStatus
) {
67 printf ( "ERROR - address info not found, errno: %d\r\n", AppStatus
);
69 if ( NULL
== pAddrInfo
) {
70 printf ( "ERROR - No address info structure allocated\r\n" );
74 // Walk the list of addresses
77 while ( NULL
!= pInfo
) {
81 printf ( "0x%08x: ai_flags\r\n", pInfo
->ai_flags
);
82 printf ( "0x%08x: ai_family\r\n", pInfo
->ai_family
);
83 printf ( "0x%08x: ai_socktype\r\n", pInfo
->ai_socktype
);
84 printf ( "0x%08x: ai_protocol\r\n", pInfo
->ai_protocol
);
85 printf ( "0x%08x: ai_addrlen\r\n", pInfo
->ai_addrlen
);
86 printf ( "%s: ai_canonname\r\n", pInfo
->ai_canonname
);
87 printf ( " 0x%02x: ai_addr->sa_len\r\n", (UINT8
)pInfo
->ai_addr
->sa_len
);
88 printf ( " 0x%02x: ai_addr->sa_family\r\n", (UINT8
)pInfo
->ai_addr
->sa_family
);
89 MaxLen
= pInfo
->ai_addr
->sa_len
;
90 if ( sizeof ( struct sockaddr_in6
) < MaxLen
) {
91 MaxLen
= sizeof ( struct sockaddr_in6
);
93 for ( Index
= 0; ( MaxLen
- 2 ) > Index
; Index
++ ) {
94 printf ( " 0x%02x: ai_addr->sa_data[%02d]\r\n", (UINT8
)pInfo
->ai_addr
->sa_data
[ Index
], Index
);
100 pInfo
= pInfo
->ai_next
;
104 // Done with this structures
106 freeaddrinfo ( pAddrInfo
);