Changeset 2651 for trunk/include/win/winsock.h
- Timestamp:
- Feb 5, 2000, 3:42:20 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/win/winsock.h
r2524 r2651 1 /* $Id: winsock.h,v 1. 3 2000-01-26 23:17:52sandervl Exp $ */1 /* $Id: winsock.h,v 1.4 2000-02-05 02:42:20 sandervl Exp $ */ 2 2 3 3 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL … … 10 10 #define _WINSOCKAPI_ 11 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 12 #ifndef __WINE_WINDOWS_H 13 #include <windows.h> 14 #endif // __WINE_WINDOWS_H 15 16 typedef unsigned char u_char; 17 typedef unsigned short u_short; 18 typedef unsigned int u_int; 19 typedef unsigned long u_long; 20 typedef u_int SOCKET; 21 22 #ifndef FD_SETSIZE 23 #define FD_SETSIZE 64 24 #endif /* FD_SETSIZE */ 25 26 typedef struct fd_set { 27 u_int fd_count; 28 SOCKET fd_array[FD_SETSIZE]; 29 } fd_set; 30 31 #ifdef __cplusplus 32 extern "C" { 23 33 #endif 24 34 25 #ifdef HAVE_IPX_LINUX 26 # include <asm/types.h> 27 # include <linux/ipx.h>28 # define HAVE_IPX 35 extern int WIN32API __WSAFDIsSet(SOCKET, fd_set *); 36 37 #ifdef __cplusplus 38 } 29 39 #endif 30 40 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]; \ 41 42 #define FD_CLR(fd, set) do { \ 43 u_int __i; \ 44 for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) { \ 45 if (((fd_set *)(set))->fd_array[__i] == fd) { \ 46 while (__i < ((fd_set *)(set))->fd_count-1) { \ 47 ((fd_set *)(set))->fd_array[__i] = \ 48 ((fd_set *)(set))->fd_array[__i+1]; \ 102 49 __i++; \ 103 50 } \ 104 (( cast*)(set))->fd_count--; \51 ((fd_set *)(set))->fd_count--; \ 105 52 break; \ 106 53 } \ 107 54 } \ 108 55 } 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);\ 56 57 #define FD_SET(fd, set) do { \ 58 if (((fd_set *)(set))->fd_count < FD_SETSIZE) \ 59 ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++]=(fd);\ 115 60 } 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 { 61 62 #define FD_ZERO(set) (((fd_set *)(set))->fd_count=0) 63 64 #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set)) 65 66 struct timeval { 67 long tv_sec; /* seconds */ 68 long tv_usec; /* and microseconds */ 69 }; 70 71 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 72 #define timercmp(tvp, uvp, cmp) \ 73 ((tvp)->tv_sec cmp (uvp)->tv_sec || \ 74 (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) 75 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 76 77 #define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */ 78 #define IOC_VOID 0x20000000 /* no parameters */ 79 #define IOC_OUT 0x40000000 /* copy out parameters */ 80 #define IOC_IN 0x80000000 /* copy in parameters */ 81 #define IOC_INOUT (IOC_IN|IOC_OUT) 82 /* 0x20000000 distinguishes new & 83 old ioctl's */ 84 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y)) 85 86 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) 87 88 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) 89 90 #define FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */ 91 #define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o */ 92 #define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */ 93 94 #define SIOCSHIWAT _IOW('s', 0, u_long) /* set high watermark */ 95 #define SIOCGHIWAT _IOR('s', 1, u_long) /* get high watermark */ 96 #define SIOCSLOWAT _IOW('s', 2, u_long) /* set low watermark */ 97 #define SIOCGLOWAT _IOR('s', 3, u_long) /* get low watermark */ 98 #define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */ 99 100 struct hostent { 101 char * h_name; 102 char * * h_aliases; 103 short h_addrtype; 104 short h_length; 105 char * * h_addr_list; 106 #define h_addr h_addr_list[0] 107 }; 108 109 struct netent { 110 char * n_name; 111 char * * n_aliases; 112 short n_addrtype; 113 u_long n_net; 114 }; 115 116 struct servent { 117 char * s_name; 118 char * * s_aliases; 119 short s_port; 120 char * s_proto; 121 }; 122 123 struct protoent { 124 char * p_name; 125 char * * p_aliases; 126 short p_proto; 127 }; 128 129 #define IPPROTO_IP 0 130 #define IPPROTO_ICMP 1 131 #define IPPROTO_IGMP 2 132 #define IPPROTO_GGP 3 133 #define IPPROTO_TCP 6 134 #define IPPROTO_PUP 12 135 #define IPPROTO_UDP 17 136 #define IPPROTO_IDP 22 137 #define IPPROTO_ND 77 138 139 #define IPPROTO_RAW 255 140 #define IPPROTO_MAX 256 141 142 #define IPPORT_ECHO 7 143 #define IPPORT_DISCARD 9 144 #define IPPORT_SYSTAT 11 145 #define IPPORT_DAYTIME 13 146 #define IPPORT_NETSTAT 15 147 #define IPPORT_FTP 21 148 #define IPPORT_TELNET 23 149 #define IPPORT_SMTP 25 150 #define IPPORT_TIMESERVER 37 151 #define IPPORT_NAMESERVER 42 152 #define IPPORT_WHOIS 43 153 #define IPPORT_MTP 57 154 155 #define IPPORT_TFTP 69 156 #define IPPORT_RJE 77 157 #define IPPORT_FINGER 79 158 #define IPPORT_TTYLINK 87 159 #define IPPORT_SUPDUP 95 160 161 #define IPPORT_EXECSERVER 512 162 #define IPPORT_LOGINSERVER 513 163 #define IPPORT_CMDSERVER 514 164 #define IPPORT_EFSSERVER 520 165 166 #define IPPORT_BIFFUDP 512 167 #define IPPORT_WHOSERVER 513 168 #define IPPORT_ROUTESERVER 520 169 170 #define IPPORT_RESERVED 1024 171 172 #define IMPLINK_IP 155 173 #define IMPLINK_LOWEXPER 156 174 #define IMPLINK_HIGHEXPER 158 175 176 struct in_addr { 131 177 union { 132 struct { BYTEs_b1,s_b2,s_b3,s_b4; } S_un_b;133 struct { UINT16s_w1,s_w2; } S_un_w;134 UINTS_addr;178 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; 179 struct { u_short s_w1,s_w2; } S_un_w; 180 u_long S_addr; 135 181 } 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]; 182 183 #define s_addr S_un.S_addr 184 #define s_host S_un.S_un_b.s_b2 185 #define s_net S_un.S_un_b.s_b1 186 #define s_imp S_un.S_un_w.s_w2 187 #define s_impno S_un.S_un_b.s_b4 188 #define s_lh S_un.S_un_b.s_b3 189 }; 190 191 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 192 #define IN_CLASSA_NET 0xff000000 193 #define IN_CLASSA_NSHIFT 24 194 #define IN_CLASSA_HOST 0x00ffffff 195 #define IN_CLASSA_MAX 128 196 197 #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 198 #define IN_CLASSB_NET 0xffff0000 199 #define IN_CLASSB_NSHIFT 16 200 #define IN_CLASSB_HOST 0x0000ffff 201 #define IN_CLASSB_MAX 65536 202 203 #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 204 #define IN_CLASSC_NET 0xffffff00 205 #define IN_CLASSC_NSHIFT 8 206 #define IN_CLASSC_HOST 0x000000ff 207 208 #define INADDR_ANY (u_long)0x00000000 209 #define INADDR_LOOPBACK 0x7f000001 210 #define INADDR_BROADCAST (u_long)0xffffffff 211 #define INADDR_NONE 0xffffffff 212 213 struct sockaddr_in { 214 short sin_family; 215 u_short sin_port; 216 struct in_addr sin_addr; 217 char sin_zero[8]; 150 218 }; 151 219 … … 158 226 char szDescription[WSADESCRIPTION_LEN+1]; 159 227 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 228 unsigned short iMaxSockets; 229 unsigned short iMaxUdpDg; 230 char * lpVendorInfo; 231 } WSADATA; 232 233 typedef WSADATA *LPWSADATA; 234 235 #define IP_OPTIONS 1 236 #define IP_MULTICAST_IF 2 237 #define IP_MULTICAST_TTL 3 238 #define IP_MULTICAST_LOOP 4 239 #define IP_ADD_MEMBERSHIP 5 240 #define IP_DROP_MEMBERSHIP 6 241 #define IP_TTL 7 242 #define IP_TOS 8 243 #define IP_DONTFRAGMENT 9 244 245 246 #define IP_DEFAULT_MULTICAST_TTL 1 247 #define IP_DEFAULT_MULTICAST_LOOP 1 248 #define IP_MAX_MEMBERSHIPS 20 249 250 struct ip_mreq { 251 struct in_addr imr_multiaddr; 252 struct in_addr imr_interface; 253 }; 254 255 #define INVALID_SOCKET (SOCKET)(~0) 256 #define SOCKET_ERROR (-1) 257 258 #define SOCK_STREAM 1 259 #define SOCK_DGRAM 2 260 #define SOCK_RAW 3 261 #define SOCK_RDM 4 262 #define SOCK_SEQPACKET 5 263 264 #define SO_DEBUG 0x0001 265 #define SO_ACCEPTCONN 0x0002 266 #define SO_REUSEADDR 0x0004 267 #define SO_KEEPALIVE 0x0008 268 #define SO_DONTROUTE 0x0010 269 #define SO_BROADCAST 0x0020 270 #define SO_USELOOPBACK 0x0040 271 #define SO_LINGER 0x0080 272 #define SO_OOBINLINE 0x0100 273 274 #define SO_DONTLINGER (u_int)(~SO_LINGER) 275 276 #define SO_SNDBUF 0x1001 277 #define SO_RCVBUF 0x1002 278 #define SO_SNDLOWAT 0x1003 279 #define SO_RCVLOWAT 0x1004 280 #define SO_SNDTIMEO 0x1005 281 #define SO_RCVTIMEO 0x1006 282 #define SO_ERROR 0x1007 283 #define SO_TYPE 0x1008 284 285 #define SO_CONNDATA 0x7000 286 #define SO_CONNOPT 0x7001 287 #define SO_DISCDATA 0x7002 288 #define SO_DISCOPT 0x7003 289 #define SO_CONNDATALEN 0x7004 290 #define SO_CONNOPTLEN 0x7005 291 #define SO_DISCDATALEN 0x7006 292 #define SO_DISCOPTLEN 0x7007 293 294 #define SO_OPENTYPE 0x7008 295 296 #define SO_SYNCHRONOUS_ALERT 0x10 297 #define SO_SYNCHRONOUS_NONALERT 0x20 298 299 #define SO_MAXDG 0x7009 300 #define SO_MAXPATHDG 0x700A 301 #define SO_UPDATE_ACCEPT_CONTEXT 0x700B 302 #define SO_CONNECT_TIME 0x700C 303 304 #define TCP_NODELAY 0x0001 305 #define TCP_BSDURGENT 0x7000 306 307 #define AF_UNSPEC 0 308 #define AF_UNIX 1 309 #define AF_INET 2 310 #define AF_IMPLINK 3 311 #define AF_PUP 4 312 #define AF_CHAOS 5 313 #define AF_IPX 6 314 #define AF_NS 6 315 #define AF_ISO 7 316 #define AF_OSI AF_ISO 317 #define AF_ECMA 8 318 #define AF_DATAKIT 9 319 #define AF_CCITT 10 320 #define AF_SNA 11 321 #define AF_DECnet 12 322 #define AF_DLI 13 323 #define AF_LAT 14 324 #define AF_HYLINK 15 325 #define AF_APPLETALK 16 326 #define AF_NETBIOS 17 327 #define AF_VOICEVIEW 18 328 #define AF_FIREFOX 19 329 #define AF_UNKNOWN1 20 330 #define AF_BAN 21 331 332 #define AF_MAX 22 333 334 struct sockaddr { 335 u_short sa_family; 336 char sa_data[14]; 337 }; 338 339 struct sockproto { 340 u_short sp_family; /* address family */ 341 u_short sp_protocol; /* protocol */ 342 }; 343 344 #define PF_UNSPEC AF_UNSPEC 345 #define PF_UNIX AF_UNIX 346 #define PF_INET AF_INET 347 #define PF_IMPLINK AF_IMPLINK 348 #define PF_PUP AF_PUP 349 #define PF_CHAOS AF_CHAOS 350 #define PF_NS AF_NS 351 #define PF_IPX AF_IPX 352 #define PF_ISO AF_ISO 353 #define PF_OSI AF_OSI 354 #define PF_ECMA AF_ECMA 355 #define PF_DATAKIT AF_DATAKIT 356 #define PF_CCITT AF_CCITT 357 #define PF_SNA AF_SNA 358 #define PF_DECnet AF_DECnet 359 #define PF_DLI AF_DLI 360 #define PF_LAT AF_LAT 361 #define PF_HYLINK AF_HYLINK 362 #define PF_APPLETALK AF_APPLETALK 363 #define PF_VOICEVIEW AF_VOICEVIEW 364 #define PF_FIREFOX AF_FIREFOX 365 #define PF_UNKNOWN1 AF_UNKNOWN1 366 #define PF_BAN AF_BAN 367 368 #define PF_MAX AF_MAX 369 370 struct linger { 371 u_short l_onoff; /* option on/off */ 372 u_short l_linger; /* linger time */ 373 }; 374 375 #define SOL_SOCKET 0xffff /* options for socket level */ 376 243 377 #define SOMAXCONN 5 244 378 245 #ifndef MSG_DONTROUTE 379 #define MSG_OOB 0x1 /* process out-of-band data */ 380 #define MSG_PEEK 0x2 /* peek at incoming message */ 246 381 #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 247 #endif 382 248 383 #define MSG_MAXIOVLEN 16 249 384 250 /* 251 * Define constant based on rfc883, used by gethostbyxxxx() calls. 252 */ 385 #define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */ 386 253 387 #define MAXGETHOSTSTRUCT 1024 254 388 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 */ 389 #define FD_READ 0x01 390 #define FD_WRITE 0x02 391 #define FD_OOB 0x04 392 #define FD_ACCEPT 0x08 393 #define FD_CONNECT 0x10 394 #define FD_CLOSE 0x20 395 281 396 #define WSABASEERR 10000 282 /* 283 * Windows Sockets definitions of regular Microsoft C error constants 284 */ 397 285 398 #define WSAEINTR (WSABASEERR+4) 286 399 #define WSAEBADF (WSABASEERR+9) … … 290 403 #define WSAEMFILE (WSABASEERR+24) 291 404 292 /*293 * Windows Sockets definitions of regular Berkeley error constants294 */295 405 #define WSAEWOULDBLOCK (WSABASEERR+35) 296 406 #define WSAEINPROGRESS (WSABASEERR+36) … … 331 441 #define WSAEREMOTE (WSABASEERR+71) 332 442 333 /* 334 * Extended Windows Sockets error constant definitions 335 */ 443 #define WSAEDISCON (WSABASEERR+101) 444 336 445 #define WSASYSNOTREADY (WSABASEERR+91) 337 446 #define WSAVERNOTSUPPORTED (WSABASEERR+92) 338 447 #define WSANOTINITIALISED (WSABASEERR+93) 339 448 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 */ 449 #define h_errno WSAGetLastError() 450 354 451 #define WSAHOST_NOT_FOUND (WSABASEERR+1001) 355 356 /* Non-Authoritative: Host not found, or SERVERFAIL */ 452 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 453 357 454 #define WSATRY_AGAIN (WSABASEERR+1002) 358 359 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 455 #define TRY_AGAIN WSATRY_AGAIN 456 360 457 #define WSANO_RECOVERY (WSABASEERR+1003) 361 362 /* Valid name, no data record of requested type */ 458 #define NO_RECOVERY WSANO_RECOVERY 459 363 460 #define WSANO_DATA (WSABASEERR+1004) 364 365 /* no address, look for MX record */ 461 #define NO_DATA WSANO_DATA 462 366 463 #define WSANO_ADDRESS WSANO_DATA 367 368 /* Socket function prototypes */ 464 #define NO_ADDRESS WSANO_ADDRESS 369 465 370 466 #ifdef __cplusplus … … 372 468 #endif 373 469 374 u_short PASCAL FAR htons (u_short hostshort); 375 int PASCAL FAR closesocket (SOCKET s); 376 470 SOCKET WIN32API accept (SOCKET s, struct sockaddr *addr, 471 int *addrlen); 472 473 int WIN32API bind (SOCKET s, const struct sockaddr *addr, int namelen); 474 475 int WIN32API closesocket (SOCKET s); 476 477 int WIN32API connect (SOCKET s, const struct sockaddr *name, int namelen); 478 479 int WIN32API ioctlsocket (SOCKET s, long cmd, u_long *argp); 480 481 int WIN32API getpeername (SOCKET s, struct sockaddr *name, 482 int * namelen); 483 484 int WIN32API getsockname (SOCKET s, struct sockaddr *name, 485 int * namelen); 486 487 int WIN32API getsockopt (SOCKET s, int level, int optname, 488 char * optval, int *optlen); 489 490 u_long WIN32API htonl (u_long hostlong); 491 492 u_short WIN32API htons (u_short hostshort); 493 494 unsigned long WIN32API inet_addr (const char * cp); 495 496 char * WIN32API inet_ntoa (struct in_addr in); 497 498 int WIN32API listen (SOCKET s, int backlog); 499 500 u_long WIN32API ntohl (u_long netlong); 501 502 u_short WIN32API ntohs (u_short netshort); 503 504 int WIN32API recv (SOCKET s, char * buf, int len, int flags); 505 506 int WIN32API recvfrom (SOCKET s, char * buf, int len, int flags, 507 struct sockaddr *from, int * fromlen); 508 509 int WIN32API select (int nfds, fd_set *readfds, fd_set *writefds, 510 fd_set *exceptfds, const struct timeval *timeout); 511 512 int WIN32API send (SOCKET s, const char * buf, int len, int flags); 513 514 int WIN32API sendto (SOCKET s, const char * buf, int len, int flags, 515 const struct sockaddr *to, int tolen); 516 517 int WIN32API setsockopt (SOCKET s, int level, int optname, 518 const char * optval, int optlen); 519 520 int WIN32API shutdown (SOCKET s, int how); 521 522 SOCKET WIN32API socket (int af, int type, int protocol); 523 377 524 /* Database function prototypes */ 378 int PASCAL FAR gethostname (char FAR * name, int namelen); 525 526 struct hostent * WIN32API gethostbyaddr(const char * addr, 527 int len, int type); 528 529 struct hostent * WIN32API gethostbyname(const char * name); 530 531 int WIN32API gethostname (char * name, int namelen); 532 533 struct servent * WIN32API getservbyport(int port, const char * proto); 534 535 struct servent * WIN32API getservbyname(const char * name, 536 const char * proto); 537 538 struct protoent * WIN32API getprotobynumber(int proto); 539 540 struct protoent * WIN32API getprotobyname(const char * name); 379 541 380 542 /* Microsoft Windows Extension function prototypes */ 381 543 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 }; 544 int WIN32API WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); 545 546 int WIN32API WSACleanup(void); 547 548 void WIN32API WSASetLastError(int iError); 549 550 int WIN32API WSAGetLastError(void); 551 552 BOOL WIN32API WSAIsBlocking(void); 553 554 int WIN32API WSAUnhookBlockingHook(void); 555 556 FARPROC WIN32API WSASetBlockingHook(FARPROC lpBlockFunc); 557 558 int WIN32API WSACancelBlockingCall(void); 559 560 HANDLE WIN32API WSAAsyncGetServByName(HWND hWnd, u_int wMsg, 561 const char * name, 562 const char * proto, 563 char * buf, int buflen); 564 565 HANDLE WIN32API WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port, 566 const char * proto, char * buf, 567 int buflen); 568 569 HANDLE WIN32API WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg, 570 const char * name, char * buf, 571 int buflen); 572 573 HANDLE WIN32API WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg, 574 int number, char * buf, 575 int buflen); 576 577 HANDLE WIN32API WSAAsyncGetHostByName(HWND hWnd, u_int wMsg, 578 const char * name, char * buf, 579 int buflen); 580 581 HANDLE WIN32API WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg, 582 const char * addr, int len, int type, 583 char * buf, int buflen); 584 585 int WIN32API WSACancelAsyncRequest(HANDLE hAsyncTaskHandle); 586 587 int WIN32API WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg, 588 long lEvent); 589 590 int WIN32API WSARecvEx (SOCKET s, char * buf, int len, int *flags); 591 592 typedef struct _TRANSMIT_FILE_BUFFERS { 593 PVOID Head; 594 DWORD HeadLength; 595 PVOID Tail; 596 DWORD TailLength; 597 } TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS; 598 599 #define TF_DISCONNECT 0x01 600 #define TF_REUSE_SOCKET 0x02 601 #define TF_WRITE_BEHIND 0x04 602 603 BOOL WIN32API TransmitFile ( 604 SOCKET hSocket, 605 HANDLE hFile, 606 DWORD nNumberOfBytesToWrite, 607 DWORD nNumberOfBytesPerSend, 608 LPOVERLAPPED lpOverlapped, 609 LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, 610 DWORD dwReserved 611 ); 612 613 BOOL WIN32API AcceptEx ( 614 SOCKET sListenSocket, 615 SOCKET sAcceptSocket, 616 PVOID lpOutputBuffer, 617 DWORD dwReceiveDataLength, 618 DWORD dwLocalAddressLength, 619 DWORD dwRemoteAddressLength, 620 LPDWORD lpdwBytesReceived, 621 LPOVERLAPPED lpOverlapped 622 ); 623 624 VOID WIN32API GetAcceptExSockaddrs ( 625 PVOID lpOutputBuffer, 626 DWORD dwReceiveDataLength, 627 DWORD dwLocalAddressLength, 628 DWORD dwRemoteAddressLength, 629 struct sockaddr **LocalSockaddr, 630 LPINT LocalSockaddrLength, 631 struct sockaddr **RemoteSockaddr, 632 LPINT RemoteSockaddrLength 633 ); 474 634 475 635 #ifdef __cplusplus … … 477 637 #endif 478 638 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 */ 639 typedef struct sockaddr SOCKADDR; 640 typedef struct sockaddr *PSOCKADDR; 641 typedef struct sockaddr *LPSOCKADDR; 642 643 typedef struct sockaddr_in SOCKADDR_IN; 644 typedef struct sockaddr_in *PSOCKADDR_IN; 645 typedef struct sockaddr_in *LPSOCKADDR_IN; 646 647 typedef struct linger LINGER; 648 typedef struct linger *PLINGER; 649 typedef struct linger *LPLINGER; 650 651 typedef struct in_addr IN_ADDR; 652 typedef struct in_addr *PIN_ADDR; 653 typedef struct in_addr *LPIN_ADDR; 654 655 typedef struct fd_set FD_SET; 656 typedef struct fd_set *PFD_SET; 657 typedef struct fd_set *LPFD_SET; 658 659 typedef struct hostent HOSTENT; 660 typedef struct hostent *PHOSTENT; 661 typedef struct hostent *LPHOSTENT; 662 663 typedef struct servent SERVENT; 664 typedef struct servent *PSERVENT; 665 typedef struct servent *LPSERVENT; 666 667 typedef struct protoent PROTOENT; 668 typedef struct protoent *PPROTOENT; 669 typedef struct protoent *LPPROTOENT; 670 671 typedef struct timeval TIMEVAL; 672 typedef struct timeval *PTIMEVAL; 673 typedef struct timeval *LPTIMEVAL; 674 497 675 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error) 498 /*499 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation500 * when constructing the response to WSAAsyncSelect().501 */502 676 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error) 503 /*504 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application505 * to extract the buffer length from the lParam in the response506 * to a WSAGetXByY().507 */508 677 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam) 509 /*510 * WSAGETASYNCERROR is intended for use by the Windows Sockets application511 * to extract the error code from the lParam in the response512 * to a WSAGetXByY().513 */514 678 #define WSAGETASYNCERROR(lParam) HIWORD(lParam) 515 /*516 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application517 * to extract the event code from the lParam in the response518 * to a WSAAsyncSelect().519 */520 679 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam) 521 /*522 * WSAGETSELECTERROR is intended for use by the Windows Sockets application523 * to extract the error code from the lParam in the response524 * to a WSAAsyncSelect().525 */526 680 #define WSAGETSELECTERROR(lParam) HIWORD(lParam) 527 681 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 682 #endif // _WINSOCKAPI_ 683 684
Note:
See TracChangeset
for help on using the changeset viewer.