summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-08-19 09:37:23 +0000
committerdarkvater <darkvater@openttd.org>2004-08-19 09:37:23 +0000
commitdd5f3bbe3723d9cd12867d09bc0b6e5972e1079e (patch)
tree892358a0c1369f45b8946c16a27f4d678c36f40b /network.c
parentadd3151b118a252501a4c5ea2d726c9c1599cb2b (diff)
downloadopenttd-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.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/network.c b/network.c
index 4ddf34fca..e7a9b69cf 100644
--- a/network.c
+++ b/network.c
@@ -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;