NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/10911 - ifconfig requires address to set netmask, broadcast



The following reply was made to PR bin/10911; it has been noted by GNATS.

From: Nat Sloss <nathanialsloss%yahoo.com.au@localhost>
To: "gnats-bugs" <gnats-bugs%netbsd.org@localhost>
Cc: 
Subject: Re: bin/10911 - ifconfig requires address to set netmask, broadcast
Date: Sun, 13 Apr 2014 01:43:15 +1000

 Hi,
 
 I've found a way to solve this by falling back to the existing address of the 
 interface if an address is not specified.  This allows setting the broadcast 
 address and netmask without specifying an address.
 
 Here is my patch:
 Index: src/sbin/ifconfig/af_inetany.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/ifconfig/af_inetany.c,v
 retrieving revision 1.17
 diff -u -r1.17 af_inetany.c
 --- src/sbin/ifconfig/af_inetany.c     30 Dec 2012 22:52:35 -0000      1.17
 +++ src/sbin/ifconfig/af_inetany.c     12 Apr 2014 15:30:28 -0000
 @@ -68,12 +68,15 @@
      const struct afparam *param)
  {
        const char *ifname;
 +      struct ifreq ifr;
        int af, rc, s;
        bool alias, delete, replace;
        prop_data_t d;
        const struct paddr_prefix *addr, *brd, *dst, *mask;
        unsigned short flags;
  
 +      addr = NULL;
 +
        if ((af = getaf(env)) == -1)
                af = AF_INET;
  
 @@ -89,8 +92,22 @@
        if ((d = (prop_data_t)prop_dictionary_get(env, "address")) != NULL)
                addr = prop_data_data_nocopy(d);
        else if (!prop_dictionary_get_bool(env, "alias", &alias) || alias ||
 -          param->gifaddr.cmd == 0)
 -              return;
 +          param->gifaddr.cmd == 0) {
 +              if (addr == NULL) {
 +                      static struct paddr_prefix existingaddr;
 +
 +                      memset(&ifr, 0, sizeof(ifr));
 +                      estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 +                      if (prog_ioctl(s, SIOCGIFADDR, &ifr) == -1) {
 +                              if (errno == EADDRNOTAVAIL || errno == 
EAFNOSUPPORT)
 +                                      return;
 +                              err(EXIT_FAILURE,"SIOCGIFADDR");
 +                      }
 +
 +                      existingaddr.pfx_addr = ifr.ifr_addr;
 +                      addr = &existingaddr;
 +              }
 +      }
        else if (prog_ioctl(s, param->gifaddr.cmd, param->dgreq.buf) == -1)
                err(EXIT_FAILURE, "%s", param->gifaddr.desc);
        else if (prog_ioctl(s, param->difaddr.cmd, param->dgreq.buf) == -1)
 
 Regards,
 
 Nat.
 
 This also applies to bin/31940 - ifconfig behaves unexpectedly, one part of it 
 not the rest of #31940, still investigating.
 


Home | Main Index | Thread Index | Old Index