]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Sockets/GetAddrInfo/GetAddrInfo.c
Fix VS X64 Compiler Failure
[mirror_edk2.git] / AppPkg / Applications / Sockets / GetAddrInfo / GetAddrInfo.c
CommitLineData
f6e5cdd5 1/** @file\r
2 Test the getaddrinfo API\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <errno.h>\r
16#include <netdb.h>\r
17#include <string.h>\r
18#include <stdio.h>\r
19#include <Uefi.h>\r
20#include <unistd.h>\r
21\r
22#include <netinet/in.h>\r
23\r
24#include <sys/socket.h>\r
25\r
26char mBuffer[65536];\r
27\r
28\r
29/**\r
30 Test the getaddrinfo API\r
31\r
32 @param [in] Argc The number of arguments\r
33 @param [in] Argv The argument value array\r
34\r
35 @retval 0 The application exited normally.\r
36 @retval Other An error occurred.\r
37**/\r
38int\r
39main (\r
40 IN int Argc,\r
41 IN char **Argv\r
42 )\r
43{\r
44 int AppStatus;\r
45 int Index;\r
46 int MaxLen;\r
47 struct addrinfo * pAddrInfo;\r
48 char * pHostName;\r
49 struct addrinfo * pInfo;\r
50 char * pServerName;\r
51\r
52 //\r
53 // Determine if the host name is specified\r
54 //\r
55 AppStatus = 0;\r
56 if ( 1 == Argc ) {\r
57 printf ( "%s <host name> <server name>\r\n", Argv[0]);\r
58 }\r
59 else {\r
60 //\r
61 // Translate the host name\r
62 //\r
63 pHostName = Argv[1];\r
64 pServerName = NULL;\r
65 if ( 2 < Argc ) {\r
66 pServerName = Argv[2];\r
67 }\r
68 AppStatus = getaddrinfo ( pHostName,\r
69 pServerName,\r
70 NULL,\r
71 &pAddrInfo );\r
72 if ( 0 != AppStatus ) {\r
73 printf ( "ERROR - address info not found, errno: %d\r\n", AppStatus );\r
74 }\r
75 if ( NULL == pAddrInfo ) {\r
76 printf ( "ERROR - No address info structure allocated\r\n" );\r
77 }\r
78 else {\r
79 //\r
80 // Walk the list of addresses\r
81 //\r
82 pInfo = pAddrInfo;\r
83 while ( NULL != pInfo ) {\r
84 //\r
85 // Display this entry\r
86 //\r
87 printf ( "0x%08x: ai_flags\r\n", pInfo->ai_flags );\r
88 printf ( "0x%08x: ai_family\r\n", pInfo->ai_family );\r
89 printf ( "0x%08x: ai_socktype\r\n", pInfo->ai_socktype );\r
90 printf ( "0x%08x: ai_protocol\r\n", pInfo->ai_protocol );\r
91 printf ( "0x%08x: ai_addrlen\r\n", pInfo->ai_addrlen );\r
92 printf ( "%s: ai_canonname\r\n", pInfo->ai_canonname );\r
93 printf ( " 0x%02x: ai_addr->sa_len\r\n", (UINT8)pInfo->ai_addr->sa_len );\r
94 printf ( " 0x%02x: ai_addr->sa_family\r\n", (UINT8)pInfo->ai_addr->sa_family );\r
95 MaxLen = pInfo->ai_addr->sa_len;\r
96 if ( sizeof ( struct sockaddr_in6 ) < MaxLen ) {\r
97 MaxLen = sizeof ( struct sockaddr_in6 );\r
98 }\r
99 for ( Index = 0; ( MaxLen - 2 ) > Index; Index++ ) {\r
100 printf ( " 0x%02x: ai_addr->sa_data[%02d]\r\n", (UINT8)pInfo->ai_addr->sa_data [ Index ], Index );\r
101 }\r
102\r
103 //\r
104 // Set the next entry\r
105 //\r
106 pInfo = pInfo->ai_next;\r
107 }\r
108\r
109 //\r
110 // Done with this structures\r
111 //\r
112 freeaddrinfo ( pAddrInfo );\r
113 }\r
114 }\r
115\r
116 //\r
117 // All done\r
118 //\r
119 return AppStatus;\r
120}\r