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.

467 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. iwinsock.hxx
  5. Abstract:
  6. Contains prototypes for indirected sockets functions
  7. Author:
  8. Richard L Firth (rfirth) 12-Apr-1995
  9. Revision History:
  10. 12-Apr-1995 rfirth
  11. Created
  12. 08-May-1996 arthurbi
  13. Moved into SOCKET_FUNC_ARRAY in order to supports Socks.
  14. --*/
  15. #if !defined(_IWINSOCK_)
  16. #define _WINSOCK_
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. //
  21. // includes
  22. //
  23. #include <winsock2.h>
  24. #include <basetyps.h>
  25. #include <ws2tcpip.h>
  26. #include <nspapi.h>
  27. #include <svcguid.h>
  28. //
  29. // prototypes
  30. //
  31. BOOL
  32. IwinsockInitialize(
  33. VOID
  34. );
  35. VOID
  36. IwinsockTerminate(
  37. VOID
  38. );
  39. DWORD
  40. LoadWinsock(
  41. VOID
  42. );
  43. VOID
  44. UnloadWinsock(
  45. BOOL fOverrideRefCount = FALSE
  46. );
  47. DWORD
  48. SafeCloseSocket(
  49. IN SOCKET Socket
  50. );
  51. BOOL
  52. ParseHostName(
  53. IN LPSTR lpHostName,
  54. IN DWORD cchHostName,
  55. OUT LPBOOL lpbIsLiteral,
  56. OUT LPBOOL lpbIsLocalHost,
  57. IN OUT LPSOCKADDR_IN6 lpSockAddr OPTIONAL
  58. );
  59. //
  60. // sockets functions
  61. //
  62. extern
  63. SOCKET
  64. (PASCAL FAR * _I_accept)(
  65. SOCKET s,
  66. struct sockaddr FAR *addr,
  67. int FAR *addrlen
  68. );
  69. extern
  70. int
  71. (PASCAL FAR * _I_bind)(
  72. SOCKET s,
  73. const struct sockaddr FAR *addr,
  74. int namelen
  75. );
  76. extern
  77. int
  78. (PASCAL FAR * _I_closesocket)(
  79. SOCKET s
  80. );
  81. extern
  82. int
  83. (PASCAL FAR * _I_connect)(
  84. SOCKET s,
  85. const struct sockaddr FAR *name,
  86. int namelen
  87. );
  88. extern
  89. int
  90. (PASCAL FAR * _I_gethostname)(
  91. char FAR * name,
  92. int namelen
  93. );
  94. extern
  95. LPHOSTENT
  96. (PASCAL FAR * _I_gethostbyaddr)(
  97. const char FAR * addr,
  98. int len,
  99. int type
  100. );
  101. extern
  102. LPHOSTENT
  103. (PASCAL FAR * _I_gethostbyname)(
  104. const char FAR * lpHostName
  105. );
  106. extern
  107. int
  108. (PASCAL FAR * _I_getsockname)(
  109. SOCKET s,
  110. struct sockaddr FAR *name,
  111. int FAR * namelen
  112. );
  113. extern
  114. int
  115. (PASCAL FAR * _I_getsockopt)(
  116. SOCKET s,
  117. int level,
  118. int optname,
  119. char FAR * optval,
  120. int FAR *optlen
  121. );
  122. extern
  123. u_long
  124. (PASCAL FAR * _I_htonl)(
  125. u_long hostlong
  126. );
  127. extern
  128. u_short
  129. (PASCAL FAR * _I_htons)(
  130. u_short hostshort
  131. );
  132. extern
  133. unsigned long
  134. (PASCAL FAR * _I_inet_addr)(
  135. const char FAR * cp
  136. );
  137. extern
  138. char FAR *
  139. (PASCAL FAR * _I_inet_ntoa)(
  140. struct in_addr in
  141. );
  142. extern
  143. int
  144. (PASCAL FAR * _I_ioctlsocket)(
  145. SOCKET s,
  146. long cmd,
  147. u_long FAR *argp
  148. );
  149. extern
  150. int
  151. (PASCAL FAR * _I_listen)(
  152. SOCKET s,
  153. int backlog
  154. );
  155. extern
  156. u_short
  157. (PASCAL FAR * _I_ntohs)(
  158. u_short netshort
  159. );
  160. extern
  161. int
  162. (PASCAL FAR * _I_recv)(
  163. SOCKET s,
  164. char FAR * buf,
  165. int len,
  166. int flags
  167. );
  168. extern
  169. int
  170. (PASCAL FAR * _I_WSARecv)(
  171. SOCKET s,
  172. LPWSABUF lpBuffers,
  173. DWORD dwBufferCount,
  174. LPDWORD lpNumberOfBytesRecvd,
  175. LPDWORD lpFlags,
  176. LPWSAOVERLAPPED lpOverlapped,
  177. LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  178. );
  179. extern
  180. int
  181. (PASCAL FAR * _I_recvfrom)(
  182. SOCKET s,
  183. char FAR * buf,
  184. int len,
  185. int flags,
  186. struct sockaddr FAR *from,
  187. int FAR * fromlen
  188. );
  189. extern
  190. int
  191. (PASCAL FAR * _I_select)(
  192. int nfds,
  193. fd_set FAR *readfds,
  194. fd_set FAR *writefds,
  195. fd_set FAR *exceptfds,
  196. const struct timeval FAR *timeout
  197. );
  198. extern
  199. int
  200. (PASCAL FAR * _I_send)(
  201. SOCKET s,
  202. const char FAR * buf,
  203. int len,
  204. int flags
  205. );
  206. extern
  207. int
  208. (PASCAL FAR * _I_WSASend)(
  209. SOCKET s,
  210. LPWSABUF lpBuffers,
  211. DWORD dwBufferCount,
  212. LPDWORD lpNumberOfBytesSent,
  213. DWORD dwFlags,
  214. LPWSAOVERLAPPED lpOverlapped,
  215. LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  216. );
  217. extern
  218. int
  219. (PASCAL FAR * _I_sendto)(
  220. SOCKET s,
  221. const char FAR * buf,
  222. int len,
  223. int flags,
  224. const struct sockaddr FAR *to,
  225. int tolen
  226. );
  227. extern
  228. int
  229. (PASCAL FAR * _I_setsockopt)(
  230. SOCKET s,
  231. int level,
  232. int optname,
  233. const char FAR * optval,
  234. int optlen
  235. );
  236. extern
  237. int
  238. (PASCAL FAR * _I_shutdown)(
  239. SOCKET s,
  240. int how
  241. );
  242. extern
  243. SOCKET
  244. (PASCAL FAR * _I_socket)(
  245. int af,
  246. int type,
  247. int protocol
  248. );
  249. //
  250. // WSA functions
  251. //
  252. extern
  253. int
  254. (PASCAL FAR * _I_WSAStartup)(
  255. WORD wVersionRequired,
  256. LPWSADATA lpWSAData
  257. );
  258. extern
  259. int
  260. (PASCAL FAR * _I_WSACleanup)(
  261. void
  262. );
  263. extern
  264. int
  265. (PASCAL FAR * _I_WSAGetLastError)(
  266. void
  267. );
  268. extern
  269. void
  270. (PASCAL FAR * _I_WSASetLastError)(
  271. int iError
  272. );
  273. extern
  274. int
  275. (PASCAL FAR * _I___WSAFDIsSet)(
  276. SOCKET,
  277. fd_set FAR *
  278. );
  279. class CWrapOverlapped
  280. {
  281. WSAOVERLAPPED m_Overlapped;
  282. LONG m_dwReferenceCount;
  283. public:
  284. CWrapOverlapped()
  285. {
  286. //Don't need to zero out the overlapped struct here.
  287. // since we zero it out in the fsm's before using (see icsocket.cxx)
  288. m_dwReferenceCount = 1;
  289. }
  290. LONG Reference()
  291. {
  292. return InterlockedIncrement(&m_dwReferenceCount);
  293. }
  294. BOOL Dereference()
  295. {
  296. BOOL bRet = FALSE;
  297. LONG lResult = InterlockedDecrement(&m_dwReferenceCount);
  298. if (lResult == 0)
  299. {
  300. delete this;
  301. bRet = TRUE;
  302. }
  303. return bRet;
  304. }
  305. LPWSAOVERLAPPED GetOverlapped()
  306. {
  307. return &m_Overlapped;
  308. }
  309. friend CWrapOverlapped* GetWrapOverlappedObject(LPVOID lpAddress);
  310. };
  311. //
  312. // address family independent APIs
  313. //
  314. extern
  315. int
  316. (PASCAL FAR * _I_getaddrinfo)(
  317. IN const char FAR * nodename,
  318. IN const char FAR * servname,
  319. IN const struct addrinfo FAR * hints,
  320. OUT struct addrinfo FAR * FAR * res
  321. );
  322. extern
  323. void
  324. (PASCAL FAR * _I_freeaddrinfo)(
  325. IN struct addrinfo *ai
  326. );
  327. extern
  328. int
  329. (PASCAL FAR * _I_getnameinfo)(
  330. IN const struct sockaddr FAR * sa,
  331. IN socklen_t salen,
  332. OUT char FAR * host,
  333. IN size_t hostlen,
  334. OUT char FAR * serv,
  335. IN size_t servlen,
  336. IN int flags
  337. );
  338. extern
  339. INT
  340. (PASCAL FAR * _I_WSAStringToAddressA)(
  341. IN LPSTR AddressString,
  342. IN INT AddressFamily,
  343. IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
  344. OUT LPSOCKADDR lpAddress,
  345. IN OUT LPINT lpAddressLength
  346. );
  347. extern
  348. INT
  349. (PASCAL FAR * _I_WSAStringToAddressW)(
  350. IN LPWSTR AddressString,
  351. IN INT AddressFamily,
  352. IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
  353. OUT LPSOCKADDR lpAddress,
  354. IN OUT LPINT lpAddressLength
  355. );
  356. extern
  357. INT
  358. (PASCAL FAR * _I_WSAAddressToStringA)(
  359. IN LPSOCKADDR lpsaAddress,
  360. IN DWORD dwAddressLength,
  361. IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
  362. IN OUT LPSTR lpszAddressString,
  363. IN OUT LPDWORD lpdwAddressStringLength
  364. );
  365. //
  366. // macros
  367. //
  368. #ifndef unix
  369. #if defined(FD_ISSET)
  370. #undef FD_ISSET
  371. #endif
  372. #define FD_ISSET(fd, set) _I___WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
  373. #endif /* unix */
  374. #if INET_DEBUG
  375. VOID
  376. IWinsockCheckSockets(
  377. VOID
  378. );
  379. #define CHECK_SOCKETS() IWinsockCheckSockets()
  380. #else
  381. #define CHECK_SOCKETS() /* NOTHING */
  382. #endif
  383. #if defined(__cplusplus)
  384. }
  385. #endif
  386. #endif // _IWINSOCK_