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

Diff for /src/usr.bin/netstat/main.c between version 1.115 and 1.116

version 1.115, 2019/03/05 06:47:12 version 1.116, 2019/04/28 17:59:51
Line 54 
Line 54 
 #include "netstat.h"  #include "netstat.h"
   
 struct nlist nl[] = {  struct nlist nl[] = {
 #define N_RTREE         0  #define N_AFMAP         0
         { "_rt_tables"},          { "_afmap"},
 #define N_RTMASK        1  #define N_AF2IDX        1
         { "_mask_rnhead" },          { "_af2idx" },
 #define N_AF2RTAFIDX    2  #define N_AF2IDXMAX     2
         { "_af2rtafidx" },          { "_af2idx_max" },
 #define N_RTBLIDMAX     3  
         { "_rtbl_id_max" },  
   
         { "" }          { "" }
 };  };
Line 104 
Line 102 
 static void usage(void);  static void usage(void);
 static struct protox *name2protox(char *);  static struct protox *name2protox(char *);
 static struct protox *knownname(char *);  static struct protox *knownname(char *);
 u_int gettable(const char *);  void gettable(u_int);
   
 kvm_t *kvmd;  kvm_t *kvmd;
   
Line 168 
Line 166 
                                 af = AF_UNIX;                                  af = AF_UNIX;
                         else if (strcmp(optarg, "mpls") == 0)                          else if (strcmp(optarg, "mpls") == 0)
                                 af = AF_MPLS;                                  af = AF_MPLS;
                         else if (strcmp(optarg, "mask") == 0)  
                                 af = 0xff;  
                         else {                          else {
                                 (void)fprintf(stderr,                                  (void)fprintf(stderr,
                                     "%s: %s: unknown address family\n",                                      "%s: %s: unknown address family\n",
Line 236 
Line 232 
                         ++sflag;                          ++sflag;
                         break;                          break;
                 case 'T':                  case 'T':
                           tableid = strtonum(optarg, 0, RT_TABLEID_MAX, &errstr);
                           if (errstr)
                                   errx(1, "invalid table id: %s", errstr);
                         Tflag = 1;                          Tflag = 1;
                         tableid = gettable(optarg);  
                         break;                          break;
                 case 't':                  case 't':
                         tflag = 1;                          tflag = 1;
Line 341 
Line 339 
                         errx(1, "no namelist");                          errx(1, "no namelist");
         }          }
   
           if (!need_nlist && Tflag)
                   gettable(tableid);
   
         if (rflag) {          if (rflag) {
                 if (Aflag || nlistf != NULL || memf != NULL)                  if (Aflag || nlistf != NULL || memf != NULL)
                         routepr(nl[N_RTREE].n_value, nl[N_RTMASK].n_value,                          routepr(nl[N_AFMAP].n_value, nl[N_AF2IDX].n_value,
                             nl[N_AF2RTAFIDX].n_value, nl[N_RTBLIDMAX].n_value,                              nl[N_AF2IDXMAX].n_value, tableid);
                             tableid);  
                 else                  else
                         p_rttables(af, tableid);                          p_rttables(af, tableid);
                 exit(0);                  exit(0);
Line 458 
Line 458 
         exit(1);          exit(1);
 }  }
   
 u_int  void
 gettable(const char *s)  gettable(u_int tableid)
 {  {
         const char *errstr;  
         struct rt_tableinfo info;          struct rt_tableinfo info;
         int mib[6];          int mib[6];
         size_t len;          size_t len;
         u_int tableid;  
   
         tableid = strtonum(s, 0, RT_TABLEID_MAX, &errstr);  
         if (errstr)  
                 errx(1, "invalid table id: %s", errstr);  
   
         mib[0] = CTL_NET;          mib[0] = CTL_NET;
         mib[1] = PF_ROUTE;          mib[1] = PF_ROUTE;
         mib[2] = 0;          mib[2] = 0;
Line 481 
Line 475 
         len = sizeof(info);          len = sizeof(info);
         if (sysctl(mib, 6, &info, &len, NULL, 0) == -1)          if (sysctl(mib, 6, &info, &len, NULL, 0) == -1)
                 err(1, "routing table %d", tableid);                  err(1, "routing table %d", tableid);
   
         return (tableid);  
 }  }

Legend:
Removed from v.1.115  
changed lines
  Added in v.1.116