+/** @file\r
+ Test the getnameinfo 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
+char mHostName[256];\r
+char mServiceName[256];\r
+\r
+/**\r
+ Test the getnameinfo 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
+ 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 address> <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 names\r
+ //\r
+ pInfo = pAddrInfo;\r
+ while ( NULL != pInfo ) {\r
+ //\r
+ // Get the name info\r
+ //\r
+ AppStatus = getnameinfo ((struct sockaddr *)pInfo->ai_addr,\r
+ pInfo->ai_addrlen,\r
+ &mHostName[0],\r
+ sizeof ( mHostName ),\r
+ &mServiceName[0],\r
+ sizeof ( mServiceName ),\r
+ 0 );\r
+ if ( 0 != AppStatus ) {\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Display this entry\r
+ //\r
+ printf ( "%s: HostName\r\n", mHostName[0]);\r
+ printf ( "%s: Service Name\r\n", &mServiceName[0]);\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