]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
no longer dynamically loads portions of wsock32.dll (because it required static linki...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 28 Mar 2003 03:21:12 +0000 (03:21 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 28 Mar 2003 03:21:12 +0000 (03:21 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2862 d7cf8633-e32d-0410-b094-e92efae38249

net_wins.c

index 16c1eb7a153339bc6db1abcf941b7f6558d35c93..30d1d41ab047312be4a2e1079f37af260696933f 100644 (file)
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -31,27 +31,6 @@ static struct qsockaddr broadcastaddr;
 
 static unsigned long myAddr;
 
-qboolean       winsock_lib_initialized;
-
-int (PASCAL FAR *pWSAStartup)(WORD wVersionRequired, LPWSADATA lpWSAData);
-int (PASCAL FAR *pWSACleanup)(void);
-int (PASCAL FAR *pWSAGetLastError)(void);
-SOCKET (PASCAL FAR *psocket)(int af, int type, int protocol);
-int (PASCAL FAR *pioctlsocket)(SOCKET s, long cmd, u_long FAR *argp);
-int (PASCAL FAR *psetsockopt)(SOCKET s, int level, int optname,
-                                                         const char FAR * optval, int optlen);
-int (PASCAL FAR *precvfrom)(SOCKET s, char FAR * buf, int len, int flags,
-                                                       struct sockaddr FAR *from, int FAR * fromlen);
-int (PASCAL FAR *psendto)(SOCKET s, const char FAR * buf, int len, int flags,
-                                                 const struct sockaddr FAR *to, int tolen);
-int (PASCAL FAR *pclosesocket)(SOCKET s);
-int (PASCAL FAR *pgethostname)(char FAR * name, int namelen);
-struct hostent FAR * (PASCAL FAR *pgethostbyname)(const char FAR * name);
-struct hostent FAR * (PASCAL FAR *pgethostbyaddr)(const char FAR * addr,
-                                                                                                 int len, int type);
-int (PASCAL FAR *pgetsockname)(SOCKET s, struct sockaddr FAR *name,
-                                                          int FAR * namelen);
-
 #include "net_wins.h"
 
 int winsock_initialized = 0;
@@ -61,29 +40,29 @@ WSADATA             winsockdata;
 
 static double  blocktime;
 
-BOOL PASCAL FAR BlockingHook(void)  
-{ 
-    MSG                msg;
-    BOOL       ret;
+BOOL PASCAL FAR BlockingHook(void)
+{
+       MSG             msg;
+       BOOL    ret;
+
        if ((Sys_DoubleTime() - blocktime) > 2.0)
        {
                WSACancelBlockingCall();
                return false;
        }
 
-    /* get the next message, if any */ 
-    ret = (BOOL) PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); 
-    /* if we got one, process it */ 
-    if (ret) { 
-        TranslateMessage(&msg); 
-        DispatchMessage(&msg); 
-    } 
-    /* true if we got a message */ 
-    return ret; 
-} 
+       /* get the next message, if any */
+       ret = (BOOL) PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
+
+       /* if we got one, process it */
+       if (ret) {
+               TranslateMessage(&msg);
+               DispatchMessage(&msg);
+       }
+
+       /* true if we got a message */
+       return ret;
+}
 
 
 void WINS_GetLocalAddress(void)
@@ -95,12 +74,12 @@ void WINS_GetLocalAddress(void)
        if (myAddr != INADDR_ANY)
                return;
 
-       if (pgethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
+       if (gethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
                return;
 
        blocktime = Sys_DoubleTime();
        WSASetBlockingHook(BlockingHook);
-       local = pgethostbyname(buff);
+       local = gethostbyname(buff);
        WSAUnhookBlockingHook();
        if (local == NULL)
                return;
@@ -118,55 +97,13 @@ int WINS_Init (void)
        char    buff[MAXHOSTNAMELEN];
        char    *p;
        int             r;
-       WORD    wVersionRequested;
-       HINSTANCE hInst;
-
-// initialize the Winsock function vectors (we do this instead of statically linking
-// so we can run on Win 3.1, where there isn't necessarily Winsock)
-    hInst = LoadLibrary("wsock32.dll");
-       
-       if (hInst == NULL)
-       {
-               Con_SafePrintf ("Failed to load wsock32.dll\n");
-               winsock_lib_initialized = false;
-               return -1;
-       }
-
-       winsock_lib_initialized = true;
-
-    pWSAStartup = (void *)GetProcAddress(hInst, "WSAStartup");
-    pWSACleanup = (void *)GetProcAddress(hInst, "WSACleanup");
-    pWSAGetLastError = (void *)GetProcAddress(hInst, "WSAGetLastError");
-    psocket = (void *)GetProcAddress(hInst, "socket");
-    pioctlsocket = (void *)GetProcAddress(hInst, "ioctlsocket");
-    psetsockopt = (void *)GetProcAddress(hInst, "setsockopt");
-    precvfrom = (void *)GetProcAddress(hInst, "recvfrom");
-    psendto = (void *)GetProcAddress(hInst, "sendto");
-    pclosesocket = (void *)GetProcAddress(hInst, "closesocket");
-    pgethostname = (void *)GetProcAddress(hInst, "gethostname");
-    pgethostbyname = (void *)GetProcAddress(hInst, "gethostbyname");
-    pgethostbyaddr = (void *)GetProcAddress(hInst, "gethostbyaddr");
-    pgetsockname = (void *)GetProcAddress(hInst, "getsockname");
-
-    if (!pWSAStartup || !pWSACleanup || !pWSAGetLastError ||
-               !psocket || !pioctlsocket || !psetsockopt ||
-               !precvfrom || !psendto || !pclosesocket ||
-               !pgethostname || !pgethostbyname || !pgethostbyaddr ||
-               !pgetsockname)
-       {
-               Con_SafePrintf ("Couldn't GetProcAddress from wsock32.dll\n");
-               return -1;
-       }
 
        if (COM_CheckParm ("-noudp"))
                return -1;
 
        if (winsock_initialized == 0)
        {
-               wVersionRequested = MAKEWORD(1, 1); 
-
-               r = pWSAStartup (MAKEWORD(1, 1), &winsockdata);
-
+               r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
                if (r)
                {
                        Con_SafePrintf ("Winsock initialization failed.\n");
@@ -176,11 +113,11 @@ int WINS_Init (void)
        winsock_initialized++;
 
        // determine my name
-       if (pgethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
+       if (gethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
        {
                Con_DPrintf ("Winsock TCP/IP Initialization failed.\n");
                if (--winsock_initialized == 0)
-                       pWSACleanup ();
+                       WSACleanup ();
                return -1;
        }
 
@@ -228,7 +165,7 @@ int WINS_Init (void)
        {
                Con_Printf("WINS_Init: Unable to open control socket\n");
                if (--winsock_initialized == 0)
-                       pWSACleanup ();
+                       WSACleanup ();
                return -1;
        }
 
@@ -249,7 +186,7 @@ void WINS_Shutdown (void)
        WINS_Listen (false);
        WINS_CloseSocket (net_controlsocket);
        if (--winsock_initialized == 0)
-               pWSACleanup ();
+               WSACleanup ();
 }
 
 //=============================================================================
@@ -282,10 +219,10 @@ int WINS_OpenSocket (int port)
        struct sockaddr_in address;
        u_long _true = 1;
 
-       if ((newsocket = psocket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+       if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
                return -1;
 
-       if (pioctlsocket (newsocket, FIONBIO, &_true) == -1)
+       if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
                goto ErrorReturn;
 
        address.sin_family = AF_INET;
@@ -296,7 +233,7 @@ int WINS_OpenSocket (int port)
 
        Sys_Error ("Unable to bind to %s", WINS_AddrToString((struct qsockaddr *)&address));
 ErrorReturn:
-       pclosesocket (newsocket);
+       closesocket (newsocket);
        return -1;
 }
 
@@ -306,7 +243,7 @@ int WINS_CloseSocket (int socket)
 {
        if (socket == net_broadcastsocket)
                net_broadcastsocket = 0;
-       return pclosesocket (socket);
+       return closesocket (socket);
 }
 
 
@@ -328,7 +265,7 @@ static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
        int mask;
        int run;
        int port;
-       
+
        buff[0] = '.';
        b = buff;
        strcpy(buff+1, in);
@@ -346,7 +283,7 @@ static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
                {
                  num = num*10 + *b++ - '0';
                  if (++run > 3)
-                       return -1;
+                       return -1;
                }
                if ((*b < '0' || *b > '9') && *b != '.' && *b != ':' && *b != 0)
                        return -1;
@@ -355,16 +292,16 @@ static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
                mask<<=8;
                addr = (addr<<8) + num;
        }
-       
+
        if (*b++ == ':')
                port = atoi(b);
        else
                port = net_hostport;
 
        hostaddr->sa_family = AF_INET;
-       ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port);        
+       ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port);
        ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr = (myAddr & htonl(mask)) | htonl(addr);
-       
+
        return 0;
 }
 //=============================================================================
@@ -383,10 +320,8 @@ int WINS_CheckNewConnections (void)
        if (net_acceptsocket == -1)
                return -1;
 
-       if (precvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) >= 0)
-       {
+       if (recvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) >= 0)
                return net_acceptsocket;
-       }
        return -1;
 }
 
@@ -412,10 +347,10 @@ int WINS_Read (int socket, qbyte *buf, int len, struct qsockaddr *addr)
        int ret;
        int errno;
 
-       ret = precvfrom (socket, buf, len, 0, (struct sockaddr *)addr, &addrlen);
+       ret = recvfrom (socket, buf, len, 0, (struct sockaddr *)addr, &addrlen);
        if (ret == -1)
        {
-                errno = pWSAGetLastError();
+               errno = WSAGetLastError();
 
                if (errno == WSAEWOULDBLOCK || errno == WSAECONNREFUSED)
                        return 0;
@@ -431,7 +366,7 @@ int WINS_MakeSocketBroadcastCapable (int socket)
        int     i = 1;
 
        // make this socket broadcast capable
-       if (psetsockopt(socket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) < 0)
+       if (setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) < 0)
                return -1;
        net_broadcastsocket = socket;
 
@@ -466,9 +401,9 @@ int WINS_Write (int socket, qbyte *buf, int len, struct qsockaddr *addr)
 {
        int ret;
 
-       ret = psendto (socket, buf, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr));
+       ret = sendto (socket, buf, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr));
        if (ret == -1)
-               if (pWSAGetLastError() == WSAEWOULDBLOCK)
+               if (WSAGetLastError() == WSAEWOULDBLOCK)
                        return 0;
 
        return ret;
@@ -510,7 +445,7 @@ int WINS_GetSocketAddr (int socket, struct qsockaddr *addr)
        unsigned int a;
 
        memset(addr, 0, sizeof(struct qsockaddr));
-       pgetsockname(socket, (struct sockaddr *)addr, &addrlen);
+       getsockname(socket, (struct sockaddr *)addr, &addrlen);
        a = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
        if (a == 0 || a == inet_addr("127.0.0.1"))
                ((struct sockaddr_in *)addr)->sin_addr.s_addr = myAddr;
@@ -524,7 +459,7 @@ int WINS_GetNameFromAddr (const struct qsockaddr *addr, char *name)
 {
        struct hostent *hostentry;
 
-       hostentry = pgethostbyaddr ((char *)&((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr), AF_INET);
+       hostentry = gethostbyaddr ((char *)&((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr), AF_INET);
        if (hostentry)
        {
                strncpy (name, (char *)hostentry->h_name, NET_NAMELEN - 1);
@@ -543,13 +478,13 @@ int WINS_GetAddrFromName(const char *name, struct qsockaddr *addr)
 
        if (name[0] >= '0' && name[0] <= '9')
                return PartialIPAddress (name, addr);
-       
-       hostentry = pgethostbyname (name);
+
+       hostentry = gethostbyname (name);
        if (!hostentry)
                return -1;
 
        addr->sa_family = AF_INET;
-       ((struct sockaddr_in *)addr)->sin_port = htons((unsigned short)net_hostport);   
+       ((struct sockaddr_in *)addr)->sin_port = htons((unsigned short)net_hostport);
        ((struct sockaddr_in *)addr)->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0];
 
        return 0;