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;
{
if (stringbuffersize >= 6)
{
- strcpy(string, "local");
+ memcpy(string, "local", 6);
return 1;
}
}
int main(int argc, char **argv)
{
#if 1
- char *buffer = "socket to socket test successful", buffer2[1024];
+ char *buffer = "test", buffer2[1024];
int blen = strlen(buffer);
int b2len = 1024;
lhnetsocket_t *sock1;
int test1;
int test2;
- strcpy(buffer2, "socket to socket test failed");
-
printf("calling LHNET_Init\n");
LHNET_Init();
usleep (100000);
#endif
printf("calling LHNET_Read on the second socket to read the packet sent from the first socket\n");
- test2 = LHNET_Read(sock2, buffer2, b2len, &myaddy3);
- Con_Printf("%s\n", buffer2);
+ test2 = LHNET_Read(sock2, buffer2, b2len - 1, &myaddy3);
+ if (test2 > 0)
+ Con_Printf("socket to socket test succeeded\n");
+ else
+ Con_Printf("socket to socket test failed\n");
+
#ifdef WIN32
printf("press any key to exit\n");
getchar();