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.

388 lines
6.0 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 <nspapi.h>
  26. #include <svcguid.h>
  27. //
  28. // prototypes
  29. //
  30. BOOL
  31. IwinsockInitialize(
  32. VOID
  33. );
  34. VOID
  35. IwinsockTerminate(
  36. VOID
  37. );
  38. DWORD
  39. LoadWinsock(
  40. VOID
  41. );
  42. VOID
  43. UnloadWinsock(
  44. VOID
  45. );
  46. DWORD
  47. SafeCloseSocket(
  48. IN SOCKET Socket
  49. );
  50. //
  51. // sockets functions
  52. //
  53. extern
  54. SOCKET
  55. (PASCAL FAR * _I_accept)(
  56. SOCKET s,
  57. struct sockaddr FAR *addr,
  58. int FAR *addrlen
  59. );
  60. extern
  61. int
  62. (PASCAL FAR * _I_bind)(
  63. SOCKET s,
  64. const struct sockaddr FAR *addr,
  65. int namelen
  66. );
  67. extern
  68. int
  69. (PASCAL FAR * _I_closesocket)(
  70. SOCKET s
  71. );
  72. extern
  73. int
  74. (PASCAL FAR * _I_connect)(
  75. SOCKET s,
  76. const struct sockaddr FAR *name,
  77. int namelen
  78. );
  79. extern
  80. int
  81. (PASCAL FAR * _I_gethostname)(
  82. char FAR * name,
  83. int namelen
  84. );
  85. extern
  86. LPHOSTENT
  87. (PASCAL FAR * _I_gethostbyname)(
  88. LPSTR lpHostName
  89. );
  90. extern
  91. int
  92. (PASCAL FAR * _I_getsockname)(
  93. SOCKET s,
  94. struct sockaddr FAR *name,
  95. int FAR * namelen
  96. );
  97. extern
  98. int
  99. (PASCAL FAR * _I_getsockopt)(
  100. SOCKET s,
  101. int level,
  102. int optname,
  103. char FAR * optval,
  104. int FAR *optlen
  105. );
  106. extern
  107. u_long
  108. (PASCAL FAR * _I_htonl)(
  109. u_long hostlong
  110. );
  111. extern
  112. u_short
  113. (PASCAL FAR * _I_htons)(
  114. u_short hostshort
  115. );
  116. extern
  117. unsigned long
  118. (PASCAL FAR * _I_inet_addr)(
  119. const char FAR * cp
  120. );
  121. extern
  122. char FAR *
  123. (PASCAL FAR * _I_inet_ntoa)(
  124. struct in_addr in
  125. );
  126. extern
  127. int
  128. (PASCAL FAR * _I_ioctlsocket)(
  129. SOCKET s,
  130. long cmd,
  131. u_long FAR *argp
  132. );
  133. extern
  134. int
  135. (PASCAL FAR * _I_listen)(
  136. SOCKET s,
  137. int backlog
  138. );
  139. extern
  140. u_short
  141. (PASCAL FAR * _I_ntohs)(
  142. u_short netshort
  143. );
  144. extern
  145. int
  146. (PASCAL FAR * _I_recv)(
  147. SOCKET s,
  148. char FAR * buf,
  149. int len,
  150. int flags
  151. );
  152. extern
  153. int
  154. (PASCAL FAR * _I_WSARecv)(
  155. SOCKET s,
  156. LPWSABUF lpBuffers,
  157. DWORD dwBufferCount,
  158. LPDWORD lpNumberOfBytesRecvd,
  159. LPDWORD lpFlags,
  160. LPWSAOVERLAPPED lpOverlapped,
  161. LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  162. );
  163. extern
  164. int
  165. (PASCAL FAR * _I_recvfrom)(
  166. SOCKET s,
  167. char FAR * buf,
  168. int len,
  169. int flags,
  170. struct sockaddr FAR *from,
  171. int FAR * fromlen
  172. );
  173. extern
  174. int
  175. (PASCAL FAR * _I_select)(
  176. int nfds,
  177. fd_set FAR *readfds,
  178. fd_set FAR *writefds,
  179. fd_set FAR *exceptfds,
  180. const struct timeval FAR *timeout
  181. );
  182. extern
  183. int
  184. (PASCAL FAR * _I_send)(
  185. SOCKET s,
  186. const char FAR * buf,
  187. int len,
  188. int flags
  189. );
  190. extern
  191. int
  192. (PASCAL FAR * _I_WSASend)(
  193. SOCKET s,
  194. LPWSABUF lpBuffers,
  195. DWORD dwBufferCount,
  196. LPDWORD lpNumberOfBytesSent,
  197. DWORD dwFlags,
  198. LPWSAOVERLAPPED lpOverlapped,
  199. LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  200. );
  201. extern
  202. int
  203. (PASCAL FAR * _I_sendto)(
  204. SOCKET s,
  205. const char FAR * buf,
  206. int len,
  207. int flags,
  208. const struct sockaddr FAR *to,
  209. int tolen
  210. );
  211. extern
  212. int
  213. (PASCAL FAR * _I_setsockopt)(
  214. SOCKET s,
  215. int level,
  216. int optname,
  217. const char FAR * optval,
  218. int optlen
  219. );
  220. extern
  221. int
  222. (PASCAL FAR * _I_shutdown)(
  223. SOCKET s,
  224. int how
  225. );
  226. extern
  227. SOCKET
  228. (PASCAL FAR * _I_socket)(
  229. int af,
  230. int type,
  231. int protocol
  232. );
  233. //
  234. // WSA functions
  235. //
  236. extern
  237. int
  238. (PASCAL FAR * _I_WSAStartup)(
  239. WORD wVersionRequired,
  240. LPWSADATA lpWSAData
  241. );
  242. extern
  243. int
  244. (PASCAL FAR * _I_WSACleanup)(
  245. void
  246. );
  247. extern
  248. int
  249. (PASCAL FAR * _I_WSAGetLastError)(
  250. void
  251. );
  252. extern
  253. void
  254. (PASCAL FAR * _I_WSASetLastError)(
  255. int iError
  256. );
  257. extern
  258. int
  259. (PASCAL FAR * _I___WSAFDIsSet)(
  260. SOCKET,
  261. fd_set FAR *
  262. );
  263. class CWrapOverlapped
  264. {
  265. WSAOVERLAPPED m_Overlapped;
  266. LONG m_dwReferenceCount;
  267. public:
  268. CWrapOverlapped()
  269. {
  270. //Don't need to zero out the overlapped struct here.
  271. // since we zero it out in the fsm's before using (see icsocket.cxx)
  272. m_dwReferenceCount = 1;
  273. }
  274. LONG Reference()
  275. {
  276. return InterlockedIncrement(&m_dwReferenceCount);
  277. }
  278. BOOL Dereference()
  279. {
  280. BOOL bRet = FALSE;
  281. LONG lResult = InterlockedDecrement(&m_dwReferenceCount);
  282. if (lResult == 0)
  283. {
  284. delete this;
  285. bRet = TRUE;
  286. }
  287. return bRet;
  288. }
  289. LPWSAOVERLAPPED GetOverlapped()
  290. {
  291. return &m_Overlapped;
  292. }
  293. friend CWrapOverlapped* GetWrapOverlappedObject(LPVOID lpAddress);
  294. };
  295. //
  296. // macros
  297. //
  298. #ifndef unix
  299. #if defined(FD_ISSET)
  300. #undef FD_ISSET
  301. #endif
  302. #define FD_ISSET(fd, set) _I___WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
  303. #endif /* unix */
  304. #if INET_DEBUG
  305. VOID
  306. IWinsockCheckSockets(
  307. VOID
  308. );
  309. #define CHECK_SOCKETS() IWinsockCheckSockets()
  310. #else
  311. #define CHECK_SOCKETS() /* NOTHING */
  312. #endif
  313. #if defined(__cplusplus)
  314. }
  315. #endif
  316. #endif // _IWINSOCK_