winsock.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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
  4. * specification.
  5. *
  6. * Copyright (C) the Wine project
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifdef __WINESRC__
  23. # ifndef __WINE_WINSOCK2__
  24. # error Please use Winsock2 in Wine
  25. # endif
  26. #endif
  27. #ifndef __WINE_WINSOCKAPI_STDLIB_H
  28. #define __WINE_WINSOCKAPI_STDLIB_H
  29. /*
  30. * This section defines the items that conflict with the Unix headers.
  31. */
  32. #ifndef USE_WS_PREFIX
  33. /* We are not using the WS_ prefix we risk getting conflicts for
  34. * everything related to select.
  35. */
  36. # ifdef FD_CLR
  37. /* Too late, the Unix version of stdlib.h was included before winsock.h.
  38. * This means select and all the related stuff is already defined and we
  39. * cannot override types and function prototypes.
  40. * All we can do is disable all these symbols so that they are not used
  41. * inadvertantly.
  42. */
  43. # undef FD_SETSIZE
  44. # undef FD_CLR
  45. # undef FD_SET
  46. # undef FD_ZERO
  47. # undef FD_ISSET
  48. # define FD_SETSIZE Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  49. # define FD_CLR Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  50. # define FD_SET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  51. # define FD_ZERO Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  52. # define FD_ISSET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  53. # define fd_set Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  54. # define select Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
  55. # else /* FD_CLR */
  56. /* stdlib.h has not been included yet so it's not too late. Include it now
  57. * making sure that none of the select symbols is affected. Then we can
  58. * define them with our own values.
  59. */
  60. # define fd_set unix_fd_set
  61. # define timeval unix_timeval
  62. # define select unix_select
  63. # include <sys/types.h>
  64. # include <time.h>
  65. # include <stdlib.h>
  66. # undef fd_set
  67. # undef timeval
  68. # undef select
  69. # undef FD_SETSIZE
  70. # undef FD_CLR
  71. # undef FD_SET
  72. # undef FD_ZERO
  73. # undef FD_ISSET
  74. # define WS_DEFINE_SELECT
  75. # endif /* FD_CLR */
  76. #else
  77. # define WS_DEFINE_SELECT
  78. # include <sys/types.h>
  79. # include <stdlib.h>
  80. #endif /* !USE_WS_PREFIX */
  81. #endif /* __WINE_WINSOCKAPI_STDLIB_H */
  82. #ifndef __WINESRC__
  83. # include <windows.h>
  84. #else
  85. # include <windef.h>
  86. #endif
  87. #ifndef _WINSOCKAPI_
  88. #define _WINSOCKAPI_
  89. #if (defined(_MSC_VER) || defined(__MINGW_H)) && !defined(_BSD_TYPES_DEFINED)
  90. /* MinGW doesn't define the u_xxx types */
  91. typedef unsigned char u_char;
  92. typedef unsigned short u_short;
  93. typedef unsigned int u_int;
  94. typedef unsigned long u_long;
  95. #endif
  96. #ifdef USE_WS_PREFIX
  97. # define WS(x) WS_##x
  98. #else
  99. # define WS(x) x
  100. #endif
  101. #ifdef __cplusplus
  102. extern "C" {
  103. #endif /* defined(__cplusplus) */
  104. /* proper 4-byte packing */
  105. #include <pshpack4.h>
  106. /*
  107. * Address families
  108. */
  109. #ifndef USE_WS_PREFIX
  110. #define AF_UNSPEC 0
  111. #define AF_UNIX 1
  112. #define AF_INET 2
  113. #define AF_IMPLINK 3
  114. #define AF_PUP 4
  115. #define AF_CHAOS 5
  116. #define AF_NS 6
  117. #define AF_IPX AF_NS
  118. #define AF_ISO 7
  119. #define AF_OSI AF_ISO
  120. #define AF_ECMA 8
  121. #define AF_DATAKIT 9
  122. #define AF_CCITT 10
  123. #define AF_SNA 11
  124. #define AF_DECnet 12
  125. #define AF_DLI 13
  126. #define AF_LAT 14
  127. #define AF_HYLINK 15
  128. #define AF_APPLETALK 16
  129. #define AF_NETBIOS 17
  130. #define AF_VOICEVIEW 18
  131. #define AF_FIREFOX 19
  132. #define AF_UNKNOWN1 20
  133. #define AF_BAN 21
  134. #define AF_ATM 22
  135. #define AF_INET6 23
  136. #define AF_CLUSTER 24
  137. #define AF_12844 25
  138. #define AF_IRDA 26
  139. #define AF_MAX 27
  140. #define PF_UNSPEC AF_UNSPEC
  141. #define PF_UNIX AF_UNIX
  142. #define PF_INET AF_INET
  143. #define PF_IMPLINK AF_IMPLINK
  144. #define PF_PUP AF_PUP
  145. #define PF_CHAOS AF_CHAOS
  146. #define PF_NS AF_NS
  147. #define PF_IPX AF_IPX
  148. #define PF_ISO AF_ISO
  149. #define PF_OSI AF_OSI
  150. #define PF_ECMA AF_ECMA
  151. #define PF_DATAKIT AF_DATAKIT
  152. #define PF_CCITT AF_CCITT
  153. #define PF_SNA AF_SNA
  154. #define PF_DECnet AF_DECnet
  155. #define PF_DLI AF_DLI
  156. #define PF_LAT AF_LAT
  157. #define PF_HYLINK AF_HYLINK
  158. #define PF_APPLETALK AF_APPLETALK
  159. #define PF_VOICEVIEW AF_VOICEVIEW
  160. #define PF_FIREFOX AF_FIREFOX
  161. #define PF_UNKNOWN1 AF_UNKNOWN1
  162. #define PF_BAN AF_BAN
  163. #define PF_MAX AF_MAX
  164. #else /* USE_WS_PREFIX */
  165. #define WS_AF_UNSPEC 0
  166. #define WS_AF_UNIX 1
  167. #define WS_AF_INET 2
  168. #define WS_AF_IMPLINK 3
  169. #define WS_AF_PUP 4
  170. #define WS_AF_CHAOS 5
  171. #define WS_AF_NS 6
  172. #define WS_AF_IPX WS_AF_NS
  173. #define WS_AF_ISO 7
  174. #define WS_AF_OSI AF_ISO
  175. #define WS_AF_ECMA 8
  176. #define WS_AF_DATAKIT 9
  177. #define WS_AF_CCITT 10
  178. #define WS_AF_SNA 11
  179. #define WS_AF_DECnet 12
  180. #define WS_AF_DLI 13
  181. #define WS_AF_LAT 14
  182. #define WS_AF_HYLINK 15
  183. #define WS_AF_APPLETALK 16
  184. #define WS_AF_NETBIOS 17
  185. #define WS_AF_VOICEVIEW 18
  186. #define WS_AF_FIREFOX 19
  187. #define WS_AF_UNKNOWN1 20
  188. #define WS_AF_BAN 21
  189. #define WS_AF_ATM 22
  190. #define WS_AF_INET6 23
  191. #define WS_AF_CLUSTER 24
  192. #define WS_AF_12844 25
  193. #define WS_AF_IRDA 26
  194. #define WS_AF_MAX 27
  195. #endif /* USE_WS_PREFIX */
  196. /*
  197. * Types
  198. */
  199. #ifndef USE_WS_PREFIX
  200. #define SOCK_STREAM 1
  201. #define SOCK_DGRAM 2
  202. #define SOCK_RAW 3
  203. #define SOCK_RDM 4
  204. #define SOCK_SEQPACKET 5
  205. #else /* USE_WS_PREFIX */
  206. #define WS_SOCK_STREAM 1
  207. #define WS_SOCK_DGRAM 2
  208. #define WS_SOCK_RAW 3
  209. #define WS_SOCK_RDM 4
  210. #define WS_SOCK_SEQPACKET 5
  211. #endif /* USE_WS_PREFIX */
  212. /*
  213. * Protocols
  214. */
  215. #ifndef USE_WS_PREFIX
  216. #define IPPROTO_IP 0
  217. #define IPPROTO_ICMP 1
  218. #define IPPROTO_IGMP 2
  219. #define IPPROTO_GGP 3
  220. #define IPPROTO_TCP 6
  221. #define IPPROTO_UDP 17
  222. #define IPPROTO_IDP 22
  223. #define IPPROTO_ND 77
  224. #define IPPROTO_RAW 255
  225. #define IPPROTO_MAX 256
  226. #else /* USE_WS_PREFIX */
  227. #define WS_IPPROTO_IP 0
  228. #define WS_IPPROTO_ICMP 1
  229. #define WS_IPPROTO_IGMP 2
  230. #define WS_IPPROTO_GGP 3
  231. #define WS_IPPROTO_TCP 6
  232. #define WS_IPPROTO_UDP 17
  233. #define WS_IPPROTO_IDP 22
  234. #define WS_IPPROTO_ND 77
  235. #define WS_IPPROTO_RAW 255
  236. #define WS_IPPROTO_MAX 256
  237. #endif /* USE_WS_PREFIX */
  238. typedef struct WS(protoent)
  239. {
  240. char* p_name;
  241. char** p_aliases;
  242. short p_proto;
  243. } PROTOENT, *PPROTOENT, *LPPROTOENT;
  244. /*
  245. * Networks
  246. */
  247. struct WS(netent)
  248. {
  249. char* n_name; /* official name of net */
  250. char** n_aliases; /* alias list */
  251. short n_addrtype; /* net address type */
  252. u_long n_net; /* network # */
  253. };
  254. /*
  255. * Services
  256. */
  257. #ifndef USE_WS_PREFIX
  258. #define IPPORT_ECHO 7
  259. #define IPPORT_DISCARD 9
  260. #define IPPORT_SYSTAT 11
  261. #define IPPORT_DAYTIME 13
  262. #define IPPORT_NETSTAT 15
  263. #define IPPORT_FTP 21
  264. #define IPPORT_TELNET 23
  265. #define IPPORT_SMTP 25
  266. #define IPPORT_TIMESERVER 37
  267. #define IPPORT_NAMESERVER 42
  268. #define IPPORT_WHOIS 43
  269. #define IPPORT_MTP 57
  270. #define IPPORT_TFTP 69
  271. #define IPPORT_RJE 77
  272. #define IPPORT_FINGER 79
  273. #define IPPORT_TTYLINK 87
  274. #define IPPORT_SUPDUP 95
  275. #define IPPORT_EXECSERVER 512
  276. #define IPPORT_LOGINSERVER 513
  277. #define IPPORT_CMDSERVER 514
  278. #define IPPORT_EFSSERVER 520
  279. #define IPPORT_BIFFUDP 512
  280. #define IPPORT_WHOSERVER 513
  281. #define IPPORT_ROUTESERVER 520
  282. #define IPPORT_RESERVED 1024
  283. #else /* USE_WS_PREFIX */
  284. #define WS_IPPORT_ECHO 7
  285. #define WS_IPPORT_DISCARD 9
  286. #define WS_IPPORT_SYSTAT 11
  287. #define WS_IPPORT_DAYTIME 13
  288. #define WS_IPPORT_NETSTAT 15
  289. #define WS_IPPORT_FTP 21
  290. #define WS_IPPORT_TELNET 23
  291. #define WS_IPPORT_SMTP 25
  292. #define WS_IPPORT_TIMESERVER 37
  293. #define WS_IPPORT_NAMESERVER 42
  294. #define WS_IPPORT_WHOIS 43
  295. #define WS_IPPORT_MTP 57
  296. #define WS_IPPORT_TFTP 69
  297. #define WS_IPPORT_RJE 77
  298. #define WS_IPPORT_FINGER 79
  299. #define WS_IPPORT_TTYLINK 87
  300. #define WS_IPPORT_SUPDUP 95
  301. #define WS_IPPORT_EXECSERVER 512
  302. #define WS_IPPORT_LOGINSERVER 513
  303. #define WS_IPPORT_CMDSERVER 514
  304. #define WS_IPPORT_EFSSERVER 520
  305. #define WS_IPPORT_BIFFUDP 512
  306. #define WS_IPPORT_WHOSERVER 513
  307. #define WS_IPPORT_ROUTESERVER 520
  308. #define WS_IPPORT_RESERVED 1024
  309. #endif /* USE_WS_PREFIX */
  310. typedef struct WS(servent)
  311. {
  312. char* s_name; /* official service name */
  313. char** s_aliases; /* alias list */
  314. short s_port; /* port # */
  315. char* s_proto; /* protocol to use */
  316. } SERVENT, *PSERVENT, *LPSERVENT;
  317. /*
  318. * Hosts
  319. */
  320. typedef struct WS(hostent)
  321. {
  322. char* h_name; /* official name of host */
  323. char** h_aliases; /* alias list */
  324. short h_addrtype; /* host address type */
  325. short h_length; /* length of address */
  326. char** h_addr_list; /* list of addresses from name server */
  327. #define h_addr h_addr_list[0] /* address, for backward compat */
  328. } HOSTENT, *PHOSTENT, *LPHOSTENT;
  329. /*
  330. * Sockets
  331. */
  332. typedef UINT_PTR SOCKET;
  333. /*
  334. * This is used instead of -1, since the
  335. * SOCKET type is unsigned.
  336. */
  337. #define INVALID_SOCKET (~0)
  338. #define SOCKET_ERROR (-1)
  339. typedef struct WS(sockaddr)
  340. {
  341. u_short sa_family;
  342. char sa_data[14];
  343. } SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
  344. typedef struct WS(linger)
  345. {
  346. u_short l_onoff; /* option on/off */
  347. u_short l_linger; /* linger time */
  348. } LINGER, *PLINGER, *LPLINGER;
  349. /*
  350. * Select
  351. */
  352. #ifdef WS_DEFINE_SELECT
  353. /* Define our own version of select and the associated types and macros */
  354. # ifndef USE_WS_PREFIX
  355. # ifndef FD_SETSIZE
  356. # define FD_SETSIZE 64
  357. # endif
  358. # else
  359. # ifndef WS_FD_SETSIZE
  360. # define WS_FD_SETSIZE 64
  361. # endif
  362. # endif
  363. typedef struct WS(fd_set)
  364. {
  365. u_int fd_count; /* how many are SET? */
  366. # ifndef USE_WS_PREFIX
  367. SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
  368. # else
  369. SOCKET fd_array[WS_FD_SETSIZE];/* an array of SOCKETs */
  370. # endif
  371. } WS(fd_set), FD_SET, *PFD_SET, *LPFD_SET;
  372. #ifndef _TIMEVAL_DEFINED
  373. #define _TIMEVAL_DEFINED
  374. typedef struct WS(timeval)
  375. {
  376. long tv_sec; /* seconds */
  377. long tv_usec; /* and microseconds */
  378. } TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
  379. #endif
  380. #define WINE_FD_CLR(fd, set, cast) do { \
  381. u_int __i; \
  382. for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
  383. { \
  384. if (((cast*)(set))->fd_array[__i] == fd) \
  385. { \
  386. while (__i < ((cast*)(set))->fd_count-1) \
  387. { \
  388. ((cast*)(set))->fd_array[__i] = \
  389. ((cast*)(set))->fd_array[__i+1]; \
  390. __i++; \
  391. } \
  392. ((cast*)(set))->fd_count--; \
  393. break; \
  394. } \
  395. } \
  396. } while(0)
  397. #define __WS_FD_SET1(fd, set, cast) do { \
  398. if (((cast*)(set))->fd_count < FD_SETSIZE) \
  399. ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd); \
  400. } while(0)
  401. /* This version checks if the filedesc is already in the list, and appends it
  402. * only if it's not the case
  403. */
  404. #define __WS_FD_SET2(fd, set, cast) do { \
  405. u_int __i; \
  406. for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
  407. { \
  408. if (((cast*)(set))->fd_array[__i]==(fd)) \
  409. break; \
  410. } \
  411. if (__i == ((cast*)(set))->fd_count && ((cast*)(set))->fd_count < FD_SETSIZE) \
  412. { \
  413. ((cast*)(set))->fd_count++; \
  414. ((cast*)(set))->fd_array[__i]=(fd);\
  415. } \
  416. } while(0)
  417. #ifndef __WINE_WINSOCK2__
  418. #define __WS_FD_SET(fd, set, cast) __WS_FD_SET1((fd),(set), cast)
  419. #else
  420. #define __WS_FD_SET(fd, set, cast) __WS_FD_SET2((fd),(set), cast)
  421. #endif
  422. #ifndef USE_WS_PREFIX
  423. #define FD_CLR(fd, set) __WS_FD_CLR((fd),(set), fd_set)
  424. #define FD_SET(fd, set) __WS_FD_SET((fd),(set), fd_set)
  425. #define FD_ZERO(set) (((fd_set*)(set))->fd_count=0)
  426. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set*)(set))
  427. #else
  428. #define WS_FD_CLR(fd, set) WINE_FD_CLR((fd),(set), WS_fd_set)
  429. #define WS_FD_SET(fd, set) WINE_FD_SET((fd),(set), WS_fd_set)
  430. #define WS_FD_ZERO(set) ((WS_fd_set*)(set))->fd_count=0)
  431. #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (WS_fd_set*)(set))
  432. #endif
  433. int WINAPI __WSAFDIsSet(SOCKET,WS(fd_set)*);
  434. #endif /* WS_DEFINE_SELECT */
  435. /* we have to define hton/ntoh as macros to avoid conflicts with Unix headers */
  436. #ifndef USE_WS_PREFIX
  437. #undef htonl
  438. #undef htons
  439. #undef ntohl
  440. #undef ntohs
  441. #ifdef WORDS_BIGENDIAN
  442. #define htonl(l) ((u_long)(l))
  443. #define htons(s) ((u_short)(s))
  444. #define ntohl(l) ((u_long)(l))
  445. #define ntohs(s) ((u_short)(s))
  446. #else /* WORDS_BIGENDIAN */
  447. inline static u_short __wine_ushort_swap(u_short s)
  448. {
  449. return (s >> 8) | (s << 8);
  450. }
  451. inline static u_long __wine_ulong_swap(u_long l)
  452. {
  453. return ((u_long)__wine_ushort_swap((u_short)l) << 16) | __wine_ushort_swap((u_short)(l >> 16));
  454. }
  455. #define htonl(l) __wine_ulong_swap(l)
  456. #define htons(s) __wine_ushort_swap(s)
  457. #define ntohl(l) __wine_ulong_swap(l)
  458. #define ntohs(s) __wine_ushort_swap(s)
  459. #endif /* WORDS_BIGENDIAN */
  460. #endif /* USE_WS_PREFIX */
  461. /*
  462. * Internet address (old style... should be updated)
  463. */
  464. #ifndef USE_WS_PREFIX
  465. #define IN_CLASSA_NSHIFT 24
  466. #define IN_CLASSA_MAX 128
  467. #define IN_CLASSA_NET 0xff000000
  468. #define IN_CLASSA_HOST 0x00ffffff
  469. #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
  470. #define IN_CLASSB_NSHIFT 16
  471. #define IN_CLASSB_MAX 65536
  472. #define IN_CLASSB_NET 0xffff0000
  473. #define IN_CLASSB_HOST 0x0000ffff
  474. #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
  475. #define IN_CLASSC_NSHIFT 8
  476. #define IN_CLASSC_NET 0xffffff00
  477. #define IN_CLASSC_HOST 0x000000ff
  478. #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
  479. #else
  480. #define WS_IN_CLASSA_NSHIFT 24
  481. #define WS_IN_CLASSA_MAX 128
  482. #define WS_IN_CLASSA_NET 0xff000000
  483. #define WS_IN_CLASSA_HOST 0x00ffffff
  484. #define WS_IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
  485. #define WS_IN_CLASSB_NSHIFT 16
  486. #define WS_IN_CLASSB_MAX 65536
  487. #define WS_IN_CLASSB_NET 0xffff0000
  488. #define WS_IN_CLASSB_HOST 0x0000ffff
  489. #define WS_IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
  490. #define WS_IN_CLASSC_NSHIFT 8
  491. #define WS_IN_CLASSC_NET 0xffffff00
  492. #define WS_IN_CLASSC_HOST 0x000000ff
  493. #define WS_IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
  494. #endif /* USE_WS_PREFIX */
  495. #ifndef USE_WS_PREFIX
  496. #define INADDR_ANY (u_long)0x00000000
  497. #define INADDR_LOOPBACK 0x7f000001
  498. #define INADDR_BROADCAST (u_long)0xffffffff
  499. #define INADDR_NONE 0xffffffff
  500. #else
  501. #define WS_INADDR_ANY (u_long)0x00000000
  502. #define WS_INADDR_LOOPBACK 0x7f000001
  503. #define WS_INADDR_BROADCAST (u_long)0xffffffff
  504. #define WS_INADDR_NONE 0xffffffff
  505. #endif /* USE_WS_PREFIX */
  506. typedef struct WS(in_addr)
  507. {
  508. union {
  509. struct {
  510. u_char s_b1,s_b2,s_b3,s_b4;
  511. } S_un_b;
  512. struct {
  513. u_short s_w1,s_w2;
  514. } S_un_w;
  515. u_long S_addr;
  516. } S_un;
  517. #ifndef USE_WS_PREFIX
  518. #define s_addr S_un.S_addr
  519. #define s_host S_un.S_un_b.s_b2
  520. #define s_net S_un.S_un_b.s_b1
  521. #define s_imp S_un.S_un_w.s_w2
  522. #define s_impno S_un.S_un_b.s_b4
  523. #define s_lh S_un.S_un_b.s_b3
  524. #else
  525. #define WS_s_addr S_un.S_addr
  526. #define WS_s_host S_un.S_un_b.s_b2
  527. #define WS_s_net S_un.S_un_b.s_b1
  528. #define WS_s_imp S_un.S_un_w.s_w2
  529. #define WS_s_impno S_un.S_un_b.s_b4
  530. #define WS_s_lh S_un.S_un_b.s_b3
  531. #endif /* USE_WS_PREFIX */
  532. } IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
  533. typedef struct WS(sockaddr_in)
  534. {
  535. short sin_family;
  536. u_short sin_port;
  537. struct WS(in_addr) sin_addr;
  538. char sin_zero[8];
  539. } SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
  540. /*
  541. * Multicast group information
  542. */
  543. #if !defined(__WINE_WINSOCK2__)
  544. struct WS(ip_mreq)
  545. {
  546. struct WS(in_addr) imr_multiaddr;
  547. struct WS(in_addr) imr_interface;
  548. };
  549. #endif
  550. /*
  551. * WSAStartup
  552. */
  553. #define WSADESCRIPTION_LEN 256
  554. #define WSASYS_STATUS_LEN 128
  555. typedef struct WS(WSAData)
  556. {
  557. WORD wVersion;
  558. WORD wHighVersion;
  559. char szDescription[WSADESCRIPTION_LEN+1];
  560. char szSystemStatus[WSASYS_STATUS_LEN+1];
  561. WORD iMaxSockets;
  562. WORD iMaxUdpDg;
  563. char *lpVendorInfo;
  564. } WSADATA, *LPWSADATA;
  565. /*
  566. * {get,set}sockopt
  567. */
  568. #ifndef USE_WS_PREFIX
  569. #define SOL_SOCKET 0xffff
  570. #define SO_DEBUG 0x0001
  571. #define SO_ACCEPTCONN 0x0002
  572. #define SO_REUSEADDR 0x0004
  573. #define SO_KEEPALIVE 0x0008
  574. #define SO_DONTROUTE 0x0010
  575. #define SO_BROADCAST 0x0020
  576. #define SO_USELOOPBACK 0x0040
  577. #define SO_LINGER 0x0080
  578. #define SO_OOBINLINE 0x0100
  579. #define SO_DONTLINGER (u_int)(~SO_LINGER)
  580. #define SO_SNDBUF 0x1001
  581. #define SO_RCVBUF 0x1002
  582. #define SO_SNDLOWAT 0x1003
  583. #define SO_RCVLOWAT 0x1004
  584. #define SO_SNDTIMEO 0x1005
  585. #define SO_RCVTIMEO 0x1006
  586. #define SO_ERROR 0x1007
  587. #define SO_TYPE 0x1008
  588. #define IOCPARM_MASK 0x7f
  589. #define IOC_VOID 0x20000000
  590. #define IOC_OUT 0x40000000
  591. #define IOC_IN 0x80000000
  592. #define IOC_INOUT (IOC_IN|IOC_OUT)
  593. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  594. #define _IOR(x,y,t) (IOC_OUT|(((UINT)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  595. #define _IOW(x,y,t) (IOC_IN|(((UINT)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  596. #else
  597. #define WS_SOL_SOCKET 0xffff
  598. #define WS_SO_DEBUG 0x0001
  599. #define WS_SO_ACCEPTCONN 0x0002
  600. #define WS_SO_REUSEADDR 0x0004
  601. #define WS_SO_KEEPALIVE 0x0008
  602. #define WS_SO_DONTROUTE 0x0010
  603. #define WS_SO_BROADCAST 0x0020
  604. #define WS_SO_USELOOPBACK 0x0040
  605. #define WS_SO_LINGER 0x0080
  606. #define WS_SO_OOBINLINE 0x0100
  607. #define WS_SO_DONTLINGER (u_int)(~WS_SO_LINGER)
  608. #define WS_SO_SNDBUF 0x1001
  609. #define WS_SO_RCVBUF 0x1002
  610. #define WS_SO_SNDLOWAT 0x1003
  611. #define WS_SO_RCVLOWAT 0x1004
  612. #define WS_SO_SNDTIMEO 0x1005
  613. #define WS_SO_RCVTIMEO 0x1006
  614. #define WS_SO_ERROR 0x1007
  615. #define WS_SO_TYPE 0x1008
  616. #define WS_IOCPARM_MASK 0x7f
  617. #define WS_IOC_VOID 0x20000000
  618. #define WS_IOC_OUT 0x40000000
  619. #define WS_IOC_IN 0x80000000
  620. #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
  621. #define WS__IO(x,y) (WS_IOC_VOID|((x)<<8)|(y))
  622. #define WS__IOR(x,y,t) (WS_IOC_OUT|(((long)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
  623. #define WS__IOW(x,y,t) (WS_IOC_IN|(((long)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
  624. #endif
  625. /* IPPROTO_TCP options */
  626. #ifndef USE_WS_PREFIX
  627. #define TCP_NODELAY 1
  628. #else
  629. #define WS_TCP_NODELAY 1
  630. #endif
  631. /* IPPROTO_IP options */
  632. #ifndef __WINE_WINSOCK2__ /* WinSock2 has different values for the IP_ constants */
  633. # ifndef USE_WS_PREFIX
  634. # define IP_OPTIONS 1
  635. # define IP_MULTICAST_IF 2
  636. # define IP_MULTICAST_TTL 3
  637. # define IP_MULTICAST_LOOP 4
  638. # define IP_ADD_MEMBERSHIP 5
  639. # define IP_DROP_MEMBERSHIP 6
  640. # define IP_TTL 7
  641. # define IP_TOS 8
  642. # define IP_DONTFRAGMENT 9
  643. # else
  644. # define WS_IP_OPTIONS 1
  645. # define WS_IP_MULTICAST_IF 2
  646. # define WS_IP_MULTICAST_TTL 3
  647. # define WS_IP_MULTICAST_LOOP 4
  648. # define WS_IP_ADD_MEMBERSHIP 5
  649. # define WS_IP_DROP_MEMBERSHIP 6
  650. # define WS_IP_TTL 7
  651. # define WS_IP_TOS 8
  652. # define WS_IP_DONTFRAGMENT 9
  653. # endif
  654. #endif
  655. /*
  656. * Socket I/O flags (supported by spec 1.1)
  657. */
  658. #ifndef USE_WS_PREFIX
  659. #define FIONREAD _IOR('f', 127, u_long)
  660. #define FIONBIO _IOW('f', 126, u_long)
  661. #define SIOCATMARK _IOR('s', 7, u_long)
  662. #else
  663. #define WS_FIONREAD WS__IOR('f', 127, u_long)
  664. #define WS_FIONBIO WS__IOW('f', 126, u_long)
  665. #define WS_SIOCATMARK WS__IOR('s', 7, u_long)
  666. #endif
  667. /*
  668. * Maximum queue length specifiable by listen.
  669. */
  670. #ifndef USE_WS_PREFIX
  671. #define SOMAXCONN 5
  672. #define MSG_OOB 0x0001
  673. #define MSG_PEEK 0x0002
  674. #define MSG_DONTROUTE 0x0004
  675. #define MSG_MAXIOVLEN 0x000a
  676. #define MSG_PARTIAL 0x8000
  677. #else /* USE_WS_PREFIX */
  678. #define WS_SOMAXCONN 5
  679. #define WS_MSG_OOB 0x0001
  680. #define WS_MSG_PEEK 0x0002
  681. #define WS_MSG_DONTROUTE 0x0004
  682. #define WS_MSG_MAXIOVLEN 0x000a
  683. #define WS_MSG_PARTIAL 0x8000
  684. #endif /* USE_WS_PREFIX */
  685. /*
  686. * Define constant based on rfc883, used by gethostbyxxxx() calls.
  687. */
  688. #ifndef USE_WS_PREFIX
  689. #define MAXGETHOSTSTRUCT 1024
  690. #else
  691. #define MAXGETHOSTSTRUCT 1024
  692. #endif
  693. /*
  694. * Define flags to be used with the WSAAsyncSelect() call.
  695. */
  696. #define FD_READ 0x00000001
  697. #define FD_WRITE 0x00000002
  698. #define FD_OOB 0x00000004
  699. #define FD_ACCEPT 0x00000008
  700. #define FD_CONNECT 0x00000010
  701. #define FD_CLOSE 0x00000020
  702. /* internal per-socket flags */
  703. #ifdef __WINESRC__
  704. #define FD_WINE_LISTENING 0x10000000
  705. #define FD_WINE_NONBLOCKING 0x20000000
  706. #define FD_WINE_CONNECTED 0x40000000
  707. #define FD_WINE_RAW 0x80000000
  708. #define FD_WINE_INTERNAL 0xFFFF0000
  709. #endif
  710. /*
  711. * All Windows Sockets error constants are biased by WSABASEERR from
  712. * the "normal"
  713. */
  714. #define WSABASEERR 10000
  715. /*
  716. * Windows Sockets definitions of regular Microsoft C error constants
  717. */
  718. #define WSAEINTR (WSABASEERR+4)
  719. #define WSAEBADF (WSABASEERR+9)
  720. #define WSAEACCES (WSABASEERR+13)
  721. #define WSAEFAULT (WSABASEERR+14)
  722. #define WSAEINVAL (WSABASEERR+22)
  723. #define WSAEMFILE (WSABASEERR+24)
  724. /*
  725. * Windows Sockets definitions of regular Berkeley error constants
  726. */
  727. #define WSAEWOULDBLOCK (WSABASEERR+35)
  728. #define WSAEINPROGRESS (WSABASEERR+36)
  729. #define WSAEALREADY (WSABASEERR+37)
  730. #define WSAENOTSOCK (WSABASEERR+38)
  731. #define WSAEDESTADDRREQ (WSABASEERR+39)
  732. #define WSAEMSGSIZE (WSABASEERR+40)
  733. #define WSAEPROTOTYPE (WSABASEERR+41)
  734. #define WSAENOPROTOOPT (WSABASEERR+42)
  735. #define WSAEPROTONOSUPPORT (WSABASEERR+43)
  736. #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
  737. #define WSAEOPNOTSUPP (WSABASEERR+45)
  738. #define WSAEPFNOSUPPORT (WSABASEERR+46)
  739. #define WSAEAFNOSUPPORT (WSABASEERR+47)
  740. #define WSAEADDRINUSE (WSABASEERR+48)
  741. #define WSAEADDRNOTAVAIL (WSABASEERR+49)
  742. #define WSAENETDOWN (WSABASEERR+50)
  743. #define WSAENETUNREACH (WSABASEERR+51)
  744. #define WSAENETRESET (WSABASEERR+52)
  745. #define WSAECONNABORTED (WSABASEERR+53)
  746. #define WSAECONNRESET (WSABASEERR+54)
  747. #define WSAENOBUFS (WSABASEERR+55)
  748. #define WSAEISCONN (WSABASEERR+56)
  749. #define WSAENOTCONN (WSABASEERR+57)
  750. #define WSAESHUTDOWN (WSABASEERR+58)
  751. #define WSAETOOMANYREFS (WSABASEERR+59)
  752. #define WSAETIMEDOUT (WSABASEERR+60)
  753. #define WSAECONNREFUSED (WSABASEERR+61)
  754. #define WSAELOOP (WSABASEERR+62)
  755. #define WSAENAMETOOLONG (WSABASEERR+63)
  756. #define WSAEHOSTDOWN (WSABASEERR+64)
  757. #define WSAEHOSTUNREACH (WSABASEERR+65)
  758. #define WSAENOTEMPTY (WSABASEERR+66)
  759. #define WSAEPROCLIM (WSABASEERR+67)
  760. #define WSAEUSERS (WSABASEERR+68)
  761. #define WSAEDQUOT (WSABASEERR+69)
  762. #define WSAESTALE (WSABASEERR+70)
  763. #define WSAEREMOTE (WSABASEERR+71)
  764. #define WSAEDISCON (WSABASEERR+101)
  765. /*
  766. * Extended Windows Sockets error constant definitions
  767. */
  768. #define WSASYSNOTREADY (WSABASEERR+91)
  769. #define WSAVERNOTSUPPORTED (WSABASEERR+92)
  770. #define WSANOTINITIALISED (WSABASEERR+93)
  771. #define WSAEDISCON (WSABASEERR+101)
  772. #define WSAENOMORE (WSABASEERR+102)
  773. #define WSAECANCELLED (WSABASEERR+103)
  774. #define WSAEINVALIDPROCTABLE (WSABASEERR+104)
  775. #define WSAEINVALIDPROVIDER (WSABASEERR+105)
  776. #define WSAEPROVIDERFAILEDINIT (WSABASEERR+106)
  777. #define WSASYSCALLFAILURE (WSABASEERR+107)
  778. #define WSASERVICE_NOT_FOUND (WSABASEERR+108)
  779. #define WSATYPE_NOT_FOUND (WSABASEERR+109)
  780. #define WSA_E_NO_MORE (WSABASEERR+110)
  781. #define WSA_E_CANCELLED (WSABASEERR+111)
  782. #define WSAEREFUSED (WSABASEERR+112)
  783. /*
  784. * Error return codes from gethostbyname() and gethostbyaddr()
  785. * (when using the resolver). Note that these errors are
  786. * retrieved via WSAGetLastError() and must therefore follow
  787. * the rules for avoiding clashes with error numbers from
  788. * specific implementations or language run-time systems.
  789. * For this reason the codes are based at WSABASEERR+1001.
  790. * Note also that [WSA]NO_ADDRESS is defined only for
  791. * compatibility purposes.
  792. */
  793. #ifndef USE_WS_PREFIX
  794. #define h_errno WSAGetLastError()
  795. #else
  796. #define WS_h_errno WSAGetLastError()
  797. #endif
  798. /* Authoritative Answer: Host not found */
  799. #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
  800. /* Non-Authoritative: Host not found, or SERVERFAIL */
  801. #define WSATRY_AGAIN (WSABASEERR+1002)
  802. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  803. #define WSANO_RECOVERY (WSABASEERR+1003)
  804. /* Valid name, no data record of requested type */
  805. #define WSANO_DATA (WSABASEERR+1004)
  806. /* no address, look for MX record */
  807. #define WSANO_ADDRESS WSANO_DATA
  808. #ifndef USE_WS_PREFIX
  809. #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
  810. #define TRY_AGAIN WSATRY_AGAIN
  811. #define NO_RECOVERY WSANO_RECOVERY
  812. #define NO_DATA WSANO_DATA
  813. #define NO_ADDRESS WSANO_ADDRESS
  814. #endif /* USE_WS_PREFIX */
  815. /*
  816. * Windows message parameter composition and decomposition
  817. * macros.
  818. */
  819. /*
  820. * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  821. * when constructing the response to a WSAAsyncGetXByY() routine.
  822. */
  823. #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
  824. /*
  825. * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  826. * when constructing the response to WSAAsyncSelect().
  827. */
  828. #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
  829. /*
  830. * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  831. * to extract the buffer length from the lParam in the response
  832. * to a WSAGetXByY().
  833. */
  834. #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
  835. /*
  836. * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  837. * to extract the error code from the lParam in the response
  838. * to a WSAGetXByY().
  839. */
  840. #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
  841. /*
  842. * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  843. * to extract the event code from the lParam in the response
  844. * to a WSAAsyncSelect().
  845. */
  846. #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
  847. /*
  848. * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  849. * to extract the error code from the lParam in the response
  850. * to a WSAAsyncSelect().
  851. */
  852. #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
  853. /*
  854. * Prototypes
  855. *
  856. * Remember to keep this section in sync with the
  857. * "Winsock Function Typedefs" section in winsock2.h.
  858. */
  859. #if !defined(__WINE_WINSOCK2__) || WS_API_PROTOTYPES
  860. HANDLE WINAPI WSAAsyncGetHostByAddr(HWND,u_int,const char*,int,int,char*,int);
  861. HANDLE WINAPI WSAAsyncGetHostByName(HWND,u_int,const char*,char*,int);
  862. HANDLE WINAPI WSAAsyncGetProtoByName(HWND,u_int,const char*,char*,int);
  863. HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND,u_int,int,char*,int);
  864. HANDLE WINAPI WSAAsyncGetServByName(HWND,u_int,const char*,const char*,char*,int);
  865. HANDLE WINAPI WSAAsyncGetServByPort(HWND,u_int,int,const char*,char*,int);
  866. int WINAPI WSAAsyncSelect(SOCKET,HWND,u_int,long);
  867. int WINAPI WSACancelAsyncRequest(HANDLE);
  868. int WINAPI WSACancelBlockingCall(void);
  869. int WINAPI WSACleanup(void);
  870. int WINAPI WSAGetLastError(void);
  871. BOOL WINAPI WSAIsBlocking(void);
  872. FARPROC WINAPI WSASetBlockingHook(FARPROC);
  873. void WINAPI WSASetLastError(int);
  874. int WINAPI WSAStartup(WORD,LPWSADATA);
  875. int WINAPI WSAUnhookBlockingHook(void);
  876. SOCKET WINAPI WS(accept)(SOCKET,struct WS(sockaddr)*,int*);
  877. int WINAPI WS(bind)(SOCKET,const struct WS(sockaddr)*,int);
  878. int WINAPI WS(closesocket)(SOCKET);
  879. int WINAPI WS(connect)(SOCKET,const struct WS(sockaddr)*,int);
  880. struct WS(hostent)* WINAPI WS(gethostbyaddr)(const char*,int,int);
  881. struct WS(hostent)* WINAPI WS(gethostbyname)(const char*);
  882. /* gethostname not defined because of conflicts with unistd.h */
  883. int WINAPI WS(getpeername)(SOCKET,struct WS(sockaddr)*,int*);
  884. struct WS(protoent)* WINAPI WS(getprotobyname)(const char*);
  885. struct WS(protoent)* WINAPI WS(getprotobynumber)(int);
  886. #ifdef WS_DEFINE_SELECT
  887. int WINAPI WS(select)(int,WS(fd_set)*,WS(fd_set)*,WS(fd_set)*,const struct WS(timeval)*);
  888. #endif
  889. struct WS(servent)* WINAPI WS(getservbyname)(const char*,const char*);
  890. struct WS(servent)* WINAPI WS(getservbyport)(int,const char*);
  891. int WINAPI WS(getsockname)(SOCKET,struct WS(sockaddr)*,int*);
  892. int WINAPI WS(getsockopt)(SOCKET,int,int,char*,int*);
  893. unsigned long WINAPI WS(inet_addr)(const char*);
  894. char* WINAPI WS(inet_ntoa)(struct WS(in_addr));
  895. int WINAPI WS(ioctlsocket)(SOCKET,long,u_long*);
  896. int WINAPI WS(listen)(SOCKET,int);
  897. int WINAPI WS(recv)(SOCKET,char*,int,int);
  898. int WINAPI WS(recvfrom)(SOCKET,char*,int,int,struct WS(sockaddr)*,int*);
  899. int WINAPI WS(send)(SOCKET,const char*,int,int);
  900. int WINAPI WS(sendto)(SOCKET,const char*,int,int,const struct WS(sockaddr)*,int);
  901. int WINAPI WS(setsockopt)(SOCKET,int,int,const char*,int);
  902. int WINAPI WS(shutdown)(SOCKET,int);
  903. SOCKET WINAPI WS(socket)(int,int,int);
  904. #endif /* !defined(__WINE_WINSOCK2__) || WS_API_PROTOTYPES */
  905. #include <poppack.h>
  906. #ifdef __cplusplus
  907. }
  908. #endif
  909. #ifndef __WINE_WINSOCK2__
  910. #undef WS
  911. #undef WS_API_PROTOTYPES
  912. #undef WS_API_TYPEDEFS
  913. #endif
  914. #endif /* _WINSOCKAPI_ */