| 1 | /* $Id: winsock.h,v 1.2 1999-10-16 11:03:19 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* WINSOCK.H--definitions to be used with the WINSOCK.DLL | 
|---|
| 4 | * | 
|---|
| 5 | * This header file corresponds to version 1.1 of the Windows Sockets | 
|---|
| 6 | * specification. | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef _WINSOCKAPI_ | 
|---|
| 10 | #define _WINSOCKAPI_ | 
|---|
| 11 |  | 
|---|
| 12 | #include <netinet/in.h> | 
|---|
| 13 | #include <arpa/inet.h> | 
|---|
| 14 | #include <sys/types.h> | 
|---|
| 15 | #include <sys/time.h> | 
|---|
| 16 | #include <fcntl.h> | 
|---|
| 17 | #include <netdb.h> | 
|---|
| 18 | #include <sys/socket.h> | 
|---|
| 19 |  | 
|---|
| 20 | #ifdef HAVE_IPX_GNU | 
|---|
| 21 | # include <netipx/ipx.h> | 
|---|
| 22 | # define HAVE_IPX | 
|---|
| 23 | #endif | 
|---|
| 24 |  | 
|---|
| 25 | #ifdef HAVE_IPX_LINUX | 
|---|
| 26 | # include <asm/types.h> | 
|---|
| 27 | # include <linux/ipx.h> | 
|---|
| 28 | # define HAVE_IPX | 
|---|
| 29 | #endif | 
|---|
| 30 |  | 
|---|
| 31 | #include "windef.h" | 
|---|
| 32 | #include "task.h" | 
|---|
| 33 |  | 
|---|
| 34 | #include "pshpack1.h" | 
|---|
| 35 |  | 
|---|
| 36 | /* Win16 socket-related types */ | 
|---|
| 37 |  | 
|---|
| 38 | typedef UINT16          SOCKET16; | 
|---|
| 39 | typedef UINT            SOCKET; | 
|---|
| 40 |  | 
|---|
| 41 | typedef struct ws_hostent | 
|---|
| 42 | { | 
|---|
| 43 | SEGPTR  h_name;         /* official name of host */ | 
|---|
| 44 | SEGPTR  h_aliases;      /* alias list */ | 
|---|
| 45 | INT16   h_addrtype;     /* host address type */ | 
|---|
| 46 | INT16   h_length;       /* length of address */ | 
|---|
| 47 | SEGPTR  h_addr_list;    /* list of addresses from name server */ | 
|---|
| 48 | } _ws_hostent; | 
|---|
| 49 |  | 
|---|
| 50 | typedef struct ws_protoent | 
|---|
| 51 | { | 
|---|
| 52 | SEGPTR  p_name;         /* official protocol name */ | 
|---|
| 53 | SEGPTR  p_aliases;      /* alias list */ | 
|---|
| 54 | INT16   p_proto;        /* protocol # */ | 
|---|
| 55 | } _ws_protoent; | 
|---|
| 56 |  | 
|---|
| 57 | typedef struct ws_servent | 
|---|
| 58 | { | 
|---|
| 59 | SEGPTR  s_name;         /* official service name */ | 
|---|
| 60 | SEGPTR  s_aliases;      /* alias list */ | 
|---|
| 61 | INT16   s_port;         /* port # */ | 
|---|
| 62 | SEGPTR  s_proto;        /* protocol to use */ | 
|---|
| 63 | } _ws_servent; | 
|---|
| 64 |  | 
|---|
| 65 | typedef struct ws_netent | 
|---|
| 66 | { | 
|---|
| 67 | SEGPTR  n_name;         /* official name of net */ | 
|---|
| 68 | SEGPTR  n_aliases;      /* alias list */ | 
|---|
| 69 | INT16   n_addrtype;     /* net address type */ | 
|---|
| 70 | INT   n_net;          /* network # */ | 
|---|
| 71 | } _ws_netent; | 
|---|
| 72 |  | 
|---|
| 73 | typedef struct sockaddr         ws_sockaddr; | 
|---|
| 74 |  | 
|---|
| 75 | typedef struct | 
|---|
| 76 | { | 
|---|
| 77 | UINT16    fd_count;               /* how many are SET? */ | 
|---|
| 78 | SOCKET16  fd_array[FD_SETSIZE];   /* an array of SOCKETs */ | 
|---|
| 79 | } ws_fd_set16; | 
|---|
| 80 |  | 
|---|
| 81 | typedef struct | 
|---|
| 82 | { | 
|---|
| 83 | UINT    fd_count;               /* how many are SET? */ | 
|---|
| 84 | SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */ | 
|---|
| 85 | } ws_fd_set32; | 
|---|
| 86 |  | 
|---|
| 87 | /* ws_fd_set operations */ | 
|---|
| 88 |  | 
|---|
| 89 | INT16 WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set16 * ); | 
|---|
| 90 | INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * ); | 
|---|
| 91 |  | 
|---|
| 92 | #define __WS_FD_CLR(fd, set, cast) do { \ | 
|---|
| 93 | UINT16 __i; \ | 
|---|
| 94 | for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \ | 
|---|
| 95 | { \ | 
|---|
| 96 | if (((cast*)(set))->fd_array[__i] == fd) \ | 
|---|
| 97 | { \ | 
|---|
| 98 | while (__i < ((cast*)(set))->fd_count-1) \ | 
|---|
| 99 | { \ | 
|---|
| 100 | ((cast*)(set))->fd_array[__i] = \ | 
|---|
| 101 | ((cast*)(set))->fd_array[__i+1]; \ | 
|---|
| 102 | __i++; \ | 
|---|
| 103 | } \ | 
|---|
| 104 | ((cast*)(set))->fd_count--; \ | 
|---|
| 105 | break; \ | 
|---|
| 106 | } \ | 
|---|
| 107 | } \ | 
|---|
| 108 | } while(0) | 
|---|
| 109 | #define WS_FD_CLR16(fd, set)    __WS_FD_CLR((fd),(set), ws_fd_set16) | 
|---|
| 110 | #define WS_FD_CLR(fd, set)      __WS_FD_CLR((fd),(set), ws_fd_set32) | 
|---|
| 111 |  | 
|---|
| 112 | #define __WS_FD_SET(fd, set, cast) do { \ | 
|---|
| 113 | if (((cast*)(set))->fd_count < FD_SETSIZE) \ | 
|---|
| 114 | ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\ | 
|---|
| 115 | } while(0) | 
|---|
| 116 | #define WS_FD_SET16(fd, set)    __WS_FD_SET((fd),(set), ws_fd_set16) | 
|---|
| 117 | #define WS_FD_SET(fd, set)    __WS_FD_SET((fd),(set), ws_fd_set32) | 
|---|
| 118 |  | 
|---|
| 119 | #define WS_FD_ZERO16(set) (((ws_fd_set16*)(set))->fd_count=0) | 
|---|
| 120 | #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0) | 
|---|
| 121 |  | 
|---|
| 122 | #define WS_FD_ISSET16(fd, set) __WSAFDIsSet16((SOCKET16)(fd), (ws_fd_set16*)(set)) | 
|---|
| 123 | #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set)) | 
|---|
| 124 |  | 
|---|
| 125 | /* | 
|---|
| 126 | * Internet address (old style... should be updated) | 
|---|
| 127 | */ | 
|---|
| 128 |  | 
|---|
| 129 | struct ws_in_addr | 
|---|
| 130 | { | 
|---|
| 131 | union { | 
|---|
| 132 | struct { BYTE   s_b1,s_b2,s_b3,s_b4; } S_un_b; | 
|---|
| 133 | struct { UINT16 s_w1,s_w2; } S_un_w; | 
|---|
| 134 | UINT S_addr; | 
|---|
| 135 | } S_un; | 
|---|
| 136 | #define ws_addr  S_un.S_addr            /* can be used for most tcp & ip code */ | 
|---|
| 137 | #define ws_host  S_un.S_un_b.s_b2       /* host on imp */ | 
|---|
| 138 | #define ws_net   S_un.S_un_b.s_b1       /* network */ | 
|---|
| 139 | #define ws_imp   S_un.S_un_w.s_w2       /* imp */ | 
|---|
| 140 | #define ws_impno S_un.S_un_b.s_b4       /* imp # */ | 
|---|
| 141 | #define ws_lh    S_un.S_un_b.s_b3       /* logical host */ | 
|---|
| 142 | }; | 
|---|
| 143 |  | 
|---|
| 144 | struct ws_sockaddr_in | 
|---|
| 145 | { | 
|---|
| 146 | INT16           sin_family; | 
|---|
| 147 | UINT16          sin_port; | 
|---|
| 148 | struct ws_in_addr sin_addr; | 
|---|
| 149 | BYTE            sin_zero[8]; | 
|---|
| 150 | }; | 
|---|
| 151 |  | 
|---|
| 152 | #define WSADESCRIPTION_LEN      256 | 
|---|
| 153 | #define WSASYS_STATUS_LEN       128 | 
|---|
| 154 |  | 
|---|
| 155 | typedef struct WSAData { | 
|---|
| 156 | WORD                    wVersion; | 
|---|
| 157 | WORD                    wHighVersion; | 
|---|
| 158 | char                    szDescription[WSADESCRIPTION_LEN+1]; | 
|---|
| 159 | char                    szSystemStatus[WSASYS_STATUS_LEN+1]; | 
|---|
| 160 | UINT16                  iMaxSockets; | 
|---|
| 161 | UINT16                  iMaxUdpDg; | 
|---|
| 162 | SEGPTR                  lpVendorInfo; | 
|---|
| 163 | } WSADATA, *LPWSADATA; | 
|---|
| 164 |  | 
|---|
| 165 | #include "poppack.h" | 
|---|
| 166 |  | 
|---|
| 167 | /* ----------------------------------- no Win16 structure defs beyond this line! */ | 
|---|
| 168 |  | 
|---|
| 169 | /* | 
|---|
| 170 | * This is used instead of -1, since the | 
|---|
| 171 | * SOCKET type is unsigned. | 
|---|
| 172 | */ | 
|---|
| 173 | #define INVALID_SOCKET16           (~0) | 
|---|
| 174 | #define INVALID_SOCKET     (~0) | 
|---|
| 175 | #define SOCKET_ERROR               (-1) | 
|---|
| 176 |  | 
|---|
| 177 |  | 
|---|
| 178 | /* | 
|---|
| 179 | * Types | 
|---|
| 180 | */ | 
|---|
| 181 | #define WS_SOCK_STREAM     1               /* stream socket */ | 
|---|
| 182 | #define WS_SOCK_DGRAM      2               /* datagram socket */ | 
|---|
| 183 | #define WS_SOCK_RAW        3               /* raw-protocol interface */ | 
|---|
| 184 | #define WS_SOCK_RDM        4               /* reliably-delivered message */ | 
|---|
| 185 | #define WS_SOCK_SEQPACKET  5               /* sequenced packet stream */ | 
|---|
| 186 |  | 
|---|
| 187 | #define WS_SOL_SOCKET           0xffff | 
|---|
| 188 | #define WS_IPPROTO_TCP          6 | 
|---|
| 189 |  | 
|---|
| 190 | /* | 
|---|
| 191 | * Option flags per-socket. | 
|---|
| 192 | */ | 
|---|
| 193 | #define WS_SO_DEBUG        0x0001          /* turn on debugging info recording */ | 
|---|
| 194 | #define WS_SO_ACCEPTCONN   0x0002          /* socket has had listen() */ | 
|---|
| 195 | #define WS_SO_REUSEADDR    0x0004          /* allow local address reuse */ | 
|---|
| 196 | #define WS_SO_KEEPALIVE    0x0008          /* keep connections alive */ | 
|---|
| 197 | #define WS_SO_DONTROUTE    0x0010          /* just use interface addresses */ | 
|---|
| 198 | #define WS_SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */ | 
|---|
| 199 | #define WS_SO_USELOOPBACK  0x0040          /* bypass hardware when possible */ | 
|---|
| 200 | #define WS_SO_LINGER       0x0080          /* linger on close if data present */ | 
|---|
| 201 | #define WS_SO_OOBINLINE    0x0100          /* leave received OOB data in line */ | 
|---|
| 202 |  | 
|---|
| 203 | #define WS_SO_DONTLINGER   (UINT)(~WS_SO_LINGER) | 
|---|
| 204 |  | 
|---|
| 205 | /* | 
|---|
| 206 | * Additional options. | 
|---|
| 207 | */ | 
|---|
| 208 | #define WS_SO_SNDBUF       0x1001          /* send buffer size */ | 
|---|
| 209 | #define WS_SO_RCVBUF       0x1002          /* receive buffer size */ | 
|---|
| 210 | #define WS_SO_SNDLOWAT     0x1003          /* send low-water mark */ | 
|---|
| 211 | #define WS_SO_RCVLOWAT     0x1004          /* receive low-water mark */ | 
|---|
| 212 | #define WS_SO_SNDTIMEO     0x1005          /* send timeout */ | 
|---|
| 213 | #define WS_SO_RCVTIMEO     0x1006          /* receive timeout */ | 
|---|
| 214 | #define WS_SO_ERROR        0x1007          /* get error status and clear */ | 
|---|
| 215 | #define WS_SO_TYPE         0x1008          /* get socket type */ | 
|---|
| 216 |  | 
|---|
| 217 | #define WS_IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */ | 
|---|
| 218 | #define WS_IOC_VOID        0x20000000      /* no parameters */ | 
|---|
| 219 | #define WS_IOC_OUT         0x40000000      /* copy out parameters */ | 
|---|
| 220 | #define WS_IOC_IN          0x80000000      /* copy in parameters */ | 
|---|
| 221 | #define WS_IOC_INOUT       (WS_IOC_IN|WS_IOC_OUT) | 
|---|
| 222 | #define WS_IOR(x,y,t)      (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y)) | 
|---|
| 223 | #define WS_IOW(x,y,t)      (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y)) | 
|---|
| 224 |  | 
|---|
| 225 | /* IPPROTO_TCP options */ | 
|---|
| 226 | #define WS_TCP_NODELAY  1               /* do not apply nagle algorithm */ | 
|---|
| 227 |  | 
|---|
| 228 | /* | 
|---|
| 229 | * Socket I/O flags (supported by spec 1.1) | 
|---|
| 230 | */ | 
|---|
| 231 |  | 
|---|
| 232 | #define WS_FIONREAD    WS_IOR('f', 127, u_long) | 
|---|
| 233 | #define WS_FIONBIO     WS_IOW('f', 126, u_long) | 
|---|
| 234 |  | 
|---|
| 235 | #define WS_SIOCATMARK  WS_IOR('s',  7, u_long) | 
|---|
| 236 |  | 
|---|
| 237 | /* | 
|---|
| 238 | * Maximum queue length specifiable by listen. | 
|---|
| 239 | */ | 
|---|
| 240 | #ifdef SOMAXCONN | 
|---|
| 241 | #undef SOMAXCONN | 
|---|
| 242 | #endif | 
|---|
| 243 | #define SOMAXCONN       5 | 
|---|
| 244 |  | 
|---|
| 245 | #ifndef MSG_DONTROUTE | 
|---|
| 246 | #define MSG_DONTROUTE   0x4             /* send without using routing tables */ | 
|---|
| 247 | #endif | 
|---|
| 248 | #define MSG_MAXIOVLEN   16 | 
|---|
| 249 |  | 
|---|
| 250 | /* | 
|---|
| 251 | * Define constant based on rfc883, used by gethostbyxxxx() calls. | 
|---|
| 252 | */ | 
|---|
| 253 | #define MAXGETHOSTSTRUCT        1024 | 
|---|
| 254 |  | 
|---|
| 255 | /* | 
|---|
| 256 | * Define flags to be used with the WSAAsyncSelect() call. | 
|---|
| 257 | */ | 
|---|
| 258 | #define FD_READ            WS_FD_READ | 
|---|
| 259 | #define FD_WRITE           WS_FD_WRITE | 
|---|
| 260 | #define FD_OOB             WS_FD_OOB | 
|---|
| 261 | #define FD_ACCEPT          WS_FD_ACCEPT | 
|---|
| 262 | #define FD_CONNECT         WS_FD_CONNECT | 
|---|
| 263 | #define FD_CLOSE           WS_FD_CLOSE | 
|---|
| 264 | #define WS_FD_READ         0x0001 | 
|---|
| 265 | #define WS_FD_WRITE        0x0002 | 
|---|
| 266 | #define WS_FD_OOB          0x0004 | 
|---|
| 267 | #define WS_FD_ACCEPT       0x0008 | 
|---|
| 268 | #define WS_FD_CONNECT      0x0010 | 
|---|
| 269 | #define WS_FD_CLOSE        0x0020 | 
|---|
| 270 |  | 
|---|
| 271 | #define WS_FD_LISTENING    0x10000000   /* internal per-socket flags */ | 
|---|
| 272 | #define WS_FD_INACTIVE     0x20000000 | 
|---|
| 273 | #define WS_FD_CONNECTED    0x40000000 | 
|---|
| 274 | #define WS_FD_RAW          0x80000000 | 
|---|
| 275 | #define WS_FD_INTERNAL     0xFFFF0000 | 
|---|
| 276 |  | 
|---|
| 277 | /* | 
|---|
| 278 | * All Windows Sockets error constants are biased by WSABASEERR from | 
|---|
| 279 | * the "normal" | 
|---|
| 280 | */ | 
|---|
| 281 | #define WSABASEERR              10000 | 
|---|
| 282 | /* | 
|---|
| 283 | * Windows Sockets definitions of regular Microsoft C error constants | 
|---|
| 284 | */ | 
|---|
| 285 | #define WSAEINTR                (WSABASEERR+4) | 
|---|
| 286 | #define WSAEBADF                (WSABASEERR+9) | 
|---|
| 287 | #define WSAEACCES               (WSABASEERR+13) | 
|---|
| 288 | #define WSAEFAULT               (WSABASEERR+14) | 
|---|
| 289 | #define WSAEINVAL               (WSABASEERR+22) | 
|---|
| 290 | #define WSAEMFILE               (WSABASEERR+24) | 
|---|
| 291 |  | 
|---|
| 292 | /* | 
|---|
| 293 | * Windows Sockets definitions of regular Berkeley error constants | 
|---|
| 294 | */ | 
|---|
| 295 | #define WSAEWOULDBLOCK          (WSABASEERR+35) | 
|---|
| 296 | #define WSAEINPROGRESS          (WSABASEERR+36) | 
|---|
| 297 | #define WSAEALREADY             (WSABASEERR+37) | 
|---|
| 298 | #define WSAENOTSOCK             (WSABASEERR+38) | 
|---|
| 299 | #define WSAEDESTADDRREQ         (WSABASEERR+39) | 
|---|
| 300 | #define WSAEMSGSIZE             (WSABASEERR+40) | 
|---|
| 301 | #define WSAEPROTOTYPE           (WSABASEERR+41) | 
|---|
| 302 | #define WSAENOPROTOOPT          (WSABASEERR+42) | 
|---|
| 303 | #define WSAEPROTONOSUPPORT      (WSABASEERR+43) | 
|---|
| 304 | #define WSAESOCKTNOSUPPORT      (WSABASEERR+44) | 
|---|
| 305 | #define WSAEOPNOTSUPP           (WSABASEERR+45) | 
|---|
| 306 | #define WSAEPFNOSUPPORT         (WSABASEERR+46) | 
|---|
| 307 | #define WSAEAFNOSUPPORT         (WSABASEERR+47) | 
|---|
| 308 | #define WSAEADDRINUSE           (WSABASEERR+48) | 
|---|
| 309 | #define WSAEADDRNOTAVAIL        (WSABASEERR+49) | 
|---|
| 310 | #define WSAENETDOWN             (WSABASEERR+50) | 
|---|
| 311 | #define WSAENETUNREACH          (WSABASEERR+51) | 
|---|
| 312 | #define WSAENETRESET            (WSABASEERR+52) | 
|---|
| 313 | #define WSAECONNABORTED         (WSABASEERR+53) | 
|---|
| 314 | #define WSAECONNRESET           (WSABASEERR+54) | 
|---|
| 315 | #define WSAENOBUFS              (WSABASEERR+55) | 
|---|
| 316 | #define WSAEISCONN              (WSABASEERR+56) | 
|---|
| 317 | #define WSAENOTCONN             (WSABASEERR+57) | 
|---|
| 318 | #define WSAESHUTDOWN            (WSABASEERR+58) | 
|---|
| 319 | #define WSAETOOMANYREFS         (WSABASEERR+59) | 
|---|
| 320 | #define WSAETIMEDOUT            (WSABASEERR+60) | 
|---|
| 321 | #define WSAECONNREFUSED         (WSABASEERR+61) | 
|---|
| 322 | #define WSAELOOP                (WSABASEERR+62) | 
|---|
| 323 | #define WSAENAMETOOLONG         (WSABASEERR+63) | 
|---|
| 324 | #define WSAEHOSTDOWN            (WSABASEERR+64) | 
|---|
| 325 | #define WSAEHOSTUNREACH         (WSABASEERR+65) | 
|---|
| 326 | #define WSAENOTEMPTY            (WSABASEERR+66) | 
|---|
| 327 | #define WSAEPROCLIM             (WSABASEERR+67) | 
|---|
| 328 | #define WSAEUSERS               (WSABASEERR+68) | 
|---|
| 329 | #define WSAEDQUOT               (WSABASEERR+69) | 
|---|
| 330 | #define WSAESTALE               (WSABASEERR+70) | 
|---|
| 331 | #define WSAEREMOTE              (WSABASEERR+71) | 
|---|
| 332 |  | 
|---|
| 333 | /* | 
|---|
| 334 | * Extended Windows Sockets error constant definitions | 
|---|
| 335 | */ | 
|---|
| 336 | #define WSASYSNOTREADY          (WSABASEERR+91) | 
|---|
| 337 | #define WSAVERNOTSUPPORTED      (WSABASEERR+92) | 
|---|
| 338 | #define WSANOTINITIALISED       (WSABASEERR+93) | 
|---|
| 339 |  | 
|---|
| 340 | /* | 
|---|
| 341 | * Error return codes from gethostbyname() and gethostbyaddr() | 
|---|
| 342 | * (when using the resolver). Note that these errors are | 
|---|
| 343 | * retrieved via WSAGetLastError() and must therefore follow | 
|---|
| 344 | * the rules for avoiding clashes with error numbers from | 
|---|
| 345 | * specific implementations or language run-time systems. | 
|---|
| 346 | * For this reason the codes are based at WSABASEERR+1001. | 
|---|
| 347 | * Note also that [WSA]NO_ADDRESS is defined only for | 
|---|
| 348 | * compatibility purposes. | 
|---|
| 349 | */ | 
|---|
| 350 |  | 
|---|
| 351 | /* #define h_errno         WSAGetLastError() */ | 
|---|
| 352 |  | 
|---|
| 353 | /* Authoritative Answer: Host not found */ | 
|---|
| 354 | #define WSAHOST_NOT_FOUND       (WSABASEERR+1001) | 
|---|
| 355 |  | 
|---|
| 356 | /* Non-Authoritative: Host not found, or SERVERFAIL */ | 
|---|
| 357 | #define WSATRY_AGAIN            (WSABASEERR+1002) | 
|---|
| 358 |  | 
|---|
| 359 | /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ | 
|---|
| 360 | #define WSANO_RECOVERY          (WSABASEERR+1003) | 
|---|
| 361 |  | 
|---|
| 362 | /* Valid name, no data record of requested type */ | 
|---|
| 363 | #define WSANO_DATA              (WSABASEERR+1004) | 
|---|
| 364 |  | 
|---|
| 365 | /* no address, look for MX record */ | 
|---|
| 366 | #define WSANO_ADDRESS           WSANO_DATA | 
|---|
| 367 |  | 
|---|
| 368 | /* Socket function prototypes */ | 
|---|
| 369 |  | 
|---|
| 370 | #ifdef __cplusplus | 
|---|
| 371 | extern "C" { | 
|---|
| 372 | #endif | 
|---|
| 373 |  | 
|---|
| 374 | u_short PASCAL FAR htons (u_short hostshort); | 
|---|
| 375 | int PASCAL FAR closesocket (SOCKET s); | 
|---|
| 376 |  | 
|---|
| 377 | /* Database function prototypes */ | 
|---|
| 378 | int PASCAL FAR gethostname (char FAR * name, int namelen); | 
|---|
| 379 |  | 
|---|
| 380 | /* Microsoft Windows Extension function prototypes */ | 
|---|
| 381 |  | 
|---|
| 382 | INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData); | 
|---|
| 383 | INT     WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData); | 
|---|
| 384 | void      WINAPI WSASetLastError16(INT16 iError); | 
|---|
| 385 | void      WINAPI WSASetLastError(INT iError); | 
|---|
| 386 | INT     WINAPI WSACleanup(void); | 
|---|
| 387 | INT     WINAPI WSAGetLastError(void); | 
|---|
| 388 | BOOL    WINAPI WSAIsBlocking(void); | 
|---|
| 389 | INT     WINAPI WSACancelBlockingCall(void); | 
|---|
| 390 | INT16     WINAPI WSAUnhookBlockingHook16(void); | 
|---|
| 391 | INT     WINAPI WSAUnhookBlockingHook(void); | 
|---|
| 392 | FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc); | 
|---|
| 393 | FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc); | 
|---|
| 394 |  | 
|---|
| 395 | HANDLE16  WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 wMsg, LPCSTR name, LPCSTR proto, | 
|---|
| 396 | SEGPTR buf, INT16 buflen); | 
|---|
| 397 | HANDLE  WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto, | 
|---|
| 398 | LPSTR sbuf, INT buflen); | 
|---|
| 399 |  | 
|---|
| 400 | HANDLE16  WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 wMsg, INT16 port, | 
|---|
| 401 | LPCSTR proto, SEGPTR buf, INT16 buflen); | 
|---|
| 402 | HANDLE  WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port, | 
|---|
| 403 | LPCSTR proto, LPSTR sbuf, INT buflen); | 
|---|
| 404 |  | 
|---|
| 405 | HANDLE16  WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 wMsg, | 
|---|
| 406 | LPCSTR name, SEGPTR buf, INT16 buflen); | 
|---|
| 407 | HANDLE  WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, | 
|---|
| 408 | LPCSTR name, LPSTR sbuf, INT buflen); | 
|---|
| 409 |  | 
|---|
| 410 | HANDLE16  WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd, UINT16 wMsg, | 
|---|
| 411 | INT16 number, SEGPTR buf, INT16 buflen); | 
|---|
| 412 | HANDLE  WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, | 
|---|
| 413 | INT number, LPSTR sbuf, INT buflen); | 
|---|
| 414 |  | 
|---|
| 415 | HANDLE16  WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 wMsg, | 
|---|
| 416 | LPCSTR name, SEGPTR buf, INT16 buflen); | 
|---|
| 417 | HANDLE  WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, | 
|---|
| 418 | LPCSTR name, LPSTR sbuf, INT buflen); | 
|---|
| 419 |  | 
|---|
| 420 | HANDLE16  WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 wMsg, LPCSTR addr, | 
|---|
| 421 | INT16 len, INT16 type, SEGPTR buf, INT16 buflen); | 
|---|
| 422 | HANDLE  WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr, | 
|---|
| 423 | INT len, INT type, LPSTR sbuf, INT buflen); | 
|---|
| 424 |  | 
|---|
| 425 | INT16     WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle); | 
|---|
| 426 | INT     WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle); | 
|---|
| 427 |  | 
|---|
| 428 | INT16     WINAPI WSAAsyncSelect16(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, UINT lEvent); | 
|---|
| 429 | INT     WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, UINT lEvent); | 
|---|
| 430 |  | 
|---|
| 431 |  | 
|---|
| 432 | /* | 
|---|
| 433 | * Address families | 
|---|
| 434 | */ | 
|---|
| 435 | #define WS_AF_UNSPEC       0               /* unspecified */ | 
|---|
| 436 | #define WS_AF_UNIX         1               /* local to host (pipes, portals) */ | 
|---|
| 437 | #define WS_AF_INET         2               /* internetwork: UDP, TCP, etc. */ | 
|---|
| 438 | #define WS_AF_IMPLINK      3               /* arpanet imp addresses */ | 
|---|
| 439 | #define WS_AF_PUP          4               /* pup protocols: e.g. BSP */ | 
|---|
| 440 | #define WS_AF_CHAOS        5               /* mit CHAOS protocols */ | 
|---|
| 441 | #define WS_AF_NS           6               /* XEROX NS protocols */ | 
|---|
| 442 | #define WS_AF_IPX          WS_AF_NS        /* IPX protocols: IPX, SPX, etc. */ | 
|---|
| 443 | #define WS_AF_ISO          7               /* ISO protocols */ | 
|---|
| 444 | #define WS_AF_OSI          AF_ISO          /* OSI is ISO */ | 
|---|
| 445 | #define WS_AF_ECMA         8               /* european computer manufacturers */ | 
|---|
| 446 | #define WS_AF_DATAKIT      9               /* datakit protocols */ | 
|---|
| 447 | #define WS_AF_CCITT        10              /* CCITT protocols, X.25 etc */ | 
|---|
| 448 | #define WS_AF_SNA          11              /* IBM SNA */ | 
|---|
| 449 | #define WS_AF_DECnet       12              /* DECnet */ | 
|---|
| 450 | #define WS_AF_DLI          13              /* Direct data link interface */ | 
|---|
| 451 | #define WS_AF_LAT          14              /* LAT */ | 
|---|
| 452 | #define WS_AF_HYLINK       15              /* NSC Hyperchannel */ | 
|---|
| 453 | #define WS_AF_APPLETALK    16              /* AppleTalk */ | 
|---|
| 454 | #define WS_AF_NETBIOS      17              /* NetBios-style addresses */ | 
|---|
| 455 | #define WS_AF_VOICEVIEW    18              /* VoiceView */ | 
|---|
| 456 | #define WS_AF_FIREFOX      19              /* Protocols from Firefox */ | 
|---|
| 457 | #define WS_AF_UNKNOWN1     20              /* Somebody is using this! */ | 
|---|
| 458 | #define WS_AF_BAN          21              /* Banyan */ | 
|---|
| 459 | #define WS_AF_ATM          22              /* Native ATM Services */ | 
|---|
| 460 | #define WS_AF_INET6        23              /* Internetwork Version 6 */ | 
|---|
| 461 | #define WS_AF_CLUSTER      24              /* Microsoft Wolfpack */ | 
|---|
| 462 | #define WS_AF_12844        25              /* IEEE 1284.4 WG AF */ | 
|---|
| 463 | #define WS_AF_IRDA         26              /* IrDA */ | 
|---|
| 464 |  | 
|---|
| 465 | #define WS_AF_MAX          27 | 
|---|
| 466 |  | 
|---|
| 467 | struct ws_sockaddr_ipx | 
|---|
| 468 | { | 
|---|
| 469 | INT16           sipx_family     __attribute__((packed)); | 
|---|
| 470 | UINT            sipx_network    __attribute__((packed)); | 
|---|
| 471 | CHAR            sipx_node[6]    __attribute__((packed)); | 
|---|
| 472 | UINT16          sipx_port       __attribute__((packed)); | 
|---|
| 473 | }; | 
|---|
| 474 |  | 
|---|
| 475 | #ifdef __cplusplus | 
|---|
| 476 | } | 
|---|
| 477 | #endif | 
|---|
| 478 |  | 
|---|
| 479 | /* Microsoft Windows Extended data types */ | 
|---|
| 480 | typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR; | 
|---|
| 481 | typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN; | 
|---|
| 482 | typedef struct linger LINGER, *PLINGER, *LPLINGER; | 
|---|
| 483 | typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR; | 
|---|
| 484 | typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET; | 
|---|
| 485 | typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT; | 
|---|
| 486 | typedef struct servent SERVENT, *PSERVENT, *LPSERVENT; | 
|---|
| 487 | typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT; | 
|---|
| 488 | typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL; | 
|---|
| 489 |  | 
|---|
| 490 | /* | 
|---|
| 491 | * Windows message parameter composition and decomposition | 
|---|
| 492 | * macros. | 
|---|
| 493 | * | 
|---|
| 494 | * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation | 
|---|
| 495 | * when constructing the response to a WSAAsyncGetXByY() routine. | 
|---|
| 496 | */ | 
|---|
| 497 | #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error) | 
|---|
| 498 | /* | 
|---|
| 499 | * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation | 
|---|
| 500 | * when constructing the response to WSAAsyncSelect(). | 
|---|
| 501 | */ | 
|---|
| 502 | #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error) | 
|---|
| 503 | /* | 
|---|
| 504 | * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application | 
|---|
| 505 | * to extract the buffer length from the lParam in the response | 
|---|
| 506 | * to a WSAGetXByY(). | 
|---|
| 507 | */ | 
|---|
| 508 | #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam) | 
|---|
| 509 | /* | 
|---|
| 510 | * WSAGETASYNCERROR is intended for use by the Windows Sockets application | 
|---|
| 511 | * to extract the error code from the lParam in the response | 
|---|
| 512 | * to a WSAGetXByY(). | 
|---|
| 513 | */ | 
|---|
| 514 | #define WSAGETASYNCERROR(lParam)            HIWORD(lParam) | 
|---|
| 515 | /* | 
|---|
| 516 | * WSAGETSELECTEVENT is intended for use by the Windows Sockets application | 
|---|
| 517 | * to extract the event code from the lParam in the response | 
|---|
| 518 | * to a WSAAsyncSelect(). | 
|---|
| 519 | */ | 
|---|
| 520 | #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam) | 
|---|
| 521 | /* | 
|---|
| 522 | * WSAGETSELECTERROR is intended for use by the Windows Sockets application | 
|---|
| 523 | * to extract the error code from the lParam in the response | 
|---|
| 524 | * to a WSAAsyncSelect(). | 
|---|
| 525 | */ | 
|---|
| 526 | #define WSAGETSELECTERROR(lParam)           HIWORD(lParam) | 
|---|
| 527 |  | 
|---|
| 528 | /* ----------------------------------- internal structures */ | 
|---|
| 529 |  | 
|---|
| 530 | /* ws_... struct conversion flags */ | 
|---|
| 531 |  | 
|---|
| 532 | #define WS_DUP_LINEAR           0x0001 | 
|---|
| 533 | #define WS_DUP_NATIVE           0x0000          /* not used anymore */ | 
|---|
| 534 | #define WS_DUP_OFFSET           0x0002          /* internal pointers are offsets */ | 
|---|
| 535 | #define WS_DUP_SEGPTR           0x0004          /* internal pointers are SEGPTRs */ | 
|---|
| 536 | /* by default, internal pointers are linear */ | 
|---|
| 537 |  | 
|---|
| 538 | typedef struct __sop    /* WSAAsyncSelect() control struct */ | 
|---|
| 539 | { | 
|---|
| 540 | struct __sop *next, *prev; | 
|---|
| 541 |  | 
|---|
| 542 | struct __ws*  pws; | 
|---|
| 543 | HWND        hWnd; | 
|---|
| 544 | UINT        uMsg; | 
|---|
| 545 | } ws_select_op; | 
|---|
| 546 |  | 
|---|
| 547 | typedef struct  __ws    /* socket */ | 
|---|
| 548 | { | 
|---|
| 549 | int           fd; | 
|---|
| 550 | unsigned      flags; | 
|---|
| 551 | ws_select_op* psop; | 
|---|
| 552 | } ws_socket; | 
|---|
| 553 |  | 
|---|
| 554 | #define WS_MAX_SOCKETS_PER_PROCESS      16 | 
|---|
| 555 | #define WS_MAX_UDP_DATAGRAM             1024 | 
|---|
| 556 |  | 
|---|
| 557 | #define WSI_BLOCKINGCALL        0x00000001      /* per-thread info flags */ | 
|---|
| 558 | #define WSI_BLOCKINGHOOK        0x00000002      /* 32-bit callback */ | 
|---|
| 559 |  | 
|---|
| 560 | typedef struct _WSINFO | 
|---|
| 561 | { | 
|---|
| 562 | struct _WSINFO*       prev,*next; | 
|---|
| 563 |  | 
|---|
| 564 | unsigned              flags; | 
|---|
| 565 | INT                   err;                    /* WSAGetLastError() return value */ | 
|---|
| 566 | INT16                 num_startup;            /* reference counter */ | 
|---|
| 567 | INT16                 num_async_rq; | 
|---|
| 568 | INT16                 last_free;              /* entry in the socket table */ | 
|---|
| 569 | UINT16                buflen; | 
|---|
| 570 | char*                 buffer;                 /* allocated from SEGPTR heap */ | 
|---|
| 571 | struct ws_hostent     *he; | 
|---|
| 572 | int                   helen; | 
|---|
| 573 | struct ws_servent     *se; | 
|---|
| 574 | int                   selen; | 
|---|
| 575 | struct ws_protoent    *pe; | 
|---|
| 576 | int                   pelen; | 
|---|
| 577 | char*                 dbuffer;                /* buffer for dummies (32 bytes) */ | 
|---|
| 578 |  | 
|---|
| 579 | ws_socket             sock[WS_MAX_SOCKETS_PER_PROCESS]; | 
|---|
| 580 | DWORD                 blocking_hook; | 
|---|
| 581 | HTASK16               tid;                    /* owning task id - process might be better */ | 
|---|
| 582 | } WSINFO, *LPWSINFO; | 
|---|
| 583 |  | 
|---|
| 584 | /* function prototypes */ | 
|---|
| 585 | int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag); | 
|---|
| 586 | int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag); | 
|---|
| 587 | int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag); | 
|---|
| 588 |  | 
|---|
| 589 | BOOL WINSOCK_HandleIO(int* fd_max, int num_pending, fd_set pending_set[3], fd_set master_set[3] ); | 
|---|
| 590 | void   WINSOCK_Shutdown(void); | 
|---|
| 591 | UINT16 wsaErrno(void); | 
|---|
| 592 | UINT16 wsaHerrno(void); | 
|---|
| 593 |  | 
|---|
| 594 | extern INT WINSOCK_DeleteTaskWSI( TDB* pTask, struct _WSINFO* ); | 
|---|
| 595 |  | 
|---|
| 596 | #endif  /* _WINSOCKAPI_ */ | 
|---|
| 597 |  | 
|---|