Author: allanjude
Date: Thu Jun  2 03:16:02 2016
New Revision: 301185
URL: https://svnweb.freebsd.org/changeset/base/301185

Log:
  Address feedback from hrs@ re: r301059 (ifconfig subnet mask)
  
  - Use NI_MAXHOST to size buffers for getnameinfo()
  - remove non-standard 'full' inet6 address printing
  - remove 'no scope' option
  - use strchr(3) to optimize replacing separator character in lladdrs
  
  Reviewed by:  gnn, jhb
  Differential Revision:        https://reviews.freebsd.org/D2856

Modified:
  head/sbin/ifconfig/af_inet.c
  head/sbin/ifconfig/af_inet6.c
  head/sbin/ifconfig/af_link.c
  head/sbin/ifconfig/ifconfig.8
  head/sbin/ifconfig/ifconfig.c

Modified: head/sbin/ifconfig/af_inet.c
==============================================================================
--- head/sbin/ifconfig/af_inet.c        Thu Jun  2 02:39:40 2016        
(r301184)
+++ head/sbin/ifconfig/af_inet.c        Thu Jun  2 03:16:02 2016        
(r301185)
@@ -54,7 +54,7 @@ static const char rcsid[] =
 
 static struct in_aliasreq in_addreq;
 static struct ifreq in_ridreq;
-static char addr_buf[MAXHOSTNAMELEN *2 + 1];   /*for getnameinfo()*/
+static char addr_buf[NI_MAXHOST];      /*for getnameinfo()*/
 extern char *f_inet, *f_addr;
 
 static void

Modified: head/sbin/ifconfig/af_inet6.c
==============================================================================
--- head/sbin/ifconfig/af_inet6.c       Thu Jun  2 02:39:40 2016        
(r301184)
+++ head/sbin/ifconfig/af_inet6.c       Thu Jun  2 03:16:02 2016        
(r301185)
@@ -65,13 +65,13 @@ static      int ip6lifetime;
 static int prefix(void *, int);
 static char *sec2str(time_t);
 static int explicit_prefix = 0;
-extern char *f_inet6, *f_addr, *f_scope;
+extern char *f_inet6, *f_addr;
 
 extern void setnd6flags(const char *, int, int, const struct afswtch *);
 extern void setnd6defif(const char *, int, int, const struct afswtch *);
 extern void nd6_status(int);
 
-static char addr_buf[MAXHOSTNAMELEN *2 + 1];   /*for getnameinfo()*/
+static char addr_buf[NI_MAXHOST];      /*for getnameinfo()*/
 
 static void
 setifprefixlen(const char *addr, int dummy __unused, int s,
@@ -173,10 +173,9 @@ in6_status(int s __unused, const struct 
        struct in6_ifreq ifr6;
        int s6;
        u_int32_t flags6;
-       const u_int16_t *a;
        struct in6_addrlifetime lifetime;
        struct timespec now;
-       int error, n_flags, i;
+       int error, n_flags;
 
        clock_gettime(CLOCK_MONOTONIC_FAST, &now);
 
@@ -208,30 +207,19 @@ in6_status(int s __unused, const struct 
        lifetime = ifr6.ifr_ifru.ifru_lifetime;
        close(s6);
 
-       if (f_addr != NULL && strcmp(f_addr, "full") == 0) {
-               a = (const u_int16_t *)&sin->sin6_addr;
-               printf("\tinet6 ");
-               for (i = 0; i < 8; i++) {
-                       printf("%04hx", ntohs(*(a + i)));
-                       if (i < 7)
-                               printf(":");
-               }
-       } else {
-               if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
-                       n_flags = 0;
-               else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
-                       n_flags = NI_NOFQDN;
-               else
-                       n_flags = NI_NUMERICHOST;
-               error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
-                                   addr_buf, sizeof(addr_buf), NULL, 0,
-                                   n_flags);
-               if (error != 0 ||
-                   (f_scope != NULL && strcmp(f_scope, "none") == 0))
-                       inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
-                                 sizeof(addr_buf));
-               printf("\tinet6 %s", addr_buf);
-       }
+       if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
+               n_flags = 0;
+       else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
+               n_flags = NI_NOFQDN;
+       else
+               n_flags = NI_NUMERICHOST;
+       error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
+                           addr_buf, sizeof(addr_buf), NULL, 0,
+                           n_flags);
+       if (error != 0)
+               inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
+                         sizeof(addr_buf));
+       printf("\tinet6 %s", addr_buf);
 
        if (ifa->ifa_flags & IFF_POINTOPOINT) {
                sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
@@ -280,8 +268,7 @@ in6_status(int s __unused, const struct 
        if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
                printf("prefer_source ");
 
-       if ((f_scope == NULL || strcmp(f_scope, "none") != 0) &&
-           ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
+       if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
                printf("scopeid 0x%x ",
                    ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
 

Modified: head/sbin/ifconfig/af_link.c
==============================================================================
--- head/sbin/ifconfig/af_link.c        Thu Jun  2 02:39:40 2016        
(r301184)
+++ head/sbin/ifconfig/af_link.c        Thu Jun  2 03:16:02 2016        
(r301185)
@@ -58,25 +58,22 @@ link_status(int s __unused, const struct
 {
        /* XXX no const 'cuz LLADDR is defined wrong */
        struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
-       char *ether_format;
-       int i;
+       char *ether_format, *format_char;
 
        if (sdl != NULL && sdl->sdl_alen > 0) {
                if ((sdl->sdl_type == IFT_ETHER ||
                    sdl->sdl_type == IFT_L2VLAN ||
                    sdl->sdl_type == IFT_BRIDGE) &&
-                   sdl->sdl_alen == ETHER_ADDR_LEN)
+                   sdl->sdl_alen == ETHER_ADDR_LEN) {
+                       ether_format = ether_ntoa((struct ether_addr 
*)LLADDR(sdl));
                        if (f_ether != NULL && strcmp(f_ether, "dash") == 0) {
-                               ether_format = ether_ntoa((struct ether_addr 
*)LLADDR(sdl));
-                               for (i = 0; i < strlen(ether_format); i++) {
-                                       if (ether_format[i] == ':')
-                                               ether_format[i] = '-';
-                               }
-                               printf("\tether %s\n", ether_format);
-                       } else
-                               printf("\tether %s\n",
-                                   ether_ntoa((struct ether_addr 
*)LLADDR(sdl)));
-               else {
+                               for (format_char = strchr(ether_format, ':'); 
+                                   format_char != NULL; 
+                                   format_char = strchr(ether_format, ':'))
+                                       *format_char = '-';
+                       }
+                       printf("\tether %s\n", ether_format);
+               } else {
                        int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
 
                        printf("\tlladdr %s\n", link_ntoa(sdl) + n);

Modified: head/sbin/ifconfig/ifconfig.8
==============================================================================
--- head/sbin/ifconfig/ifconfig.8       Thu Jun  2 02:39:40 2016        
(r301184)
+++ head/sbin/ifconfig/ifconfig.8       Thu Jun  2 03:16:02 2016        
(r301185)
@@ -213,7 +213,7 @@ The
 and their associated
 .Sy format
 strings are:
-.Bl -tag -width scope
+.Bl -tag -width ether
 .It Sy addr
 Adjust the display of inet and inet6 addresses
 .Bl -tag -width default
@@ -223,9 +223,6 @@ Display inet and inet6 addresses in the 
 .It Sy fqdn
 Display inet and inet6 addresses as fully qualified domain names
 .Pq FQDN
-.It Sy full
-Display inet6 addresses without suppressing zeroes.
-Only applicable to inet6
 .It Sy host
 Display inet and inet6 addresses as unqualified hostnames
 .It Sy numeric
@@ -276,19 +273,6 @@ Display subnet prefix in integer format,
 .br
 prefixlen 64
 .El
-.It Sy scope
-Controls the display of the interface scope as part of the address.
-Only applicable to inet6 addresses.
-.Bl -tag -width default
-.It Sy default
-The interface scope and scopeid are included in the address, for example:
-.br
-inet6 fe80::1%lo0 prefixlen 64 scopeid 0x7
-.It Sy none
-The interface scope and scopeid are not displayed, for example:
-.br
-inet6 fe80::1 prefixlen 64
-.El
 .El
 .Pp
 The following parameters may be set with

Modified: head/sbin/ifconfig/ifconfig.c
==============================================================================
--- head/sbin/ifconfig/ifconfig.c       Thu Jun  2 02:39:40 2016        
(r301184)
+++ head/sbin/ifconfig/ifconfig.c       Thu Jun  2 03:16:02 2016        
(r301185)
@@ -99,7 +99,7 @@ int   supmedia = 0;
 int    printkeys = 0;          /* Print keying material for interfaces. */
 
 /* Formatter Strings */
-char   *f_inet, *f_inet6, *f_ether, *f_addr, *f_scope;
+char   *f_inet, *f_inet6, *f_ether, *f_addr;
 
 static int ifconfig(int argc, char *const *argv, int iscreate,
                const struct afswtch *afp);
@@ -257,8 +257,6 @@ static void freeformat(void)
                free(f_ether);
        if (f_addr != NULL)
                free(f_addr);
-       if (f_scope != NULL)
-               free(f_scope);
 }
 
 static void setformat(char *input)
@@ -286,8 +284,6 @@ static void setformat(char *input)
                        f_inet = strdup(modifier);
                else if (strcmp(category, "inet6") == 0)
                        f_inet6 = strdup(modifier);
-               else if (strcmp(category, "scope") == 0)
-                       f_scope = strdup(modifier);
        }
        free(formatstr);
 }
@@ -372,7 +368,7 @@ main(int argc, char *argv[])
        size_t iflen;
 
        all = downonly = uponly = namesonly = noload = verbose = 0;
-       f_inet = f_inet6 = f_ether = f_addr = f_scope = NULL;
+       f_inet = f_inet6 = f_ether = f_addr = NULL;
 
        envformat = getenv("IFCONFIG_FORMAT");
        if (envformat != NULL)
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to