Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

491 lines
13 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. mswsock.h
  5. Abstract:
  6. This module contains the Microsoft-specific extensions to the Windows
  7. Sockets API.
  8. Revision History:
  9. --*/
  10. #ifndef _MSWSOCK_
  11. #define _MSWSOCK_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*
  19. * Options for connect and disconnect data and options. Used only by
  20. * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  21. */
  22. #define SO_CONNDATA 0x7000
  23. #define SO_CONNOPT 0x7001
  24. #define SO_DISCDATA 0x7002
  25. #define SO_DISCOPT 0x7003
  26. #define SO_CONNDATALEN 0x7004
  27. #define SO_CONNOPTLEN 0x7005
  28. #define SO_DISCDATALEN 0x7006
  29. #define SO_DISCOPTLEN 0x7007
  30. /*
  31. * Option for opening sockets for synchronous access.
  32. */
  33. #define SO_OPENTYPE 0x7008
  34. #define SO_SYNCHRONOUS_ALERT 0x10
  35. #define SO_SYNCHRONOUS_NONALERT 0x20
  36. /*
  37. * Other NT-specific options.
  38. */
  39. #define SO_MAXDG 0x7009
  40. #define SO_MAXPATHDG 0x700A
  41. #define SO_UPDATE_ACCEPT_CONTEXT 0x700B
  42. #define SO_CONNECT_TIME 0x700C
  43. #define SO_UPDATE_CONNECT_CONTEXT 0x7010
  44. /*
  45. * TCP options.
  46. */
  47. #define TCP_BSDURGENT 0x7000
  48. /*
  49. * MS Transport Provider IOCTL to control
  50. * reporting PORT_UNREACHABLE messages
  51. * on UDP sockets via recv/WSARecv/etc.
  52. * Path TRUE in input buffer to enable (default if supported),
  53. * FALSE to disable.
  54. */
  55. #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
  56. /*
  57. * Microsoft extended APIs.
  58. */
  59. int
  60. PASCAL FAR
  61. WSARecvEx (
  62. SOCKET s,
  63. char FAR *buf,
  64. int len,
  65. int FAR *flags
  66. );
  67. typedef struct _TRANSMIT_FILE_BUFFERS {
  68. LPVOID Head;
  69. DWORD HeadLength;
  70. LPVOID Tail;
  71. DWORD TailLength;
  72. } TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, FAR *LPTRANSMIT_FILE_BUFFERS;
  73. #define TF_DISCONNECT 0x01
  74. #define TF_REUSE_SOCKET 0x02
  75. #define TF_WRITE_BEHIND 0x04
  76. #define TF_USE_DEFAULT_WORKER 0x00
  77. #define TF_USE_SYSTEM_THREAD 0x10
  78. #define TF_USE_KERNEL_APC 0x20
  79. BOOL
  80. PASCAL FAR
  81. TransmitFile (
  82. IN SOCKET hSocket,
  83. IN HANDLE hFile,
  84. IN DWORD nNumberOfBytesToWrite,
  85. IN DWORD nNumberOfBytesPerSend,
  86. IN LPOVERLAPPED lpOverlapped,
  87. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
  88. IN DWORD dwReserved
  89. );
  90. BOOL
  91. PASCAL FAR
  92. AcceptEx (
  93. IN SOCKET sListenSocket,
  94. IN SOCKET sAcceptSocket,
  95. IN PVOID lpOutputBuffer,
  96. IN DWORD dwReceiveDataLength,
  97. IN DWORD dwLocalAddressLength,
  98. IN DWORD dwRemoteAddressLength,
  99. OUT LPDWORD lpdwBytesReceived,
  100. IN LPOVERLAPPED lpOverlapped
  101. );
  102. VOID
  103. PASCAL FAR
  104. GetAcceptExSockaddrs (
  105. IN PVOID lpOutputBuffer,
  106. IN DWORD dwReceiveDataLength,
  107. IN DWORD dwLocalAddressLength,
  108. IN DWORD dwRemoteAddressLength,
  109. OUT struct sockaddr **LocalSockaddr,
  110. OUT LPINT LocalSockaddrLength,
  111. OUT struct sockaddr **RemoteSockaddr,
  112. OUT LPINT RemoteSockaddrLength
  113. );
  114. /*
  115. * "QueryInterface" versions of the above APIs.
  116. */
  117. typedef
  118. BOOL
  119. (PASCAL FAR * LPFN_TRANSMITFILE)(
  120. IN SOCKET hSocket,
  121. IN HANDLE hFile,
  122. IN DWORD nNumberOfBytesToWrite,
  123. IN DWORD nNumberOfBytesPerSend,
  124. IN LPOVERLAPPED lpOverlapped,
  125. IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
  126. IN DWORD dwReserved
  127. );
  128. #define WSAID_TRANSMITFILE \
  129. {0xb5367df0,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
  130. typedef
  131. BOOL
  132. (PASCAL FAR * LPFN_ACCEPTEX)(
  133. IN SOCKET sListenSocket,
  134. IN SOCKET sAcceptSocket,
  135. IN PVOID lpOutputBuffer,
  136. IN DWORD dwReceiveDataLength,
  137. IN DWORD dwLocalAddressLength,
  138. IN DWORD dwRemoteAddressLength,
  139. OUT LPDWORD lpdwBytesReceived,
  140. IN LPOVERLAPPED lpOverlapped
  141. );
  142. #define WSAID_ACCEPTEX \
  143. {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
  144. typedef
  145. VOID
  146. (PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
  147. IN PVOID lpOutputBuffer,
  148. IN DWORD dwReceiveDataLength,
  149. IN DWORD dwLocalAddressLength,
  150. IN DWORD dwRemoteAddressLength,
  151. OUT struct sockaddr **LocalSockaddr,
  152. OUT LPINT LocalSockaddrLength,
  153. OUT struct sockaddr **RemoteSockaddr,
  154. OUT LPINT RemoteSockaddrLength
  155. );
  156. #define WSAID_GETACCEPTEXSOCKADDRS \
  157. {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
  158. #if _MSC_VER >= 1200
  159. #pragma warning(push)
  160. #endif
  161. #pragma warning(disable:4201) /* Nonstandard extension, nameless struct/union */
  162. typedef struct _TRANSMIT_PACKETS_ELEMENT {
  163. ULONG dwElFlags;
  164. #define TP_ELEMENT_MEMORY 1
  165. #define TP_ELEMENT_FILE 2
  166. #define TP_ELEMENT_EOP 4
  167. ULONG cLength;
  168. union {
  169. struct {
  170. LARGE_INTEGER nFileOffset;
  171. HANDLE hFile;
  172. };
  173. PVOID pBuffer;
  174. };
  175. } TRANSMIT_PACKETS_ELEMENT, *PTRANSMIT_PACKETS_ELEMENT, FAR *LPTRANSMIT_PACKETS_ELEMENT;
  176. #if _MSC_VER >= 1200
  177. #pragma warning(pop)
  178. #else
  179. #pragma warning(default:4201)
  180. #endif
  181. #define TP_DISCONNECT TF_DISCONNECT
  182. #define TP_REUSE_SOCKET TF_REUSE_SOCKET
  183. #define TP_USE_DEFAULT_WORKER TF_USE_DEFAULT_WORKER
  184. #define TP_USE_SYSTEM_THREAD TF_USE_SYSTEM_THREAD
  185. #define TP_USE_KERNEL_APC TF_USE_KERNEL_APC
  186. typedef
  187. BOOL
  188. (PASCAL FAR * LPFN_TRANSMITPACKETS) (
  189. SOCKET hSocket,
  190. LPTRANSMIT_PACKETS_ELEMENT lpPacketArray,
  191. DWORD nElementCount,
  192. DWORD nSendSize,
  193. LPOVERLAPPED lpOverlapped,
  194. DWORD dwFlags
  195. );
  196. #define WSAID_TRANSMITPACKETS \
  197. {0xd9689da0,0x1f90,0x11d3,{0x99,0x71,0x00,0xc0,0x4f,0x68,0xc8,0x76}}
  198. typedef
  199. BOOL
  200. (PASCAL FAR * LPFN_CONNECTEX) (
  201. IN SOCKET s,
  202. IN const struct sockaddr FAR *name,
  203. IN int namelen,
  204. IN PVOID lpSendBuffer OPTIONAL,
  205. IN DWORD dwSendDataLength,
  206. OUT LPDWORD lpdwBytesSent,
  207. IN LPOVERLAPPED lpOverlapped
  208. );
  209. #define WSAID_CONNECTEX \
  210. {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}
  211. typedef
  212. BOOL
  213. (PASCAL FAR * LPFN_DISCONNECTEX) (
  214. IN SOCKET s,
  215. IN LPOVERLAPPED lpOverlapped,
  216. IN DWORD dwFlags,
  217. IN DWORD dwReserved
  218. );
  219. #define WSAID_DISCONNECTEX \
  220. {0x7fda2e11,0x8630,0x436f,{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}
  221. #define DE_REUSE_SOCKET TF_REUSE_SOCKET
  222. /*
  223. * Network-location awareness -- Name registration values for use
  224. * with WSASetService and other structures.
  225. */
  226. // {6642243A-3BA8-4aa6-BAA5-2E0BD71FDD83}
  227. #define NLA_NAMESPACE_GUID \
  228. {0x6642243a,0x3ba8,0x4aa6,{0xba,0xa5,0x2e,0xb,0xd7,0x1f,0xdd,0x83}}
  229. // {6642243A-3BA8-4aa6-BAA5-2E0BD71FDD83}
  230. #define NLA_SERVICE_CLASS_GUID \
  231. {0x37e515,0xb5c9,0x4a43,{0xba,0xda,0x8b,0x48,0xa8,0x7a,0xd2,0x39}}
  232. #define NLA_ALLUSERS_NETWORK 0x00000001
  233. #define NLA_FRIENDLY_NAME 0x00000002
  234. typedef enum _NLA_BLOB_DATA_TYPE {
  235. NLA_RAW_DATA = 0,
  236. NLA_INTERFACE = 1,
  237. NLA_802_1X_LOCATION = 2,
  238. NLA_CONNECTIVITY = 3,
  239. NLA_ICS = 4,
  240. } NLA_BLOB_DATA_TYPE, *PNLA_BLOB_DATA_TYPE;
  241. typedef enum _NLA_CONNECTIVITY_TYPE {
  242. NLA_NETWORK_AD_HOC = 0,
  243. NLA_NETWORK_MANAGED = 1,
  244. NLA_NETWORK_UNMANAGED = 2,
  245. NLA_NETWORK_UNKNOWN = 3,
  246. } NLA_CONNECTIVITY_TYPE, *PNLA_CONNECTIVITY_TYPE;
  247. typedef enum _NLA_INTERNET {
  248. NLA_INTERNET_UNKNOWN = 0,
  249. NLA_INTERNET_NO = 1,
  250. NLA_INTERNET_YES = 2,
  251. } NLA_INTERNET, *PNLA_INTERNET;
  252. typedef struct _NLA_BLOB {
  253. struct {
  254. NLA_BLOB_DATA_TYPE type;
  255. DWORD dwSize;
  256. DWORD nextOffset;
  257. } header;
  258. union {
  259. // header.type -> NLA_RAW_DATA
  260. CHAR rawData[1];
  261. // header.type -> NLA_INTERFACE
  262. struct {
  263. DWORD dwType;
  264. DWORD dwSpeed;
  265. CHAR adapterName[1];
  266. } interfaceData;
  267. // header.type -> NLA_802_1X_LOCATION
  268. struct {
  269. CHAR information[1];
  270. } locationData;
  271. // header.type -> NLA_CONNECTIVITY
  272. struct {
  273. NLA_CONNECTIVITY_TYPE type;
  274. NLA_INTERNET internet;
  275. } connectivity;
  276. // header.type -> NLA_ICS
  277. struct {
  278. struct {
  279. DWORD speed;
  280. DWORD type;
  281. DWORD state;
  282. WCHAR machineName[256];
  283. WCHAR sharedAdapterName[256];
  284. } remote;
  285. } ICS;
  286. } data;
  287. } NLA_BLOB, *PNLA_BLOB, * FAR LPNLA_BLOB;
  288. typedef struct _WSAMSG {
  289. LPSOCKADDR name; /* Remote address */
  290. INT namelen; /* Remote address length */
  291. LPWSABUF lpBuffers; /* Data buffer array */
  292. DWORD dwBufferCount; /* Number of elements in the array */
  293. WSABUF Control; /* Control buffer */
  294. DWORD dwFlags; /* Flags */
  295. } WSAMSG, *PWSAMSG, * FAR LPWSAMSG;
  296. /*
  297. * Layout of ancillary data objects in the control buffer
  298. */
  299. typedef struct _WSACMSGHDR {
  300. SIZE_T cmsg_len;
  301. INT cmsg_level;
  302. INT cmsg_type;
  303. /* followed by UCHAR cmsg_data[] */
  304. } WSACMSGHDR, *PWSACMSGHDR, FAR *LPWSACMSGHDR;
  305. /*
  306. * Alignment macros for header and data members of
  307. * the control buffer.
  308. */
  309. #define WSA_CMSGHDR_ALIGN(length) \
  310. ( ((length) + TYPE_ALIGNMENT(WSACMSGHDR)-1) & \
  311. (~(TYPE_ALIGNMENT(WSACMSGHDR)-1)) ) \
  312. #define WSA_CMSGDATA_ALIGN(length) \
  313. ( ((length) + MAX_NATURAL_ALIGNMENT-1) & \
  314. (~(MAX_NATURAL_ALIGNMENT-1)) )
  315. /*
  316. * WSA_CMSG_FIRSTHDR
  317. *
  318. * Returns a pointer to the first ancillary data object,
  319. * or a null pointer if there is no ancillary data in the
  320. * control buffer of the WSAMSG structure.
  321. *
  322. * LPCMSGHDR
  323. * WSA_CMSG_FIRSTHDR (
  324. * LPWSAMSG msg
  325. * );
  326. */
  327. #define WSA_CMSG_FIRSTHDR(msg) \
  328. ( ((msg)->Control.len >= sizeof(WSACMSGHDR)) \
  329. ? (LPWSACMSGHDR)(msg)->Control.buf \
  330. : (LPWSACMSGHDR)NULL )
  331. /*
  332. * WSA_CMSG_NXTHDR
  333. *
  334. * Returns a pointer to the next ancillary data object,
  335. * or a null if there are no more data objects.
  336. *
  337. * LPCMSGHDR
  338. * WSA_CMSG_NEXTHDR (
  339. * LPWSAMSG msg,
  340. * LPWSACMSGHDR cmsg
  341. * );
  342. */
  343. #define WSA_CMSG_NXTHDR(msg, cmsg) \
  344. ( ((cmsg) == NULL) \
  345. ? WSA_CMSG_FIRSTHDR(msg) \
  346. : ( ( ((u_char *)(cmsg) + \
  347. WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len) + \
  348. sizeof(WSACMSGHDR) ) > \
  349. (u_char *)((msg)->Control.buf) + \
  350. (msg)->Control.len ) \
  351. ? (LPWSACMSGHDR)NULL \
  352. : (LPWSACMSGHDR)((u_char *)(cmsg) + \
  353. WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len)) ) )
  354. /*
  355. * WSA_CMSG_DATA
  356. *
  357. * Returns a pointer to the first byte of data (what is referred
  358. * to as the cmsg_data member though it is not defined in
  359. * the structure).
  360. *
  361. * u_char *
  362. * WSA_CMSG_DATA (
  363. * LPWSACMSGHDR pcmsg
  364. * );
  365. */
  366. #define WSA_CMSG_DATA(cmsg) \
  367. ( (u_char *)(cmsg) + WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR)) )
  368. /*
  369. * WSA_CMSG_SPACE
  370. *
  371. * Returns total size of an ancillary data object given
  372. * the amount of data. Used to allocate the correct amount
  373. * of space.
  374. *
  375. * SIZE_T
  376. * WSA_CMSG_SPACE (
  377. * SIZE_T length
  378. * );
  379. */
  380. #define WSA_CMSG_SPACE(length) \
  381. (WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR) + WSA_CMSGHDR_ALIGN(length)))
  382. /*
  383. * WSA_CMSG_LEN
  384. *
  385. * Returns the value to store in cmsg_len given the amount of data.
  386. *
  387. * SIZE_T
  388. * WSA_CMSG_LEN (
  389. * SIZE_T length
  390. * );
  391. */
  392. #define WSA_CMSG_LEN(length) \
  393. (WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR)) + length)
  394. /*
  395. * Definition for flags member of the WSAMSG structure
  396. * This is in addition to other MSG_xxx flags defined
  397. * for recv/recvfrom/send/sendto.
  398. */
  399. #define MSG_TRUNC 0x0100
  400. #define MSG_CTRUNC 0x0200
  401. #define MSG_BCAST 0x0400
  402. #define MSG_MCAST 0x0800
  403. typedef
  404. INT
  405. (PASCAL FAR * LPFN_WSARECVMSG) (
  406. IN SOCKET s,
  407. IN OUT LPWSAMSG lpMsg,
  408. OUT LPDWORD lpdwNumberOfBytesRecvd,
  409. IN LPWSAOVERLAPPED lpOverlapped,
  410. IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  411. );
  412. #define WSAID_WSARECVMSG \
  413. {0xf689d7c8,0x6f1f,0x436b,{0x8a,0x53,0xe5,0x4f,0xe3,0x51,0xc3,0x22}}
  414. #ifdef __cplusplus
  415. }
  416. #endif
  417. #endif /* _MSWSOCK_ */