diff options
author | darkvater <darkvater@openttd.org> | 2004-08-19 09:37:23 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-08-19 09:37:23 +0000 |
commit | dd5f3bbe3723d9cd12867d09bc0b6e5972e1079e (patch) | |
tree | 892358a0c1369f45b8946c16a27f4d678c36f40b /network.c | |
parent | add3151b118a252501a4c5ea2d726c9c1599cb2b (diff) | |
download | openttd-dd5f3bbe3723d9cd12867d09bc0b6e5972e1079e.tar.xz |
(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
Diffstat (limited to 'network.c')
-rw-r--r-- | network.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -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; |