Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c
          +++ new/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c
↓ open down ↓ 47 lines elided ↑ open up ↑
  48   48  #include <stdlib.h>
  49   49  #include <stdarg.h>
  50   50  #include <unistd.h>
  51   51  #include <strings.h>
  52   52  #include <string.h>
  53   53  #include <errno.h>
  54   54  #include <ctype.h>
  55   55  #include <kstat.h>
  56   56  #include <assert.h>
  57   57  #include <locale.h>
       58 +#include <pwd.h>
       59 +#include <limits.h>
  58   60  
  59   61  #include <sys/types.h>
       62 +#include <sys/stat.h>
  60   63  #include <sys/stream.h>
  61   64  #include <stropts.h>
  62   65  #include <sys/strstat.h>
  63   66  #include <sys/tihdr.h>
       67 +#include <procfs.h>
  64   68  
  65   69  #include <sys/socket.h>
       70 +#include <sys/socketvar.h>
  66   71  #include <sys/sockio.h>
  67   72  #include <netinet/in.h>
  68   73  #include <net/if.h>
  69   74  #include <net/route.h>
  70   75  
  71   76  #include <inet/mib2.h>
  72   77  #include <inet/ip.h>
  73   78  #include <inet/arp.h>
  74   79  #include <inet/tcp.h>
  75   80  #include <netinet/igmp_var.h>
↓ open down ↓ 8 lines elided ↑ open up ↑
  84   89  #include <netinet/dhcp.h>
  85   90  #include <dhcpagent_ipc.h>
  86   91  #include <dhcpagent_util.h>
  87   92  #include <compat.h>
  88   93  
  89   94  #include <libtsnet.h>
  90   95  #include <tsol/label.h>
  91   96  
  92   97  #include "statcommon.h"
  93   98  
  94      -extern void     unixpr(kstat_ctl_t *kc);
  95   99  
  96  100  #define STR_EXPAND      4
  97  101  
  98  102  #define V4MASK_TO_V6(v4, v6)    ((v6)._S6_un._S6_u32[0] = 0xfffffffful, \
  99  103                                  (v6)._S6_un._S6_u32[1] = 0xfffffffful, \
 100  104                                  (v6)._S6_un._S6_u32[2] = 0xfffffffful, \
 101  105                                  (v6)._S6_un._S6_u32[3] = (v4))
 102  106  
 103  107  #define IN6_IS_V4MASK(v6)       ((v6)._S6_un._S6_u32[0] == 0xfffffffful && \
 104  108                                  (v6)._S6_un._S6_u32[1] == 0xfffffffful && \
↓ open down ↓ 23 lines elided ↑ open up ↑
 128  132          uint64_t        oerrors;
 129  133          uint64_t        collisions;
 130  134  };
 131  135  
 132  136  struct iflist {
 133  137          struct iflist   *next_if;
 134  138          char            ifname[LIFNAMSIZ];
 135  139          struct ifstat   tot;
 136  140  };
 137  141  
      142 +typedef struct proc_info {
      143 +        char *pr_user;
      144 +        char *pr_fname;
      145 +        char *pr_psargs;
      146 +} proc_info_t;
      147 +
 138  148  static  mib_item_t      *mibget(int sd);
 139  149  static  void            mibfree(mib_item_t *firstitem);
 140  150  static  int             mibopen(void);
 141  151  static void             mib_get_constants(mib_item_t *item);
 142  152  static mib_item_t       *mib_item_dup(mib_item_t *item);
 143  153  static mib_item_t       *mib_item_diff(mib_item_t *item1,
 144  154      mib_item_t *item2);
 145  155  static void             mib_item_destroy(mib_item_t **item);
 146  156  
 147  157  static boolean_t        octetstrmatch(const Octet_t *a, const Octet_t *b);
↓ open down ↓ 36 lines elided ↑ open up ↑
 184  194                              int Iflag_only, boolean_t once_only);
 185  195  static void             if_report_ip4(mib2_ipAddrEntry_t *ap,
 186  196                              char ifname[], char logintname[],
 187  197                              struct ifstat *statptr, boolean_t ksp_not_null);
 188  198  static void             if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
 189  199                              char ifname[], char logintname[],
 190  200                              struct ifstat *statptr, boolean_t ksp_not_null);
 191  201  static void             ire_report(const mib_item_t *item);
 192  202  static void             tcp_report(const mib_item_t *item);
 193  203  static void             udp_report(const mib_item_t *item);
      204 +static void             uds_report(kstat_ctl_t *);
 194  205  static void             group_report(mib_item_t *item);
 195  206  static void             dce_report(mib_item_t *item);
 196  207  static void             print_ip_stats(mib2_ip_t *ip);
 197  208  static void             print_icmp_stats(mib2_icmp_t *icmp);
 198  209  static void             print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
 199  210  static void             print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
 200  211  static void             print_sctp_stats(mib2_sctp_t *tcp);
 201  212  static void             print_tcp_stats(mib2_tcp_t *tcp);
 202  213  static void             print_udp_stats(mib2_udp_t *udp);
 203  214  static void             print_rawip_stats(mib2_rawip_t *rawip);
↓ open down ↓ 11 lines elided ↑ open up ↑
 215  226  static  kid_t           safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
 216  227  static int              isnum(char *);
 217  228  static char             *plural(int n);
 218  229  static char             *pluraly(int n);
 219  230  static char             *plurales(int n);
 220  231  static void             process_filter(char *arg);
 221  232  static char             *ifindex2str(uint_t, char *);
 222  233  static boolean_t        family_selected(int family);
 223  234  
 224  235  static void             usage(char *);
      236 +static char             *get_username(uid_t);
      237 +proc_info_t             *get_proc_info(pid_t);
 225  238  static void             fatal(int errcode, char *str1, ...);
 226  239  
 227  240  #define PLURAL(n) plural((int)n)
 228  241  #define PLURALY(n) pluraly((int)n)
 229  242  #define PLURALES(n) plurales((int)n)
 230  243  #define IFLAGMOD(flg, val1, val2)       if (flg == val1) flg = val2
 231  244  #define MDIFF(diff, elem2, elem1, member)       (diff)->member = \
 232  245          (elem2)->member - (elem1)->member
 233  246  
 234  247  
 235  248  static  boolean_t       Aflag = B_FALSE;        /* All sockets/ifs/rtng-tbls */
 236  249  static  boolean_t       Dflag = B_FALSE;        /* DCE info */
 237  250  static  boolean_t       Iflag = B_FALSE;        /* IP Traffic Interfaces */
 238  251  static  boolean_t       Mflag = B_FALSE;        /* STREAMS Memory Statistics */
 239  252  static  boolean_t       Nflag = B_FALSE;        /* Numeric Network Addresses */
 240  253  static  boolean_t       Rflag = B_FALSE;        /* Routing Tables */
 241  254  static  boolean_t       RSECflag = B_FALSE;     /* Security attributes */
 242  255  static  boolean_t       Sflag = B_FALSE;        /* Per-protocol Statistics */
 243  256  static  boolean_t       Vflag = B_FALSE;        /* Verbose */
      257 +static  boolean_t       Uflag = B_FALSE;        /* Show PID and UID info. */
 244  258  static  boolean_t       Pflag = B_FALSE;        /* Net to Media Tables */
 245  259  static  boolean_t       Gflag = B_FALSE;        /* Multicast group membership */
 246  260  static  boolean_t       MMflag = B_FALSE;       /* Multicast routing table */
 247  261  static  boolean_t       DHCPflag = B_FALSE;     /* DHCP statistics */
 248  262  static  boolean_t       Xflag = B_FALSE;        /* Debug Info */
 249  263  
 250  264  static  int     v4compat = 0;   /* Compatible printing format for status */
 251  265  
 252  266  static int      proto = IPPROTO_MAX;    /* all protocols */
 253  267  kstat_ctl_t     *kc = NULL;
↓ open down ↓ 124 lines elided ↑ open up ↑
 378  392  
 379  393          v4compat = get_compat_flag(&default_ip_str);
 380  394          if (v4compat == DEFAULT_PROT_BAD_VALUE)
 381  395                  fatal(2, "%s: %s: Bad value for %s in %s\n", name,
 382  396                      default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE);
 383  397          free(default_ip_str);
 384  398  
 385  399          (void) setlocale(LC_ALL, "");
 386  400          (void) textdomain(TEXT_DOMAIN);
 387  401  
 388      -        while ((c = getopt(argc, argv, "adimnrspMgvxf:P:I:DRT:")) != -1) {
      402 +        while ((c = getopt(argc, argv, "adimnrspMgvuxf:P:I:DRT:")) != -1) {
 389  403                  switch ((char)c) {
 390  404                  case 'a':               /* all connections */
 391  405                          Aflag = B_TRUE;
 392  406                          break;
 393  407  
 394  408                  case 'd':               /* DCE info */
 395  409                          Dflag = B_TRUE;
 396  410                          IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
 397  411                          break;
 398  412  
↓ open down ↓ 39 lines elided ↑ open up ↑
 438  452                  case 'g':               /* multicast group membership */
 439  453                          Gflag = B_TRUE;
 440  454                          IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
 441  455                          break;
 442  456  
 443  457                  case 'v':               /* verbose output format */
 444  458                          Vflag = B_TRUE;
 445  459                          IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
 446  460                          break;
 447  461  
      462 +                case 'u':               /* show pid and uid information */
      463 +                        Uflag = B_TRUE;
      464 +                        break;
      465 +
 448  466                  case 'x':               /* turn on debugging */
 449  467                          Xflag = B_TRUE;
 450  468                          break;
 451  469  
 452  470                  case 'f':
 453  471                          process_filter(optarg);
 454  472                          break;
 455  473  
 456  474                  case 'P':
 457  475                          if (strcmp(optarg, "ip") == 0) {
↓ open down ↓ 189 lines elided ↑ open up ↑
 647  665                          }
 648  666                          if (Dflag)
 649  667                                  dce_report(item);
 650  668                          mib_item_destroy(&curritem);
 651  669                  }
 652  670  
 653  671                  /* netstat: AF_UNIX behaviour */
 654  672                  if (family_selected(AF_UNIX) &&
 655  673                      (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
 656  674                      MMflag || Pflag || Gflag)))
 657      -                        unixpr(kc);
      675 +                        uds_report(kc);
 658  676                  (void) kstat_close(kc);
 659  677  
 660  678                  /* iteration handling code */
 661  679                  if (count > 0 && --count == 0)
 662  680                          break;
 663  681                  (void) sleep(interval);
 664  682  
 665  683                  /* re-populating of data structures */
 666  684                  if (family_selected(AF_INET) || family_selected(AF_INET6)) {
 667  685                          if (Sflag) {
↓ open down ↓ 4067 lines elided ↑ open up ↑
4735 4753  static const char tcp_hdr_v4_verbose[] =
4736 4754  "Local/Remote Address Swind  Snext     Suna   Rwind  Rnext     Rack   "
4737 4755  " Rto   Mss     State\n"
4738 4756  "-------------------- ----- -------- -------- ----- -------- -------- "
4739 4757  "----- ----- -----------\n";
4740 4758  static const char tcp_hdr_v4_normal[] =
4741 4759  "   Local Address        Remote Address    Swind Send-Q Rwind Recv-Q "
4742 4760  "   State\n"
4743 4761  "-------------------- -------------------- ----- ------ ----- ------ "
4744 4762  "-----------\n";
     4763 +static const char tcp_hdr_v4_pid[] =
     4764 +"   Local Address        Remote Address      User     Pid     Command     Swind"
     4765 +"   Send-Q  Rwind  Recv-Q    State\n"
     4766 +"-------------------- -------------------- -------- ------ ------------- ------"
     4767 +"- ------ ------- ------ -----------\n";
     4768 +static const char tcp_hdr_v4_pid_verbose[] =
     4769 +"Local/Remote Address  Swind   Snext     Suna    Rwind   Rnext     Rack    Rto "
     4770 +"  Mss     State      User    Pid      Command\n"
     4771 +"-------------------- ------- -------- -------- ------- -------- -------- -----"
     4772 +" ----- ----------- -------- ------ --------------\n";
4745 4773  
4746 4774  static const char tcp_hdr_v6[] =
4747 4775  "\nTCP: IPv6\n";
4748 4776  static const char tcp_hdr_v6_verbose[] =
4749 4777  "Local/Remote Address              Swind  Snext     Suna   Rwind  Rnext   "
4750 4778  "  Rack    Rto   Mss    State      If\n"
4751 4779  "--------------------------------- ----- -------- -------- ----- -------- "
4752 4780  "-------- ----- ----- ----------- -----\n";
4753 4781  static const char tcp_hdr_v6_normal[] =
4754 4782  "   Local Address                     Remote Address                 "
4755 4783  "Swind Send-Q Rwind Recv-Q   State      If\n"
4756 4784  "--------------------------------- --------------------------------- "
4757 4785  "----- ------ ----- ------ ----------- -----\n";
     4786 +static const char tcp_hdr_v6_pid[] =
     4787 +"   Local Address                     Remote Address                   User"
     4788 +"    Pid      Command      Swind  Send-Q  Rwind  Recv-Q   State      If\n"
     4789 +"--------------------------------- --------------------------------- --------"
     4790 +" ------ -------------- ------- ------ ------- ------ ----------- -----\n";
     4791 +static const char tcp_hdr_v6_pid_verbose[] =
     4792 +"Local/Remote Address               Swind   Snext     Suna    Rwind   Rnext"
     4793 +"     Rack    Rto   Mss    State      If     User    Pid     Command\n"
     4794 +"--------------------------------- ------- -------- -------- ------- --------"
     4795 +" -------- ----- ----- ----------- ----- -------- ------ --------------\n";
4758 4796  
4759 4797  static boolean_t tcp_report_item_v4(const mib2_tcpConnEntry_t *,
4760      -    boolean_t first, const mib2_transportMLPEntry_t *);
     4798 +    conn_pid_info_t *, boolean_t first,
     4799 +    const mib2_transportMLPEntry_t *);
4761 4800  static boolean_t tcp_report_item_v6(const mib2_tcp6ConnEntry_t *,
4762      -    boolean_t first, const mib2_transportMLPEntry_t *);
     4801 +    conn_pid_info_t *, boolean_t first,
     4802 +    const mib2_transportMLPEntry_t *);
     4803 +
4763 4804  
4764 4805  static void
4765 4806  tcp_report(const mib_item_t *item)
4766 4807  {
4767      -        int                     jtemp = 0;
4768      -        boolean_t               print_hdr_once_v4 = B_TRUE;
4769      -        boolean_t               print_hdr_once_v6 = B_TRUE;
4770      -        mib2_tcpConnEntry_t     *tp;
4771      -        mib2_tcp6ConnEntry_t    *tp6;
4772      -        mib2_transportMLPEntry_t **v4_attrs, **v6_attrs;
4773      -        mib2_transportMLPEntry_t **v4a, **v6a;
4774      -        mib2_transportMLPEntry_t *aptr;
     4808 +        int                             jtemp = 0;
     4809 +        boolean_t                       print_hdr_once_v4 = B_TRUE;
     4810 +        boolean_t                       print_hdr_once_v6 = B_TRUE;
     4811 +        mib2_tcpConnEntry_t             *tp;
     4812 +        mib2_tcp6ConnEntry_t            *tp6;
     4813 +        mib2_transportMLPEntry_t        **v4_attrs, **v6_attrs;
     4814 +        mib2_transportMLPEntry_t        **v4a, **v6a;
     4815 +        mib2_transportMLPEntry_t        *aptr;
     4816 +        conn_pid_info_t                 *cpi;
4775 4817  
4776 4818          if (!protocol_selected(IPPROTO_TCP))
4777 4819                  return;
4778 4820  
4779 4821          /*
4780 4822           * Preparation pass: the kernel returns separate entries for TCP
4781 4823           * connection table entries and Multilevel Port attributes.  We loop
4782 4824           * through the attributes first and set up an array for each address
4783 4825           * family.
4784 4826           */
↓ open down ↓ 12 lines elided ↑ open up ↑
4797 4839                          (void) printf("\n--- Entry %d ---\n", ++jtemp);
4798 4840                          (void) printf("Group = %d, mib_id = %d, "
4799 4841                              "length = %d, valp = 0x%p\n",
4800 4842                              item->group, item->mib_id,
4801 4843                              item->length, item->valp);
4802 4844                  }
4803 4845  
4804 4846                  if (!((item->group == MIB2_TCP &&
4805 4847                      item->mib_id == MIB2_TCP_CONN) ||
4806 4848                      (item->group == MIB2_TCP6 &&
4807      -                    item->mib_id == MIB2_TCP6_CONN)))
     4849 +                    item->mib_id == MIB2_TCP6_CONN) ||
     4850 +                    (item->group == MIB2_TCP &&
     4851 +                    item->mib_id == EXPER_XPORT_PROC_INFO) ||
     4852 +                    (item->group == MIB2_TCP6 &&
     4853 +                    item->mib_id == EXPER_XPORT_PROC_INFO)))
4808 4854                          continue; /* 'for' loop 1 */
4809 4855  
4810 4856                  if (item->group == MIB2_TCP && !family_selected(AF_INET))
4811 4857                          continue; /* 'for' loop 1 */
4812 4858                  else if (item->group == MIB2_TCP6 && !family_selected(AF_INET6))
4813 4859                          continue; /* 'for' loop 1 */
4814 4860  
4815      -                if (item->group == MIB2_TCP) {
     4861 +                if ((!Uflag) && item->group == MIB2_TCP &&
     4862 +                    item->mib_id == MIB2_TCP_CONN) {
4816 4863                          for (tp = (mib2_tcpConnEntry_t *)item->valp;
4817 4864                              (char *)tp < (char *)item->valp + item->length;
4818 4865                              /* LINTED: (note 1) */
4819 4866                              tp = (mib2_tcpConnEntry_t *)((char *)tp +
4820 4867                              tcpConnEntrySize)) {
4821 4868                                  aptr = v4a == NULL ? NULL : *v4a++;
4822 4869                                  print_hdr_once_v4 = tcp_report_item_v4(tp,
4823      -                                    print_hdr_once_v4, aptr);
     4870 +                                    NULL, print_hdr_once_v4, aptr);
4824 4871                          }
4825      -                } else {
     4872 +                } else if ((!Uflag) && item->group == MIB2_TCP6 &&
     4873 +                    item->mib_id == MIB2_TCP6_CONN) {
4826 4874                          for (tp6 = (mib2_tcp6ConnEntry_t *)item->valp;
4827 4875                              (char *)tp6 < (char *)item->valp + item->length;
4828 4876                              /* LINTED: (note 1) */
4829 4877                              tp6 = (mib2_tcp6ConnEntry_t *)((char *)tp6 +
4830 4878                              tcp6ConnEntrySize)) {
4831 4879                                  aptr = v6a == NULL ? NULL : *v6a++;
4832 4880                                  print_hdr_once_v6 = tcp_report_item_v6(tp6,
4833      -                                    print_hdr_once_v6, aptr);
     4881 +                                    NULL, print_hdr_once_v6, aptr);
     4882 +                        }
     4883 +                } else if ((Uflag) && item->group == MIB2_TCP &&
     4884 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     4885 +                        for (tp = (mib2_tcpConnEntry_t *)item->valp;
     4886 +                            (char *)tp < (char *)item->valp + item->length;
     4887 +                            /* LINTED: (note 1) */
     4888 +                            tp = (mib2_tcpConnEntry_t *)((char *)cpi +
     4889 +                            cpi->cpi_tot_size)) {
     4890 +                                aptr = v4a == NULL ? NULL : *v4a++;
     4891 +                                /* LINTED: (note 1) */
     4892 +                                cpi = (conn_pid_info_t *) ((char *)tp +
     4893 +                                    tcpConnEntrySize);
     4894 +                                print_hdr_once_v4 = tcp_report_item_v4(tp,
     4895 +                                    cpi, print_hdr_once_v4, aptr);
     4896 +                        }
     4897 +                } else if ((Uflag) && item->group == MIB2_TCP6 &&
     4898 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     4899 +                        for (tp6 = (mib2_tcp6ConnEntry_t *)item->valp;
     4900 +                            (char *)tp6 < (char *)item->valp + item->length;
     4901 +                            /* LINTED: (note 1) */
     4902 +                            tp6 = (mib2_tcp6ConnEntry_t *)((char *)cpi +
     4903 +                            cpi->cpi_tot_size)) {
     4904 +                                aptr = v6a == NULL ? NULL : *v6a++;
     4905 +                                /* LINTED: (note 1) */
     4906 +                                cpi = (conn_pid_info_t *) ((char *)tp6 +
     4907 +                                    tcp6ConnEntrySize);
     4908 +                                print_hdr_once_v6 = tcp_report_item_v6(tp6,
     4909 +                                    cpi, print_hdr_once_v6, aptr);
4834 4910                          }
4835 4911                  }
     4912 +
4836 4913          } /* 'for' loop 1 ends */
4837 4914          (void) fflush(stdout);
4838 4915  
4839 4916          if (v4_attrs != NULL)
4840 4917                  free(v4_attrs);
4841 4918          if (v6_attrs != NULL)
4842 4919                  free(v6_attrs);
4843 4920  }
4844 4921  
4845 4922  static boolean_t
4846      -tcp_report_item_v4(const mib2_tcpConnEntry_t *tp, boolean_t first,
4847      -    const mib2_transportMLPEntry_t *attr)
     4923 +tcp_report_item_v4(const mib2_tcpConnEntry_t *tp, conn_pid_info_t * cpi,
     4924 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
4848 4925  {
4849 4926          /*
4850 4927           * lname and fname below are for the hostname as well as the portname
4851 4928           * There is no limit on portname length so we assume MAXHOSTNAMELEN
4852 4929           * as the limit
4853 4930           */
4854 4931          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4855 4932          char    fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4856 4933  
     4934 +
4857 4935          if (!(Aflag || tp->tcpConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
4858 4936                  return (first); /* Nothing to print */
4859 4937  
4860 4938          if (first) {
4861 4939                  (void) printf(v4compat ? tcp_hdr_v4_compat : tcp_hdr_v4);
4862      -                (void) printf(Vflag ? tcp_hdr_v4_verbose : tcp_hdr_v4_normal);
     4940 +                if (Uflag)
     4941 +                        (void) printf(Vflag ? tcp_hdr_v4_pid_verbose :
     4942 +                                tcp_hdr_v4_pid);
     4943 +                else
     4944 +                        (void) printf(Vflag ? tcp_hdr_v4_verbose :
     4945 +                                tcp_hdr_v4_normal);
4863 4946          }
4864 4947  
4865      -        if (Vflag) {
     4948 +        if ((!Uflag) && Vflag) {
4866 4949                  (void) printf("%-20s\n%-20s %5u %08x %08x %5u %08x %08x "
4867 4950                      "%5u %5u %s\n",
4868 4951                      pr_ap(tp->tcpConnLocalAddress,
4869 4952                      tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
4870 4953                      pr_ap(tp->tcpConnRemAddress,
4871 4954                      tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
4872 4955                      tp->tcpConnEntryInfo.ce_swnd,
4873 4956                      tp->tcpConnEntryInfo.ce_snxt,
4874 4957                      tp->tcpConnEntryInfo.ce_suna,
4875 4958                      tp->tcpConnEntryInfo.ce_rwnd,
4876 4959                      tp->tcpConnEntryInfo.ce_rnxt,
4877 4960                      tp->tcpConnEntryInfo.ce_rack,
4878 4961                      tp->tcpConnEntryInfo.ce_rto,
4879 4962                      tp->tcpConnEntryInfo.ce_mss,
4880 4963                      mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
4881      -        } else {
     4964 +        } else if ((!Uflag) && (!Vflag)) {
4882 4965                  int sq = (int)tp->tcpConnEntryInfo.ce_snxt -
4883 4966                      (int)tp->tcpConnEntryInfo.ce_suna - 1;
4884 4967                  int rq = (int)tp->tcpConnEntryInfo.ce_rnxt -
4885 4968                      (int)tp->tcpConnEntryInfo.ce_rack;
4886 4969  
4887 4970                  (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n",
4888 4971                      pr_ap(tp->tcpConnLocalAddress,
4889 4972                      tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
4890 4973                      pr_ap(tp->tcpConnRemAddress,
4891 4974                      tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
4892 4975                      tp->tcpConnEntryInfo.ce_swnd,
4893 4976                      (sq >= 0) ? sq : 0,
4894 4977                      tp->tcpConnEntryInfo.ce_rwnd,
4895 4978                      (rq >= 0) ? rq : 0,
4896 4979                      mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
     4980 +        } else if (Uflag && Vflag) {
     4981 +                int i = 0;
     4982 +                pid_t *pids = cpi->cpi_pids;
     4983 +                proc_info_t *pinfo;
     4984 +                do {
     4985 +                        pinfo = get_proc_info(*pids);
     4986 +                        (void) printf("%-20s\n%-20s %7u %08x %08x %7u %08x %08x "
     4987 +                            "%5u %5u %-11s %-8.8s %6u %s\n",
     4988 +                            pr_ap(tp->tcpConnLocalAddress,
     4989 +                            tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
     4990 +                            pr_ap(tp->tcpConnRemAddress,
     4991 +                            tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
     4992 +                            tp->tcpConnEntryInfo.ce_swnd,
     4993 +                            tp->tcpConnEntryInfo.ce_snxt,
     4994 +                            tp->tcpConnEntryInfo.ce_suna,
     4995 +                            tp->tcpConnEntryInfo.ce_rwnd,
     4996 +                            tp->tcpConnEntryInfo.ce_rnxt,
     4997 +                            tp->tcpConnEntryInfo.ce_rack,
     4998 +                            tp->tcpConnEntryInfo.ce_rto,
     4999 +                            tp->tcpConnEntryInfo.ce_mss,
     5000 +                            mitcp_state(tp->tcpConnEntryInfo.ce_state, attr),
     5001 +                            pinfo->pr_user, (int)*pids, pinfo->pr_psargs);
     5002 +                        i++; pids++;
     5003 +                } while (i < cpi->cpi_pids_cnt);
     5004 +        } else if (Uflag && (!Vflag)) {
     5005 +                int sq = (int)tp->tcpConnEntryInfo.ce_snxt -
     5006 +                    (int)tp->tcpConnEntryInfo.ce_suna - 1;
     5007 +                int rq = (int)tp->tcpConnEntryInfo.ce_rnxt -
     5008 +                   (int)tp->tcpConnEntryInfo.ce_rack;
     5009 +                int i = 0;
     5010 +                pid_t *pids = cpi->cpi_pids;
     5011 +                proc_info_t *pinfo;
     5012 +                do {
     5013 +                        pinfo = get_proc_info(*pids);
     5014 +                        (void) printf("%-20s %-20s %-8.8s %6u %-13.13s %7u %6d %7u %6d %s\n",
     5015 +                            pr_ap(tp->tcpConnLocalAddress,
     5016 +                            tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
     5017 +                            pr_ap(tp->tcpConnRemAddress,
     5018 +                            tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
     5019 +                            pinfo->pr_user, (int)*pids, pinfo->pr_fname,
     5020 +                            tp->tcpConnEntryInfo.ce_swnd,
     5021 +                            (sq >= 0) ? sq : 0,
     5022 +                            tp->tcpConnEntryInfo.ce_rwnd,
     5023 +                            (rq >= 0) ? rq : 0,
     5024 +                            mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
     5025 +                        i++; pids++;
     5026 +                } while (i < cpi->cpi_pids_cnt);
4897 5027          }
4898 5028  
4899 5029          print_transport_label(attr);
4900 5030  
4901 5031          return (B_FALSE);
4902 5032  }
4903 5033  
4904 5034  static boolean_t
4905      -tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6, boolean_t first,
4906      -    const mib2_transportMLPEntry_t *attr)
     5035 +tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6, conn_pid_info_t *cpi,
     5036 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
4907 5037  {
4908 5038          /*
4909 5039           * lname and fname below are for the hostname as well as the portname
4910 5040           * There is no limit on portname length so we assume MAXHOSTNAMELEN
4911 5041           * as the limit
4912 5042           */
4913 5043          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4914 5044          char    fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4915 5045          char    ifname[LIFNAMSIZ + 1];
4916 5046          char    *ifnamep;
4917 5047  
4918 5048          if (!(Aflag || tp6->tcp6ConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
4919 5049                  return (first); /* Nothing to print */
4920 5050  
4921 5051          if (first) {
4922 5052                  (void) printf(tcp_hdr_v6);
4923      -                (void) printf(Vflag ? tcp_hdr_v6_verbose : tcp_hdr_v6_normal);
     5053 +                if (Uflag)
     5054 +                        (void) printf(Vflag ? tcp_hdr_v6_pid_verbose :
     5055 +                                tcp_hdr_v6_pid);
     5056 +                else
     5057 +                        (void) printf(Vflag ? tcp_hdr_v6_verbose :
     5058 +                                tcp_hdr_v6_normal);
4924 5059          }
4925 5060  
4926 5061          ifnamep = (tp6->tcp6ConnIfIndex != 0) ?
4927 5062              if_indextoname(tp6->tcp6ConnIfIndex, ifname) : NULL;
4928 5063          if (ifnamep == NULL)
4929 5064                  ifnamep = "";
4930 5065  
4931      -        if (Vflag) {
     5066 +        if ((!Uflag) && Vflag) {
4932 5067                  (void) printf("%-33s\n%-33s %5u %08x %08x %5u %08x %08x "
4933 5068                      "%5u %5u %-11s %s\n",
4934 5069                      pr_ap6(&tp6->tcp6ConnLocalAddress,
4935 5070                      tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
4936 5071                      pr_ap6(&tp6->tcp6ConnRemAddress,
4937 5072                      tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
4938 5073                      tp6->tcp6ConnEntryInfo.ce_swnd,
4939 5074                      tp6->tcp6ConnEntryInfo.ce_snxt,
4940 5075                      tp6->tcp6ConnEntryInfo.ce_suna,
4941 5076                      tp6->tcp6ConnEntryInfo.ce_rwnd,
4942 5077                      tp6->tcp6ConnEntryInfo.ce_rnxt,
4943 5078                      tp6->tcp6ConnEntryInfo.ce_rack,
4944 5079                      tp6->tcp6ConnEntryInfo.ce_rto,
4945 5080                      tp6->tcp6ConnEntryInfo.ce_mss,
4946 5081                      mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
4947 5082                      ifnamep);
4948      -        } else {
     5083 +        } else if ((!Uflag) && (!Vflag)) {
4949 5084                  int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt -
4950 5085                      (int)tp6->tcp6ConnEntryInfo.ce_suna - 1;
4951 5086                  int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt -
4952 5087                      (int)tp6->tcp6ConnEntryInfo.ce_rack;
4953 5088  
4954 5089                  (void) printf("%-33s %-33s %5u %6d %5u %6d %-11s %s\n",
4955 5090                      pr_ap6(&tp6->tcp6ConnLocalAddress,
4956 5091                      tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
4957 5092                      pr_ap6(&tp6->tcp6ConnRemAddress,
4958 5093                      tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
4959 5094                      tp6->tcp6ConnEntryInfo.ce_swnd,
4960 5095                      (sq >= 0) ? sq : 0,
4961 5096                      tp6->tcp6ConnEntryInfo.ce_rwnd,
4962 5097                      (rq >= 0) ? rq : 0,
4963 5098                      mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
4964 5099                      ifnamep);
     5100 +        } else if (Uflag && Vflag) {
     5101 +                int i = 0;
     5102 +                pid_t *pids = cpi->cpi_pids;
     5103 +                proc_info_t *pinfo;
     5104 +                do {
     5105 +                        pinfo = get_proc_info(*pids);
     5106 +                        (void) printf("%-33s\n%-33s %7u %08x %08x %7u %08x %08x "
     5107 +                            "%5u %5u %-11s %-5.5s %-8.8s %6u %s\n",
     5108 +                            pr_ap6(&tp6->tcp6ConnLocalAddress,
     5109 +                            tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
     5110 +                            pr_ap6(&tp6->tcp6ConnRemAddress,
     5111 +                            tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
     5112 +                            tp6->tcp6ConnEntryInfo.ce_swnd,
     5113 +                            tp6->tcp6ConnEntryInfo.ce_snxt,
     5114 +                            tp6->tcp6ConnEntryInfo.ce_suna,
     5115 +                            tp6->tcp6ConnEntryInfo.ce_rwnd,
     5116 +                            tp6->tcp6ConnEntryInfo.ce_rnxt,
     5117 +                            tp6->tcp6ConnEntryInfo.ce_rack,
     5118 +                            tp6->tcp6ConnEntryInfo.ce_rto,
     5119 +                            tp6->tcp6ConnEntryInfo.ce_mss,
     5120 +                            mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
     5121 +                            ifnamep, pinfo->pr_user, (int)*pids, pinfo->pr_psargs);
     5122 +                        i++; pids++;
     5123 +                } while (i < cpi->cpi_pids_cnt);
     5124 +        } else if (Uflag && (!Vflag)) {
     5125 +                int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt -
     5126 +                    (int)tp6->tcp6ConnEntryInfo.ce_suna - 1;
     5127 +                int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt -
     5128 +                    (int)tp6->tcp6ConnEntryInfo.ce_rack;
     5129 +                int i = 0;
     5130 +                pid_t *pids = cpi->cpi_pids;
     5131 +                proc_info_t *pinfo;
     5132 +                do {
     5133 +                        pinfo = get_proc_info(*pids);
     5134 +                        (void) printf("%-33s %-33s %-8.8s %6u %-14.14s %7d %6u %7d %6d %-11s %s\n",
     5135 +                            pr_ap6(&tp6->tcp6ConnLocalAddress,
     5136 +                            tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
     5137 +                            pr_ap6(&tp6->tcp6ConnRemAddress,
     5138 +                            tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
     5139 +                            pinfo->pr_user, (int)*pids, pinfo->pr_fname,
     5140 +                            tp6->tcp6ConnEntryInfo.ce_swnd,
     5141 +                            (sq >= 0) ? sq : 0,
     5142 +                            tp6->tcp6ConnEntryInfo.ce_rwnd,
     5143 +                            (rq >= 0) ? rq : 0,
     5144 +                            mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
     5145 +                            ifnamep);
     5146 +                        i++; pids++;
     5147 +                } while (i < cpi->cpi_pids_cnt);
4965 5148          }
4966 5149  
4967 5150          print_transport_label(attr);
4968 5151  
4969 5152          return (B_FALSE);
4970 5153  }
4971 5154  
4972 5155  /* ------------------------------- UDP_REPORT------------------------------- */
4973 5156  
4974 5157  static boolean_t udp_report_item_v4(const mib2_udpEntry_t *ude,
4975      -    boolean_t first, const mib2_transportMLPEntry_t *attr);
     5158 +    conn_pid_info_t *cpi, boolean_t first,
     5159 +    const mib2_transportMLPEntry_t *attr);
4976 5160  static boolean_t udp_report_item_v6(const mib2_udp6Entry_t *ude6,
4977      -    boolean_t first, const mib2_transportMLPEntry_t *attr);
     5161 +    conn_pid_info_t *cpi, boolean_t first,
     5162 +    const mib2_transportMLPEntry_t *attr);
4978 5163  
4979 5164  static const char udp_hdr_v4[] =
4980 5165  "   Local Address        Remote Address      State\n"
4981 5166  "-------------------- -------------------- ----------\n";
     5167 +static const char udp_hdr_v4_pid[] =
     5168 +"   Local Address        Remote Address      User    Pid   "
     5169 +"   Command       State\n"
     5170 +"-------------------- -------------------- -------- ------ "
     5171 +"-------------- ----------\n";
     5172 +static const char udp_hdr_v4_pid_verbose[] =
     5173 +"   Local Address        Remote Address      User    Pid     State    "
     5174 +"   Command\n"
     5175 +"-------------------- -------------------- -------- ------ ---------- "
     5176 +"----------------\n";
4982 5177  
4983 5178  static const char udp_hdr_v6[] =
4984 5179  "   Local Address                     Remote Address                 "
4985 5180  "  State      If\n"
4986 5181  "--------------------------------- --------------------------------- "
4987 5182  "---------- -----\n";
     5183 +static const char udp_hdr_v6_pid[] =
     5184 +"   Local Address                     Remote Address                 "
     5185 +"  User    Pid      Command       State      If\n"
     5186 +"--------------------------------- --------------------------------- "
     5187 +"-------- ------ -------------- ---------- -----\n";
     5188 +static const char udp_hdr_v6_pid_verbose[] =
     5189 +"   Local Address                     Remote Address                 "
     5190 +"  User    Pid     State      If     Command\n"
     5191 +"--------------------------------- --------------------------------- "
     5192 +"-------- ------ ---------- ----- ----------------\n";
     5193 +
4988 5194  
4989 5195  static void
4990 5196  udp_report(const mib_item_t *item)
4991 5197  {
4992      -        int                     jtemp = 0;
4993      -        boolean_t               print_hdr_once_v4 = B_TRUE;
4994      -        boolean_t               print_hdr_once_v6 = B_TRUE;
4995      -        mib2_udpEntry_t         *ude;
4996      -        mib2_udp6Entry_t        *ude6;
4997      -        mib2_transportMLPEntry_t **v4_attrs, **v6_attrs;
4998      -        mib2_transportMLPEntry_t **v4a, **v6a;
4999      -        mib2_transportMLPEntry_t *aptr;
     5198 +        int                             jtemp = 0;
     5199 +        boolean_t                       print_hdr_once_v4 = B_TRUE;
     5200 +        boolean_t                       print_hdr_once_v6 = B_TRUE;
     5201 +        mib2_udpEntry_t                 *ude;
     5202 +        mib2_udp6Entry_t                *ude6;
     5203 +        mib2_transportMLPEntry_t        **v4_attrs, **v6_attrs;
     5204 +        mib2_transportMLPEntry_t        **v4a, **v6a;
     5205 +        mib2_transportMLPEntry_t        *aptr;
     5206 +        conn_pid_info_t                 *cpi;
5000 5207  
5001 5208          if (!protocol_selected(IPPROTO_UDP))
5002 5209                  return;
5003 5210  
5004 5211          /*
5005 5212           * Preparation pass: the kernel returns separate entries for UDP
5006 5213           * connection table entries and Multilevel Port attributes.  We loop
5007 5214           * through the attributes first and set up an array for each address
5008 5215           * family.
5009 5216           */
↓ open down ↓ 10 lines elided ↑ open up ↑
5020 5227                  if (Xflag) {
5021 5228                          (void) printf("\n--- Entry %d ---\n", ++jtemp);
5022 5229                          (void) printf("Group = %d, mib_id = %d, "
5023 5230                              "length = %d, valp = 0x%p\n",
5024 5231                              item->group, item->mib_id,
5025 5232                              item->length, item->valp);
5026 5233                  }
5027 5234                  if (!((item->group == MIB2_UDP &&
5028 5235                      item->mib_id == MIB2_UDP_ENTRY) ||
5029 5236                      (item->group == MIB2_UDP6 &&
5030      -                    item->mib_id == MIB2_UDP6_ENTRY)))
     5237 +                    item->mib_id == MIB2_UDP6_ENTRY) ||
     5238 +                    (item->group == MIB2_UDP &&
     5239 +                    item->mib_id == EXPER_XPORT_PROC_INFO) ||
     5240 +                    (item->group == MIB2_UDP6 &&
     5241 +                    item->mib_id == EXPER_XPORT_PROC_INFO)))
5031 5242                          continue; /* 'for' loop 1 */
5032 5243  
5033 5244                  if (item->group == MIB2_UDP && !family_selected(AF_INET))
5034 5245                          continue; /* 'for' loop 1 */
5035 5246                  else if (item->group == MIB2_UDP6 && !family_selected(AF_INET6))
5036 5247                          continue; /* 'for' loop 1 */
5037 5248  
5038 5249                  /*      xxx.xxx.xxx.xxx,pppp  sss... */
5039      -                if (item->group == MIB2_UDP) {
     5250 +                if ((!Uflag) && item->group == MIB2_UDP &&
     5251 +                    item->mib_id == MIB2_UDP_ENTRY) {
5040 5252                          for (ude = (mib2_udpEntry_t *)item->valp;
5041 5253                              (char *)ude < (char *)item->valp + item->length;
5042 5254                              /* LINTED: (note 1) */
5043 5255                              ude = (mib2_udpEntry_t *)((char *)ude +
5044 5256                              udpEntrySize)) {
5045 5257                                  aptr = v4a == NULL ? NULL : *v4a++;
5046 5258                                  print_hdr_once_v4 = udp_report_item_v4(ude,
5047      -                                    print_hdr_once_v4, aptr);
     5259 +                                    NULL, print_hdr_once_v4, aptr);
5048 5260                          }
5049      -                } else {
     5261 +                } else if ((!Uflag) && item->group == MIB2_UDP6 &&
     5262 +                     item->mib_id == MIB2_UDP6_ENTRY) {
5050 5263                          for (ude6 = (mib2_udp6Entry_t *)item->valp;
5051 5264                              (char *)ude6 < (char *)item->valp + item->length;
5052 5265                              /* LINTED: (note 1) */
5053 5266                              ude6 = (mib2_udp6Entry_t *)((char *)ude6 +
5054 5267                              udp6EntrySize)) {
5055 5268                                  aptr = v6a == NULL ? NULL : *v6a++;
5056 5269                                  print_hdr_once_v6 = udp_report_item_v6(ude6,
5057      -                                    print_hdr_once_v6, aptr);
     5270 +                                    NULL, print_hdr_once_v6, aptr);
     5271 +                        }
     5272 +                } else if ((Uflag) && item->group == MIB2_UDP &&
     5273 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5274 +                        for (ude = (mib2_udpEntry_t *)item->valp;
     5275 +                            (char *)ude < (char *)item->valp + item->length;
     5276 +                            /* LINTED: (note 1) */
     5277 +                            ude = (mib2_udpEntry_t *)((char *)cpi +
     5278 +                            cpi->cpi_tot_size)) {
     5279 +                                aptr = v4a == NULL ? NULL : *v4a++;
     5280 +                                /* LINTED: (note 1) */
     5281 +                                cpi = (conn_pid_info_t *) ((char *)ude +
     5282 +                                    udpEntrySize);
     5283 +                                print_hdr_once_v4 = udp_report_item_v4(ude,
     5284 +                                    cpi, print_hdr_once_v4, aptr);
     5285 +                        }
     5286 +                } else if ((Uflag) && item->group == MIB2_UDP6 &&
     5287 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5288 +                        for (ude6 = (mib2_udp6Entry_t *)item->valp;
     5289 +                            (char *)ude6 < (char *)item->valp + item->length;
     5290 +                            /* LINTED: (note 1) */
     5291 +                            ude6 = (mib2_udp6Entry_t *)((char *)cpi +
     5292 +                            cpi->cpi_tot_size)) {
     5293 +                                aptr = v6a == NULL ? NULL : *v6a++;
     5294 +                                /* LINTED: (note 1) */
     5295 +                                cpi = (conn_pid_info_t *) ((char *)ude6 +
     5296 +                                    udp6EntrySize);
     5297 +                                print_hdr_once_v6 = udp_report_item_v6(ude6,
     5298 +                                    cpi, print_hdr_once_v6, aptr);
5058 5299                          }
5059 5300                  }
5060 5301          } /* 'for' loop 1 ends */
5061 5302          (void) fflush(stdout);
5062 5303  
5063 5304          if (v4_attrs != NULL)
5064 5305                  free(v4_attrs);
5065 5306          if (v6_attrs != NULL)
5066 5307                  free(v6_attrs);
5067 5308  }
5068 5309  
5069 5310  static boolean_t
5070      -udp_report_item_v4(const mib2_udpEntry_t *ude, boolean_t first,
5071      -    const mib2_transportMLPEntry_t *attr)
     5311 +udp_report_item_v4(const mib2_udpEntry_t *ude, conn_pid_info_t *cpi,
     5312 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
5072 5313  {
5073 5314          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5074 5315                          /* hostname + portname */
5075 5316  
5076 5317          if (!(Aflag || ude->udpEntryInfo.ue_state >= MIB2_UDP_connected))
5077 5318                  return (first); /* Nothing to print */
5078 5319  
5079 5320          if (first) {
5080 5321                  (void) printf(v4compat ? "\nUDP\n" : "\nUDP: IPv4\n");
5081      -                (void) printf(udp_hdr_v4);
     5322 +
     5323 +                if (Uflag)
     5324 +                        (void) printf(Vflag ? udp_hdr_v4_pid_verbose :
     5325 +                                udp_hdr_v4_pid);
     5326 +                else
     5327 +                        (void) printf(udp_hdr_v4);
     5328 +
5082 5329                  first = B_FALSE;
5083 5330          }
5084 5331  
5085      -        (void) printf("%-20s ",
     5332 +        (void) printf("%-20s %-20s ",
5086 5333              pr_ap(ude->udpLocalAddress, ude->udpLocalPort, "udp",
5087      -            lname, sizeof (lname)));
5088      -        (void) printf("%-20s %s\n",
     5334 +            lname, sizeof (lname)),
5089 5335              ude->udpEntryInfo.ue_state == MIB2_UDP_connected ?
5090 5336              pr_ap(ude->udpEntryInfo.ue_RemoteAddress,
5091 5337              ude->udpEntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
5092      -            "",
5093      -            miudp_state(ude->udpEntryInfo.ue_state, attr));
     5338 +            "");
     5339 +        if (!Uflag) {
     5340 +                (void) printf("%s\n",
     5341 +                    miudp_state(ude->udpEntryInfo.ue_state, attr));
     5342 +        } else {
     5343 +                int i = 0;
     5344 +                pid_t *pids = cpi->cpi_pids;
     5345 +                proc_info_t *pinfo;
     5346 +                do {
     5347 +                        pinfo = get_proc_info(*pids);
     5348 +                        (void) printf("%-8.8s %6u ", pinfo->pr_user,
     5349 +                            (int)*pids);
     5350 +                        if (Vflag) {
     5351 +                                (void) printf("%-10.10s %s\n",
     5352 +                                    miudp_state(ude->udpEntryInfo.ue_state,
     5353 +                                    attr),
     5354 +                                    pinfo->pr_psargs);
     5355 +                        } else {
     5356 +                                (void) printf("%-14.14s %s\n", pinfo->pr_fname,
     5357 +                                  miudp_state(ude->udpEntryInfo.ue_state,
     5358 +                                  attr));
     5359 +                        }
     5360 +                        i++; pids++;
     5361 +                } while (i < cpi->cpi_pids_cnt);
     5362 +        }
5094 5363  
5095 5364          print_transport_label(attr);
5096 5365  
5097 5366          return (first);
5098 5367  }
5099 5368  
5100 5369  static boolean_t
5101      -udp_report_item_v6(const mib2_udp6Entry_t *ude6, boolean_t first,
5102      -    const mib2_transportMLPEntry_t *attr)
     5370 +udp_report_item_v6(const mib2_udp6Entry_t *ude6, conn_pid_info_t *cpi,
     5371 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
5103 5372  {
5104 5373          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5105 5374                          /* hostname + portname */
5106 5375          char    ifname[LIFNAMSIZ + 1];
5107 5376          const char *ifnamep;
5108 5377  
5109 5378          if (!(Aflag || ude6->udp6EntryInfo.ue_state >= MIB2_UDP_connected))
5110 5379                  return (first); /* Nothing to print */
5111 5380  
5112 5381          if (first) {
5113 5382                  (void) printf("\nUDP: IPv6\n");
5114      -                (void) printf(udp_hdr_v6);
     5383 +
     5384 +                if (Uflag)
     5385 +                        (void) printf(Vflag ? udp_hdr_v6_pid_verbose :
     5386 +                                udp_hdr_v6_pid);
     5387 +                else
     5388 +                        (void) printf(udp_hdr_v6);
     5389 +
5115 5390                  first = B_FALSE;
5116 5391          }
5117 5392  
5118 5393          ifnamep = (ude6->udp6IfIndex != 0) ?
5119 5394              if_indextoname(ude6->udp6IfIndex, ifname) : NULL;
5120 5395  
5121      -        (void) printf("%-33s ",
     5396 +        (void) printf("%-33s %-33s ",
5122 5397              pr_ap6(&ude6->udp6LocalAddress,
5123      -            ude6->udp6LocalPort, "udp", lname, sizeof (lname)));
5124      -        (void) printf("%-33s %-10s %s\n",
     5398 +            ude6->udp6LocalPort, "udp", lname, sizeof (lname)),
5125 5399              ude6->udp6EntryInfo.ue_state == MIB2_UDP_connected ?
5126 5400              pr_ap6(&ude6->udp6EntryInfo.ue_RemoteAddress,
5127 5401              ude6->udp6EntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
5128      -            "",
5129      -            miudp_state(ude6->udp6EntryInfo.ue_state, attr),
5130      -            ifnamep == NULL ? "" : ifnamep);
     5402 +            "");
     5403 +        if (!Uflag) {
     5404 +                (void) printf("%-10s %s\n",
     5405 +                    miudp_state(ude6->udp6EntryInfo.ue_state, attr),
     5406 +                    ifnamep == NULL ? "" : ifnamep);
     5407 +        } else {
     5408 +                int i = 0;
     5409 +                pid_t *pids = cpi->cpi_pids;
     5410 +                proc_info_t *pinfo;
     5411 +                do {
     5412 +                        pinfo = get_proc_info(*pids);
     5413 +                        (void) printf("%-8.8s %6u ", pinfo->pr_user,
     5414 +                            (int)*pids);
     5415 +                        if (Vflag) {
     5416 +                                (void) printf("%-10.10s %-5.5s %s\n",
     5417 +                                    miudp_state(ude6->udp6EntryInfo.ue_state,
     5418 +                                    attr),
     5419 +                                    ifnamep == NULL ? "" : ifnamep,
     5420 +                                    pinfo->pr_psargs);
     5421 +                        } else {
     5422 +                                (void) printf("%-14.14s %-10.10s %s\n",
     5423 +                                    pinfo->pr_fname,
     5424 +                                    miudp_state(ude6->udp6EntryInfo.ue_state,
     5425 +                                    attr),
     5426 +                                    ifnamep == NULL ? "" : ifnamep);
     5427 +                        }
     5428 +                        i++; pids++;
     5429 +                } while (i < cpi->cpi_pids_cnt);
     5430 +        }
5131 5431  
5132 5432          print_transport_label(attr);
5133 5433  
5134 5434          return (first);
5135 5435  }
5136 5436  
5137 5437  /* ------------------------------ SCTP_REPORT------------------------------- */
5138 5438  
5139 5439  static const char sctp_hdr[] =
5140 5440  "\nSCTP:";
5141 5441  static const char sctp_hdr_normal[] =
5142 5442  "        Local Address                   Remote Address          "
5143 5443  "Swind  Send-Q Rwind  Recv-Q StrsI/O  State\n"
5144 5444  "------------------------------- ------------------------------- "
5145 5445  "------ ------ ------ ------ ------- -----------";
     5446 +static const char sctp_hdr_pid[] =
     5447 +"        Local Address                   Remote Address          "
     5448 +"Swind  Send-Q Rwind  Recv-Q StrsI/O   User    Pid      Command      State\n"
     5449 +"------------------------------- ------------------------------- ------ "
     5450 +"------ ------ ------ ------- -------- ------ -------------- -----------";
     5451 +static const char sctp_hdr_pid_verbose[] =
     5452 +"        Local Address                   Remote Address          "
     5453 +"Swind  Send-Q Rwind  Recv-Q StrsI/O   User    Pid    State         Command\n"
     5454 +"------------------------------- ------------------------------- ------ "
     5455 +"------ ------ ------ ------- -------- ------ ----------- --------------";
5146 5456  
5147 5457  static const char *
5148 5458  nssctp_state(int state, const mib2_transportMLPEntry_t *attr)
5149 5459  {
5150 5460          static char sctpsbuf[50];
5151 5461          const char *cp;
5152 5462  
5153 5463          switch (state) {
5154 5464          case MIB2_SCTP_closed:
5155 5465                  cp = "CLOSED";
↓ open down ↓ 146 lines elided ↑ open up ↑
5302 5612                          (void) pr_addr6(addr, name, namelen);
5303 5613                  }
5304 5614                  break;
5305 5615  
5306 5616          default:
5307 5617                  (void) snprintf(name, namelen, "<unknown addr type>");
5308 5618                  break;
5309 5619          }
5310 5620  }
5311 5621  
5312      -static void
5313      -sctp_conn_report_item(const mib_item_t *head, const mib2_sctpConnEntry_t *sp,
     5622 +static boolean_t
     5623 +sctp_conn_report_item(const mib_item_t *head, conn_pid_info_t * cpi,
     5624 +    boolean_t print_sctp_hdr, const mib2_sctpConnEntry_t *sp,
5314 5625      const mib2_transportMLPEntry_t *attr)
5315 5626  {
5316 5627          char            lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5317 5628          char            fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5318 5629          const mib2_sctpConnRemoteEntry_t        *sre = NULL;
5319 5630          const mib2_sctpConnLocalEntry_t *sle = NULL;
5320 5631          const mib_item_t *local = head;
5321 5632          const mib_item_t *remote = head;
5322 5633          uint32_t        id = sp->sctpAssocId;
5323 5634          boolean_t       printfirst = B_TRUE;
5324 5635  
     5636 +        if (print_sctp_hdr == B_TRUE) {
     5637 +                (void) puts(sctp_hdr);
     5638 +                if (Uflag)
     5639 +                        (void) puts(Vflag? sctp_hdr_pid_verbose: sctp_hdr_pid);
     5640 +                else
     5641 +                        (void) puts(sctp_hdr_normal);
     5642 +
     5643 +                print_sctp_hdr = B_FALSE;
     5644 +        }
     5645 +
5325 5646          sctp_pr_addr(sp->sctpAssocRemPrimAddrType, fname, sizeof (fname),
5326 5647              &sp->sctpAssocRemPrimAddr, sp->sctpAssocRemPort);
5327 5648          sctp_pr_addr(sp->sctpAssocRemPrimAddrType, lname, sizeof (lname),
5328 5649              &sp->sctpAssocLocPrimAddr, sp->sctpAssocLocalPort);
5329 5650  
5330      -        (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n",
5331      -            lname, fname,
5332      -            sp->sctpConnEntryInfo.ce_swnd,
5333      -            sp->sctpConnEntryInfo.ce_sendq,
5334      -            sp->sctpConnEntryInfo.ce_rwnd,
5335      -            sp->sctpConnEntryInfo.ce_recvq,
5336      -            sp->sctpAssocInStreams, sp->sctpAssocOutStreams,
5337      -            nssctp_state(sp->sctpAssocState, attr));
     5651 +        if (Uflag) {
     5652 +                int i = 0;
     5653 +                pid_t *pids = cpi->cpi_pids;
     5654 +                proc_info_t *pinfo;
     5655 +                do {
     5656 +                        pinfo = get_proc_info(*pids);
     5657 +                        (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %-8.8s %6u ",
     5658 +                            lname, fname,
     5659 +                            sp->sctpConnEntryInfo.ce_swnd,
     5660 +                            sp->sctpConnEntryInfo.ce_sendq,
     5661 +                            sp->sctpConnEntryInfo.ce_rwnd,
     5662 +                            sp->sctpConnEntryInfo.ce_recvq,
     5663 +                            sp->sctpAssocInStreams,
     5664 +                            sp->sctpAssocOutStreams,
     5665 +                            pinfo->pr_user, (int)*pids);
     5666 +                        if (Vflag) {
     5667 +                                (void) printf("%-11.11s %s\n",
     5668 +                                    nssctp_state(sp->sctpAssocState, attr),
     5669 +                                    pinfo->pr_psargs);
     5670 +                        } else {
     5671 +                                (void) printf("%-14.14s %s\n",
     5672 +                                    pinfo->pr_fname,
     5673 +                                    nssctp_state(sp->sctpAssocState, attr));
     5674 +                        }
     5675 +                        i++; pids++;
     5676 +                } while (i < cpi->cpi_pids_cnt);
     5677 +
     5678 +        } else {
     5679 +
     5680 +                (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n",
     5681 +                    lname, fname,
     5682 +                    sp->sctpConnEntryInfo.ce_swnd,
     5683 +                    sp->sctpConnEntryInfo.ce_sendq,
     5684 +                    sp->sctpConnEntryInfo.ce_rwnd,
     5685 +                    sp->sctpConnEntryInfo.ce_recvq,
     5686 +                    sp->sctpAssocInStreams, sp->sctpAssocOutStreams,
     5687 +                    nssctp_state(sp->sctpAssocState, attr));
     5688 +        }
5338 5689  
5339 5690          print_transport_label(attr);
5340 5691  
5341 5692          if (!Vflag) {
5342      -                return;
     5693 +                return (print_sctp_hdr);
5343 5694          }
5344 5695  
5345 5696          /* Print remote addresses/local addresses on following lines */
5346 5697          while ((sre = sctp_getnext_rem(&remote, sre, id)) != NULL) {
5347 5698                  if (!IN6_ARE_ADDR_EQUAL(&sre->sctpAssocRemAddr,
5348 5699                      &sp->sctpAssocRemPrimAddr)) {
5349 5700                          if (printfirst == B_TRUE) {
5350 5701                                  (void) fputs("\t<Remote: ", stdout);
5351 5702                                  printfirst = B_FALSE;
5352 5703                          } else {
↓ open down ↓ 22 lines elided ↑ open up ↑
5375 5726                                  (void) fputs(", ", stdout);
5376 5727                          }
5377 5728                          sctp_pr_addr(sle->sctpAssocLocalAddrType, lname,
5378 5729                              sizeof (lname), &sle->sctpAssocLocalAddr, -1);
5379 5730                          (void) fputs(lname, stdout);
5380 5731                  }
5381 5732          }
5382 5733          if (printfirst == B_FALSE) {
5383 5734                  (void) puts(">");
5384 5735          }
     5736 +
     5737 +        return (print_sctp_hdr);
5385 5738  }
5386 5739  
5387 5740  static void
5388 5741  sctp_report(const mib_item_t *item)
5389 5742  {
5390 5743          const mib_item_t                *head;
5391 5744          const mib2_sctpConnEntry_t      *sp;
5392      -        boolean_t               first = B_TRUE;
5393      -        mib2_transportMLPEntry_t **attrs, **aptr;
5394      -        mib2_transportMLPEntry_t *attr;
     5745 +        boolean_t                       print_sctp_hdr_once = B_TRUE;
     5746 +        mib2_transportMLPEntry_t        **attrs, **aptr;
     5747 +        mib2_transportMLPEntry_t        *attr;
     5748 +        conn_pid_info_t                 *cpi;
5395 5749  
5396 5750          /*
5397 5751           * Preparation pass: the kernel returns separate entries for SCTP
5398 5752           * connection table entries and Multilevel Port attributes.  We loop
5399 5753           * through the attributes first and set up an array for each address
5400 5754           * family.
5401 5755           */
5402 5756          attrs = RSECflag ?
5403 5757              gather_attrs(item, MIB2_SCTP, MIB2_SCTP_CONN, sctpEntrySize) :
5404 5758              NULL;
5405 5759  
5406 5760          aptr = attrs;
5407 5761          head = item;
5408 5762          for (; item != NULL; item = item->next_item) {
5409 5763  
5410      -                if (!(item->group == MIB2_SCTP &&
5411      -                    item->mib_id == MIB2_SCTP_CONN))
     5764 +                if (!((item->group == MIB2_SCTP &&
     5765 +                    item->mib_id == MIB2_SCTP_CONN) ||
     5766 +                    (item->group == MIB2_SCTP &&
     5767 +                    item->mib_id == EXPER_XPORT_PROC_INFO)))
5412 5768                          continue;
5413 5769  
5414      -                for (sp = item->valp;
5415      -                    (char *)sp < (char *)item->valp + item->length;
5416      -                    /* LINTED: (note 1) */
5417      -                    sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
5418      -                        attr = aptr == NULL ? NULL : *aptr++;
5419      -                        if (Aflag ||
5420      -                            sp->sctpAssocState >= MIB2_SCTP_established) {
5421      -                                if (first == B_TRUE) {
5422      -                                        (void) puts(sctp_hdr);
5423      -                                        (void) puts(sctp_hdr_normal);
5424      -                                        first = B_FALSE;
5425      -                                }
5426      -                                sctp_conn_report_item(head, sp, attr);
     5770 +                if ((!Uflag) && item->group == MIB2_SCTP
     5771 +                    && item->mib_id == MIB2_SCTP_CONN) {
     5772 +                        for (sp = item->valp;
     5773 +                            (char *)sp < (char *)item->valp + item->length;
     5774 +                            /* LINTED: (note 1) */
     5775 +                            sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
     5776 +                                if (!(Aflag ||
     5777 +                                  sp->sctpAssocState >= MIB2_SCTP_established))
     5778 +                                        continue;
     5779 +                                attr = aptr == NULL ? NULL : *aptr++;
     5780 +                                print_sctp_hdr_once = sctp_conn_report_item(head, NULL,
     5781 +                                                        print_sctp_hdr_once, sp,
     5782 +                                                        attr);
     5783 +                        }
     5784 +                } else if ((Uflag) && item->group == MIB2_SCTP &&
     5785 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5786 +                        for (sp = (mib2_sctpConnEntry_t *)item->valp;
     5787 +                            (char *)sp < (char *)item->valp + item->length;
     5788 +                            /* LINTED: (note 1) */
     5789 +                            sp = (mib2_sctpConnEntry_t *)((char *)cpi +
     5790 +                            cpi->cpi_tot_size)) {
     5791 +                                /* LINTED: (note 1) */
     5792 +                                cpi = (conn_pid_info_t *) ((char *)sp +
     5793 +                                    sctpEntrySize);
     5794 +                                if (!(Aflag ||
     5795 +                                  sp->sctpAssocState >= MIB2_SCTP_established))
     5796 +                                        continue;
     5797 +                                attr = aptr == NULL ? NULL : *aptr++;
     5798 +                                print_sctp_hdr_once =
     5799 +                                    sctp_conn_report_item(head, cpi,
     5800 +                                        print_sctp_hdr_once, sp, attr);
5427 5801                          }
5428 5802                  }
5429 5803          }
5430 5804          if (attrs != NULL)
5431 5805                  free(attrs);
5432 5806  }
5433 5807  
5434 5808  static char *
5435 5809  plural(int n)
5436 5810  {
↓ open down ↓ 967 lines elided ↑ open up ↑
6404 6778  static char *
6405 6779  ifindex2str(uint_t ifindex, char *ifname)
6406 6780  {
6407 6781          if (if_indextoname(ifindex, ifname) == NULL)
6408 6782                  (void) snprintf(ifname, LIFNAMSIZ, "if#%d", ifindex);
6409 6783  
6410 6784          return (ifname);
6411 6785  }
6412 6786  
6413 6787  /*
     6788 + * Gets proc info in (proc_info_t) given pid. It doesn't return NULL.
     6789 + */
     6790 +proc_info_t *
     6791 +get_proc_info(pid_t pid)
     6792 +{
     6793 +        static pid_t saved_pid = 0;
     6794 +        static proc_info_t saved_proc_info;
     6795 +        static proc_info_t unknown_proc_info = {"<unknown>","",""};
     6796 +        static psinfo_t pinfo;
     6797 +        char path[128];
     6798 +        int fd;
     6799 +
     6800 +        /* hardcode pid = 0 */
     6801 +        if (pid == 0) {
     6802 +                saved_proc_info.pr_user = "root";
     6803 +                saved_proc_info.pr_fname = "sched";
     6804 +                saved_proc_info.pr_psargs = "sched";
     6805 +                saved_pid = 0;
     6806 +                return &saved_proc_info;
     6807 +        }
     6808 +
     6809 +        if (pid == saved_pid)
     6810 +                return &saved_proc_info;
     6811 +        if ((snprintf(path, 128, "/proc/%u/psinfo",(int)pid) > 0) &&
     6812 +            ((fd = open(path, O_RDONLY)) != -1)) {
     6813 +                if (read(fd, &pinfo, sizeof(pinfo)) == sizeof(pinfo)){
     6814 +                        saved_proc_info.pr_user = get_username(pinfo.pr_uid);
     6815 +                        saved_proc_info.pr_fname = pinfo.pr_fname;
     6816 +                        saved_proc_info.pr_psargs = pinfo.pr_psargs;
     6817 +                        saved_pid = pid;
     6818 +                        (void) close(fd);
     6819 +                        return &saved_proc_info;
     6820 +                } else {
     6821 +                        (void) close(fd);
     6822 +                }
     6823 +        }
     6824 +
     6825 +        return (&unknown_proc_info);
     6826 +}
     6827 +
     6828 +/*
     6829 + * Gets username given uid. It doesn't return NULL.
     6830 + */
     6831 +static char *
     6832 +get_username(uid_t u)
     6833 +{
     6834 +        static uid_t saved_uid = UINT_MAX;
     6835 +        static char  saved_username[128];
     6836 +        struct passwd *pw = NULL;
     6837 +        if (u == UINT_MAX)
     6838 +                return "<unknown>";
     6839 +        if (u == saved_uid && saved_username[0] != '\0')
     6840 +                return  (saved_username);
     6841 +        setpwent();
     6842 +        if ((pw = getpwuid(u)) != NULL)
     6843 +                (void) strlcpy(saved_username, pw->pw_name, 128);
     6844 +        else
     6845 +                (void) snprintf(saved_username, 128, "%u", u);
     6846 +        saved_uid = u;
     6847 +        return saved_username;
     6848 +}
     6849 +
     6850 +/*
6414 6851   * print the usage line
6415 6852   */
6416 6853  static void
6417 6854  usage(char *cmdname)
6418 6855  {
6419      -        (void) fprintf(stderr, "usage: %s [-anv] [-f address_family] "
     6856 +        (void) fprintf(stderr, "usage: %s [-anuv] [-f address_family] "
6420 6857              "[-T d|u]\n", cmdname);
6421 6858          (void) fprintf(stderr, "       %s [-n] [-f address_family] "
6422 6859              "[-P protocol] [-T d|u] [-g | -p | -s [interval [count]]]\n",
6423 6860              cmdname);
6424 6861          (void) fprintf(stderr, "       %s -m [-v] [-T d|u] "
6425 6862              "[interval [count]]\n", cmdname);
6426 6863          (void) fprintf(stderr, "       %s -i [-I interface] [-an] "
6427 6864              "[-f address_family] [-T d|u] [interval [count]]\n", cmdname);
6428 6865          (void) fprintf(stderr, "       %s -r [-anv] "
6429 6866              "[-f address_family|filter] [-T d|u]\n", cmdname);
↓ open down ↓ 15 lines elided ↑ open up ↑
6445 6882          va_list argp;
6446 6883  
6447 6884          if (format == NULL)
6448 6885                  return;
6449 6886  
6450 6887          va_start(argp, format);
6451 6888          (void) vfprintf(stderr, format, argp);
6452 6889          va_end(argp);
6453 6890  
6454 6891          exit(errcode);
     6892 +}
     6893 +
     6894 +
     6895 +/* -------------------UNIX Domain Sockets Report---------------------------- */
     6896 +
     6897 +
     6898 +#define NO_ADDR         "                                       "
     6899 +#define SO_PAIR         " (socketpair)                          "
     6900 +
     6901 +static char             *typetoname(t_scalar_t);
     6902 +static boolean_t        uds_report_item(struct sockinfo *, boolean_t);
     6903 +
     6904 +
     6905 +static char uds_hdr[] = "\nActive UNIX domain sockets\n";
     6906 +
     6907 +static char uds_hdr_normal[] =
     6908 +" Type       Local Adress                           "
     6909 +" Remote Address\n"
     6910 +"---------- --------------------------------------- "
     6911 +"---------------------------------------\n";
     6912 +
     6913 +static char uds_hdr_pid[] =
     6914 +" Type       User     Pid     Command       "
     6915 +" Local Address                         "
     6916 +" Remote Address\n"
     6917 +"---------- -------- ------ -------------- "
     6918 +"--------------------------------------- "
     6919 +"---------------------------------------\n";
     6920 +static char uds_hdr_pid_verbose[] =
     6921 +" Type       User     Pid    Local Address                          "
     6922 +" Remote Address                          Command\n"
     6923 +"---------- -------- ------ --------------------------------------- "
     6924 +"--------------------------------------- --------------\n";
     6925 +
     6926 +/*
     6927 + * Print a summary of connections related to unix protocols.
     6928 + */
     6929 +static void
     6930 +uds_report(kstat_ctl_t  *kc)
     6931 +{
     6932 +        int             i;
     6933 +        kstat_t         *ksp;
     6934 +        struct sockinfo *psi;
     6935 +        boolean_t       print_uds_hdr_once = B_TRUE;
     6936 +
     6937 +        if (kc == NULL) {
     6938 +                fail(0, "uds_report: No kstat");
     6939 +                exit(3);
     6940 +        }
     6941 +
     6942 +        if ((ksp = kstat_lookup(kc, "sockfs", 0, "sock_unix_list")) ==
     6943 +            (kstat_t *)NULL) {
     6944 +                fail(0, "kstat_data_lookup failed\n");
     6945 +        }
     6946 +
     6947 +        if (kstat_read(kc, ksp, NULL) == -1) {
     6948 +                fail(0, "kstat_read failed for sock_unix_list\n");
     6949 +        }
     6950 +
     6951 +        if (ksp->ks_ndata == 0) {
     6952 +                return;                 /* no AF_UNIX sockets found     */
     6953 +        }
     6954 +
     6955 +        /*
     6956 +         * Having ks_data set with ks_data == NULL shouldn't happen;
     6957 +         * If it does, the sockfs kstat is seriously broken.
     6958 +         */
     6959 +        if ((psi = ksp->ks_data) == NULL) {
     6960 +                fail(0, "uds_report: no kstat data\n");
     6961 +        }
     6962 +
     6963 +        for (i = 0; i < ksp->ks_ndata; i++) {
     6964 +
     6965 +                print_uds_hdr_once = uds_report_item(psi, print_uds_hdr_once);
     6966 +
     6967 +                /* if si_size didn't get filled in, then we're done     */
     6968 +                if (psi->si_size == 0 ||
     6969 +                    !IS_P2ALIGNED(psi->si_size, sizeof (psi))) {
     6970 +                        break;
     6971 +                }
     6972 +
     6973 +                /* point to the next sockinfo in the array */
     6974 +                /* LINTED: (note 1) */
     6975 +                psi = (struct sockinfo *)(((char *)psi) + psi->si_size);
     6976 +        }
     6977 +}
     6978 +
     6979 +static boolean_t
     6980 +uds_report_item(struct sockinfo *psi, boolean_t first)
     6981 +{
     6982 +        int             i = 0;
     6983 +        pid_t           *pids;
     6984 +        proc_info_t     *pinfo;
     6985 +        char            *laddr, *raddr;
     6986 +
     6987 +        if(first) {
     6988 +                (void) printf("%s", uds_hdr);
     6989 +                if (Uflag)
     6990 +                        (void) printf("%s", Vflag?uds_hdr_pid_verbose:
     6991 +                            uds_hdr_pid);
     6992 +                else
     6993 +                        (void) printf("%s", uds_hdr_normal);
     6994 +
     6995 +                first = B_FALSE;
     6996 +        }
     6997 +
     6998 +        pids = psi->si_pids;
     6999 +
     7000 +        do {
     7001 +                pinfo = get_proc_info(*pids);
     7002 +                raddr = laddr = NO_ADDR;
     7003 +
     7004 +                /* Try to fill laddr */
     7005 +                if ((psi->si_state & SS_ISBOUND) &&
     7006 +                    strlen(psi->si_laddr_sun_path) != 0 &&
     7007 +                    psi->si_laddr_soa_len != 0) {
     7008 +                        if (psi->si_faddr_noxlate) {
     7009 +                                laddr = SO_PAIR;
     7010 +                        } else {
     7011 +                                if (psi->si_laddr_soa_len >
     7012 +                                    sizeof (psi->si_laddr_family))
     7013 +                                        laddr = psi->si_laddr_sun_path;
     7014 +                        }
     7015 +                }
     7016 +
     7017 +                /* Try to fill raddr */
     7018 +                if ((psi->si_state & SS_ISCONNECTED) &&
     7019 +                    strlen(psi->si_faddr_sun_path) != 0 &&
     7020 +                    psi->si_faddr_soa_len != 0) {
     7021 +
     7022 +                        if (psi->si_faddr_noxlate) {
     7023 +                                raddr = SO_PAIR;
     7024 +                        } else {
     7025 +                                if (psi->si_faddr_soa_len >
     7026 +                                    sizeof (psi->si_faddr_family))
     7027 +                                        raddr = psi->si_faddr_sun_path;
     7028 +                        }
     7029 +                }
     7030 +
     7031 +                if (Uflag && Vflag) {
     7032 +                        (void) printf("%-10.10s %-8.8s %6u "
     7033 +                                "%-39.39s %-39.39s %s\n",
     7034 +                                typetoname(psi->si_serv_type), pinfo->pr_user,
     7035 +                                (int)*pids, laddr, raddr, pinfo->pr_psargs);
     7036 +                } else if (Uflag && (!Vflag)) {
     7037 +                        (void) printf("%-10.10s %-8.8s %6u %-14.14s"
     7038 +                                "%-39.39s %-39.39s\n",
     7039 +                                typetoname(psi->si_serv_type), pinfo->pr_user,
     7040 +                                (int)*pids, pinfo->pr_fname, laddr, raddr);
     7041 +                } else {
     7042 +                        (void) printf("%-10.10s %s %s\n",
     7043 +                                typetoname(psi->si_serv_type), laddr, raddr);
     7044 +                }
     7045 +
     7046 +                i++; pids++;
     7047 +        } while (i < psi->si_pn_cnt);
     7048 +
     7049 +        return (first);
     7050 +}
     7051 +
     7052 +static char *
     7053 +typetoname(t_scalar_t type)
     7054 +{
     7055 +        switch (type) {
     7056 +        case T_CLTS:
     7057 +                return ("dgram");
     7058 +
     7059 +        case T_COTS:
     7060 +                return ("stream");
     7061 +
     7062 +        case T_COTS_ORD:
     7063 +                return ("stream-ord");
     7064 +
     7065 +        default:
     7066 +                return ("");
     7067 +        }
6455 7068  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX