[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.95 and 1.96

version 1.95, 2013/03/20 15:23:37 version 1.96, 2013/10/22 16:40:28
Line 31 
Line 31 
  */   */
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/file.h>  
 #include <sys/protosw.h>  #include <sys/protosw.h>
 #include <sys/socket.h>  #include <sys/socket.h>
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
Line 42 
Line 41 
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
 #include <errno.h>  #include <errno.h>
   #include <fcntl.h>
 #include <kvm.h>  #include <kvm.h>
 #include <limits.h>  #include <limits.h>
 #include <netdb.h>  #include <netdb.h>
Line 162 
Line 162 
         u_int tableid;          u_int tableid;
         int Tflag = 0;          int Tflag = 0;
         int repeatcount = 0;          int repeatcount = 0;
           int need_nlist;
   
         hideroot = getuid();          hideroot = getuid();
   
Line 331 
Line 332 
         }          }
 #endif  #endif
   
           need_nlist = !mflag && (pflag || nlistf != NULL || memf != NULL ||
               (!iflag && !sflag && (rflag ? Aflag :
               (gflag || af != AF_UNIX || Pflag))));
   
         /*          /*
          * Discard setgid privileges if not the running kernel so that bad           * Discard setgid privileges if not the running kernel so that bad
          * guys can't print interesting stuff from kernel memory.           * guys can't print interesting stuff from kernel memory.
Line 341 
Line 346 
                 if (setresgid(gid, gid, gid) == -1)                  if (setresgid(gid, gid, gid) == -1)
                         err(1, "setresgid");                          err(1, "setresgid");
   
         if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,          if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY |
             buf)) == NULL) {              (need_nlist ? 0 : KVM_NO_FILES), buf)) == NULL) {
                 fprintf(stderr, "%s: kvm_openfiles: %s\n", __progname, buf);                  fprintf(stderr, "%s: kvm_openfiles: %s\n", __progname, buf);
                 exit(1);                  exit(1);
         }          }
Line 351 
Line 356 
                 if (setresgid(gid, gid, gid) == -1)                  if (setresgid(gid, gid, gid) == -1)
                         err(1, "setresgid");                          err(1, "setresgid");
   
         if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) {          if (need_nlist && (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0)) {
                 if (nlistf)                  if (nlistf)
                         fprintf(stderr, "%s: %s: no namelist\n", __progname,                          fprintf(stderr, "%s: %s: no namelist\n", __progname,
                             nlistf);                              nlistf);
Line 429 
Line 434 
                         printproto(tp, tp->pr_name, AF_INET6, tableid,                          printproto(tp, tp->pr_name, AF_INET6, tableid,
                             pcbaddr);                              pcbaddr);
         if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)          if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
                 unixpr(nl[N_UNIXSW].n_value, pcbaddr);                  unixpr(kvmd, pcbaddr);
         exit(0);          exit(0);
 }  }
   

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.96