]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - lhnet.c
Kill more unreachable code.
[xonotic/darkplaces.git] / lhnet.c
diff --git a/lhnet.c b/lhnet.c
index bb1e0085aaf0240af6555f4565d1213e3240f88d..229825711dad97a57819daa6750fc8c127636473 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -154,7 +154,7 @@ int LHNETADDRESS_FromPort(lhnetaddress_t *vaddress, lhnetaddresstype_t addressty
 }
 
 #ifdef SUPPORTIPV6
-int LHNETADDRESS_Resolve(lhnetaddressnative_t *address, const char *name, int port)
+static int LHNETADDRESS_Resolve(lhnetaddressnative_t *address, const char *name, int port)
 {
        char port_buff [16];
        struct addrinfo hints;
@@ -389,7 +389,7 @@ int LHNETADDRESS_FromString(lhnetaddress_t *vaddress, const char *string, int de
        address->addresstype = LHNETADDRESSTYPE_NONE;
        port = 0;
        colon = strrchr(string, ':');
-       if (colon && (colon == strchr(string, ':') || (string[0] == '[' && colon - string > 0 && colon[-1] == ']'))I)
+       if (colon && (colon == strchr(string, ':') || (string[0] == '[' && colon - string > 0 && colon[-1] == ']')))
        //           EITHER: colon is the ONLY colon  OR: colon comes after [...] delimited IPv6 address
        //           fixes misparsing of IPv6 addresses without port
        {
@@ -535,9 +535,9 @@ int LHNETADDRESS_ToString(const lhnetaddress_t *vaddress, char *string, int stri
 {
        lhnetaddressnative_t *address = (lhnetaddressnative_t *)vaddress;
        const unsigned char *a;
-       *string = 0;
        if (!address || !string || stringbuffersize < 1)
                return 0;
+       *string = 0;
        switch(address->addresstype)
        {
        default:
@@ -612,7 +612,7 @@ int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address)
                return LHNETADDRESSTYPE_NONE;
 }
 
-const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *vaddress)
+const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *vaddress, char *ifname, size_t ifnamelength)
 {
 #ifdef SUPPORTIPV6
        lhnetaddressnative_t *address = (lhnetaddressnative_t *)vaddress;
@@ -621,8 +621,6 @@ const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *vaddress)
        {
 #ifndef _WIN32
 
-               static char ifname [IF_NAMESIZE];
-               
                if (if_indextoname(address->addr.in6.sin6_scope_id, ifname) == ifname)
                        return ifname;
 
@@ -631,9 +629,7 @@ const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *vaddress)
                // The Win32 API doesn't have if_indextoname() until Windows Vista,
                // but luckily it just uses the interface ID as the interface name
 
-               static char ifname [16];
-
-               if (dpsnprintf(ifname, sizeof(ifname), "%lu", address->addr.in6.sin6_scope_id) > 0)
+               if (dpsnprintf(ifname, ifnamelength, "%lu", address->addr.in6.sin6_scope_id) > 0)
                        return ifname;
 
 #endif
@@ -727,6 +723,7 @@ lhnetpacket_t;
 static int lhnet_active;
 static lhnetsocket_t lhnet_socketlist;
 static lhnetpacket_t lhnet_packetlist;
+static int lhnet_default_dscp = 0;
 #ifdef WIN32
 static int lhnet_didWSAStartup = 0;
 static WSADATA lhnet_winsockdata;
@@ -746,6 +743,18 @@ void LHNET_Init(void)
 #endif
 }
 
+int LHNET_DefaultDSCP(int dscp)
+{
+#ifdef IP_TOS
+       int prev = lhnet_default_dscp;
+       if(dscp >= 0)
+               lhnet_default_dscp = dscp;
+       return prev;
+#else
+       return -1;
+#endif
+}
+
 void LHNET_Shutdown(void)
 {
        lhnetpacket_t *p;
@@ -949,6 +958,20 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
                                                        lhnetaddressnative_t *localaddress = (lhnetaddressnative_t *)&lhnetsocket->address;
                                                        SOCKLEN_T namelen;
                                                        int bindresult;
+
+#if defined(SOL_RFC1149) && defined(RFC1149_1149ONLY)
+                                                       // we got reports of massive lags when this protocol was chosen as transport
+                                                       // so better turn it off
+                                                       {
+                                                               int rfc1149only = 0;
+                                                               int rfc1149enabled = 0;
+                                                               if(setsockopt(lhnetsocket->inetsocket, SOL_RFC1149, RFC1149_1149ONLY, &rfc1149only))
+                                                                       Con_Printf("LHNET_OpenSocket_Connectionless: warning: setsockopt(RFC1149_1149ONLY) returned error: %s\n", LHNETPRIVATE_StrError());
+                                                               if(setsockopt(lhnetsocket->inetsocket, SOL_RFC1149, RFC1149_ENABLED, &rfc1149enabled))
+                                                                       Con_Printf("LHNET_OpenSocket_Connectionless: warning: setsockopt(RFC1149_ENABLED) returned error: %s\n", LHNETPRIVATE_StrError());
+                                                       }
+#endif
+
 #ifdef SUPPORTIPV6
                                                        if (address->addresstype == LHNETADDRESSTYPE_INET6)
                                                        {
@@ -970,6 +993,13 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
                                                                int i = 1;
                                                                // enable broadcast on this socket
                                                                setsockopt(lhnetsocket->inetsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i));
+#ifdef IP_TOS
+                                                               {
+                                                                       // enable DSCP for ToS support
+                                                                       int tos = lhnet_default_dscp << 2;
+                                                                       setsockopt(lhnetsocket->inetsocket, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos));
+                                                               }
+#endif
                                                                lhnetsocket->next = &lhnet_socketlist;
                                                                lhnetsocket->prev = lhnetsocket->next->prev;
                                                                lhnetsocket->next->prev = lhnetsocket;
@@ -1107,7 +1137,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                                        Con_Print("Connection refused\n");
                                        return 0;
                        }
-                       Con_Printf("LHNET_Read: recvfrom returned error: %s\n", LHNETPRIVATE_StrError());
+                       Con_DPrintf("LHNET_Read: recvfrom returned error: %s\n", LHNETPRIVATE_StrError());
                }
        }
 #ifdef SUPPORTIPV6
@@ -1134,7 +1164,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                                        Con_Print("Connection refused\n");
                                        return 0;
                        }
-                       Con_Printf("LHNET_Read: recvfrom returned error: %s\n", LHNETPRIVATE_StrError());
+                       Con_DPrintf("LHNET_Read: recvfrom returned error: %s\n", LHNETPRIVATE_StrError());
                }
        }
 #endif
@@ -1175,7 +1205,7 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng
                {
                        if (SOCKETERRNO == EWOULDBLOCK)
                                return 0;
-                       Con_Printf("LHNET_Write: sendto returned error: %s\n", LHNETPRIVATE_StrError());
+                       Con_DPrintf("LHNET_Write: sendto returned error: %s\n", LHNETPRIVATE_StrError());
                }
        }
 #ifdef SUPPORTIPV6
@@ -1186,7 +1216,7 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng
                {
                        if (SOCKETERRNO == EWOULDBLOCK)
                                return 0;
-                       Con_Printf("LHNET_Write: sendto returned error: %s\n", LHNETPRIVATE_StrError());
+                       Con_DPrintf("LHNET_Write: sendto returned error: %s\n", LHNETPRIVATE_StrError());
                }
        }
 #endif