diff options
Diffstat (limited to 'resolv/res_hconf.c')
-rw-r--r-- | resolv/res_hconf.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c index b4c86227f8..0d4f3f45bc 100644 --- a/resolv/res_hconf.c +++ b/resolv/res_hconf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2014 Free Software Foundation, Inc. +/* Copyright (C) 1993-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by David Mosberger (davidm@azstarnet.com). @@ -46,6 +46,10 @@ #include "res_hconf.h" #include <wchar.h> +#if IS_IN (libc) +# define fgets_unlocked __fgets_unlocked +#endif + #define _PATH_HOSTCONF "/etc/host.conf" /* Environment vars that all user to override default behavior: */ @@ -358,7 +362,7 @@ _res_hconf_init (void) } -#ifndef NOT_IN_libc +#if IS_IN (libc) # if defined SIOCGIFCONF && defined SIOCGIFNETMASK /* List of known interfaces. */ libc_freeres_ptr ( @@ -417,7 +421,7 @@ _res_hconf_reorder_addrs (struct hostent *hp) /* Get lock. */ __libc_lock_lock (lock); - /* Recheck, somebody else might have done the work by done. */ + /* Recheck, somebody else might have done the work by now. */ if (num_ifs <= 0) { int new_num_ifs = 0; @@ -435,18 +439,24 @@ _res_hconf_reorder_addrs (struct hostent *hp) for (cur_ifr = ifr, i = 0; i < num; cur_ifr = __if_nextreq (cur_ifr), ++i) { + union + { + struct sockaddr sa; + struct sockaddr_in sin; + } ss; + if (cur_ifr->ifr_addr.sa_family != AF_INET) continue; ifaddrs[new_num_ifs].addrtype = AF_INET; - ifaddrs[new_num_ifs].u.ipv4.addr = - ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr; + ss.sa = cur_ifr->ifr_addr; + ifaddrs[new_num_ifs].u.ipv4.addr = ss.sin.sin_addr.s_addr; if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0) continue; - ifaddrs[new_num_ifs].u.ipv4.mask = - ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr; + ss.sa = cur_ifr->ifr_netmask; + ifaddrs[new_num_ifs].u.ipv4.mask = ss.sin.sin_addr.s_addr; /* Now we're committed to this entry. */ ++new_num_ifs; @@ -463,10 +473,10 @@ _res_hconf_reorder_addrs (struct hostent *hp) errno = save; num_ifs = new_num_ifs; - - __libc_lock_unlock (lock); } + __libc_lock_unlock (lock); + __close (sd); } |