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.

1486 lines
40 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Copyright (c) 1996 Hummingbird Corporation of Canada
  4. Module Name:
  5. wsock32.c
  6. Abstract:
  7. Contains Socks V4 support, written by Hummingbird corporation. Licensed from
  8. Hummingbird for ulimited use by Microsoft. Ported to WININET code base.
  9. Contents:
  10. FindSocket
  11. closesocket
  12. connect
  13. getpeername
  14. ALL WSOCK32.DLL exports.
  15. Author:
  16. Arthur L Bierer (arthurbi) 13-Dec-1996
  17. Environment:
  18. Win32 user-mode DLL
  19. Revision History:
  20. 13-Dec-1996 arthurbi
  21. Created, removed flagrent calls to CRTs, and unchecked memory allocations.
  22. 29-Aug-1997 rfirth
  23. Further reduced from general-purpose SOCKS implementation to Wininet-
  24. specific SOCKS support
  25. --*/
  26. #define _WINSOCKAPI_
  27. #include <windows.h>
  28. #ifdef DO_FILE_CONFIG
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <io.h>
  32. #include <malloc.h>
  33. #include <ctype.h>
  34. #include <stdlib.h>
  35. #endif
  36. #ifdef OLD_SOCKS
  37. struct User {
  38. char *Name;
  39. struct User *Next;
  40. };
  41. struct Server {
  42. char *Name;
  43. struct Server *Next;
  44. unsigned short port;
  45. };
  46. struct Hosts {
  47. struct User *Users;
  48. struct Server *Servers;
  49. unsigned long dst;
  50. unsigned long mask;
  51. unsigned short port;
  52. unsigned char op;
  53. unsigned char type;
  54. struct Hosts *Next;
  55. } *Head=NULL;
  56. struct Sockets {
  57. int s;
  58. HWND hWnd;
  59. unsigned int wMsg;
  60. long lEvent;
  61. unsigned long Blocking;
  62. int type;
  63. unsigned long ip;
  64. unsigned short port;
  65. struct Sockets *Next;
  66. struct Sockets *Last;
  67. int Socked:1;
  68. } *SHead=NULL;
  69. HANDLE SMutex;
  70. #define CREATE_MUTEX() SMutex = CreateMutex(NULL, FALSE, NULL)
  71. #define DELETE_MUTEX() if (SMutex) CloseHandle(SMutex)
  72. #define ENTER_MUTEX() WaitForSingleObject(SMutex, INFINITE)
  73. #define LEAVE_MUTEX() ReleaseMutex(SMutex)
  74. #else
  75. struct Hosts {
  76. char * user;
  77. int userlen;
  78. unsigned long ip;
  79. unsigned short port;
  80. } *Head = NULL;
  81. struct Sockets {
  82. int s;
  83. int type;
  84. unsigned long ip;
  85. unsigned short port;
  86. struct Sockets * Next;
  87. struct Sockets * Last;
  88. int Socked : 1;
  89. int Blocking : 1;
  90. } *SHead = NULL;
  91. CRITICAL_SECTION CritSec;
  92. #define CREATE_MUTEX() InitializeCriticalSection(&CritSec)
  93. #define DELETE_MUTEX() DeleteCriticalSection(&CritSec)
  94. #define ENTER_MUTEX() EnterCriticalSection(&CritSec)
  95. #define LEAVE_MUTEX() LeaveCriticalSection(&CritSec)
  96. #endif
  97. #define DENY 1
  98. #define DIRECT 2
  99. #define SOCKD 3
  100. #define ANY 0
  101. #define EQ 1
  102. #define NEQ 2
  103. #define LT 3
  104. #define GT 4
  105. #define LE 5
  106. #define GE 6
  107. /*
  108. * Internet address (old style... should be updated)
  109. */
  110. struct in_addr {
  111. union {
  112. struct { unsigned char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  113. struct { unsigned short s_w1,s_w2; } S_un_w;
  114. unsigned long S_addr;
  115. } S_un;
  116. #define s_addr S_un.S_addr
  117. /* can be used for most tcp & ip code */
  118. #define s_host S_un.S_un_b.s_b2
  119. /* host on imp */
  120. #define s_net S_un.S_un_b.s_b1
  121. /* network */
  122. #define s_imp S_un.S_un_w.s_w2
  123. /* imp */
  124. #define s_impno S_un.S_un_b.s_b4
  125. /* imp # */
  126. #define s_lh S_un.S_un_b.s_b3
  127. /* logical host */
  128. };
  129. /*
  130. * Socket address, internet style.
  131. */
  132. struct sockaddr_in {
  133. short sin_family;
  134. unsigned short sin_port;
  135. struct in_addr sin_addr;
  136. char sin_zero[8];
  137. };
  138. struct servent {
  139. char * s_name; /* official service name */
  140. char * * s_aliases; /* alias list */
  141. short s_port; /* port # */
  142. char * s_proto; /* protocol to use */
  143. };
  144. struct hostent {
  145. char * h_name; /* official name of host */
  146. char * * h_aliases; /* alias list */
  147. short h_addrtype; /* host address type */
  148. short h_length; /* length of address */
  149. char * * h_addr_list; /* list of addresses */
  150. #define h_addr h_addr_list[0] /* address, for backward compat */
  151. };
  152. #define WSABASEERR 10000
  153. #define WSAECONNREFUSED (WSABASEERR+61)
  154. #define WSAEWOULDBLOCK (WSABASEERR+35)
  155. #define WSAENOBUFS (WSABASEERR+55)
  156. #define SOCKET_ERROR (-1)
  157. #define INVALID_SOCKET (int)(~0)
  158. /*
  159. * Define flags to be used with the WSAAsyncSelect() call.
  160. */
  161. #define FD_READ 0x01
  162. #define FD_WRITE 0x02
  163. #define FD_OOB 0x04
  164. #define FD_ACCEPT 0x08
  165. #define FD_CONNECT 0x10
  166. #define FD_CLOSE 0x20
  167. #define SOCK_STREAM 1 /* stream socket */
  168. /*
  169. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  170. *
  171. *
  172. * Ioctl's have the command encoded in the lower word,
  173. * and the size of any in or out parameters in the upper
  174. * word. The high 2 bits of the upper word are used
  175. * to encode the in/out status of the parameter; for now
  176. * we restrict parameters to at most 128 bytes.
  177. */
  178. #define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
  179. #define IOC_VOID 0x20000000 /* no parameters */
  180. #define IOC_OUT 0x40000000 /* copy out parameters */
  181. #define IOC_IN 0x80000000 /* copy in parameters */
  182. #define IOC_INOUT (IOC_IN|IOC_OUT)
  183. /* 0x20000000 distinguishes new &
  184. old ioctl's */
  185. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  186. #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  187. #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  188. #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
  189. #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
  190. #define FIOASYNC _IOW('f', 125, unsigned long) /* set/clear async i/o */
  191. #define SO_SET_SOCKS_FIREWALL 0xF0000
  192. DWORD (WINAPI * VArecv)(int a,int b,int c, int d);
  193. DWORD (WINAPI * VAsend)(int a,int b,int c, int d);
  194. DWORD (WINAPI * VEnumProtocolsA)(int a,int b,int c);
  195. DWORD (WINAPI * VEnumProtocolsW)(int a,int b,int c);
  196. DWORD (WINAPI * VGetAddressByNameA)(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j);
  197. DWORD (WINAPI * VGetAddressByNameW)(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j);
  198. DWORD (WINAPI * VGetNameByTypeA)(int a,int b,int c);
  199. DWORD (WINAPI * VGetNameByTypeW)(int a,int b,int c);
  200. DWORD (WINAPI * VGetServiceA)(int a,int b,int c,int d,int e,int f,int g);
  201. DWORD (WINAPI * VGetServiceW)(int a,int b,int c,int d,int e,int f,int g);
  202. DWORD (WINAPI * VGetTypeByNameA)(int a,int b);
  203. DWORD (WINAPI * VGetTypeByNameW)(int a,int b);
  204. DWORD (WINAPI * VNPLoadNameSpaces)(int a,int b,int c);
  205. DWORD (WINAPI * VSetServiceA)(int a,int b,int c,int d,int e,int f);
  206. DWORD (WINAPI * VSetServiceW)(int a,int b,int c,int d,int e,int f);
  207. DWORD (WINAPI * VTransmitFile)(int a,int b,int c,int d,int e,int f,int g);
  208. DWORD (WINAPI * VWSAAsyncGetHostByAddr)(int a,int b,int c,int d,int e,int f,int g);
  209. DWORD (WINAPI * VWSAAsyncGetHostByName)(int a,int b,int c,int d,int e);
  210. DWORD (WINAPI * VWSAAsyncGetProtoByName)(int a,int b,int c,int d,int e);
  211. DWORD (WINAPI * VWSAAsyncGetProtoByNumber)(int a,int b,int c,int d,int e);
  212. DWORD (WINAPI * VWSAAsyncGetServByName)(int a,int b,int c,int d,int e,int f);
  213. DWORD (WINAPI * VWSAAsyncGetServByPort)(int a,int b,int c,int d,int e,int f);
  214. DWORD (WINAPI * VWSAAsyncSelect)(int s, HWND hWnd, unsigned int wMsg, long lEvent);
  215. DWORD (WINAPI * VWSACancelAsyncRequest)(int a);
  216. DWORD (WINAPI * VWSACancelBlockingCall)(void);
  217. DWORD (WINAPI * VWSACleanup)(void);
  218. DWORD (WINAPI * VWSAGetLastError)(void);
  219. DWORD (WINAPI * VWSAIsBlocking)(void);
  220. DWORD (WINAPI * VWSARecvEx)(int a,int b,int c,int d);
  221. DWORD (WINAPI * VWSASetBlockingHook)(int a);
  222. DWORD (WINAPI * VWSASetLastError)(int a);
  223. DWORD (WINAPI * VWSAStartup)(int a,int b);
  224. DWORD (WINAPI * VWSAUnhookBlockingHook)(void);
  225. DWORD ( * VWSHEnumProtocols)(int a,int b,int c,int d);
  226. DWORD (WINAPI * VWsControl)(int a,int b,int c,int d,int e,int f);
  227. DWORD (WINAPI * V__WSAFDIsSet)(int a,int b);
  228. DWORD (WINAPI * Vaccept)(int a,int b,int c);
  229. DWORD (WINAPI * Vbind)(int a,int b,int c);
  230. DWORD (WINAPI * Vclosesocket)(int a);
  231. DWORD (WINAPI * Vclosesockinfo)(int a);
  232. DWORD (WINAPI * Vconnect)(int s, const struct sockaddr_in FAR *name, int namelen);
  233. DWORD (WINAPI * Vdn_expand)(int a,int b,int c,int d,int e);
  234. DWORD (WINAPI * Vgethostbyaddr)(int a,int b,int c);
  235. struct hostent * (WINAPI * Vgethostbyname)(char *);
  236. DWORD (WINAPI * Vgethostname)(int a,int b);
  237. DWORD (WINAPI * Vgetnetbyname)(int a);
  238. DWORD (WINAPI * Vgetpeername)(int s, struct sockaddr_in *name,int *namelen);
  239. DWORD (WINAPI * Vgetprotobyname)(int a);
  240. DWORD (WINAPI * Vgetprotobynumber)(int a);
  241. struct servent * (WINAPI * Vgetservbyname)(const char FAR * name, const char FAR * proto);
  242. DWORD (WINAPI * Vgetservbyport)(int a,int b);
  243. DWORD (WINAPI * Vgetsockname)(int a,int b,int c);
  244. DWORD (WINAPI * Vgetsockopt)(int a,int b,int c,int d,int e);
  245. DWORD (WINAPI * Vhtonl)(int a);
  246. DWORD (WINAPI * Vhtons)(int a);
  247. DWORD (WINAPI * Vinet_addr)(char *p);
  248. DWORD (WINAPI * Vinet_network)(int a);
  249. DWORD (WINAPI * Vinet_ntoa)(int a);
  250. DWORD (WINAPI * Vioctlsocket)(int s, long cmd, unsigned long *argp);
  251. DWORD (WINAPI * Vlisten)(int a,int b);
  252. DWORD (WINAPI * Vntohl)(int a);
  253. DWORD (WINAPI * Vntohs)(int a);
  254. DWORD (WINAPI * Vrcmd)(int a,int b,int c,int d,int e,int f);
  255. DWORD (WINAPI * Vrecv)(int a,int b,int c,int d);
  256. DWORD (WINAPI * Vrecvfrom)(int a,int b,int c,int d,int e,int f);
  257. DWORD (WINAPI * Vrexec)(int a,int b,int c,int d,int e,int f);
  258. DWORD (WINAPI * Vrresvport)(int a);
  259. DWORD (WINAPI * Vs_perror)(int a,int b);
  260. DWORD (WINAPI * Vselect)(int a,int b,int c,int d,int e);
  261. DWORD (WINAPI * Vsend)(int a,int b,int c,int d);
  262. DWORD (WINAPI * Vsendto)(int a,int b,int c,int d,int e,int f);
  263. DWORD (WINAPI * Vsethostname)(int a,int b);
  264. DWORD (WINAPI * Vsetsockopt)(int s,int level,int optname,const char FAR * optval, int optlen);
  265. DWORD (WINAPI * Vshutdown)(int a,int b);
  266. DWORD (WINAPI * Vsocket)(int a,int b,int c);
  267. DWORD (WINAPI * VWEP)(void);
  268. DWORD (WINAPI * VAcceptEx)(int a,int b,int c,int d,int e,int f,int g,int h);
  269. DWORD (WINAPI * VGetAcceptExSockaddrs)(int a,int b,int c,int d,int e,int f,int g,int h);
  270. DWORD (WINAPI * VMigrateWinsockConfiguration)(int a,int b, int c);
  271. DWORD (WINAPI * VWSApSetPostRoutine)(void *a);
  272. BOOL (WINAPI * VPostMessage)(HWND hWnd, unsigned int wMsg, WPARAM wPAram, LPARAM lParam) = NULL;
  273. BOOL MyPostMessage(HWND hWnd, unsigned int wMsg, WPARAM wParam, LPARAM lParam) {
  274. if ( VPostMessage)
  275. return(VPostMessage(hWnd,wMsg, wParam, lParam));
  276. PostMessage(hWnd,wMsg, wParam, lParam);
  277. }
  278. struct Sockets *
  279. FindSocket(
  280. int s
  281. )
  282. /*++
  283. Routine Description:
  284. Find or create SOCKS socket object. Returns with MUTEX held
  285. Arguments:
  286. s - associated socket handle
  287. Return Value:
  288. struct Sockets *
  289. Success - address of Sockets object
  290. Failure - NULL
  291. --*/
  292. {
  293. struct Sockets *So;
  294. ENTER_MUTEX();
  295. So = SHead;
  296. while (So) {
  297. if (s == So->s) {
  298. return So;
  299. }
  300. So = So->Next;
  301. }
  302. if (So = (struct Sockets *)LocalAlloc(LPTR, sizeof(struct Sockets))) {
  303. So->s = s;
  304. So->Next = SHead;
  305. SHead = So;
  306. if (So->Next) {
  307. (So->Next)->Last = So;
  308. }
  309. }
  310. return So;
  311. }
  312. //LPSTR
  313. //NewString(
  314. // IN LPCSTR String
  315. // )
  316. //
  317. ///*++
  318. //
  319. //Routine Description:
  320. //
  321. // kind of version of strdup() but using LocalAlloc to allocate memory
  322. //
  323. //Arguments:
  324. //
  325. // String - pointer to string to make copy of
  326. //
  327. //Return Value:
  328. //
  329. // LPSTR
  330. // Success - pointer to duplicated string
  331. // Failure - NULL
  332. //
  333. //--*/
  334. //
  335. //{
  336. // int len = strlen(String) + 1;
  337. // LPSTR string;
  338. //
  339. // if (string = (LPSTR)LocalAlloc(LMEM_FIXED, len)) {
  340. // CopyMemory(string, String, len);
  341. // }
  342. // return string;
  343. //}
  344. DWORD WINAPI __WSAFDIsSet(int a,int b) {
  345. return(V__WSAFDIsSet(a, b));
  346. }
  347. DWORD WINAPI accept(int a,int b,int c) {
  348. return(Vaccept(a, b, c));
  349. }
  350. DWORD WINAPI Arecv(int a,int b,int c,int d) {
  351. return(VArecv(a,b,c,d));
  352. }
  353. DWORD WINAPI Asend(int a,int b,int c,int d) {
  354. return(VAsend(a,b,c,d));
  355. }
  356. DWORD WINAPI bind(int a,int b,int c) {
  357. return(Vbind(a, b, c));
  358. }
  359. DWORD WINAPI AcceptEx(int a,int b,int c,int d,int e,int f,int g,int h) {
  360. return(VAcceptEx(a,b,c,d,e,f,g,h));
  361. }
  362. DWORD WINAPI GetAcceptExSockaddrs(int a,int b,int c,int d,int e,int f,int g,int h) {
  363. return(VGetAcceptExSockaddrs(a,b,c,d,e,f,g,h));
  364. }
  365. DWORD WINAPI MigrateWinsockConfiguration(int a,int b, int c) {
  366. return(VMigrateWinsockConfiguration(a,b,c));
  367. }
  368. DWORD WINAPI WSApSetPostRoutine(void *a) {
  369. VPostMessage=a;
  370. return(VWSApSetPostRoutine(a));
  371. }
  372. DWORD
  373. WINAPI
  374. closesocket(
  375. int s
  376. )
  377. /*++
  378. Routine Description:
  379. Closes socket handle and destroys associated Sockets object if found
  380. Arguments:
  381. s - socket handle
  382. Return Value:
  383. int
  384. Success - 0
  385. Failure - -1
  386. --*/
  387. {
  388. struct Sockets * So = FindSocket(s);
  389. if (So == NULL) {
  390. VWSASetLastError(WSAENOBUFS);
  391. LEAVE_MUTEX();
  392. return SOCKET_ERROR;
  393. }
  394. if (So->Last == NULL) {
  395. SHead = So->Next;
  396. } else {
  397. (So->Last)->Next = So->Next;
  398. }
  399. if (So->Next) {
  400. (So->Next)->Last = So->Last;
  401. }
  402. LEAVE_MUTEX();
  403. LocalFree(So);
  404. return Vclosesocket(s);
  405. }
  406. DWORD WINAPI closesockinfo(int a) {
  407. return(Vclosesockinfo(a));
  408. }
  409. DWORD
  410. WINAPI
  411. connect(
  412. int s,
  413. const struct sockaddr_in FAR * name,
  414. int namelen
  415. )
  416. /*++
  417. Routine Description:
  418. Connect to remote host via SOCKS proxy. Modified from original. If we are
  419. here then we are going specifically via a known SOCKS proxy. There is now
  420. only one Hosts object, containing a single SOCKD socks proxy address and
  421. user name
  422. Arguments:
  423. s - socket to connect
  424. name - sockaddr of remote host
  425. namelen - length of sockaddr
  426. Return Value:
  427. int
  428. Success - 0
  429. Failure - -1
  430. --*/
  431. {
  432. unsigned long ip;
  433. unsigned short port;
  434. struct Hosts * pHost;
  435. int serr;
  436. int blocking;
  437. struct Sockets * pSocket;
  438. struct sockaddr_in sin;
  439. struct {
  440. unsigned char VN;
  441. unsigned char CD;
  442. unsigned short DSTPORT;
  443. unsigned long DSTIP;
  444. char UserId[255];
  445. } request;
  446. int length;
  447. char response[256];
  448. int val;
  449. //
  450. // get IP address and port we want to connect to on other side of firewall
  451. //
  452. port = name->sin_port;
  453. ip = name->sin_addr.s_addr;
  454. //
  455. // initialize sockaddr for connecting to SOCKS firewall
  456. //
  457. memset(&sin, 0, sizeof(sin));
  458. sin.sin_family = 2;
  459. //
  460. // initialize SOCKS request packet
  461. //
  462. request.VN = 4;
  463. request.CD = 1;
  464. request.DSTPORT = port;
  465. request.DSTIP = ip;
  466. pSocket = FindSocket(s);
  467. if (pSocket == NULL) {
  468. VWSASetLastError(WSAENOBUFS);
  469. LEAVE_MUTEX();
  470. return SOCKET_ERROR;
  471. }
  472. pHost = Head;
  473. if (!pHost || (pSocket->type != SOCK_STREAM) || (pSocket->Socked)) {
  474. LEAVE_MUTEX();
  475. return Vconnect(s, name, namelen);
  476. }
  477. //
  478. // get information from pSocket and pHost structures before releasing mutex
  479. //
  480. blocking = pSocket->Blocking;
  481. pSocket->port = port;
  482. pSocket->ip = ip;
  483. memcpy(request.UserId, pHost->user, pHost->userlen);
  484. length = pHost->userlen + 8; // 8 == sizeof fixed portion of request
  485. sin.sin_port = pHost->port;
  486. sin.sin_addr.s_addr = pHost->ip;
  487. //
  488. // from this point, we cannot touch pHost or pSocket until we take the mutex
  489. // again
  490. //
  491. LEAVE_MUTEX();
  492. //
  493. // put socket into blocking mode
  494. //
  495. val = 0;
  496. Vioctlsocket(s, FIONBIO, &val);
  497. //
  498. // communicate with SOCKS firewall: send SOCKS request & receive response
  499. //
  500. serr = Vconnect(s, &sin, sizeof(sin));
  501. if (serr != SOCKET_ERROR) {
  502. serr = Vsend(s, (int)&request, length, 0);
  503. if (serr == length) {
  504. serr = Vrecv(s, (int)response, sizeof(response), 0);
  505. }
  506. }
  507. //
  508. // if originally non-blocking, make socket non-blocking again
  509. //
  510. if (blocking) {
  511. Vioctlsocket(s, FIONBIO, &blocking);
  512. }
  513. //
  514. // if success, mark the socket as being connected through firewall
  515. //
  516. if ((serr == SOCKET_ERROR) || (response[1] != 90)) {
  517. VWSASetLastError(WSAECONNREFUSED);
  518. serr = SOCKET_ERROR;
  519. } else {
  520. //
  521. // if we can't find/crea
  522. //
  523. pSocket = FindSocket(s);
  524. if (pSocket) {
  525. pSocket->Socked = 1;
  526. serr = 0;
  527. } else {
  528. VWSASetLastError(WSAENOBUFS);
  529. serr = SOCKET_ERROR;
  530. }
  531. LEAVE_MUTEX();
  532. }
  533. return serr;
  534. }
  535. DWORD WINAPI dn_expand(int a,int b,int c,int d,int e) {
  536. return(Vdn_expand(a, b, c, d, e));
  537. }
  538. DWORD WINAPI EnumProtocolsA(int a,int b,int c) {
  539. return(VEnumProtocolsA(a, b, c));
  540. }
  541. DWORD WINAPI EnumProtocolsW(int a,int b,int c) {
  542. return(VEnumProtocolsW(a, b, c));
  543. }
  544. DWORD WINAPI GetAddressByNameA(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) {
  545. return(VGetAddressByNameA(a, b, c, d, e, f, g, h, i, j));
  546. }
  547. DWORD WINAPI GetAddressByNameW(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) {
  548. return(VGetAddressByNameW(a, b, c, d, e, f, g, h, i, j));
  549. }
  550. DWORD WINAPI gethostbyaddr(int a,int b,int c) {
  551. return(Vgethostbyaddr(a, b, c));
  552. }
  553. struct hostent FAR * WINAPI gethostbyname(char *a) {
  554. return(Vgethostbyname(a));
  555. }
  556. DWORD WINAPI gethostname(int a,int b) {
  557. return(Vgethostname(a, b));
  558. }
  559. DWORD WINAPI GetNameByTypeA(int a,int b,int c) {
  560. return(VGetNameByTypeA(a, b, c));
  561. }
  562. DWORD WINAPI GetNameByTypeW(int a,int b,int c) {
  563. return(VGetNameByTypeW(a, b, c));
  564. }
  565. DWORD WINAPI getnetbyname(int a) {
  566. return(Vgetnetbyname(a));
  567. }
  568. DWORD
  569. WINAPI
  570. getpeername(
  571. int s,
  572. struct sockaddr_in * name,
  573. int *namelen
  574. )
  575. /*++
  576. Routine Description:
  577. description-of-function.
  578. Arguments:
  579. s -
  580. name -
  581. namelen -
  582. Return Value:
  583. int
  584. --*/
  585. {
  586. DWORD ret;
  587. struct Sockets *So;
  588. ret = Vgetpeername(s, name, namelen);
  589. if (ret == 0) {
  590. So = FindSocket(s);
  591. if (So) {
  592. if (So->Socked) {
  593. if (*namelen >= sizeof(struct sockaddr_in)) {
  594. name->sin_port = So->port;
  595. name->sin_addr.s_addr = So->ip;
  596. }
  597. }
  598. } else {
  599. VWSASetLastError(WSAENOBUFS);
  600. ret = SOCKET_ERROR;
  601. }
  602. LEAVE_MUTEX();
  603. }
  604. return ret;
  605. }
  606. DWORD WINAPI getprotobyname(int a) {
  607. return(Vgetprotobyname(a));
  608. }
  609. DWORD WINAPI getprotobynumber(int a) {
  610. return(Vgetprotobynumber(a));
  611. }
  612. struct servent * WINAPI getservbyname(const char FAR * name, const char FAR * proto) {
  613. return(Vgetservbyname(name, proto));
  614. }
  615. DWORD WINAPI getservbyport(int a,int b) {
  616. return(Vgetservbyport(a, b));
  617. }
  618. DWORD WINAPI GetServiceA(int a,int b,int c,int d,int e,int f,int g) {
  619. return(VGetServiceA(a, b, c, d, e, f, g));
  620. }
  621. DWORD WINAPI GetServiceW(int a,int b,int c,int d,int e,int f,int g) {
  622. return(VGetServiceW(a, b, c, d, e, f, g));
  623. }
  624. DWORD WINAPI getsockname(int a,int b,int c) {
  625. return(Vgetsockname(a, b, c));
  626. }
  627. DWORD WINAPI getsockopt(int a,int b,int c,int d,int e) {
  628. return(Vgetsockopt(a, b, c, d, e));
  629. }
  630. DWORD WINAPI GetTypeByNameA(int a,int b) {
  631. return(VGetTypeByNameA(a, b));
  632. }
  633. DWORD WINAPI GetTypeByNameW(int a,int b) {
  634. return(VGetTypeByNameW(a, b));
  635. }
  636. DWORD WINAPI htonl(int a) {
  637. return(Vhtonl(a));
  638. }
  639. DWORD WINAPI htons(int a) {
  640. return(Vhtons(a));
  641. }
  642. DWORD WINAPI inet_addr(char *p) {
  643. return(Vinet_addr(p));
  644. }
  645. DWORD WINAPI inet_network(int a) {
  646. return(Vinet_network(a));
  647. }
  648. DWORD WINAPI inet_ntoa(int a) {
  649. return(Vinet_ntoa(a));
  650. }
  651. DWORD WINAPI ioctlsocket(int s, long cmd, unsigned long *argp) {
  652. if (cmd == FIONBIO) {
  653. struct Sockets * So = FindSocket(s);
  654. if (So == NULL) {
  655. VWSASetLastError(WSAENOBUFS);
  656. LEAVE_MUTEX();
  657. return SOCKET_ERROR;
  658. }
  659. So->Blocking = *argp ? 1 : 0;
  660. LEAVE_MUTEX();
  661. }
  662. return Vioctlsocket(s, cmd, argp);
  663. }
  664. DWORD WINAPI listen(int a,int b) {
  665. return(Vlisten(a, b));
  666. }
  667. DWORD WINAPI NPLoadNameSpaces(int a,int b,int c) {
  668. return(VNPLoadNameSpaces(a, b, c));
  669. }
  670. DWORD WINAPI ntohl(int a) {
  671. return(Vntohl(a));
  672. }
  673. DWORD WINAPI ntohs(int a) {
  674. return(Vntohs(a));
  675. }
  676. DWORD WINAPI rcmd(int a,int b,int c,int d,int e,int f) {
  677. return(Vrcmd(a, b, c, d, e, f));
  678. }
  679. DWORD WINAPI recv(int a,int b,int c,int d) {
  680. return(Vrecv(a, b, c, d));
  681. }
  682. DWORD WINAPI recvfrom(int a,int b,int c,int d,int e,int f) {
  683. return(Vrecvfrom(a, b, c, d, e, f));
  684. }
  685. DWORD WINAPI rexec(int a,int b,int c,int d,int e,int f) {
  686. return(Vrexec(a, b, c, d, e, f));
  687. }
  688. DWORD WINAPI rresvport(int a) {
  689. return(Vrresvport(a));
  690. }
  691. DWORD WINAPI s_perror(int a,int b) {
  692. return(Vs_perror(a, b));
  693. }
  694. DWORD WINAPI select(int a,int b,int c,int d,int e) {
  695. return(Vselect(a, b, c, d, e));
  696. }
  697. DWORD WINAPI send(int a,int b,int c,int d) {
  698. return(Vsend(a, b, c, d));
  699. }
  700. DWORD WINAPI sendto(int a,int b,int c,int d,int e,int f) {
  701. return(Vsendto(a, b, c, d, e, f));
  702. }
  703. DWORD WINAPI sethostname(int a,int b) {
  704. return(Vsethostname(a, b));
  705. }
  706. DWORD WINAPI SetServiceA(int a,int b,int c,int d,int e,int f) {
  707. return(VSetServiceA(a, b, c, d, e, f));
  708. }
  709. DWORD WINAPI SetServiceW(int a,int b,int c,int d,int e,int f) {
  710. return(VSetServiceW(a, b, c, d, e, f));
  711. }
  712. DWORD
  713. WINAPI
  714. setsockopt(
  715. int s,
  716. int level,
  717. int optname,
  718. const char FAR * optval,
  719. int optlen
  720. )
  721. /*++
  722. Routine Description:
  723. If SO_SET_SOCKS_FIREWALL, create SOCKS information if it is new or changed
  724. from current, else pass on the request to wsock32!setsockopt()
  725. Arguments:
  726. s - socket on which to set option
  727. level - option type parameter (SO_SET_SOCKS_FIREWALL)
  728. optname - option type sub-parameter (SOCKS firewall port # in host format)
  729. optval - value to set (pointer to SOCKS information:
  730. DWORD ip address;
  731. LPSTR username
  732. )
  733. optlen - length of value (8)
  734. Return Value:
  735. DWORD
  736. Success - 0
  737. Failure - -1
  738. --*/
  739. {
  740. int rc;
  741. if (level != SO_SET_SOCKS_FIREWALL) {
  742. rc = Vsetsockopt(s, level, optname, optval, optlen);
  743. } else {
  744. struct Hosts * pHost;
  745. struct FirewallInfo {
  746. DWORD ipAddress;
  747. LPSTR userName;
  748. } * pInfo = (struct FirewallInfo *)optval;
  749. optname = Vhtons(optname);
  750. ENTER_MUTEX();
  751. if (pHost = Head) {
  752. if ((pHost->ip != pInfo->ipAddress)
  753. || (pHost->port != optname)
  754. || (pHost->user && lstrcmp(pHost->user, pInfo->userName))) {
  755. //char buf[256];
  756. //wsprintf(buf,
  757. // "throwing out: host: %d.%d.%d.%d:%d,%s; info: %d.%d.%d.%d:%d,%s\n",
  758. // pHost->ip & 0xff,
  759. // (pHost->ip >> 8) & 0xff,
  760. // (pHost->ip >> 16) & 0xff,
  761. // (pHost->ip >> 24) & 0xff,
  762. // Vhtons(pHost->port) & 0xffff,
  763. // pHost->user,
  764. // pInfo->ipAddress & 0xff,
  765. // (pInfo->ipAddress >> 8) & 0xff,
  766. // (pInfo->ipAddress >> 16) & 0xff,
  767. // (pInfo->ipAddress >> 24) & 0xff,
  768. // Vhtons(optname) & 0xffff,
  769. // pInfo->userName
  770. // );
  771. //OutputDebugString(buf);
  772. LocalFree(pHost);
  773. pHost = NULL;
  774. }
  775. }
  776. if (!pHost) {
  777. int userlen = lstrlen(pInfo->userName) + 1;
  778. if (pHost = (struct Hosts *)LocalAlloc(LPTR,
  779. sizeof(struct Hosts)
  780. + userlen
  781. )) {
  782. memcpy(pHost + 1, pInfo->userName, userlen);
  783. pHost->user = (LPSTR)(pHost + 1);
  784. pHost->userlen = userlen;
  785. pHost->ip = pInfo->ipAddress;
  786. pHost->port = (unsigned short)optname;
  787. }
  788. }
  789. Head = pHost;
  790. if (pHost) {
  791. rc = 0;
  792. } else {
  793. VWSASetLastError(WSAENOBUFS);
  794. rc = SOCKET_ERROR;
  795. }
  796. LEAVE_MUTEX();
  797. }
  798. return rc;
  799. }
  800. DWORD WINAPI shutdown(int a,int b) {
  801. return(Vshutdown(a, b));
  802. }
  803. DWORD WINAPI socket(int af,int type,int protocol) {
  804. struct Sockets * So;
  805. int s;
  806. s = Vsocket(af, type, protocol);
  807. if (s != INVALID_SOCKET) {
  808. So = FindSocket(s);
  809. if (So) {
  810. So->type = type;
  811. } else {
  812. Vclosesocket(s);
  813. VWSASetLastError(WSAENOBUFS);
  814. s = INVALID_SOCKET;
  815. }
  816. LEAVE_MUTEX();
  817. }
  818. return s;
  819. }
  820. DWORD WINAPI TransmitFile(int a,int b,int c,int d,int e,int f,int g) {
  821. return(VTransmitFile(a, b, c, d, e, f, g));
  822. }
  823. DWORD WINAPI WEP() {
  824. return(VWEP());
  825. }
  826. DWORD WINAPI WSAAsyncGetHostByAddr(int a,int b,int c,int d,int e,int f,int g) {
  827. return(VWSAAsyncGetHostByAddr(a, b, c, d, e, f, g));
  828. }
  829. DWORD WINAPI WSAAsyncGetHostByName(int a,int b,int c,int d,int e) {
  830. return(VWSAAsyncGetHostByName(a, b, c, d, e));
  831. }
  832. DWORD WINAPI WSAAsyncGetProtoByName(int a,int b,int c,int d,int e) {
  833. return(VWSAAsyncGetProtoByName(a, b, c, d, e));
  834. }
  835. DWORD WINAPI WSAAsyncGetProtoByNumber(int a,int b,int c,int d,int e) {
  836. return(VWSAAsyncGetProtoByNumber(a, b, c, d, e));
  837. }
  838. DWORD WINAPI WSAAsyncGetServByName(int a,int b,int c,int d,int e,int f) {
  839. return(VWSAAsyncGetServByName(a, b, c, d, e, f));
  840. }
  841. DWORD WINAPI WSAAsyncGetServByPort(int a,int b,int c,int d,int e,int f) {
  842. return(VWSAAsyncGetServByPort(a, b, c, d, e, f));
  843. }
  844. DWORD WINAPI WSAAsyncSelect(int s, HWND hWnd, unsigned int wMsg, long lEvent) {
  845. return(VWSAAsyncSelect(s,hWnd,wMsg,lEvent));
  846. }
  847. DWORD WINAPI WSACancelAsyncRequest(int a) {
  848. return(VWSACancelAsyncRequest(a));
  849. }
  850. DWORD WINAPI WSACancelBlockingCall() {
  851. return(VWSACancelBlockingCall());
  852. }
  853. DWORD WINAPI WSACleanup() {
  854. return(VWSACleanup());
  855. }
  856. DWORD WINAPI WSAGetLastError() {
  857. return(VWSAGetLastError());
  858. }
  859. DWORD WINAPI WSAIsBlocking() {
  860. return(VWSAIsBlocking());
  861. }
  862. DWORD WINAPI WSARecvEx(int a,int b,int c,int d) {
  863. return(VWSARecvEx(a, b, c, d));
  864. }
  865. DWORD WINAPI WSASetBlockingHook(int a) {
  866. return(VWSASetBlockingHook(a));
  867. }
  868. DWORD WINAPI WSASetLastError(int a) {
  869. return(VWSASetLastError(a));
  870. }
  871. DWORD WINAPI WSAStartup(int a,int b) {
  872. return(VWSAStartup(a, b));
  873. }
  874. DWORD WINAPI WSAUnhookBlockingHook() {
  875. return(VWSAUnhookBlockingHook());
  876. }
  877. DWORD WINAPI WsControl(int a,int b,int c,int d,int e,int f) {
  878. return(VWsControl(a,b,c,d,e,f));
  879. }
  880. DWORD WSHEnumProtocols(int a,int b, int c,int d) {
  881. return(VWSHEnumProtocols(a,b,c,d));
  882. }
  883. //#ifdef DO_FILE_CONFIG
  884. //
  885. //void
  886. //ParseList(char *List,struct Server **Head,int IsSvr) {
  887. //
  888. // char *p;
  889. // char *p1;
  890. // char *pTok;
  891. // struct Server *tmp,*Current=NULL;
  892. //
  893. // *Head = NULL;
  894. //
  895. // if ( *(List+1) != '=')
  896. // return;
  897. // pTok = List+2;
  898. // List=StrTokEx(&pTok,"\t ");
  899. // p = StrTokEx(&List,",");
  900. // while ( p) {
  901. // if (IsSvr) {
  902. // tmp = (struct Server *)LocalAlloc(LPTR, (sizeof(struct Server)));
  903. // if ( tmp == NULL )
  904. // return;
  905. //
  906. // p1 = strchr(p,':');
  907. // if (p1) {
  908. // *p1++ = 0;
  909. // tmp->port = atoi(p1);
  910. // }
  911. // else
  912. // tmp->port = 1080;
  913. // }
  914. // else {
  915. // tmp = (struct Server *)LocalAlloc(LPTR, (sizeof(struct Server)));
  916. // if ( tmp == NULL )
  917. // return;
  918. // }
  919. // tmp->Name = NewString(p);
  920. // tmp->Next = NULL;
  921. // if (Current == NULL) {
  922. // Current = *Head = tmp;
  923. // }
  924. // else {
  925. // Current->Next = tmp;
  926. // Current=tmp;
  927. // }
  928. // p = StrTokEx(&List,",");
  929. // }
  930. //}
  931. //
  932. //
  933. //void
  934. //LoadConfig(void) {
  935. //
  936. // struct Hosts *Current=NULL,*tmp;
  937. // char Buffer[1024];
  938. // FILE *f;
  939. // char *p;
  940. // char *ServerList;
  941. // char *UserList;
  942. // struct Server *Default=NULL;
  943. // HKEY Key;
  944. //
  945. // GetSystemDirectory(Buffer,sizeof(Buffer));
  946. // strcat(Buffer, "\\socks.cnf");
  947. // f = fopen(Buffer,"rt");
  948. // if ( f == NULL)
  949. // return;
  950. // if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\HummingBird", 0, KEY_QUERY_VALUE, &Key) == ERROR_SUCCESS) {
  951. // int Type, Length=sizeof(Buffer);
  952. // if ( RegQueryValueEx(Key, "SOCKS_SERVER", NULL, &Type, Buffer, &Length) == ERROR_SUCCESS) {
  953. // Buffer[Length] = '\0';
  954. // Default=LocalAlloc(LPTR, sizeof(struct Server));
  955. // if ( Default == NULL )
  956. // return;
  957. //
  958. // p = strchr(Buffer,':');
  959. // if (p) {
  960. // *p++ = 0;
  961. // Default->port = atoi(p);
  962. // }
  963. // else
  964. // Default->port = 1080;
  965. // Default->Name = NewString(Buffer);
  966. // Default->Next = NULL;
  967. // }
  968. // RegCloseKey(Key);
  969. // }
  970. //
  971. // while ( fgets(Buffer,sizeof(Buffer)-1,f) != NULL) {
  972. // Buffer[strlen(Buffer)-1]='\0';
  973. // if ( Buffer[0] == '#')
  974. // continue;
  975. // tmp = (struct Hosts *) LocalAlloc(LPTR, sizeof(struct Hosts));
  976. // if ( tmp == NULL )
  977. // return;
  978. //
  979. // memset(tmp,0,sizeof(struct Hosts));
  980. // ServerList=NULL;
  981. // UserList=NULL;
  982. // p = StrTokEx(&Buffer,"\t ");
  983. // if ( p == NULL) {
  984. // LocalFree(tmp);
  985. // continue;
  986. // }
  987. // if ( lstrcmpi(p,"DENY") == 0) {
  988. // tmp->type = DENY;
  989. // } else if (lstrcmpi(p,"DIRECT") == 0) {
  990. // tmp->type = DIRECT;
  991. // } else if (lstrcmpi(p,"SOCKD") == 0) {
  992. // tmp->type = SOCKD;
  993. // } else {
  994. // LocalFree(tmp);
  995. // continue;
  996. // }
  997. //LookMore:
  998. // p = StrTokEx(&Buffer,"\t ");
  999. // if ( p == NULL) {
  1000. // LocalFree(tmp);
  1001. // continue;
  1002. // }
  1003. // if (*p == '*') {
  1004. // UserList=p;
  1005. // goto LookMore;
  1006. // }
  1007. // if (*p == '@') {
  1008. // ServerList=p;
  1009. // goto LookMore;
  1010. // }
  1011. // tmp->dst = Vinet_addr(p);
  1012. // p = StrTokEx(&Buffer,"\t ");
  1013. // if ( p == NULL) {
  1014. // LocalFree(tmp);
  1015. // continue;
  1016. // }
  1017. // tmp->mask = Vinet_addr(p);
  1018. // p = StrTokEx(&Buffer,"\t ");
  1019. // if (p) {
  1020. // if ( lstrcmpi(p,"EQ") == 0)
  1021. // tmp->op = EQ;
  1022. // else if ( lstrcmpi(p,"NEQ") == 0)
  1023. // tmp->op = NEQ;
  1024. // else if ( lstrcmpi(p,"LT") == 0)
  1025. // tmp->op = LT;
  1026. // else if ( lstrcmpi(p,"GT") == 0)
  1027. // tmp->op = GT;
  1028. // else if ( lstrcmpi(p,"LE") == 0)
  1029. // tmp->op = LE;
  1030. // else if ( lstrcmpi(p,"GE") == 0)
  1031. // tmp->op = GE;
  1032. // else {
  1033. // LocalFree(tmp);
  1034. // continue;
  1035. // }
  1036. // p = StrTokEx(&Buffer,"\t ");
  1037. // if ( p == NULL) {
  1038. // LocalFree(tmp);
  1039. // continue;
  1040. // }
  1041. // if ( isdigit(*p))
  1042. // tmp->port = atoi(p);
  1043. // else {
  1044. // struct servent *se;
  1045. // se=Vgetservbyname(p,"tcp");
  1046. // if ( se == NULL) {
  1047. // LocalFree(tmp);
  1048. // continue;
  1049. // }
  1050. // tmp->port = se->s_port;
  1051. // }
  1052. // }
  1053. // if ( UserList)
  1054. // ParseList(UserList,(struct Server **)&tmp->Users,0);
  1055. // if ( ServerList)
  1056. // ParseList(ServerList,&tmp->Servers,1);
  1057. // if ( (tmp->type == SOCKD) && (tmp->Servers == NULL))
  1058. // tmp->Servers=Default;
  1059. // if ( Current == NULL) {
  1060. // Head = Current = tmp;
  1061. // }
  1062. // else {
  1063. // Current->Next = tmp;
  1064. // Current = tmp;
  1065. // }
  1066. // }
  1067. // fclose(f);
  1068. //}
  1069. //
  1070. //#endif
  1071. HMODULE hModule = NULL;
  1072. int LoadCount = 0;
  1073. BOOL
  1074. WINAPI
  1075. DllMain(
  1076. IN HINSTANCE hInstance,
  1077. IN DWORD reason,
  1078. IN LPVOID Reserved
  1079. )
  1080. {
  1081. HKEY hKey;
  1082. TCHAR szRegBuf[MAX_PATH+1];
  1083. DWORD dwRegBufSize = sizeof(szRegBuf);
  1084. DWORD dwRegType;
  1085. LONG lResult;
  1086. switch(reason) {
  1087. case DLL_PROCESS_DETACH:
  1088. if (LoadCount == 0) {
  1089. DELETE_MUTEX();
  1090. return 1;
  1091. }
  1092. if (--LoadCount == 0) {
  1093. FreeLibrary(hModule);
  1094. }
  1095. return 1;
  1096. case DLL_PROCESS_ATTACH:
  1097. case DLL_THREAD_ATTACH:
  1098. if (++LoadCount == 1) {
  1099. break;
  1100. }
  1101. default:
  1102. return 1;
  1103. }
  1104. // Load an alternate Winsock DLL based on a registry value,
  1105. // in the event that a customer wants to load a different wsock32.
  1106. //
  1107. if (ERROR_SUCCESS == (lResult = RegOpenKeyEx(
  1108. HKEY_CURRENT_USER,
  1109. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
  1110. 0,
  1111. KEY_QUERY_VALUE,
  1112. &hKey
  1113. )))
  1114. {
  1115. if (ERROR_SUCCESS == (lResult = RegQueryValueEx(
  1116. hKey,
  1117. TEXT("AlternateWinsock"),
  1118. NULL,
  1119. &dwRegType,
  1120. (LPBYTE) szRegBuf,
  1121. &dwRegBufSize
  1122. )) && dwRegType == REG_SZ) // only allow type REG_SZ
  1123. {
  1124. // Found a string, so try to load it as the alternate Winsock DLL.
  1125. hModule = LoadLibrary(szRegBuf);
  1126. }
  1127. RegCloseKey(hKey);
  1128. }
  1129. if (lResult != ERROR_SUCCESS)
  1130. {
  1131. hModule = LoadLibrary("WSOCK32.DLL");
  1132. }
  1133. if (hModule < (HMODULE) HINSTANCE_ERROR) {
  1134. MessageBox(NULL,
  1135. "Unable to find old WSOCK32.DLL named \"WSOCK32.DLL\".",
  1136. "Microsoft/Hummingbird SOCKS Shim",
  1137. MB_OK
  1138. );
  1139. LoadCount = 0;
  1140. return 0;
  1141. }
  1142. (FARPROC) VArecv=GetProcAddress(hModule,"Arecv");
  1143. (FARPROC) VAsend=GetProcAddress(hModule,"Asend");
  1144. (FARPROC) VEnumProtocolsA=GetProcAddress(hModule,"EnumProtocolsA");
  1145. (FARPROC) VEnumProtocolsW=GetProcAddress(hModule,"EnumProtocolsW");
  1146. (FARPROC) VGetAddressByNameA=GetProcAddress(hModule,"GetAddressByNameA");
  1147. (FARPROC) VGetAddressByNameW=GetProcAddress(hModule,"GetAddressByNameW");
  1148. (FARPROC) VGetNameByTypeA=GetProcAddress(hModule,"GetNameByTypeA");
  1149. (FARPROC) VGetNameByTypeW=GetProcAddress(hModule,"GetNameByTypeW");
  1150. (FARPROC) VGetServiceA=GetProcAddress(hModule,"GetServiceA");
  1151. (FARPROC) VGetServiceW=GetProcAddress(hModule,"GetServiceW");
  1152. (FARPROC) VGetTypeByNameA=GetProcAddress(hModule,"GetTypeByNameA");
  1153. (FARPROC) VGetTypeByNameW=GetProcAddress(hModule,"GetTypeByNameW");
  1154. (FARPROC) VNPLoadNameSpaces=GetProcAddress(hModule,"NPLoadNameSpaces");
  1155. (FARPROC) VSetServiceA=GetProcAddress(hModule,"SetServiceA");
  1156. (FARPROC) VSetServiceW=GetProcAddress(hModule,"SetServiceW");
  1157. (FARPROC) VTransmitFile=GetProcAddress(hModule,"TransmitFile");
  1158. (FARPROC) VWSAAsyncGetHostByAddr=GetProcAddress(hModule,"WSAAsyncGetHostByAddr");
  1159. (FARPROC) VWSAAsyncGetHostByName=GetProcAddress(hModule,"WSAAsyncGetHostByName");
  1160. (FARPROC) VWSAAsyncGetProtoByName=GetProcAddress(hModule,"WSAAsyncGetProtoByName");
  1161. (FARPROC) VWSAAsyncGetProtoByNumber=GetProcAddress(hModule,"WSAAsyncGetProtoByNumber");
  1162. (FARPROC) VWSAAsyncGetServByName=GetProcAddress(hModule,"WSAAsyncGetServByName");
  1163. (FARPROC) VWSAAsyncGetServByPort=GetProcAddress(hModule,"WSAAsyncGetServByPort");
  1164. (FARPROC) VWSAAsyncSelect=GetProcAddress(hModule,"WSAAsyncSelect");
  1165. (FARPROC) VWSACancelAsyncRequest=GetProcAddress(hModule,"WSACancelAsyncRequest");
  1166. (FARPROC) VWSACancelBlockingCall=GetProcAddress(hModule,"WSACancelBlockingCall");
  1167. (FARPROC) VWSACleanup=GetProcAddress(hModule,"WSACleanup");
  1168. (FARPROC) VWSAGetLastError=GetProcAddress(hModule,"WSAGetLastError");
  1169. (FARPROC) VWSAIsBlocking=GetProcAddress(hModule,"WSAIsBlocking");
  1170. (FARPROC) VWSARecvEx=GetProcAddress(hModule,"WSARecvEx");
  1171. (FARPROC) VWSASetBlockingHook=GetProcAddress(hModule,"WSASetBlockingHook");
  1172. (FARPROC) VWSASetLastError=GetProcAddress(hModule,"WSASetLastError");
  1173. (FARPROC) VWSAStartup=GetProcAddress(hModule,"WSAStartup");
  1174. (FARPROC) VWSAUnhookBlockingHook=GetProcAddress(hModule,"WSAUnhookBlockingHook");
  1175. (FARPROC) VWSHEnumProtocols=GetProcAddress(hModule,"WSHEnumProtocols");
  1176. (FARPROC) VWsControl=GetProcAddress(hModule,"WsControl");
  1177. (FARPROC) V__WSAFDIsSet=GetProcAddress(hModule,"__WSAFDIsSet");
  1178. (FARPROC) Vaccept=GetProcAddress(hModule,"accept");
  1179. (FARPROC) Vbind=GetProcAddress(hModule,"bind");
  1180. (FARPROC) Vclosesocket=GetProcAddress(hModule,"closesocket");
  1181. (FARPROC) Vclosesockinfo=GetProcAddress(hModule,"closesockinfo");
  1182. (FARPROC) Vconnect=GetProcAddress(hModule,"connect");
  1183. (FARPROC) Vdn_expand=GetProcAddress(hModule,"dn_expand");
  1184. (FARPROC) Vgethostbyaddr=GetProcAddress(hModule,"gethostbyaddr");
  1185. (FARPROC) Vgethostbyname=GetProcAddress(hModule,"gethostbyname");
  1186. (FARPROC) Vgethostname=GetProcAddress(hModule,"gethostname");
  1187. (FARPROC) Vgetnetbyname=GetProcAddress(hModule,"getnetbyname");
  1188. (FARPROC) Vgetpeername=GetProcAddress(hModule,"getpeername");
  1189. (FARPROC) Vgetprotobyname=GetProcAddress(hModule,"getprotobyname");
  1190. (FARPROC) Vgetprotobynumber=GetProcAddress(hModule,"getprotobynumber");
  1191. (FARPROC) Vgetservbyname=GetProcAddress(hModule,"getservbyname");
  1192. (FARPROC) Vgetservbyport=GetProcAddress(hModule,"getservbyport");
  1193. (FARPROC) Vgetsockname=GetProcAddress(hModule,"getsockname");
  1194. (FARPROC) Vgetsockopt=GetProcAddress(hModule,"getsockopt");
  1195. (FARPROC) Vhtonl=GetProcAddress(hModule,"htonl");
  1196. (FARPROC) Vhtons=GetProcAddress(hModule,"htons");
  1197. (FARPROC) Vinet_addr=GetProcAddress(hModule,"inet_addr");
  1198. (FARPROC) Vinet_network=GetProcAddress(hModule,"inet_network");
  1199. (FARPROC) Vinet_ntoa=GetProcAddress(hModule,"inet_ntoa");
  1200. (FARPROC) Vioctlsocket=GetProcAddress(hModule,"ioctlsocket");
  1201. (FARPROC) Vlisten=GetProcAddress(hModule,"listen");
  1202. (FARPROC) Vntohl=GetProcAddress(hModule,"ntohl");
  1203. (FARPROC) Vntohs=GetProcAddress(hModule,"ntohs");
  1204. (FARPROC) Vrcmd=GetProcAddress(hModule,"rcmd");
  1205. (FARPROC) Vrecv=GetProcAddress(hModule,"recv");
  1206. (FARPROC) Vrecvfrom=GetProcAddress(hModule,"recvfrom");
  1207. (FARPROC) Vrexec=GetProcAddress(hModule,"rexec");
  1208. (FARPROC) Vrresvport=GetProcAddress(hModule,"rresvport");
  1209. (FARPROC) Vs_perror=GetProcAddress(hModule,"s_perror");
  1210. (FARPROC) Vselect=GetProcAddress(hModule,"select");
  1211. (FARPROC) Vsend=GetProcAddress(hModule,"send");
  1212. (FARPROC) Vsendto=GetProcAddress(hModule,"sendto");
  1213. (FARPROC) Vsethostname=GetProcAddress(hModule,"sethostname");
  1214. (FARPROC) Vsetsockopt=GetProcAddress(hModule,"setsockopt");
  1215. (FARPROC) Vshutdown=GetProcAddress(hModule,"shutdown");
  1216. (FARPROC) Vsocket=GetProcAddress(hModule,"socket");
  1217. (FARPROC) VWEP=GetProcAddress(hModule,"WEP");
  1218. (FARPROC) VAcceptEx = GetProcAddress(hModule,"AcceptEx");
  1219. (FARPROC) VGetAcceptExSockaddrs = GetProcAddress(hModule,"GetAcceptExSockaddrs");
  1220. (FARPROC) VMigrateWinsockConfiguration = GetProcAddress(hModule,"MigrateWinsockConfiguration");
  1221. (FARPROC) VWSApSetPostRoutine = GetProcAddress(hModule,"WSApSetPostRoutine");
  1222. CREATE_MUTEX();
  1223. #ifdef DO_FILE_CONFIG
  1224. LoadConfig();
  1225. #endif
  1226. return 1;
  1227. }