}
#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;
address->addresstype = LHNETADDRESSTYPE_NONE;
port = 0;
colon = strrchr(string, ':');
- if (colon)
+ 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
+ {
port = atoi(colon + 1);
+ }
else
colon = string + strlen(string);
if (port == 0)
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;
{
#ifndef _WIN32
- static char ifname [IF_NAMESIZE];
-
if (if_indextoname(address->addr.in6.sin6_scope_id, ifname) == ifname)
return ifname;
// 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
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;
#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;
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)
{
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;
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
SOCKLEN_T inetaddresslength;
address->addresstype = LHNETADDRESSTYPE_NONE;
inetaddresslength = sizeof(address->addr.in6);
- value = recvfrom(lhnetsocket->inetsocket, (char *)content, maxcontentlength, 0, &address->addr.sock, &inetaddresslength);
+ value = recvfrom(lhnetsocket->inetsocket, (char *)content, maxcontentlength, LHNET_RECVFROM_FLAGS, &address->addr.sock, &inetaddresslength);
if (value > 0)
{
address->addresstype = LHNETADDRESSTYPE_INET6;
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
{
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
{
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