RtlUnicodeStringToCountedOemString() is now "pass"ed
[reactos.git] / include / sockets.h
1 /* 
2    Sockets.h
3
4    Windows Sockets specification version 1.1
5
6    Copyright (C) 1996 Free Software Foundation, Inc.
7    Thanks to Linux header files for supplying many needed definitions
8
9    Author:  Scott Christley <scottc@net-community.com>
10    Date: 1996
11    
12    This file is part of the Windows32 API Library.
13
14    This library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Library General Public
16    License as published by the Free Software Foundation; either
17    version 2 of the License, or (at your option) any later version.
18    
19    This library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Library General Public License for more details.
23
24    If you are interested in a warranty or support for this source code,
25    contact Scott Christley <scottc@net-community.com> for more information.
26    
27    You should have received a copy of the GNU Library General Public
28    License along with this library; see the file COPYING.LIB.
29    If not, write to the Free Software Foundation, 
30    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 */ 
32
33 /*-
34  * Portions Copyright (c) 1980, 1983, 1988, 1993
35  *     The Regents of the University of California.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *      This product includes software developed by the University of
48  *      California, Berkeley and its contributors.
49  * 4. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  * -
66  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
67  *
68  * Permission to use, copy, modify and distribute this software for any
69  * purpose with or without fee is hereby granted, provided that the above
70  * copyright notice and this permission notice appear in all copies, and that
71  * the name of Digital Equipment Corporation not be used in advertising or
72  * publicity pertaining to distribution of the document or software without
73  * specific, written prior permission.
74  *
75  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
76  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
77  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
78  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
79  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
80  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
81  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
82  * SOFTWARE.
83  * -
84  * --Copyright--
85  */
86
87 #ifndef _GNU_H_WINDOWS32_SOCKETS
88 #define _GNU_H_WINDOWS32_SOCKETS
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif /* __cplusplus */
93
94 /* BSD */
95 #ifndef _SYS_TYPES_H
96 typedef unsigned char   u_char;
97 typedef unsigned short  u_short;
98 typedef unsigned int    u_int;
99 typedef unsigned long   u_long;
100 #endif
101
102 /*
103   Default maximium number of sockets.
104   Define this before including Sockets.h to increase; this does not
105   mean that the underlying Windows Sockets implementation has to
106   support that many!
107   */
108 #ifndef FD_SETSIZE
109 #define FD_SETSIZE      64
110 #endif /* !FD_SETSIZE */
111
112 /*
113   These macros are critical to the usage of Windows Sockets.
114   According to the documentation, a SOCKET is no longer represented
115   by a "small non-negative integer"; so all programs MUST use these
116   macros for setting, initializing, clearing and checking the
117   fd_set structures.
118   */
119
120 typedef u_int           SOCKET;
121
122 /* fd_set may have been defined by the newlib <sys/types.h>.  */
123 #ifdef fd_set
124 #undef fd_set
125 #endif
126 typedef struct fd_set {
127         u_int   fd_count;
128         SOCKET  fd_array[FD_SETSIZE];
129 } fd_set;
130
131 /* Internal function, not documented except in winsock.h */
132 extern int PASCAL __WSAFDIsSet(SOCKET, fd_set*);
133
134 #ifdef FD_CLR
135 #undef FD_CLR
136 #endif
137 #define FD_CLR(fd, set) do { \
138     u_int __i; \
139     for (__i = 0; __i < ((fd_set*)(set))->fd_count ; __i++) { \
140         if (((fd_set*)(set))->fd_array[__i] == fd) { \
141             while (__i < ((fd_set*)(set))->fd_count-1) { \
142                 ((fd_set*)(set))->fd_array[__i] = \
143                     ((fd_set*)(set))->fd_array[__i+1]; \
144                 __i++; \
145             } \
146             ((fd_set*)(set))->fd_count--; \
147             break; \
148         } \
149     } \
150 } while(0)
151
152 #ifdef FD_SET
153 #undef FD_SET
154 #endif
155 #define FD_SET(fd, set) do { \
156     if (((fd_set*)(set))->fd_count < FD_SETSIZE) \
157         ((fd_set*)(set))->fd_array[((fd_set*)(set))->fd_count++]=(fd);\
158 } while(0)
159
160 #ifdef FD_ZERO
161 #undef FD_ZERO
162 #endif
163 #define FD_ZERO(set) (((fd_set*)(set))->fd_count=0)
164
165 #ifdef FD_ISSET
166 #undef FD_ISSET
167 #endif
168 #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set*)(set))
169
170 /*
171   time structures
172   */
173 struct timeval {
174   long tv_sec;     /* seconds */
175   long tv_usec;    /* microseconds */
176 };
177 struct timezone {
178   int tz_minuteswest; /* minutes west of Greenwich */
179   int tz_dsttime;     /* type of dst correction */
180 };
181
182 /*
183  Operations on timevals.
184
185  NB: timercmp does not work for >= or <=.
186  */
187 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
188 #define timercmp(tvp, uvp, cmp) \
189     (((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) \
190     || (tvp)->tv_sec cmp (uvp)->tv_sec)
191 #define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
192
193 /*
194   ioctl command encoding.
195   Some of this is different than what Linux has
196   */
197 #define IOCPARM_MASK    0x7f
198 #define IOC_VOID        0x20000000
199 #define IOC_OUT         0x40000000
200 #define IOC_IN          0x80000000
201 #define IOC_INOUT       (IOC_IN | IOC_OUT)
202
203 /* _IO(magic, subcode) */
204 #define _IO(c,d)        (IOC_VOID | ((c)<<8) | (d))
205 /* _IOXX(magic, subcode, arg_t) */
206 #define _IOW(c,d,t)     (IOC_IN | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
207                          ((c)<<8) | (d))
208 #define _IOR(c,d,t)     (IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
209                          ((c)<<8) | (d))
210
211 /*
212   This stuff is hard-coded on Linux
213   But winsock.h uses the macros defined above
214   */
215 #define FIONREAD    _IOR('f', 127, u_long)
216 #define FIONBIO     _IOW('f', 126, u_long)
217 #define FIOASYNC    _IOW('f', 125, u_long)
218
219 #define SIOCSHIWAT  _IOW('s',  0, u_long)
220 #define SIOCGHIWAT  _IOR('s',  1, u_long)
221 #define SIOCSLOWAT  _IOW('s',  2, u_long)
222 #define SIOCGLOWAT  _IOR('s',  3, u_long)
223 #define SIOCATMARK  _IOR('s',  7, u_long)
224
225 /*
226  Structures returned by network data base library, taken from the
227  BSD file netdb.h.  All addresses are supplied in host order, and
228  returned in network order (suitable for use in system calls).
229
230  Slight modifications for differences between Linux and winsock.h
231  */
232
233 struct  hostent {
234   char    *h_name;                /* official name of host */
235   char    **h_aliases;            /* alias list */
236   short   h_addrtype;             /* host address type */
237   short   h_length;               /* length of address */
238   char    **h_addr_list;          /* list of addresses */
239 #define h_addr  h_addr_list[0]    /* address, for backward compat */
240 };
241
242 /*
243  * Assumption here is that a network number
244  * fits in an unsigned long -- someday that won't be true!
245  */
246 struct  netent {
247   char    *n_name;      /* official name of net */
248   char    **n_aliases;  /* alias list */
249   short   n_addrtype;   /* net address type */
250   u_long  n_net;        /* network # */
251 };
252
253 struct  servent {
254   char    *s_name;      /* official service name */
255   char    **s_aliases;  /* alias list */
256   short   s_port;       /* port # */
257   char    *s_proto;     /* protocol to use */
258 };
259
260 struct  protoent {
261   char    *p_name;      /* official protocol name */
262   char    **p_aliases;  /* alias list */
263   short   p_proto;      /* protocol # */
264 };
265
266 /*
267   Standard well-known IP protocols.
268   For some reason there are differences between Linx and winsock.h
269   */
270 enum {
271   IPPROTO_IP = 0,
272   IPPROTO_ICMP = 1,
273   IPPROTO_GGP = 2,               /* huh? */
274   IPPROTO_IPIP = 4,
275   IPPROTO_TCP = 6,               /* Transmission Control Protocol */
276   IPPROTO_EGP = 8,
277   IPPROTO_PUP = 12,
278   IPPROTO_UDP = 17,              /* User Datagram Protocol */
279   IPPROTO_IDP = 22,
280   IPPROTO_ND = 77,               /* This one was in winsock.h */
281
282   IPPROTO_RAW = 255,             /* raw IP packets */
283   IPPROTO_MAX
284 };
285
286 /* Standard well-known ports */
287 enum {
288   IPPORT_ECHO = 7,
289   IPPORT_DISCARD = 9,
290   IPPORT_SYSTAT = 11,
291   IPPORT_DAYTIME = 13,
292   IPPORT_NETSTAT = 15,
293   IPPORT_FTP = 21,
294   IPPORT_TELNET = 23,
295   IPPORT_SMTP = 25,
296   IPPORT_TIMESERVER = 37,
297   IPPORT_NAMESERVER = 42,
298   IPPORT_WHOIS = 43,
299   IPPORT_MTP = 57,
300
301   IPPORT_TFTP = 69,
302   IPPORT_RJE = 77,
303   IPPORT_FINGER = 79,
304   IPPORT_TTYLINK = 87,
305   IPPORT_SUPDUP = 95,
306
307   IPPORT_EXECSERVER = 512,
308   IPPORT_LOGINSERVER = 513,
309   IPPORT_CMDSERVER = 514,
310   IPPORT_EFSSERVER = 520,
311
312   /* UDP ports. */
313   IPPORT_BIFFUDP = 512,
314   IPPORT_WHOSERVER = 513,
315   IPPORT_ROUTESERVER = 520,
316
317   /* Ports less than this value are reservered for privileged processes. */
318   IPPORT_RESERVED = 1024,
319
320   /* Ports greater than this value are reserved for 
321      (non-privileged) processes */
322   IPPORT_USERRESERVED = 5000
323 };
324
325 /* Link numbers. */
326 #define IMPLINK_IP              155
327 #define IMPLINK_LOWEXPER        156
328 #define IMPLINK_HIGHEXPER       158
329
330 /* Linux uses a simple unsigned long int, but winsock.h ... */
331 struct in_addr {
332         union {
333                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
334                 struct { u_short s_w1,s_w2; } S_un_w;
335                 u_long S_addr;
336         } S_un;
337 #define s_addr  S_un.S_addr
338 #define s_host  S_un.S_un_b.s_b2
339 #define s_net   S_un.S_un_b.s_b1
340 #define s_imp   S_un.S_un_w.s_w2
341 #define s_impno S_un.S_un_b.s_b4
342 #define s_lh    S_un.S_un_b.s_b3
343 };
344
345 /*
346  Definitions of bits in internet address integers.
347  On subnets, host and network parts are found according
348  to the subnet mask, not these masks.
349  */
350 #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
351 #define IN_CLASSA_NET           0xff000000
352 #define IN_CLASSA_NSHIFT        24
353 #define IN_CLASSA_HOST          0x00ffffff
354 #define IN_CLASSA_MAX           128
355
356 #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
357 #define IN_CLASSB_NET           0xffff0000
358 #define IN_CLASSB_NSHIFT        16
359 #define IN_CLASSB_HOST          0x0000ffff
360 #define IN_CLASSB_MAX           65536
361
362 #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
363 #define IN_CLASSC_NET           0xffffff00
364 #define IN_CLASSC_NSHIFT        8
365 #define IN_CLASSC_HOST          0x000000ff
366
367 #define INADDR_ANY              (u_long)0x00000000
368 #define INADDR_LOOPBACK         0x7f000001
369 #define INADDR_BROADCAST        (u_long)0xffffffff    
370 #define INADDR_NONE             0xffffffff
371
372 /*
373  Structure describing an Internet (IP) socket address.
374  */
375 struct sockaddr_in {
376   short   sin_family;
377   u_short sin_port;
378   struct  in_addr sin_addr;
379   char    sin_zero[8];
380 };
381
382 /*
383   EVERYTHING FROM THIS POINT IS MAINLY SPECIFIC TO Win32
384
385   Structure which holds the detail for the underlying Window Sockets
386   implementation.  Set when WSAStartup() is called.
387   */
388 #define WSADESCRIPTION_LEN      256
389 #define WSASYS_STATUS_LEN       128
390
391 typedef struct WSAData {
392   WORD wVersion;
393   WORD wHighVersion;
394   char szDescription[WSADESCRIPTION_LEN+1];
395   char szSystemStatus[WSASYS_STATUS_LEN+1];
396   unsigned short iMaxSockets;
397   unsigned short iMaxUdpDg;
398   char *lpVendorInfo;
399 } WSADATA, *LPWSADATA;
400
401 #define IP_OPTIONS          1
402 #define IP_MULTICAST_IF     2
403 #define IP_MULTICAST_TTL    3
404 #define IP_MULTICAST_LOOP   4
405 #define IP_ADD_MEMBERSHIP   5
406 #define IP_DROP_MEMBERSHIP  6
407
408 #define IP_DEFAULT_MULTICAST_TTL   1
409 #define IP_DEFAULT_MULTICAST_LOOP  1
410 #define IP_MAX_MEMBERSHIPS         20
411
412 struct ip_mreq {
413   struct in_addr imr_multiaddr;
414   struct in_addr imr_interface;
415 };
416
417 /*
418  * Definitions related to sockets: types, address families, options,
419  * taken from the BSD file sys/socket.h.
420  */
421
422 /*
423  * This is used instead of -1, since the
424  * SOCKET type is unsigned.
425  */
426 #define INVALID_SOCKET  (SOCKET)(~0)
427 #define SOCKET_ERROR            (-1)
428
429 /* Socket types. */
430 #define SOCK_STREAM     1
431 #define SOCK_DGRAM      2
432 #define SOCK_RAW        3
433 #define SOCK_RDM        4 
434 #define SOCK_SEQPACKET  5
435
436 /* For setsockoptions(2) */
437 #define SO_DEBUG        0x0001
438 #define SO_ACCEPTCONN   0x0002
439 #define SO_REUSEADDR    0x0004
440 #define SO_KEEPALIVE    0x0008
441 #define SO_DONTROUTE    0x0010
442 #define SO_BROADCAST    0x0020
443 #define SO_USELOOPBACK  0x0040
444 #define SO_LINGER       0x0080
445 #define SO_OOBINLINE    0x0100
446
447 #define SO_DONTLINGER   (u_int)(~SO_LINGER)
448
449 /*
450  * Additional options.
451  */
452 #define SO_SNDBUF       0x1001          /* send buffer size */
453 #define SO_RCVBUF       0x1002          /* receive buffer size */
454 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
455 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
456 #define SO_SNDTIMEO     0x1005          /* send timeout */
457 #define SO_RCVTIMEO     0x1006          /* receive timeout */
458 #define SO_ERROR        0x1007          /* get error status and clear */
459 #define SO_TYPE         0x1008          /* get socket type */
460
461 /*
462  * Options for connect and disconnect data and options.  Used only by
463  * non-TCP/IP transports such as DECNet, OSI TP4, etc.
464  */
465 #define SO_CONNDATA     0x7000
466 #define SO_CONNOPT      0x7001
467 #define SO_DISCDATA     0x7002
468 #define SO_DISCOPT      0x7003
469 #define SO_CONNDATALEN  0x7004
470 #define SO_CONNOPTLEN   0x7005
471 #define SO_DISCDATALEN  0x7006
472 #define SO_DISCOPTLEN   0x7007
473
474 /*
475  * Option for opening sockets for synchronous access.
476  */
477 #define SO_OPENTYPE     0x7008
478
479 #define SO_SYNCHRONOUS_ALERT    0x10
480 #define SO_SYNCHRONOUS_NONALERT 0x20
481
482 /*
483  * Other NT-specific options.
484  */
485 #define SO_MAXDG        0x7009
486 #define SO_MAXPATHDG    0x700A
487
488 /*
489  * TCP options.
490  */
491 #define TCP_NODELAY     0x0001
492 #define TCP_BSDURGENT   0x7000
493
494 /*
495  * Address families.
496  */
497 #define AF_UNSPEC       0               /* unspecified */
498 #define AF_UNIX         1               /* local to host (pipes, portals) */
499 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
500 #define AF_IMPLINK      3               /* arpanet imp addresses */
501 #define AF_PUP          4               /* pup protocols: e.g. BSP */
502 #define AF_CHAOS        5               /* mit CHAOS protocols */
503 #define AF_IPX          6               /* IPX and SPX */
504 #define AF_NS           6               /* XEROX NS protocols */
505 #define AF_ISO          7               /* ISO protocols */
506 #define AF_OSI          AF_ISO          /* OSI is ISO */
507 #define AF_ECMA         8               /* european computer manufacturers */
508 #define AF_DATAKIT      9               /* datakit protocols */
509 #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
510 #define AF_SNA          11              /* IBM SNA */
511 #define AF_DECnet       12              /* DECnet */
512 #define AF_DLI          13              /* Direct data link interface */
513 #define AF_LAT          14              /* LAT */
514 #define AF_HYLINK       15              /* NSC Hyperchannel */
515 #define AF_APPLETALK    16              /* AppleTalk */
516 #define AF_NETBIOS      17              /* NetBios-style addresses */
517
518 #define AF_MAX          18
519
520 /*
521  * Structure used by kernel to store most
522  * addresses.
523  */
524 struct sockaddr {
525   u_short sa_family;
526   char    sa_data[14];
527 };
528
529 /*
530  * Structure used by kernel to pass protocol
531  * information in raw sockets.
532  */
533 struct sockproto {
534   u_short sp_family;
535   u_short sp_protocol;
536 };
537
538 /*
539  * Protocol families, same as address families for now.
540  */
541 #define PF_UNSPEC       AF_UNSPEC
542 #define PF_UNIX         AF_UNIX
543 #define PF_INET         AF_INET
544 #define PF_IMPLINK      AF_IMPLINK
545 #define PF_PUP          AF_PUP
546 #define PF_CHAOS        AF_CHAOS
547 #define PF_NS           AF_NS
548 #define PF_IPX          AF_IPX
549 #define PF_ISO          AF_ISO
550 #define PF_OSI          AF_OSI
551 #define PF_ECMA         AF_ECMA
552 #define PF_DATAKIT      AF_DATAKIT
553 #define PF_CCITT        AF_CCITT
554 #define PF_SNA          AF_SNA
555 #define PF_DECnet       AF_DECnet
556 #define PF_DLI          AF_DLI
557 #define PF_LAT          AF_LAT
558 #define PF_HYLINK       AF_HYLINK
559 #define PF_APPLETALK    AF_APPLETALK
560
561 #define PF_MAX          AF_MAX
562
563 /*
564  * Structure used for manipulating linger option.
565  */
566 struct  linger {
567   u_short l_onoff;
568   u_short l_linger;
569 };
570
571 /*
572  * Level number for (get/set)sockopt() to apply to socket itself.
573  */
574 #define SOL_SOCKET      0xffff          /* options for socket level */
575
576 /*
577  * Maximum queue length specifiable by listen.
578  */
579 #define SOMAXCONN       5
580
581 #define MSG_OOB         0x1             /* process out-of-band data */
582 #define MSG_PEEK        0x2             /* peek at incoming message */
583 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
584
585 #define MSG_MAXIOVLEN   16
586
587 #define MSG_PARTIAL     0x8000          /* partial send or recv for message xport */
588
589 /*
590  * Define constant based on rfc883, used by gethostbyxxxx() calls.
591  */
592 #define MAXGETHOSTSTRUCT        1024
593 #ifndef MAXHOSTNAMELEN
594 #define MAXHOSTNAMELEN          MAXGETHOSTSTRUCT
595 #endif
596
597 /*
598  * Define flags to be used with the WSAAsyncSelect() call.
599  */
600 #define FD_READ         0x01
601 #define FD_WRITE        0x02
602 #define FD_OOB          0x04
603 #define FD_ACCEPT       0x08
604 #define FD_CONNECT      0x10
605 #define FD_CLOSE        0x20
606
607 /*
608  * All Windows Sockets error constants are biased by WSABASEERR from
609  * the "normal"
610  */
611 #define WSABASEERR              10000
612 /*
613  * Windows Sockets definitions of regular Microsoft C error constants
614  */
615 #define WSAEINTR                (WSABASEERR+4)
616 #define WSAEBADF                (WSABASEERR+9)
617 #define WSAEACCES               (WSABASEERR+13)
618 #define WSAEFAULT               (WSABASEERR+14)
619 #define WSAEINVAL               (WSABASEERR+22)
620 #define WSAEMFILE               (WSABASEERR+24)
621
622 /*
623  * Windows Sockets definitions of regular Berkeley error constants
624  */
625 #define WSAEWOULDBLOCK          (WSABASEERR+35)
626 #define WSAEINPROGRESS          (WSABASEERR+36)
627 #define WSAEALREADY             (WSABASEERR+37)
628 #define WSAENOTSOCK             (WSABASEERR+38)
629 #define WSAEDESTADDRREQ         (WSABASEERR+39)
630 #define WSAEMSGSIZE             (WSABASEERR+40)
631 #define WSAEPROTOTYPE           (WSABASEERR+41)
632 #define WSAENOPROTOOPT          (WSABASEERR+42)
633 #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
634 #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
635 #define WSAEOPNOTSUPP           (WSABASEERR+45)
636 #define WSAEPFNOSUPPORT         (WSABASEERR+46)
637 #define WSAEAFNOSUPPORT         (WSABASEERR+47)
638 #define WSAEADDRINUSE           (WSABASEERR+48)
639 #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
640 #define WSAENETDOWN             (WSABASEERR+50)
641 #define WSAENETUNREACH          (WSABASEERR+51)
642 #define WSAENETRESET            (WSABASEERR+52)
643 #define WSAECONNABORTED         (WSABASEERR+53)
644 #define WSAECONNRESET           (WSABASEERR+54)
645 #define WSAENOBUFS              (WSABASEERR+55)
646 #define WSAEISCONN              (WSABASEERR+56)
647 #define WSAENOTCONN             (WSABASEERR+57)
648 #define WSAESHUTDOWN            (WSABASEERR+58)
649 #define WSAETOOMANYREFS         (WSABASEERR+59)
650 #define WSAETIMEDOUT            (WSABASEERR+60)
651 #define WSAECONNREFUSED         (WSABASEERR+61)
652 #define WSAELOOP                (WSABASEERR+62)
653 #define WSAENAMETOOLONG         (WSABASEERR+63)
654 #define WSAEHOSTDOWN            (WSABASEERR+64)
655 #define WSAEHOSTUNREACH         (WSABASEERR+65)
656 #define WSAENOTEMPTY            (WSABASEERR+66)
657 #define WSAEPROCLIM             (WSABASEERR+67)
658 #define WSAEUSERS               (WSABASEERR+68)
659 #define WSAEDQUOT               (WSABASEERR+69)
660 #define WSAESTALE               (WSABASEERR+70)
661 #define WSAEREMOTE              (WSABASEERR+71)
662
663 #define WSAEDISCON              (WSABASEERR+101)
664
665 /*
666  * Extended Windows Sockets error constant definitions
667  */
668 #define WSASYSNOTREADY          (WSABASEERR+91)
669 #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
670 #define WSANOTINITIALISED       (WSABASEERR+93)
671
672 /*
673  * Error return codes from gethostbyname() and gethostbyaddr()
674  * (when using the resolver). Note that these errors are
675  * retrieved via WSAGetLastError() and must therefore follow
676  * the rules for avoiding clashes with error numbers from
677  * specific implementations or language run-time systems.
678  * For this reason the codes are based at WSABASEERR+1001.
679  * Note also that [WSA]NO_ADDRESS is defined only for
680  * compatibility purposes.
681  */
682
683 #define h_errno         WSAGetLastError()
684
685 /* Authoritative Answer: Host not found */
686 #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
687 #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
688
689 /* Non-Authoritative: Host not found, or SERVERFAIL */
690 #define WSATRY_AGAIN            (WSABASEERR+1002)
691 #define TRY_AGAIN               WSATRY_AGAIN
692
693 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
694 #define WSANO_RECOVERY          (WSABASEERR+1003)
695 #define NO_RECOVERY             WSANO_RECOVERY
696
697 /* Valid name, no data record of requested type */
698 #define WSANO_DATA              (WSABASEERR+1004)
699 #define NO_DATA                 WSANO_DATA
700
701 /* no address, look for MX record */
702 #define WSANO_ADDRESS           WSANO_DATA
703 #define NO_ADDRESS              WSANO_ADDRESS
704
705 /*
706  * Windows Sockets errors redefined as regular Berkeley error constants.
707  * These are commented out in Windows NT to avoid conflicts with errno.h.
708  * Use the WSA constants instead.
709  */
710 #if 0
711 #define EWOULDBLOCK             WSAEWOULDBLOCK
712 #define EINPROGRESS             WSAEINPROGRESS
713 #define EALREADY                WSAEALREADY
714 #define ENOTSOCK                WSAENOTSOCK
715 #define EDESTADDRREQ            WSAEDESTADDRREQ
716 #define EMSGSIZE                WSAEMSGSIZE
717 #define EPROTOTYPE              WSAEPROTOTYPE
718 #define ENOPROTOOPT             WSAENOPROTOOPT
719 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
720 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
721 #define EOPNOTSUPP              WSAEOPNOTSUPP
722 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
723 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
724 #define EADDRINUSE              WSAEADDRINUSE
725 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
726 #define ENETDOWN                WSAENETDOWN
727 #define ENETUNREACH             WSAENETUNREACH
728 #define ENETRESET               WSAENETRESET
729 #define ECONNABORTED            WSAECONNABORTED
730 #define ECONNRESET              WSAECONNRESET
731 #define ENOBUFS                 WSAENOBUFS
732 #define EISCONN                 WSAEISCONN
733 #define ENOTCONN                WSAENOTCONN
734 #define ESHUTDOWN               WSAESHUTDOWN
735 #define ETOOMANYREFS            WSAETOOMANYREFS
736 #define ETIMEDOUT               WSAETIMEDOUT
737 #define ECONNREFUSED            WSAECONNREFUSED
738 #define ELOOP                   WSAELOOP
739 #define ENAMETOOLONG            WSAENAMETOOLONG
740 #define EHOSTDOWN               WSAEHOSTDOWN
741 #define EHOSTUNREACH            WSAEHOSTUNREACH
742 #define ENOTEMPTY               WSAENOTEMPTY
743 #define EPROCLIM                WSAEPROCLIM
744 #define EUSERS                  WSAEUSERS
745 #define EDQUOT                  WSAEDQUOT
746 #define ESTALE                  WSAESTALE
747 #define EREMOTE                 WSAEREMOTE
748 #endif
749
750 /* Socket function prototypes */
751
752 SOCKET PASCAL accept (SOCKET s, struct sockaddr *addr,
753                           int *addrlen);
754
755 int PASCAL bind (SOCKET s, const struct sockaddr *addr, int namelen);
756
757 int PASCAL closesocket (SOCKET s);
758
759 int PASCAL connect (SOCKET s, const struct sockaddr *name, int namelen);
760
761 int PASCAL ioctlsocket (SOCKET s, long cmd, u_long *argp);
762
763 int PASCAL getpeername (SOCKET s, struct sockaddr *name,
764                             int * namelen);
765
766 int PASCAL getsockname (SOCKET s, struct sockaddr *name,
767                             int * namelen);
768
769 int PASCAL getsockopt (SOCKET s, int level, int optname,
770                            char * optval, int *optlen);
771
772 u_long PASCAL htonl (u_long hostlong);
773
774 /* For some reason WSOCK.LIB has htons defined as a 4 byte paramter?! */
775 #ifdef _WIN32
776 u_short PASCAL htons (u_long hostshort);
777 #else
778 u_short PASCAL htons (u_short hostshort);
779 #endif /* _WIN32 */
780
781 unsigned long PASCAL inet_addr (const char * cp);
782
783 char * PASCAL inet_ntoa (struct in_addr in);
784
785 int PASCAL listen (SOCKET s, int backlog);
786
787 u_long PASCAL ntohl (u_long netlong);
788
789 /* For some reason WSOCK.LIB has ntohs defined as a 4 byte paramter?! */
790 #ifdef _WIN32
791 u_short PASCAL ntohs (u_long netshort);
792 #else
793 u_short PASCAL ntohs (u_short netshort);
794 #endif /* _WIN32 */
795
796 int PASCAL recv (SOCKET s, char * buf, int len, int flags);
797
798 int PASCAL recvfrom (SOCKET s, char * buf, int len, int flags,
799                          struct sockaddr *from, int * fromlen);
800
801 int PASCAL select (int nfds, fd_set *readfds, fd_set *writefds,
802                        fd_set *exceptfds, const struct timeval *timeout);
803
804 int PASCAL send (SOCKET s, const char * buf, int len, int flags);
805
806 int PASCAL sendto (SOCKET s, const char * buf, int len, int flags,
807                        const struct sockaddr *to, int tolen);
808
809 int PASCAL setsockopt (SOCKET s, int level, int optname,
810                            const char * optval, int optlen);
811
812 int PASCAL shutdown (SOCKET s, int how);
813
814 SOCKET PASCAL socket (int af, int type, int protocol);
815
816 /* Database function prototypes */
817
818 struct hostent * PASCAL gethostbyaddr(const char * addr,
819                                               int len, int type);
820
821 struct hostent * PASCAL gethostbyname(const char * name);
822
823 int PASCAL gethostname (char * name, int namelen);
824
825 struct servent * PASCAL getservbyport(int port, const char * proto);
826
827 struct servent * PASCAL getservbyname(const char * name,
828                                               const char * proto);
829
830 struct protoent * PASCAL getprotobynumber(int proto);
831
832 struct protoent * PASCAL getprotobyname(const char * name);
833
834 /* Microsoft Windows Extension function prototypes */
835
836 /* int PASCAL WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); */
837 int PASCAL WSAStartup(int wVersionRequired, LPWSADATA lpWSAData);
838
839
840 int PASCAL WSACleanup(void);
841
842 void PASCAL WSASetLastError(int iError);
843
844 int PASCAL WSAGetLastError(void);
845
846 WINBOOL PASCAL WSAIsBlocking(void);
847
848 int PASCAL WSAUnhookBlockingHook(void);
849
850 FARPROC PASCAL WSASetBlockingHook(FARPROC lpBlockFunc);
851
852 int PASCAL WSACancelBlockingCall(void);
853
854 HANDLE PASCAL WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
855                                         const char * name, 
856                                         const char * proto,
857                                         char * buf, int buflen);
858
859 HANDLE PASCAL WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
860                                         const char * proto, char * buf,
861                                         int buflen);
862
863 HANDLE PASCAL WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
864                                          const char * name, char * buf,
865                                          int buflen);
866
867 HANDLE PASCAL WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
868                                            int number, char * buf,
869                                            int buflen);
870
871 HANDLE PASCAL WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
872                                         const char * name, char * buf,
873                                         int buflen);
874
875 HANDLE PASCAL WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
876                                         const char * addr, int len, int type,
877                                         char * buf, int buflen);
878
879 int PASCAL WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
880
881 int PASCAL WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
882                                long lEvent);
883
884 int PASCAL WSARecvEx (SOCKET s, char * buf, int len, int *flags);
885
886 /* Microsoft Windows Extended data types */
887 typedef struct sockaddr SOCKADDR;
888 typedef struct sockaddr *PSOCKADDR;
889 typedef struct sockaddr *LPSOCKADDR;
890
891 typedef struct sockaddr_in SOCKADDR_IN;
892 typedef struct sockaddr_in *PSOCKADDR_IN;
893 typedef struct sockaddr_in *LPSOCKADDR_IN;
894
895 typedef struct linger LINGER;
896 typedef struct linger *PLINGER;
897 typedef struct linger *LPLINGER;
898
899 typedef struct in_addr IN_ADDR;
900 typedef struct in_addr *PIN_ADDR;
901 typedef struct in_addr *LPIN_ADDR;
902
903 typedef struct fd_set FD_SET;
904 typedef struct fd_set *PFD_SET;
905 typedef struct fd_set *LPFD_SET;
906
907 typedef struct hostent HOSTENT;
908 typedef struct hostent *PHOSTENT;
909 typedef struct hostent *LPHOSTENT;
910
911 typedef struct servent SERVENT;
912 typedef struct servent *PSERVENT;
913 typedef struct servent *LPSERVENT;
914
915 typedef struct protoent PROTOENT;
916 typedef struct protoent *PPROTOENT;
917 typedef struct protoent *LPPROTOENT;
918
919 typedef struct timeval TIMEVAL;
920 typedef struct timeval *PTIMEVAL;
921 typedef struct timeval *LPTIMEVAL;
922
923 /*
924  * Windows message parameter composition and decomposition
925  * macros.
926  *
927  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
928  * when constructing the response to a WSAAsyncGetXByY() routine.
929  */
930 #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
931 /*
932  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
933  * when constructing the response to WSAAsyncSelect().
934  */
935 #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
936 /*
937  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
938  * to extract the buffer length from the lParam in the response
939  * to a WSAGetXByY().
940  */
941 #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
942 /*
943  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
944  * to extract the error code from the lParam in the response
945  * to a WSAGetXByY().
946  */
947 #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
948 /*
949  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
950  * to extract the event code from the lParam in the response
951  * to a WSAAsyncSelect().
952  */
953 #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
954 /*
955  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
956  * to extract the error code from the lParam in the response
957  * to a WSAAsyncSelect().
958  */
959 #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
960
961 #ifdef __cplusplus
962 }
963 #endif /* __cplusplus */
964
965 #endif /* _GNU_H_WINDOWS32_SOCKETS */