summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-10-18 23:44:00 +0000
committerRoy Marples <roy@marples.name>2008-10-18 23:44:00 +0000
commit34bf905984347f0f73a3d237408a943ce50086b1 (patch)
treee395941962cf36251b87bde28f74c5484f9dbb17 /net.c
parent159d2fcf4993252b99656febdead11b89b8701b7 (diff)
downloaddhcpcd-34bf905984347f0f73a3d237408a943ce50086b1.tar.xz
Fix obtaining netmask on NetBSD.
Diffstat (limited to 'net.c')
-rw-r--r--net.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/net.c b/net.c
index 4502a3a5..1d8e1055 100644
--- a/net.c
+++ b/net.c
@@ -285,6 +285,7 @@ do_interface(const char *ifname,
char *p, *e;
in_addr_t address, netmask;
struct ifreq *ifr;
+ struct sockaddr_in *sin;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
return -1;
@@ -312,7 +313,7 @@ do_interface(const char *ifname,
len *= 2;
}
- e = ifc.ifc_buf + ifc.ifc_len;
+ e = (char *)ifc.ifc_buf + ifc.ifc_len;
for (p = ifc.ifc_buf; p < e;) {
ifr = (struct ifreq *)p;
@@ -336,12 +337,14 @@ do_interface(const char *ifname,
}
if (ifr->ifr_addr.sa_family == AF_INET && addr) {
- address = ((struct sockaddr_in *)&ifr->ifr_addr)
- ->sin_addr.s_addr;
+ sin = (struct sockaddr_in *)&ifr->ifr_addr;
+ address = sin->sin_addr.s_addr;
+ /* Some platforms only partially fill the bits
+ * set by the netmask, so we need to zero it now. */
+ sin->sin_addr.s_addr = 0;
if (ioctl(s, SIOCGIFNETMASK, ifr) == -1)
continue;
- netmask = ((struct sockaddr_in *)&ifr->ifr_addr)
- ->sin_addr.s_addr;
+ netmask = sin->sin_addr.s_addr;
if (act == 1) {
addr->s_addr = address;
net->s_addr = netmask;