Hello t...@!
This diff prevents setting bogus netmasks, which are retrieved via
gethostbyname()
i.e.:
root ~ 0 # grep mynet /etc/networks
mynet 255.255.0.0
root ~ 0 # ifconfig vether0 inet 10.0.0.100 netmask mynet
root ~ 0 # ifconfig vether0
vether0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:bd:2d:ce:3f:01
priority: 0
groups: vether
media: Ethernet autoselect
status: active
inet 10.0.0.100 netmask 0x43d74184 broadcast 190.40.190.127
now:
root src/sbin/ifconfig 0 # obj/ifconfig vether0 inet 10.0.0.100 netmask mynet
root src/sbin/ifconfig 0 # obj/ifconfig vether0
vether0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:bd:2d:ce:3f:01
priority: 0
groups: vether
media: Ethernet autoselect
status: active
inet 10.0.0.100 netmask 0xffff0000 broadcast 10.0.255.255
Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.226
diff -u -p -r1.226 ifconfig.c
--- ifconfig.c 14 Dec 2009 17:22:58 -0000 1.226
+++ ifconfig.c 19 Dec 2009 13:39:51 -0000
@@ -4438,10 +4438,10 @@ in_getaddr(const char *s, int which)
in_getprefix(p, MASK);
memcpy(&sin->sin_addr, &tsin.sin_addr, sizeof(sin->sin_addr));
} else if (inet_aton(s, &sin->sin_addr) == 0) {
- if ((hp = gethostbyname(s)))
- memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
- else if ((np = getnetbyname(s)))
+ if (which == MASK && (np = getnetbyname(s)))
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
+ else if ((hp = gethostbyname2(s, AF_INET)))
+ memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
else
errx(1, "%s: bad value", s);
}