home *** CD-ROM | disk | FTP | other *** search
/ CD Loisirs 18 / cd.iso / PLANETE / WS_PING / WSPI_SRC.ZIP / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1993-09-07  |  29KB  |  827 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  *
  3.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  4.  *
  5.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  6.  * of the University of California.  All rights reserved.  The
  7.  * Berkeley Software License Agreement specifies the terms and
  8.  * conditions for redistribution.
  9.  */
  10.  
  11. #ifndef _WINSOCKAPI_
  12. #define _WINSOCKAPI_
  13.  
  14. /*
  15.  * Pull in WINDOWS.H if necessary
  16.  */
  17. #ifndef _INC_WINDOWS
  18. #include <windows.h>
  19. #endif /* _INC_WINDOWS */
  20.  
  21. /*
  22.  * Basic system type definitions, taken from the BSD file sys/types.h.
  23.  */
  24. typedef unsigned char   u_char;
  25. typedef unsigned short  u_short;
  26. typedef unsigned int    u_int;
  27. typedef unsigned long   u_long;
  28.  
  29. /*
  30.  * The new type to be used in all
  31.  * instances which refer to sockets.
  32.  */
  33. typedef u_int           SOCKET;
  34.  
  35. /*
  36.  * Select uses arrays of SOCKETs.  These macros manipulate such
  37.  * arrays.  FD_SETSIZE may be defined by the user before including
  38.  * this file, but the default here should be >= 64.
  39.  *
  40.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  41.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  42.  */
  43. #ifndef FD_SETSIZE
  44. #define FD_SETSIZE      64
  45. #endif /* FD_SETSIZE */
  46.  
  47. typedef struct fd_set {
  48.         u_short fd_count;               /* how many are SET? */
  49.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  50. } fd_set;
  51.  
  52. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  53.  
  54. #define FD_CLR(fd, set) do { \
  55.     u_int __i; \
  56.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  57.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  58.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  59.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  60.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  61.                 __i++; \
  62.             } \
  63.             ((fd_set FAR *)(set))->fd_count--; \
  64.             break; \
  65.         } \
  66.     } \
  67. } while(0)
  68.  
  69. #define FD_SET(fd, set) do { \
  70.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  71.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  72. } while(0)
  73.  
  74. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  75.  
  76. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  77.  
  78. /*
  79.  * Structure used in select() call, taken from the BSD file sys/time.h.
  80.  */
  81. struct timeval {
  82.         long    tv_sec;         /* seconds */
  83.         long    tv_usec;        /* and microseconds */
  84. };
  85.  
  86. /*
  87.  * Operations on timevals.
  88.  *
  89.  * NB: timercmp does not work for >= or <=.
  90.  */
  91. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  92. #define timercmp(tvp, uvp, cmp) \
  93.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  94.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  95. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  96.  
  97. /*
  98.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  99.  *
  100.  *
  101.  * Ioctl's have the command encoded in the lower word,
  102.  * and the size of any in or out parameters in the upper
  103.  * word.  The high 2 bits of the upper word are used
  104.  * to encode the in/out status of the parameter; for now
  105.  * we restrict parameters to at most 128 bytes.
  106.  */
  107. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  108. #define IOC_VOID        0x20000000      /* no parameters */
  109. #define IOC_OUT         0x40000000      /* copy out parameters */
  110. #define IOC_IN          0x80000000      /* copy in parameters */
  111. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  112.                                         /* 0x20000000 distinguishes new &
  113.                                            old ioctl's */
  114. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  115.  
  116. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  117.  
  118. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  119.  
  120. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  121. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  122. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  123.  
  124. /* Socket I/O Controls */
  125. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  126. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  127. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  128. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  129. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  130.  
  131. /*
  132.  * Structures returned by network data base library, taken from the
  133.  * BSD file netdb.h.  All addresses are supplied in host order, and
  134.  * returned in network order (suitable for use in system calls).
  135.  */
  136.  
  137. struct  hostent {
  138.         char    FAR * h_name;           /* official name of host */
  139.         char    FAR * FAR * h_aliases;  /* alias list */
  140.         short   h_addrtype;             /* host address type */
  141.         short   h_length;               /* length of address */
  142.         char    FAR * FAR * h_addr_list; /* list of addresses */
  143. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  144. };
  145.  
  146. /*
  147.  * It is assumed here that a network number
  148.  * fits in 32 bits.
  149.  */
  150. struct  netent {
  151.         char    FAR * n_name;           /* official name of net */
  152.         char    FAR * FAR * n_aliases;  /* alias list */
  153.         short   n_addrtype;             /* net address type */
  154.         u_long  n_net;                  /* network # */
  155. };
  156.  
  157. struct  servent {
  158.         char    FAR * s_name;           /* official service name */
  159.         char    FAR * FAR * s_aliases;  /* alias list */
  160.         short   s_port;                 /* port # */
  161.         char    FAR * s_proto;          /* protocol to use */
  162. };
  163.  
  164. struct  protoent {
  165.         char    FAR * p_name;           /* official protocol name */
  166.         char    FAR * FAR * p_aliases;  /* alias list */
  167.         short   p_proto;                /* protocol # */
  168. };
  169.  
  170. /*
  171.  * Constants and structures defined by the internet system,
  172.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  173.  */
  174.  
  175. /*
  176.  * Protocols
  177.  */
  178. #define IPPROTO_IP              0               /* dummy for IP */
  179. #define IPPROTO_ICMP            1               /* control message protocol */
  180. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  181. #define IPPROTO_TCP             6               /* tcp */
  182. #define IPPROTO_PUP             12              /* pup */
  183. #define IPPROTO_UDP             17              /* user datagram protocol */
  184. #define IPPROTO_IDP             22              /* xns idp */
  185. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  186.  
  187. #define IPPROTO_RAW             255             /* raw IP packet */
  188. #define IPPROTO_MAX             256
  189.  
  190. /*
  191.  * Port/socket numbers: network standard functions
  192.  */
  193. #define IPPORT_ECHO             7
  194. #define IPPORT_DISCARD          9
  195. #define IPPORT_SYSTAT           11
  196. #define IPPORT_DAYTIME          13
  197. #define IPPORT_NETSTAT          15
  198. #define IPPORT_FTP              21
  199. #define IPPORT_TELNET           23
  200. #define IPPORT_SMTP             25
  201. #define IPPORT_TIMESERVER       37
  202. #define IPPORT_NAMESERVER       42
  203. #define IPPORT_WHOIS            43
  204. #define IPPORT_MTP              57
  205.  
  206. /*
  207.  * Port/socket numbers: host specific functions
  208.  */
  209. #define IPPORT_TFTP             69
  210. #define IPPORT_RJE              77
  211. #define IPPORT_FINGER           79
  212. #define IPPORT_TTYLINK          87
  213. #define IPPORT_SUPDUP           95
  214.  
  215. /*
  216.  * UNIX TCP sockets
  217.  */
  218. #define IPPORT_EXECSERVER       512
  219. #define IPPORT_LOGINSERVER      513
  220. #define IPPORT_CMDSERVER        514
  221. #define IPPORT_EFSSERVER        520
  222.  
  223. /*
  224.  * UNIX UDP sockets
  225.  */
  226. #define IPPORT_BIFFUDP          512
  227. #define IPPORT_WHOSERVER        513
  228. #define IPPORT_ROUTESERVER      520
  229.                                         /* 520+1 also used */
  230.  
  231. /*
  232.  * Ports < IPPORT_RESERVED are reserved for
  233.  * privileged processes (e.g. root).
  234.  */
  235. #define IPPORT_RESERVED         1024
  236.  
  237. /*
  238.  * Link numbers
  239.  */
  240. #define IMPLINK_IP              155
  241. #define IMPLINK_LOWEXPER