[BACK]Return to show.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Diff for /src/usr.bin/netstat/show.c between version 1.45 and 1.46

version 1.45, 2015/02/06 03:22:00 version 1.46, 2015/02/09 12:25:03
Line 103 
Line 103 
 char    *routename4(in_addr_t);  char    *routename4(in_addr_t);
 char    *routename6(struct sockaddr_in6 *);  char    *routename6(struct sockaddr_in6 *);
   
   size_t
   get_sysctl(const int *mib, u_int mcnt, char **buf)
   {
           size_t needed;
   
           while (1) {
                   if (sysctl(mib, mcnt, NULL, &needed, NULL, 0) == -1)
                           err(1, "sysctl-estimate");
                   if (needed == 0)
                           break;
                   if ((*buf = realloc(*buf, needed)) == NULL)
                           err(1, NULL);
                   if (sysctl(mib, mcnt, *buf, &needed, NULL, 0) == -1) {
                           if (errno == ENOMEM)
                                   continue;
                           err(1, "sysctl");
                   }
                   break;
           }
   
           return needed;
   }
   
 /*  /*
  * Print routing tables.   * Print routing tables.
  */   */
Line 123 
Line 146 
         mib[5] = 0;          mib[5] = 0;
         mib[6] = tableid;          mib[6] = tableid;
         mcnt = 7;          mcnt = 7;
         while (1) {  
                 if (sysctl(mib, mcnt, NULL, &needed, NULL, 0) == -1)          needed = get_sysctl(mib, mcnt, &buf);
                         err(1, "route-sysctl-estimate");          lim = buf + needed;
                 if (needed == 0)  
                         break;  
                 if ((buf = realloc(buf, needed)) == NULL)  
                         err(1, NULL);  
                 if (sysctl(mib, mcnt, buf, &needed, NULL, 0) == -1) {  
                         if (errno == ENOMEM)  
                                 continue;  
                         err(1, "sysctl of routing table");  
                 }  
                 lim = buf + needed;  
                 break;  
         }  
   
         printf("Routing tables\n");          printf("Routing tables\n");
   

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46