(svn r82) -Fix ttd.rc issues on non VS compilers

-Fix: network.c more robust (check for NULL pointer), if gethostbyname failes, try resolving IP address
This commit is contained in:
darkvater
2004-08-19 09:37:23 +00:00
parent add3151b11
commit dd5f3bbe37
2 changed files with 172 additions and 158 deletions

View File

@@ -1116,11 +1116,21 @@ void NetworkIPListInit() {
DEBUG(misc,0) ("iplist: init for host %s", hostname);
he=gethostbyname((char *) hostname);
while(he->h_addr_list[i]) {
bcaddr = inet_addr(inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
_network_ip_list[i]=bcaddr;
DEBUG(misc,0) ("iplist: add %s",inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
i++;
if (he == NULL) {
DEBUG(misc, 0) ("iplist: gethostbyname failed for host %s...trying with IP address", hostname);
bcaddr = inet_addr(hostname);
he = gethostbyaddr(inet_ntoa(*(struct in_addr *)bcaddr), sizeof(bcaddr), AF_INET);
}
if (he == NULL) {
DEBUG(misc, 0) ("iplist: cannot resolve %s", hostname);
} else {
while(he->h_addr_list[i]) {
bcaddr = inet_addr(inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
_network_ip_list[i]=bcaddr;
DEBUG(misc,0) ("iplist: add %s",inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
i++;
}
}
_network_ip_list[i]=0;