Revert "Network and IPv{4,6} related changes"

This commit is contained in:
ailin-nemui 2015-09-22 21:59:17 +02:00
commit f5f3d7cc98
19 changed files with 241 additions and 88 deletions

View file

@ -103,12 +103,15 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
srand(time(NULL));
memset(&rec, 0, sizeof(rec));
rec.error = net_gethostbyname(addr, &rec.ip);
rec.error = net_gethostbyname(addr, &rec.ip4, &rec.ip6);
if (rec.error == 0) {
errorstr = NULL;
if (reverse_lookup) {
/* reverse lookup the IP, ignore any error */
net_gethostbyaddr(&rec.ip, &rec.host);
if (rec.ip4.family != 0)
net_gethostbyaddr(&rec.ip4, &rec.host4);
if (rec.ip6.family != 0)
net_gethostbyaddr(&rec.ip6, &rec.host6);
}
} else {
errorstr = net_gethosterror(rec.error);
@ -119,11 +122,18 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
if (rec.errlen != 0)
g_io_channel_write_block(pipe, (void *) errorstr, rec.errlen);
else {
if (rec.host) {
len = strlen(rec.host) + 1;
if (rec.host4) {
len = strlen(rec.host4) + 1;
g_io_channel_write_block(pipe, (void *) &len,
sizeof(int));
g_io_channel_write_block(pipe, (void *) rec.host,
g_io_channel_write_block(pipe, (void *) rec.host4,
len);
}
if (rec.host6) {
len = strlen(rec.host6) + 1;
g_io_channel_write_block(pipe, (void *) &len,
sizeof(int));
g_io_channel_write_block(pipe, (void *) rec.host6,
len);
}
}
@ -144,7 +154,8 @@ int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
rec->error = -1;
rec->errorstr = NULL;
rec->host = NULL;
rec->host4 = NULL;
rec->host6 = NULL;
#ifndef WIN32
fcntl(g_io_channel_unix_get_fd(pipe), F_SETFL, O_NONBLOCK);
@ -163,10 +174,15 @@ int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
rec->errorstr = g_malloc0(rec->errlen+1);
g_io_channel_read_block(pipe, rec->errorstr, rec->errlen);
} else {
if (rec->host) {
if (rec->host4) {
g_io_channel_read_block(pipe, &len, sizeof(int));
rec->host = g_malloc0(len);
g_io_channel_read_block(pipe, rec->host, len);
rec->host4 = g_malloc0(len);
g_io_channel_read_block(pipe, rec->host4, len);
}
if (rec->host6) {
g_io_channel_read_block(pipe, &len, sizeof(int));
rec->host6 = g_malloc0(len);
g_io_channel_read_block(pipe, rec->host6, len);
}
}
@ -211,6 +227,7 @@ static void simple_readpipe(SIMPLE_THREAD_REC *rec, GIOChannel *pipe)
{
RESOLVED_IP_REC iprec;
GIOChannel *handle;
IPADDR *ip;
g_return_if_fail(rec != NULL);
@ -224,8 +241,9 @@ static void simple_readpipe(SIMPLE_THREAD_REC *rec, GIOChannel *pipe)
g_io_channel_shutdown(rec->pipes[1], TRUE, NULL);
g_io_channel_unref(rec->pipes[1]);
ip = iprec.ip4.family != 0 ? &iprec.ip4 : &iprec.ip6;
handle = iprec.error == -1 ? NULL :
net_connect_ip(&iprec.ip, rec->port, rec->my_ip);
net_connect_ip(ip, rec->port, rec->my_ip);
g_free_not_null(rec->my_ip);