ReactOS  0.4.14-dev-384-g5b37caa
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

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((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 inet_addr(cp)
Definition: inet.h:98
#define ntohs(x)
Definition: module.h:208
GLenum const GLvoid * addr
Definition: glext.h:9621
USHORT port
Definition: uri.c:227
#define ok_dec(expression, result)
Definition: atltest.h:101

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  ADDRINFOA Hints;
203  CHAR LocalHostName[128];
204  struct hostent *Hostent;
205 
206  /* not yet initialized */
207  StartSeh()
211  StartSeh()
217 
218  Error = getaddrinfo("127.0.0.1", "80", NULL, &AddrInfo);
220 
221  Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
222  ok_dec(Error, 0);
223 
224  /* initialize LocalAddress for tests */
225  Error = gethostname(LocalHostName, sizeof(LocalHostName));
226  ok_dec(Error, 0);
227  ok_dec(WSAGetLastError(), 0);
228  trace("Local host name is '%s'\n", LocalHostName);
229  Hostent = gethostbyname(LocalHostName);
230  ok(Hostent != NULL, "gethostbyname failed with %d\n", WSAGetLastError());
231  if (Hostent && Hostent->h_addr_list[0] && Hostent->h_length == sizeof(IN_ADDR))
232  {
234  memcpy(&Address, Hostent->h_addr_list[0], sizeof(Address));
236  }
237  trace("Local address is '%s'\n", LocalAddress);
238  ok(LocalAddress[0] != '\0',
239  "Could not determine local address. Following test results may be wrong.\n");
240 
241  ZeroMemory(&Hints, sizeof(Hints));
242  /* parameter tests */
245  StartSeh()
250  ok_ptr(AddrInfo, NULL);
252 
253  TestNodeName();
254  TestServiceName();
255  /* TODO: test passing both node name and service name */
256  /* TODO: test hints */
257  /* TODO: test IPv6 */
258 
259  Error = WSACleanup();
260  ok_dec(Error, 0);
261 
262  /* not initialized anymore */
263  Error = getaddrinfo("127.0.0.1", "80", NULL, &AddrInfo);
265 }
char ** h_addr_list
Definition: winsock.h:138
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
static VOID TestServiceName(VOID)
Definition: getaddrinfo.c:107
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define MAKEWORD(a, b)
Definition: typedefs.h:247
char CHAR
Definition: xmlstorage.h:175
char * host
Definition: whois.c:55
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
GLdouble n
Definition: glext.h:7729
#define ZeroMemory
Definition: winbase.h:1642
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define StartSeh()
Definition: _sntprintf.h:16
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
short h_length
Definition: winsock.h:137
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
#define InvalidPointer
#define inet_ntoa(addr)
Definition: inet.h:100
#define WSANOTINITIALISED
Definition: winerror.h:1987
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define trace
Definition: atltest.h:70
#define d
Definition: ke_i.h:81
if(!(yy_init))
Definition: macro.lex.yy.c:714
Definition: tcpip.h:125
static VOID TestNodeName(VOID)
Definition: getaddrinfo.c:34
BOOL Error
Definition: chkdsk.c:66
_In_ PADDRINFOEXW AddrInfo
Definition: wsk.h:458
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: atltest.h:57
Definition: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ok_dec(expression, result)
Definition: atltest.h:101
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define getaddrinfo
Definition: wspiapi.h:44
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

◆ TestNodeName()

static VOID TestNodeName ( VOID  )
static

Definition at line 34 of file getaddrinfo.c.

35 {
36  int Error;
38  ADDRINFOA Hints;
39  struct
40  {
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);
81  ok_dec(WSAGetLastError(), 0);
83  "AddrInfo = %p\n", AddrInfo);
84  }
85  else
86  {
90  }
91  if (!Error && AddrInfo && AddrInfo != InvalidPointer)
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 }
#define ok_addrinfo(ai, flags, family, socktype, protocol, addrlen)
Definition: getaddrinfo.c:10
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
#define freeaddrinfo
Definition: wspiapi.h:46
#define ZeroMemory
Definition: winbase.h:1642
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define StartSeh()
Definition: _sntprintf.h:16
int32_t INT
Definition: typedefs.h:56
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
smooth NULL
Definition: ftsmooth.c:416
#define InvalidPointer
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define trace
Definition: atltest.h:70
if(!(yy_init))
Definition: macro.lex.yy.c:714
BOOL Error
Definition: chkdsk.c:66
_In_ PADDRINFOEXW AddrInfo
Definition: wsk.h:458
static const char * NodeName(const NOTIFICATIONLIST *item)
Definition: changenotify.c:145
#define AI_NUMERICHOST
Definition: ws2def.h:295
#define ok(value,...)
Definition: atltest.h:57
#define AF_INET
Definition: tcpip.h:117
#define ok_sockaddr_in(sockaddr, family, port, addr)
Definition: getaddrinfo.c:19
const char * PCSTR
Definition: typedefs.h:51
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ok_dec(expression, result)
Definition: atltest.h:101
struct test_data Tests[]
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define getaddrinfo
Definition: wspiapi.h:44
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170
int ai_family
Definition: ws2def.h:666

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);
173  ok_dec(WSAGetLastError(), 0);
175  "AddrInfo = %p\n", AddrInfo);
176  }
177  else
178  {
181  ok_ptr(AddrInfo, NULL);
182  }
183  if (!Error && AddrInfo && AddrInfo != InvalidPointer)
184  {
186  Tests[i].SockType, 0, sizeof(SOCKADDR_IN));
187  ok_ptr(AddrInfo->ai_canonname, NULL);
188  ok_sockaddr_in(AddrInfo->ai_addr, AF_INET,
189  Tests[i].ExpectedPort, "127.0.0.1");
190  ok_ptr(AddrInfo->ai_next, NULL);
192  }
194  }
195 }
#define ok_addrinfo(ai, flags, family, socktype, protocol, addrlen)
Definition: getaddrinfo.c:10
#define freeaddrinfo
Definition: wspiapi.h:46
#define ZeroMemory
Definition: winbase.h:1642
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define StartSeh()
Definition: _sntprintf.h:16
int32_t INT
Definition: typedefs.h:56
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
smooth NULL
Definition: ftsmooth.c:416
#define InvalidPointer
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define trace
Definition: atltest.h:70
if(!(yy_init))
Definition: macro.lex.yy.c:714
BOOL Error
Definition: chkdsk.c:66
_In_ PADDRINFOEXW AddrInfo
Definition: wsk.h:458
#define ok(value,...)
Definition: atltest.h:57
#define WSATYPE_NOT_FOUND
Definition: winerror.h:1996
#define AF_INET
Definition: tcpip.h:117
#define ok_sockaddr_in(sockaddr, family, port, addr)
Definition: getaddrinfo.c:19
const char * PCSTR
Definition: typedefs.h:51
#define SOCK_STREAM
Definition: tcpip.h:118
#define SOCK_DGRAM
Definition: winsock.h:336
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ok_dec(expression, result)
Definition: atltest.h:101
struct test_data Tests[]
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define getaddrinfo
Definition: wspiapi.h:44
int ai_family
Definition: ws2def.h:666

Referenced by START_TEST().

Variable Documentation

◆ LocalAddress

CHAR LocalAddress[sizeof("255.255.255.255")]

Definition at line 30 of file getaddrinfo.c.