void sk_cleanup(void) { Actual_Socket s; int i; if (sktree) { for (i = 0; (s = index234(sktree, i)) != NULL; i++) { p_closesocket(s->s); } freetree234(sktree); sktree = NULL; } p_WSACleanup(); if (winsock_module) FreeLibrary(winsock_module); #ifndef NO_IPV6 if (wship6_module) FreeLibrary(wship6_module); #endif }
void sk_init(void) { WORD winsock_ver; WSADATA wsadata; winsock_ver = MAKEWORD(2, 0); winsock_module = LoadLibrary("WS2_32.DLL"); if (!winsock_module) { winsock_module = LoadLibrary("WSOCK32.DLL"); winsock_ver = MAKEWORD(1, 1); } if (!winsock_module) fatalbox("Unable to load any WinSock library"); #ifndef NO_IPV6 wship6_module = LoadLibrary("wship6.dll"); if (wship6_module) { GET_WINSOCK_FUNCTION(wship6_module, getaddrinfo); GET_WINSOCK_FUNCTION(wship6_module, freeaddrinfo); GET_WINSOCK_FUNCTION(wship6_module, getnameinfo); } #endif GET_WINSOCK_FUNCTION(winsock_module, WSAAsyncSelect); GET_WINSOCK_FUNCTION(winsock_module, WSAEventSelect); GET_WINSOCK_FUNCTION(winsock_module, select); GET_WINSOCK_FUNCTION(winsock_module, WSAGetLastError); GET_WINSOCK_FUNCTION(winsock_module, WSAEnumNetworkEvents); GET_WINSOCK_FUNCTION(winsock_module, WSAStartup); GET_WINSOCK_FUNCTION(winsock_module, WSACleanup); GET_WINSOCK_FUNCTION(winsock_module, closesocket); GET_WINSOCK_FUNCTION(winsock_module, ntohl); GET_WINSOCK_FUNCTION(winsock_module, htonl); GET_WINSOCK_FUNCTION(winsock_module, htons); GET_WINSOCK_FUNCTION(winsock_module, ntohs); GET_WINSOCK_FUNCTION(winsock_module, gethostbyname); GET_WINSOCK_FUNCTION(winsock_module, getservbyname); GET_WINSOCK_FUNCTION(winsock_module, inet_addr); GET_WINSOCK_FUNCTION(winsock_module, inet_ntoa); GET_WINSOCK_FUNCTION(winsock_module, connect); GET_WINSOCK_FUNCTION(winsock_module, bind); GET_WINSOCK_FUNCTION(winsock_module, setsockopt); GET_WINSOCK_FUNCTION(winsock_module, socket); GET_WINSOCK_FUNCTION(winsock_module, listen); GET_WINSOCK_FUNCTION(winsock_module, send); GET_WINSOCK_FUNCTION(winsock_module, ioctlsocket); GET_WINSOCK_FUNCTION(winsock_module, accept); GET_WINSOCK_FUNCTION(winsock_module, recv); GET_WINSOCK_FUNCTION(winsock_module, WSAIoctl); if (p_WSAStartup(winsock_ver, &wsadata)) { fatalbox("Unable to initialise WinSock"); } if (LOBYTE(wsadata.wVersion) != LOBYTE(winsock_ver)) { p_WSACleanup(); fatalbox("WinSock version is incompatible with %d.%d", LOBYTE(winsock_ver), HIBYTE(winsock_ver)); } sktree = newtree234(cmpfortree); }