--- /dev/null
+/** @file\r
+ Test the getaddrinfo API\r
+\r
+ Copyright (c) 2011, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <errno.h>\r
+#include <netdb.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <Uefi.h>\r
+#include <unistd.h>\r
+\r
+#include <netinet/in.h>\r
+\r
+#include <sys/socket.h>\r
+\r
+char mBuffer[65536];\r
+\r
+\r
+/**\r
+ Test the getaddrinfo API\r
+\r
+ @param [in] Argc The number of arguments\r
+ @param [in] Argv The argument value array\r
+\r
+ @retval 0 The application exited normally.\r
+ @retval Other An error occurred.\r
+**/\r
+int\r
+main (\r
+ IN int Argc,\r
+ IN char **Argv\r
+ )\r
+{\r
+ int AppStatus;\r
+ int Index;\r
+ int MaxLen;\r
+ struct addrinfo * pAddrInfo;\r
+ char * pHostName;\r
+ struct addrinfo * pInfo;\r
+ char * pServerName;\r
+\r
+ //\r
+ // Determine if the host name is specified\r
+ //\r
+ AppStatus = 0;\r
+ if ( 1 == Argc ) {\r
+ printf ( "%s <host name> <server name>\r\n", Argv[0]);\r
+ }\r
+ else {\r
+ //\r
+ // Translate the host name\r
+ //\r
+ pHostName = Argv[1];\r
+ pServerName = NULL;\r
+ if ( 2 < Argc ) {\r
+ pServerName = Argv[2];\r
+ }\r
+ AppStatus = getaddrinfo ( pHostName,\r
+ pServerName,\r
+ NULL,\r
+ &pAddrInfo );\r
+ if ( 0 != AppStatus ) {\r
+ printf ( "ERROR - address info not found, errno: %d\r\n", AppStatus );\r
+ }\r
+ if ( NULL == pAddrInfo ) {\r
+ printf ( "ERROR - No address info structure allocated\r\n" );\r
+ }\r
+ else {\r
+ //\r
+ // Walk the list of addresses\r
+ //\r
+ pInfo = pAddrInfo;\r
+ while ( NULL != pInfo ) {\r
+ //\r
+ // Display this entry\r
+ //\r
+ printf ( "0x%08x: ai_flags\r\n", pInfo->ai_flags );\r
+ printf ( "0x%08x: ai_family\r\n", pInfo->ai_family );\r
+ printf ( "0x%08x: ai_socktype\r\n", pInfo->ai_socktype );\r
+ printf ( "0x%08x: ai_protocol\r\n", pInfo->ai_protocol );\r
+ printf ( "0x%08x: ai_addrlen\r\n", pInfo->ai_addrlen );\r
+ printf ( "%s: ai_canonname\r\n", pInfo->ai_canonname );\r
+ printf ( " 0x%02x: ai_addr->sa_len\r\n", (UINT8)pInfo->ai_addr->sa_len );\r
+ printf ( " 0x%02x: ai_addr->sa_family\r\n", (UINT8)pInfo->ai_addr->sa_family );\r
+ MaxLen = pInfo->ai_addr->sa_len;\r
+ if ( sizeof ( struct sockaddr_in6 ) < MaxLen ) {\r
+ MaxLen = sizeof ( struct sockaddr_in6 );\r
+ }\r
+ for ( Index = 0; ( MaxLen - 2 ) > Index; Index++ ) {\r
+ printf ( " 0x%02x: ai_addr->sa_data[%02d]\r\n", (UINT8)pInfo->ai_addr->sa_data [ Index ], Index );\r
+ }\r
+\r
+ //\r
+ // Set the next entry\r
+ //\r
+ pInfo = pInfo->ai_next;\r
+ }\r
+\r
+ //\r
+ // Done with this structures\r
+ //\r
+ freeaddrinfo ( pAddrInfo );\r
+ }\r
+ }\r
+\r
+ //\r
+ // All done\r
+ //\r
+ return AppStatus;\r
+}\r