ReactOS 0.4.15-dev-7961-gdcf9eb0
addrconv.c File Reference
#include <ws2_32.h>
#include <debug.h>
Include dependency graph for addrconv.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DN2H(dw)
 
#define DH2N(dw)
 
#define WN2H(w)
 
#define WH2N(w)
 

Functions

ULONG WSAAPI inet_addr (IN CONST CHAR FAR *cp)
 
CHAR FAR *WSAAPI inet_ntoa (IN IN_ADDR in)
 
ULONG WSAAPI htonl (IN ULONG hostlong)
 
USHORT WSAAPI htons (IN USHORT hostshort)
 
ULONG WSAAPI ntohl (IN ULONG netlong)
 
USHORT WSAAPI ntohs (IN USHORT netshort)
 
INT WSAAPI WSAHtonl (IN SOCKET s, IN ULONG hostlong, OUT ULONG FAR *lpnetlong)
 
INT WSAAPI WSAHtons (IN SOCKET s, IN USHORT hostshort, OUT USHORT FAR *lpnetshort)
 
INT WSAAPI WSANtohl (IN SOCKET s, IN ULONG netlong, OUT ULONG FAR *lphostlong)
 
INT WSAAPI WSANtohs (IN SOCKET s, IN USHORT netshort, OUT USHORT FAR *lphostshort)
 

Macro Definition Documentation

◆ DH2N

#define DH2N (   dw)
Value:
((((dw) & 0xFF000000L) >> 24) | \
(((dw) & 0x00FF0000L) >> 8) | \
(((dw) & 0x0000FF00L) << 8) | \
(((dw) & 0x000000FFL) << 24))
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40

Definition at line 28 of file addrconv.c.

◆ DN2H

#define DN2H (   dw)
Value:
((((dw) & 0xFF000000L) >> 24) | \
(((dw) & 0x00FF0000L) >> 8) | \
(((dw) & 0x0000FF00L) << 8) | \
(((dw) & 0x000000FFL) << 24))

Definition at line 21 of file addrconv.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file addrconv.c.

◆ WH2N

#define WH2N (   w)
Value:
((((w) & 0xFF00) >> 8) | \
(((w) & 0x00FF) << 8))
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102

Definition at line 40 of file addrconv.c.

◆ WN2H

#define WN2H (   w)
Value:
((((w) & 0xFF00) >> 8) | \
(((w) & 0x00FF) << 8))

Definition at line 35 of file addrconv.c.

Function Documentation

◆ htonl()

ULONG WSAAPI htonl ( IN ULONG  hostlong)

Definition at line 228 of file addrconv.c.

229{
230 return DH2N(hostlong);
231}
#define DH2N(dw)
Definition: addrconv.c:28

◆ htons()

USHORT WSAAPI htons ( IN USHORT  hostshort)

Definition at line 238 of file addrconv.c.

239{
240 return WH2N(hostshort);
241}
#define WH2N(w)
Definition: addrconv.c:40

◆ inet_addr()

ULONG WSAAPI inet_addr ( IN CONST CHAR FAR cp)

Definition at line 71 of file addrconv.c.

72{
73 register u_long val, base, n;
74 register unsigned char c;
75 u_long parts[4], *pp = parts;
76 if (!cp) return INADDR_ANY;
77 if (!isdigit(*cp)) return INADDR_NONE;
78
79again:
80 /*
81 * Collect number up to ``.''.
82 * Values are specified as for C:
83 * 0x=hex, 0=octal, other=decimal.
84 */
85 val = 0; base = 10;
86 if (*cp == '0') {
87 if (*++cp == 'x' || *cp == 'X')
88 base = 16, cp++;
89 else
90 base = 8;
91 }
92 while ((c = *cp)) {
93 if (isdigit(c)) {
94 val = (val * base) + (c - '0');
95 cp++;
96 continue;
97 }
98 if (base == 16 && isxdigit(c)) {
99 val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
100 cp++;
101 continue;
102 }
103 break;
104 }
105 if (*cp == '.') {
106 /*
107 * Internet format:
108 * a.b.c.d
109 * a.b.c (with c treated as 16-bits)
110 * a.b (with b treated as 24 bits)
111 */
112 if (pp >= parts + 4) return (INADDR_NONE);
113 *pp++ = val;
114 cp++;
115 goto again;
116 }
117 /*
118 * Check for trailing characters.
119 */
120 if (*cp && !isspace((UCHAR)*cp)) return (INADDR_NONE);
121
122 *pp++ = val;
123 /*
124 * Concoct the address according to
125 * the number of parts specified.
126 */
127 n = (u_long)(pp - parts);
128 switch (n) {
129
130 case 1: /* a -- 32 bits */
131 val = parts[0];
132 break;
133
134 case 2: /* a.b -- 8.24 bits */
135 val = (parts[0] << 24) | (parts[1] & 0xffffff);
136 break;
137
138 case 3: /* a.b.c -- 8.8.16 bits */
139 val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
140 (parts[2] & 0xffff);
141 break;
142
143 case 4: /* a.b.c.d -- 8.8.8.8 bits */
144 val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
145 ((parts[2] & 0xff) << 8) | (parts[3] & 0xff);
146 break;
147
148 default:
149 return (INADDR_NONE);
150 }
151 val = htonl(val);
152 return (val);
153}
#define isspace(c)
Definition: acclib.h:69
#define islower(c)
Definition: acclib.h:72
#define isdigit(c)
Definition: acclib.h:68
#define isxdigit(c)
Definition: acclib.h:70
#define INADDR_NONE
Definition: tcp.c:42
unsigned long u_long
Definition: linux.h:269
GLdouble n
Definition: glext.h:7729
const GLubyte * c
Definition: glext.h:8905
GLuint GLfloat * val
Definition: glext.h:7180
#define INADDR_ANY
Definition: inet.h:53
#define c
Definition: ke_i.h:80
POINT cp
Definition: magnifier.c:59
#define htonl(x)
Definition: module.h:214
static const D3D_BLOB_PART parts[]
Definition: blob.c:76
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ inet_ntoa()

CHAR FAR *WSAAPI inet_ntoa ( IN IN_ADDR  in)

Definition at line 160 of file addrconv.c.

161{
165 WSADATA WsaData;
166 BOOL ManualLoad = FALSE;
167 CHAR b[10];
168 PCHAR p;
169 DPRINT("inet_ntoa: %lx\n", in);
170
171 /* Enter prolog */
173 {
174 DPRINT("MANUAL LOAD\n");
175
176 /* Only fail if the error wasn't related to a missing WSAStartup */
178 {
179 /* Fail */
181 return NULL;
182 }
183
184 /* Apps aren't expected to call WSAStartup for this API, so we will */
185 if ((ErrorCode = WSAStartup(MAKEWORD(2,2), &WsaData)) != ERROR_SUCCESS)
186 {
187 /* We failed */
189 return NULL;
190 }
191
192 /* Try the prolog again */
193 ManualLoad = TRUE;
195 {
196 /* Failed again... */
197 WSACleanup();
199 return NULL;
200 }
201 }
202
203 p = Thread->Buffer;
204 _itoa(in.S_un.S_addr & 0xFF, b, 10);
205 strcpy(p, b);
206 _itoa((in.S_un.S_addr >> 8) & 0xFF, b, 10);
207 strcat(p, ".");
208 strcat(p, b);
209 _itoa((in.S_un.S_addr >> 16) & 0xFF, b, 10);
210 strcat(p, ".");
211 strcat(p, b);
212 _itoa((in.S_un.S_addr >> 24) & 0xFF, b, 10);
213 strcat(p, ".");
214 strcat(p, b);
215
216 /* Cleanup the manual load */
217 if (ManualLoad) WSACleanup();
218
219 /* Return the buffer */
220 return p;
221}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint in
Definition: glext.h:9616
GLfloat GLfloat p
Definition: glext.h:8902
_CRTIMP char *__cdecl _itoa(_In_ int _Value, _Pre_notnull_ _Post_z_ char *_Dest, _In_ int _Radix)
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define DPRINT
Definition: sndvol32.h:71
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
#define WSANOTINITIALISED
Definition: winerror.h:1987
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
char CHAR
Definition: xmlstorage.h:175

◆ ntohl()

ULONG WSAAPI ntohl ( IN ULONG  netlong)

Definition at line 248 of file addrconv.c.

249{
250 return DN2H(netlong);
251}
#define DN2H(dw)
Definition: addrconv.c:21

◆ ntohs()

USHORT WSAAPI ntohs ( IN USHORT  netshort)

Definition at line 258 of file addrconv.c.

259{
260 return WN2H(netshort);
261}
#define WN2H(w)
Definition: addrconv.c:35

◆ WSAHtonl()

INT WSAAPI WSAHtonl ( IN SOCKET  s,
IN ULONG  hostlong,
OUT ULONG FAR lpnetlong 
)

Definition at line 268 of file addrconv.c.

271{
273 PWSSOCKET Socket;
274 DPRINT("WSAHtonl: %p, %lx, %p\n", s, hostlong, lpnetlong);
275
276 /* Check for WSAStartup */
278 {
279 /* Make sure we got a parameter */
280 if (!lpnetlong)
281 {
282 /* Fail */
284 return SOCKET_ERROR;
285 }
286
287 /* Get the Socket Context */
288 if ((Socket = WsSockGetSocket(s)))
289 {
290 /* Check which byte order to use */
293 {
294 /* No conversion needed */
295 *lpnetlong = hostlong;
296 }
297 else
298 {
299 /* Use a swap */
300 *lpnetlong = DN2H(hostlong);
301 }
302
303 /* Dereference the socket */
304 WsSockDereference(Socket);
305
306 /* Return success */
307 return ERROR_SUCCESS;
308 }
309 else
310 {
311 /* Set the error code */
313 }
314 }
315
316 /* Return with error */
318 return SOCKET_ERROR;
319}
GLdouble s
Definition: gl.h:2039
WSAPROTOCOL_INFOW ProtocolInfo
Definition: ws2_32p.h:91
PTCATALOG_ENTRY CatalogEntry
Definition: ws2_32p.h:200
#define WSAENOTSOCK
Definition: winerror.h:1951
#define WSAEFAULT
Definition: winerror.h:1945
#define LITTLEENDIAN
Definition: winsock2.h:458
#define SOCKET_ERROR
Definition: winsock.h:333
FORCEINLINE DWORD WsQuickProlog(VOID)
Definition: ws2_32p.h:892
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
PWSSOCKET WSAAPI WsSockGetSocket(IN SOCKET Handle)
Definition: dsocket.c:140

◆ WSAHtons()

INT WSAAPI WSAHtons ( IN SOCKET  s,
IN USHORT  hostshort,
OUT USHORT FAR lpnetshort 
)

Definition at line 326 of file addrconv.c.

329{
331 PWSSOCKET Socket;
332 DPRINT("WSAHtons: %p, %lx, %p\n", s, hostshort, lpnetshort);
333
334 /* Check for WSAStartup */
336 {
337 /* Make sure we got a parameter */
338 if (!lpnetshort)
339 {
340 /* Fail */
342 return SOCKET_ERROR;
343 }
344
345 /* Get the Socket Context */
346 if ((Socket = WsSockGetSocket(s)))
347 {
348 /* Check which byte order to use */
351 {
352 /* No conversion needed */
353 *lpnetshort = hostshort;
354 }
355 else
356 {
357 /* Use a swap */
358 *lpnetshort = WN2H(hostshort);
359 }
360
361 /* Dereference the socket */
362 WsSockDereference(Socket);
363
364 /* Return success */
365 return ERROR_SUCCESS;
366 }
367 else
368 {
369 /* Set the error code */
371 }
372 }
373
374 /* Return with error */
376 return SOCKET_ERROR;
377}

◆ WSANtohl()

INT WSAAPI WSANtohl ( IN SOCKET  s,
IN ULONG  netlong,
OUT ULONG FAR lphostlong 
)

Definition at line 384 of file addrconv.c.

387{
389 PWSSOCKET Socket;
390 DPRINT("WSANtohl: %p, %lx, %p\n", s, netlong, lphostlong);
391
392 /* Check for WSAStartup */
394 {
395 /* Make sure we got a parameter */
396 if (!lphostlong)
397 {
398 /* Fail */
400 return SOCKET_ERROR;
401 }
402
403 /* Get the Socket Context */
404 if ((Socket = WsSockGetSocket(s)))
405 {
406 /* Check which byte order to use */
409 {
410 /* No conversion needed */
411 *lphostlong = netlong;
412 }
413 else
414 {
415 /* Use a swap */
416 *lphostlong = DN2H(netlong);
417 }
418
419 /* Dereference the socket */
420 WsSockDereference(Socket);
421
422 /* Return success */
423 return ERROR_SUCCESS;
424 }
425 else
426 {
427 /* Set the error code */
429 }
430 }
431
432 /* Return with error */
434 return SOCKET_ERROR;
435}

◆ WSANtohs()

INT WSAAPI WSANtohs ( IN SOCKET  s,
IN USHORT  netshort,
OUT USHORT FAR lphostshort 
)

Definition at line 442 of file addrconv.c.

445{
447 PWSSOCKET Socket;
448 DPRINT("WSANtohs: %p, %lx, %p\n", s, netshort, lphostshort);
449
450 /* Check for WSAStartup */
452 {
453 /* Make sure we got a parameter */
454 if (!lphostshort)
455 {
456 /* Fail */
458 return SOCKET_ERROR;
459 }
460
461 /* Get the Socket Context */
462 if ((Socket = WsSockGetSocket(s)))
463 {
464 /* Check which byte order to use */
467 {
468 /* No conversion needed */
469 *lphostshort = netshort;
470 }
471 else
472 {
473 /* Use a swap */
474 *lphostshort = WN2H(netshort);
475 }
476
477 /* Dereference the socket */
478 WsSockDereference(Socket);
479
480 /* Return success */
481 return ERROR_SUCCESS;
482 }
483 else
484 {
485 /* Set the error code */
487 }
488 }
489
490 /* Return with error */
492 return SOCKET_ERROR;
493}