struct hostent *hostentry;
const char *colon;
char name[128];
- if (!address || !string)
+ if (!address || !string || !*string)
return 0;
memset(address, 0, sizeof(*address));
address->addresstype = LHNETADDRESSTYPE_NONE;
return 1;
}
// try to parse as dotted decimal ipv4 address first
- if (sscanf(name, "%d.%d.%d.%d", &d1, &d2, &d3, &d4) == 4 && (unsigned int)d1 < 256 && (unsigned int)d2 < 256 && (unsigned int)d3 < 256 && (unsigned int)d4 < 256)
+ // note this supports partial ip addresses
+ d1 = d2 = d3 = d4 = 0;
+ if (sscanf(name, "%d.%d.%d.%d", &d1, &d2, &d3, &d4) >= 1 && (unsigned int)d1 < 256 && (unsigned int)d2 < 256 && (unsigned int)d3 < 256 && (unsigned int)d4 < 256)
{
// parsed a valid ipv4 address
address->addresstype = LHNETADDRESSTYPE_INET4;
#ifdef STANDALONETEST
if (i < MAX_NAMECACHE)
#else
- if (i < MAX_NAMECACHE && Sys_DoubleTime() < namecache[i].expirationtime)
+ if (i < MAX_NAMECACHE && realtime < namecache[i].expirationtime)
#endif
{
*address = namecache[i].address;
namecache[namecacheposition].name[i] = name[i];
namecache[namecacheposition].name[i] = 0;
#ifndef STANDALONETEST
- namecache[namecacheposition].expirationtime = Sys_DoubleTime() + 12 * 3600; // 12 hours
+ namecache[namecacheposition].expirationtime = realtime + 12 * 3600; // 12 hours
#endif
namecache[namecacheposition].address = *address;
namecacheposition = (namecacheposition + 1) % MAX_NAMECACHE;
namecache[namecacheposition].name[i] = name[i];
namecache[namecacheposition].name[i] = 0;
#ifndef STANDALONETEST
- namecache[namecacheposition].expirationtime = Sys_DoubleTime() + 12 * 3600; // 12 hours
+ namecache[namecacheposition].expirationtime = realtime + 12 * 3600; // 12 hours
#endif
namecache[namecacheposition].address = *address;
namecacheposition = (namecacheposition + 1) % MAX_NAMECACHE;
namecache[namecacheposition].name[i] = name[i];
namecache[namecacheposition].name[i] = 0;
#ifndef STANDALONETEST
- namecache[namecacheposition].expirationtime = Sys_DoubleTime() + 12 * 3600; // 12 hours
+ namecache[namecacheposition].expirationtime = realtime + 12 * 3600; // 12 hours
#endif
namecache[namecacheposition].address.addresstype = LHNETADDRESSTYPE_NONE;
namecacheposition = (namecacheposition + 1) % MAX_NAMECACHE;
{
if (stringbuffersize >= 6)
{
- strcpy(string, "local");
+ memcpy(string, "local", 6);
return 1;
}
}
#endif
}
+void LHNET_SleepUntilPacket_Microseconds(int microseconds)
+{
+ fd_set fdreadset;
+ struct timeval tv;
+ int lastfd;
+ lhnetsocket_t *s;
+ FD_ZERO(&fdreadset);
+ lastfd = 0;
+ for (s = lhnet_socketlist.next;s != &lhnet_socketlist;s = s->next)
+ {
+ if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6)
+ {
+ if (lastfd < s->inetsocket)
+ lastfd = s->inetsocket;
+ FD_SET(s->inetsocket, &fdreadset);
+ }
+ }
+ tv.tv_sec = microseconds / 1000000;
+ tv.tv_usec = microseconds % 1000000;
+ select(lastfd + 1, &fdreadset, NULL, NULL, &tv);
+}
+
lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
{
lhnetsocket_t *lhnetsocket, *s;
continue;
}
#ifndef STANDALONETEST
- if (cl_netlocalping.value && (Sys_DoubleTime() - cl_netlocalping.value * (1.0 / 2000.0)) < p->sentdoubletime)
+ if (cl_netlocalping.value && (realtime - cl_netlocalping.value * (1.0 / 2000.0)) < p->sentdoubletime)
continue;
#endif
if (value == 0 && p->destinationport == lhnetsocket->address.addressdata.loop.port)
p->next->prev = p;
p->prev->next = p;
#ifndef STANDALONETEST
- p->sentdoubletime = Sys_DoubleTime();
+ p->sentdoubletime = realtime;
#endif
value = contentlength;
}