ReactOS 0.4.15-dev-7934-g1dc8d80
getaddrinfo.c File Reference
#include "ws2_32.h"
Include dependency graph for getaddrinfo.c:

Go to the source code of this file.

Macros

#define ok_addrinfo(ai, flags, family, socktype, protocol, addrlen)
 
#define ok_sockaddr_in(sockaddr, family, port, addr)
 

Functions

static VOID TestNodeName (VOID)
 
static VOID TestServiceName (VOID)
 
 START_TEST (getaddrinfo)
 

Variables

static CHAR LocalAddress [sizeof("255.255.255.255")]
 

Macro Definition Documentation

◆ ok_addrinfo

#define ok_addrinfo (   ai,
  flags,
  family,
  socktype,
  protocol,
  addrlen 
)
Value:
do \
{ \
ok_hex((ai)->ai_flags, flags); \
ok_dec((ai)->ai_family, family); \
ok_dec((ai)->ai_socktype, socktype); \
ok_dec((ai)->ai_protocol, protocol); \
ok_dec((int)(ai)->ai_addrlen, addrlen); \
} while (0)
GLbitfield flags
Definition: glext.h:7161

Definition at line 10 of file getaddrinfo.c.

◆ ok_sockaddr_in

#define ok_sockaddr_in (   sockaddr,
  family,
  port,
  addr 
)
Value:
do \
{ \
int _i; \
ok_dec(((SOCKADDR_IN *)(sockaddr))->sin_family, family); \
ok_dec(ntohs(((SOCKADDR_IN *)(sockaddr))->sin_port), port); \
ok_hex(((SOCKADDR_IN *)(sockaddr))->sin_addr.S_un.S_addr, \
for (_i = 0; _i < 7; _i++) \
ok_dec(((SOCKADDR_IN *)(sockaddr))->sin_zero[_i], 0); \
} while (0)
#define ok_dec(expression, result)
Definition: atltest.h:101
USHORT port
Definition: uri.c:228
GLenum const GLvoid * addr
Definition: glext.h:9621
#define inet_addr(cp)
Definition: inet.h:98
#define ntohs(x)
Definition: module.h:210

Definition at line 19 of file getaddrinfo.c.

Function Documentation

◆ START_TEST()

START_TEST ( getaddrinfo  )

Definition at line 197 of file getaddrinfo.c.

198{
199 WSADATA WsaData;
200 int Error;
202 PADDRINFOW AddrInfoW;
203 ADDRINFOA Hints;
204 ADDRINFOW HintsW;
205 CHAR LocalHostName[128];
206 struct hostent *Hostent;
207
208 /* not yet initialized */
209 StartSeh()
213 StartSeh()
219
220 Error = getaddrinfo("127.0.0.1", "80", NULL, &AddrInfo);
222
223 Error = GetAddrInfoW(L"127.0.0.1", L"80", NULL, &AddrInfoW);
225
226 Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
227 ok_dec(Error, 0);
228
229 /* initialize LocalAddress for tests */
230 Error = gethostname(LocalHostName, sizeof(LocalHostName));
231 ok_dec(Error, 0);
233 trace("Local host name is '%s'\n", LocalHostName);
234 Hostent = gethostbyname(LocalHostName);
235 ok(Hostent != NULL, "gethostbyname failed with %d\n", WSAGetLastError());
236 if (Hostent && Hostent->h_addr_list[0] && Hostent->h_length == sizeof(IN_ADDR))
237 {
239 memcpy(&Address, Hostent->h_addr_list[0], sizeof(Address));
241 }
242 trace("Local address is '%s'\n", LocalAddress);
243 ok(LocalAddress[0] != '\0',
244 "Could not determine local address. Following test results may be wrong.\n");
245
246 ZeroMemory(&Hints, sizeof(Hints));
247 /* parameter tests for getaddrinfo */
250 StartSeh()
257
258 /* parameter tests for GetAddrInfoW */
261 StartSeh()
263 Error = GetAddrInfoW(NULL, NULL, NULL, &AddrInfoW);
266 ok_ptr(AddrInfo, InvalidPointer); /* differs from getaddrinfo */
268
269 TestNodeName();
271 /* TODO: test passing both node name and service name */
272 /* TODO: test hints */
273 /* TODO: test IPv6 */
274
275 Error = WSACleanup();
276 ok_dec(Error, 0);
277
278 /* not initialized anymore */
279 Error = getaddrinfo("127.0.0.1", "80", NULL, &AddrInfo);
281
282 Error = GetAddrInfoW(L"127.0.0.1", L"80", NULL, &AddrInfoW);
284}
#define InvalidPointer
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
INT WSAAPI GetAddrInfoW(IN PCWSTR pszNodeName, IN PCWSTR pszServiceName, IN const ADDRINFOW *ptHints, OUT PADDRINFOW *pptResult)
Definition: addrinfo.c:509
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define ok_ptr(expression, result)
Definition: atltest.h:108
BOOL Error
Definition: chkdsk.c:66
#define NULL
Definition: types.h:112
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
static VOID TestNodeName(VOID)
Definition: getaddrinfo.c:34
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
#define inet_ntoa(addr)
Definition: inet.h:100
#define d
Definition: ke_i.h:81
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define L(x)
Definition: ntvdm.h:50
static WCHAR Address[46]
Definition: ping.c:68
#define STATUS_SUCCESS
Definition: shellext.h:65
short h_length
Definition: winsock.h:137
char ** h_addr_list
Definition: winsock.h:138
Definition: tcpip.h:126
Definition: name.c:39
#define MAKEWORD(a, b)
Definition: typedefs.h:248
char * host
Definition: whois.c:55
#define ZeroMemory
Definition: winbase.h:1712
#define WSANOTINITIALISED
Definition: winerror.h:1987
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:171
_In_ PADDRINFOEXW AddrInfo
Definition: wsk.h:441
#define getaddrinfo
Definition: wspiapi.h:44
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
char CHAR
Definition: xmlstorage.h:175

◆ TestNodeName()

static VOID TestNodeName ( VOID  )
static

Definition at line 34 of file getaddrinfo.c.

35{
36 int Error;
38 ADDRINFOA Hints;
39 struct
40 {
41 PCSTR NodeName;
42 PCSTR ExpectedAddress;
43 INT Flags;
44 } Tests[] =
45 {
46 { "", LocalAddress },
47 { " ", NULL },
48 { "doesntexist.example.com", NULL },
49 { "localhost", "127.0.0.1" },
50 { "localhost:80", NULL },
51 { "7.8.9.10", "7.8.9.10", AI_NUMERICHOST },
52 { "0.0.0.0", "0.0.0.0", AI_NUMERICHOST },
53 { "255.255.255.255", "255.255.255.255", AI_NUMERICHOST },
54 { "0.0.0.0 ", "0.0.0.0", /* no AI_NUMERICHOST */ },
55 { "0.0.0.0:80", NULL },
56 { "0.0.0.0.0", NULL },
57 { "1.1.1.256", NULL },
58 { "1.2.3", NULL },
59 { "1.2.3.0x4", "1.2.3.4", AI_NUMERICHOST },
60 { "1.2.3.010", "1.2.3.8", AI_NUMERICHOST },
61 /* let's just assume this one doesn't change any time soon ;) */
62 { "google-public-dns-a.google.com", "8.8.8.8" },
63 };
64 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
65 INT i;
66
67 /* make sure we don't get IPv6 responses */
68 ZeroMemory(&Hints, sizeof(Hints));
69 Hints.ai_family = AF_INET;
70
71 trace("Nodes\n");
72 for (i = 0; i < TestCount; i++)
73 {
74 trace("%d: '%s'\n", i, Tests[i].NodeName);
75 StartSeh()
77 Error = getaddrinfo(Tests[i].NodeName, NULL, &Hints, &AddrInfo);
78 if (Tests[i].ExpectedAddress)
79 {
80 ok_dec(Error, 0);
83 "AddrInfo = %p\n", AddrInfo);
84 }
85 else
86 {
90 }
92 {
94 0, 0, sizeof(SOCKADDR_IN));
95 ok_ptr(AddrInfo->ai_canonname, NULL);
97 0, Tests[i].ExpectedAddress);
98 ok_ptr(AddrInfo->ai_next, NULL);
100 }
102 }
103}
struct test_data Tests[]
#define AF_INET
Definition: tcpip.h:117
#define ok_sockaddr_in(sockaddr, family, port, addr)
Definition: getaddrinfo.c:19
#define ok_addrinfo(ai, flags, family, socktype, protocol, addrlen)
Definition: getaddrinfo.c:10
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int ai_family
Definition: ws2def.h:666
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
#define AI_NUMERICHOST
Definition: ws2def.h:295
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define freeaddrinfo
Definition: wspiapi.h:46

Referenced by START_TEST().

◆ TestServiceName()

static VOID TestServiceName ( VOID  )
static

Definition at line 107 of file getaddrinfo.c.

108{
109 int Error;
111 ADDRINFOA Hints;
112 struct
113 {
115 INT ExpectedPort;
116 INT SockType;
117 } Tests[] =
118 {
119 { "", 0 },
120 { "0", 0 },
121 { "1", 1 },
122 { "a", -1 },
123 { "010", 10 },
124 { "0x1a", -1 },
125 { "http", 80, SOCK_STREAM },
126 { "smtp", 25, SOCK_STREAM },
127 { "mail", 25, SOCK_STREAM }, /* alias for smtp */
128 { "router", 520, SOCK_DGRAM },
129 { "domain", 53, 0 /* DNS supports both UDP and TCP */ },
130 { ":0", -1 },
131 { "123", 123 },
132 { " 123", 123 },
133 { " 123", 123 },
134 { "32767", 32767 },
135 { "32768", 32768 },
136 { "65535", 65535 },
137 { "65536", 0 },
138 { "65537", 1 },
139 { "65540", 4 },
140 { "65536", 0 },
141 { "4294967295", 65535 },
142 { "4294967296", 65535 },
143 { "9999999999", 65535 },
144 { "999999999999999999999999999999999999", 65535 },
145 { "+5", 5 },
146 { "-1", 65535 },
147 { "-4", 65532 },
148 { "-65534", 2 },
149 { "-65535", 1 },
150 { "-65536", 0 },
151 { "-65537", 65535 },
152 { "28a", -1 },
153 { "28 ", -1 },
154 { "a28", -1 },
155 };
156 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
157 INT i;
158
159 /* make sure we don't get IPv6 responses */
160 ZeroMemory(&Hints, sizeof(Hints));
161 Hints.ai_family = AF_INET;
162
163 trace("Services\n");
164 for (i = 0; i < TestCount; i++)
165 {
166 trace("%d: '%s'\n", i, Tests[i].ServiceName);
167 StartSeh()
170 if (Tests[i].ExpectedPort != -1)
171 {
172 ok_dec(Error, 0);
175 "AddrInfo = %p\n", AddrInfo);
176 }
177 else
178 {
182 }
184 {
186 Tests[i].SockType, 0, sizeof(SOCKADDR_IN));
187 ok_ptr(AddrInfo->ai_canonname, NULL);
189 Tests[i].ExpectedPort, "127.0.0.1");
190 ok_ptr(AddrInfo->ai_next, NULL);
192 }
194 }
195}
static WCHAR ServiceName[]
Definition: browser.c:19
#define SOCK_STREAM
Definition: tcpip.h:118
#define WSATYPE_NOT_FOUND
Definition: winerror.h:1996
#define SOCK_DGRAM
Definition: winsock.h:336

Variable Documentation

◆ LocalAddress

CHAR LocalAddress[sizeof("255.255.255.255")]
static

Definition at line 30 of file getaddrinfo.c.