Subject: bin/1067: ifconfig uses inet_addr rather than inet_aton
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: John Hawkinson <jhawk@MIT.EDU>
List: netbsd-bugs
Date: 05/19/1995 02:05:09
>Number: 1067
>Category: bin
>Synopsis: ifconfig uses inet_addr rather than inet_aton
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri May 19 02:05:04 1995
>Originator: John Hawkinson
>Organization:
MIT SIPB
>Release: -current Fri May 19 04:47:44 EDT 1995
>Environment:
System: NetBSD lola-granola 1.0A NetBSD 1.0A (LOLA) #14: Thu May 18 15:17:31 EDT 1995 mycroft@limekiller:/afs/sipb.mit.edu/system/i386_nbsd1/usr/src/sys/arch/i386/compile/LOLA i386
>Description:
ifconfig does not allow the all ones netmask to be specified
in hex format, but permits the dotted decimal notation.
>How-To-Repeat:
lola-granola# ifconfig ep0
ep0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST>
inet 18.70.0.26 netmask 0xffff0000 broadcast 18.70.255.255
lola-granola# ifconfig ep0 netmask 0xffffffff
ifconfig: 0xffffffff: bad value
lola-granola# ifconfig ep0
ep0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST>
inet 18.70.0.26 netmask 0xffff0000 broadcast 18.70.255.255
lola-granola# ifconfig ep0 netmask 255.255.255.255
ifconfig: SIOCAIFADDR: File exists
lola-granola# ifconfig ep0
ep0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST>
inet 18.70.0.26 netmask 0xffffffff broadcast 18.70.0.26
>Fix:
Use inet_aton() instead of inet_addr (deprecated).
*** /usr/src/sbin/ifconfig/ifconfig.c 1995/05/19 08:39:42 1.1
--- /usr/src/sbin/ifconfig/ifconfig.c 1995/05/19 08:50:27 1.2
***************
*** 644,658 ****
register struct sockaddr_in *sin = sintab[which];
struct hostent *hp;
struct netent *np;
- int val;
sin->sin_len = sizeof(*sin);
if (which != MASK)
sin->sin_family = AF_INET;
! if ((val = inet_addr(s)) != -1)
! sin->sin_addr.s_addr = val;
! else if (hp = gethostbyname(s))
memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
else if (np = getnetbyname(s))
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
--- 644,656 ----
register struct sockaddr_in *sin = sintab[which];
struct hostent *hp;
struct netent *np;
sin->sin_len = sizeof(*sin);
if (which != MASK)
sin->sin_family = AF_INET;
! if (inet_aton(s, (struct in_addr*)&sin->sin_addr.s_addr)==0)
! if (hp = gethostbyname(s))
memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
else if (np = getnetbyname(s))
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
>Audit-Trail:
>Unformatted: