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

Diff for /src/usr.bin/fstat/fstat.c between version 1.73 and 1.74

version 1.73, 2012/11/30 14:40:03 version 1.74, 2013/03/24 15:09:13
Line 123 
Line 123 
 void vtrans(struct kinfo_file2 *);  void vtrans(struct kinfo_file2 *);
 const char *inet6_addrstr(struct in6_addr *);  const char *inet6_addrstr(struct in6_addr *);
 int signame_to_signum(char *);  int signame_to_signum(char *);
   void hide(void *p);
   
   int hideroot;
   
   void
   hide(void *p)
   {
           printf("%p", hideroot ? NULL : p);
   }
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
Line 135 
Line 144 
         const char *errstr;          const char *errstr;
         int cnt, flags;          int cnt, flags;
   
           hideroot = getuid();
   
         arg = -1;          arg = -1;
         what = KERN_FILE_BYPID;          what = KERN_FILE_BYPID;
         nlistf = memf = NULL;          nlistf = memf = NULL;
Line 187 
Line 198 
                                 usage();                                  usage();
                         arg = strtonum(optarg, 0, INT_MAX, &errstr);                          arg = strtonum(optarg, 0, INT_MAX, &errstr);
                         if (errstr != NULL) {                          if (errstr != NULL) {
                                 warnx("-p requires a process id, %s: %s",                                  warnx("-p requires a process id, %s: %s",
                                         errstr, optarg);                                          errstr, optarg);
                                 usage();                                  usage();
                         }                          }
Line 208 
Line 219 
                                 usage();                                  usage();
                         if (!fuser) {                          if (!fuser) {
                                 if (!(passwd = getpwnam(optarg))) {                                  if (!(passwd = getpwnam(optarg))) {
                                         arg = strtonum(optarg, 0, UID_MAX,                                          arg = strtonum(optarg, 0, UID_MAX,
                                             &errstr);                                              &errstr);
                                         if (errstr != NULL) {                                          if (errstr != NULL) {
                                                 errx(1, "%s: unknown uid",                                                  errx(1, "%s: unknown uid",
Line 441 
Line 452 
                 if (oflg) {                  if (oflg) {
                         if (uid == 0 || uid == *procuid)                          if (uid == 0 || uid == *procuid)
                                 printf(":%-8llu", kf->f_offset);                                  printf(":%-8llu", kf->f_offset);
                         else                          else
                                 printf(":%-8s", "*");                                  printf(":%-8s", "*");
                 }                  }
         }          }
         if (sflg) {          if (sflg) {
                 if (uid == 0 || uid == *procuid) {                  if (uid == 0 || uid == *procuid) {
                         printf(" %8llu %8llu",                          printf(" %8llu %8llu",
                         (kf->f_rxfer + kf->f_rwfer),                              (kf->f_rxfer + kf->f_rwfer),
                         (kf->f_rbytes + kf->f_wbytes) / 1024);                              (kf->f_rbytes + kf->f_wbytes) / 1024);
                 } else {                  } else {
                         printf(" %8s %8s", "*", "*");                          printf(" %8s %8s", "*", "*");
                 }                  }
Line 476 
Line 487 
          */           */
         maxaddr = (void *)(uintptr_t)MAX(kf->f_data, kf->pipe_peer);          maxaddr = (void *)(uintptr_t)MAX(kf->f_data, kf->pipe_peer);
   
         printf("pipe %p state: %s%s%s", maxaddr,          printf("pipe ");
           hide(maxaddr);
           printf("state: %s%s%s",
             (kf->pipe_state & PIPE_WANTR) ? "R" : "",              (kf->pipe_state & PIPE_WANTR) ? "R" : "",
             (kf->pipe_state & PIPE_WANTW) ? "W" : "",              (kf->pipe_state & PIPE_WANTW) ? "W" : "",
             (kf->pipe_state & PIPE_EOF) ? "E" : "");              (kf->pipe_state & PIPE_EOF) ? "E" : "");
Line 495 
Line 508 
   
         printf(" ");          printf(" ");
   
         printf("kqueue %p %d state: %s%s\n", (void *)(uintptr_t)kf->f_data,          printf("kqueue ");
           hide((void *)(uintptr_t)kf->f_data);
           printf(" %d state: %s%s\n",
             kf->kq_count,              kf->kq_count,
             (kf->kq_state & KQ_SEL) ? "S" : "",              (kf->kq_state & KQ_SEL) ? "S" : "",
             (kf->kq_state & KQ_SLEEP) ? "W" : "");              (kf->kq_state & KQ_SLEEP) ? "W" : "");
Line 509 
Line 524 
   
         printf(" ");          printf(" ");
   
         printf("crypto %p\n", (void *)(uintptr_t)kf->f_data);          printf("crypto ");
           hide((void *)(uintptr_t)kf->f_data);
           printf("\n");
 }  }
   
 void  void
Line 519 
Line 536 
   
         printf(" ");          printf(" ");
   
         printf("systrace %p npol %d\n", (void *)(uintptr_t)kf->f_data,          printf("systrace ");
             kf->str_npolicies);          hide((void *)(uintptr_t)kf->f_data);
           printf(" npol %d\n", kf->str_npolicies);
         return;          return;
 }  }
   
Line 556 
Line 574 
 {  {
         ENTRY entry, *found;          ENTRY entry, *found;
   
         if (asprintf(&entry.key, "%c%llx", type, ptr) == -1)          if (asprintf(&entry.key, "%c%llx", type, hideroot ? 0 : ptr) == -1)
                 err(1, NULL);                  err(1, NULL);
         entry.data = data;          entry.data = data;
         if ((found = hsearch(entry, ENTER)) == NULL)          if ((found = hsearch(entry, ENTER)) == NULL)
Line 572 
Line 590 
         ENTRY entry, *found;          ENTRY entry, *found;
         char buf[20];          char buf[20];
   
         snprintf(buf, sizeof(buf), "%c%llx", type, ptr);          snprintf(buf, sizeof(buf), "%c%llx", type, hideroot ? 0 : ptr);
         entry.key = buf;          entry.key = buf;
         found = hsearch(entry, FIND);          found = hsearch(entry, FIND);
         return (found != NULL ? found->data : NULL);          return (found != NULL ? found->data : NULL);
Line 606 
Line 624 
         memcpy(&laddr, kf->inp_laddru, sizeof(laddr));          memcpy(&laddr, kf->inp_laddru, sizeof(laddr));
         memcpy(&faddr, kf->inp_faddru, sizeof(faddr));          memcpy(&faddr, kf->inp_faddru, sizeof(faddr));
         if (kf->so_protocol == IPPROTO_TCP) {          if (kf->so_protocol == IPPROTO_TCP) {
                 printf(" %p", (void *)(uintptr_t)kf->inp_ppcb);                  printf(" ");
                   hide((void *)(uintptr_t)kf->inp_ppcb);
                 printf(" %s:%d", laddr.s_addr == INADDR_ANY ? "*" :                  printf(" %s:%d", laddr.s_addr == INADDR_ANY ? "*" :
                     inet_ntoa(laddr), ntohs(kf->inp_lport));                      inet_ntoa(laddr), ntohs(kf->inp_lport));
                 if (kf->inp_fport) {                  if (kf->inp_fport) {
Line 626 
Line 645 
                             faddr.s_addr == INADDR_ANY ? "*" :                              faddr.s_addr == INADDR_ANY ? "*" :
                             inet_ntoa(faddr), ntohs(kf->inp_fport));                              inet_ntoa(faddr), ntohs(kf->inp_fport));
                 }                  }
         } else if (kf->so_pcb)          } else if (kf->so_pcb) {
                 printf(" %p", (void *)(uintptr_t)kf->so_pcb);                  printf(" ");
                   hide((void *)(uintptr_t)kf->so_pcb);
           }
 }  }
   
 #ifdef INET6  #ifdef INET6
Line 640 
Line 661 
         memcpy(&laddr6, kf->inp_laddru, sizeof(laddr6));          memcpy(&laddr6, kf->inp_laddru, sizeof(laddr6));
         memcpy(&faddr6, kf->inp_faddru, sizeof(faddr6));          memcpy(&faddr6, kf->inp_faddru, sizeof(faddr6));
         if (kf->so_protocol == IPPROTO_TCP) {          if (kf->so_protocol == IPPROTO_TCP) {
                 printf(" %p", (void *)(uintptr_t)kf->inp_ppcb);                  printf(" ");
                   hide((void *)(uintptr_t)kf->inp_ppcb);
                 snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]",                  snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]",
                     inet6_addrstr(&laddr6));                      inet6_addrstr(&laddr6));
                 printf(" %s:%d",                  printf(" %s:%d",
Line 670 
Line 692 
                             IN6_IS_ADDR_UNSPECIFIED(&faddr6) ? "*" :                              IN6_IS_ADDR_UNSPECIFIED(&faddr6) ? "*" :
                             xaddrbuf, ntohs(kf->inp_fport));                              xaddrbuf, ntohs(kf->inp_fport));
                 }                  }
         } else if (kf->so_pcb)          } else if (kf->so_pcb) {
                 printf(" %p", (void *)(uintptr_t)kf->so_pcb);                  printf(" ");
                   hide((void *)(uintptr_t)kf->so_pcb);
           }
 }  }
 #endif  #endif
   
Line 737 
Line 761 
                 /* print address of pcb and connected pcb */                  /* print address of pcb and connected pcb */
                 printf("* unix %s", stype);                  printf("* unix %s", stype);
                 if (kf->so_pcb) {                  if (kf->so_pcb) {
                         printf(" %p", (void *)(uintptr_t)kf->so_pcb);                          printf(" ");
                           hide((void *)(uintptr_t)kf->so_pcb);
                         if (kf->unp_conn) {                          if (kf->unp_conn) {
                                 char shoconn[4], *cp;                                  char shoconn[4], *cp;
   
Line 748 
Line 773 
                                 if (!(kf->so_state & SS_CANTSENDMORE))                                  if (!(kf->so_state & SS_CANTSENDMORE))
                                         *cp++ = '>';                                          *cp++ = '>';
                                 *cp = '\0';                                  *cp = '\0';
                                 printf(" %s %p", shoconn,                                  printf(" %s ", shoconn);
                                     (void *)(uintptr_t)kf->unp_conn);                                  hide((void *)(uintptr_t)kf->unp_conn);
                         }                          }
                 }                  }
                 break;                  break;
         case AF_MPLS:          case AF_MPLS:
                 /* print protocol number and socket address */                  /* print protocol number and socket address */
                 printf("* mpls %s", stype);                  printf("* mpls %s", stype);
                 printf(" %d %p", kf->so_protocol,                  printf(" %d ", kf->so_protocol);
                     (void *)(uintptr_t)kf->f_data);                  hide((void *)(uintptr_t)kf->f_data);
                 break;                  break;
         case AF_ROUTE:          case AF_ROUTE:
                 /* print protocol number and socket address */                  /* print protocol number and socket address */
                 printf("* route %s", stype);                  printf("* route %s", stype);
                 printf(" %d %p", kf->so_protocol,                  printf(" %d ", kf->so_protocol);
                     (void *)(uintptr_t)kf->f_data);                  hide((void *)(uintptr_t)kf->f_data);
                 break;                  break;
         case AF_BLUETOOTH:          case AF_BLUETOOTH:
                 /* print protocol number and socket address */                  /* print protocol number and socket address */
                 printf("* bluetooth %s", stype);                  printf("* bluetooth %s", stype);
                 printf(" %d %p", kf->so_protocol,                  printf(" %d ", kf->so_protocol);
                     (void *)(uintptr_t)kf->f_data);                  hide((void *)(uintptr_t)kf->f_data);
                 break;                  break;
         case AF_NATM:          case AF_NATM:
                 /* print protocol number and socket address */                  /* print protocol number and socket address */
                 printf("* natm %s", stype);                  printf("* natm %s", stype);
                 printf(" %d %p", kf->so_protocol,                  printf(" %d ", kf->so_protocol);
                     (void *)(uintptr_t)kf->f_data);                  hide((void *)(uintptr_t)kf->f_data);
                 break;                  break;
         default:          default:
                 /* print protocol number and socket address */                  /* print protocol number and socket address */
                 printf("* %d %s", kf->so_family, stype);                  printf("* %d %s", kf->so_family, stype);
                 printf(" %d %p", kf->so_protocol,                  printf(" %d ", kf->so_protocol);
                     (void *)(uintptr_t)kf->f_data);                  hide((void *)(uintptr_t)kf->f_data);
         }          }
         if (kf->so_splice != 0 || kf->so_splicelen == -1) {          if (kf->so_splice != 0 || kf->so_splicelen == -1) {
                 struct kinfo_file2 *from, *to;                  struct kinfo_file2 *from, *to;

Legend:
Removed from v.1.73  
changed lines
  Added in v.1.74