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(uint32_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_node_list_hdr_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_node_list_hdr_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_node_list_hdr_t        *cph;
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 *)cph +
     4889 +                            cph->cph_tot_size)) {
     4890 +                                aptr = v4a == NULL ? NULL : *v4a++;
     4891 +                                /* LINTED: (note 1) */
     4892 +                                cph = (conn_pid_node_list_hdr_t *)
     4893 +                                        ((char *)tp + tcpConnEntrySize);
     4894 +                                print_hdr_once_v4 = tcp_report_item_v4(tp,
     4895 +                                    cph, 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 *)cph +
     4903 +                            cph->cph_tot_size)) {
     4904 +                                aptr = v6a == NULL ? NULL : *v6a++;
     4905 +                                /* LINTED: (note 1) */
     4906 +                                cph = (conn_pid_node_list_hdr_t *)
     4907 +                                        ((char *)tp6 + tcp6ConnEntrySize);
     4908 +                                print_hdr_once_v6 = tcp_report_item_v6(tp6,
     4909 +                                    cph, 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,
     4923 +tcp_report_item_v4(const mib2_tcpConnEntry_t *tp,
     4924 +    conn_pid_node_list_hdr_t * cph, boolean_t first,
4847 4925      const mib2_transportMLPEntry_t *attr)
4848 4926  {
4849 4927          /*
4850 4928           * lname and fname below are for the hostname as well as the portname
4851 4929           * There is no limit on portname length so we assume MAXHOSTNAMELEN
4852 4930           * as the limit
4853 4931           */
4854 4932          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4855 4933          char    fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4856 4934  
     4935 +
4857 4936          if (!(Aflag || tp->tcpConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
4858 4937                  return (first); /* Nothing to print */
4859 4938  
4860 4939          if (first) {
4861 4940                  (void) printf(v4compat ? tcp_hdr_v4_compat : tcp_hdr_v4);
4862      -                (void) printf(Vflag ? tcp_hdr_v4_verbose : tcp_hdr_v4_normal);
     4941 +                if (Uflag)
     4942 +                        (void) printf(Vflag ? tcp_hdr_v4_pid_verbose :
     4943 +                                tcp_hdr_v4_pid);
     4944 +                else
     4945 +                        (void) printf(Vflag ? tcp_hdr_v4_verbose :
     4946 +                                tcp_hdr_v4_normal);
4863 4947          }
4864 4948  
4865      -        if (Vflag) {
     4949 +        if ((!Uflag) && Vflag) {
4866 4950                  (void) printf("%-20s\n%-20s %5u %08x %08x %5u %08x %08x "
4867 4951                      "%5u %5u %s\n",
4868 4952                      pr_ap(tp->tcpConnLocalAddress,
4869 4953                      tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
4870 4954                      pr_ap(tp->tcpConnRemAddress,
4871 4955                      tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
4872 4956                      tp->tcpConnEntryInfo.ce_swnd,
4873 4957                      tp->tcpConnEntryInfo.ce_snxt,
4874 4958                      tp->tcpConnEntryInfo.ce_suna,
4875 4959                      tp->tcpConnEntryInfo.ce_rwnd,
4876 4960                      tp->tcpConnEntryInfo.ce_rnxt,
4877 4961                      tp->tcpConnEntryInfo.ce_rack,
4878 4962                      tp->tcpConnEntryInfo.ce_rto,
4879 4963                      tp->tcpConnEntryInfo.ce_mss,
4880 4964                      mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
4881      -        } else {
     4965 +        } else if ((!Uflag) && (!Vflag)) {
4882 4966                  int sq = (int)tp->tcpConnEntryInfo.ce_snxt -
4883 4967                      (int)tp->tcpConnEntryInfo.ce_suna - 1;
4884 4968                  int rq = (int)tp->tcpConnEntryInfo.ce_rnxt -
4885 4969                      (int)tp->tcpConnEntryInfo.ce_rack;
4886 4970  
4887 4971                  (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n",
4888 4972                      pr_ap(tp->tcpConnLocalAddress,
4889 4973                      tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
4890 4974                      pr_ap(tp->tcpConnRemAddress,
4891 4975                      tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
4892 4976                      tp->tcpConnEntryInfo.ce_swnd,
4893 4977                      (sq >= 0) ? sq : 0,
4894 4978                      tp->tcpConnEntryInfo.ce_rwnd,
4895 4979                      (rq >= 0) ? rq : 0,
4896 4980                      mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
     4981 +        } else if (Uflag && Vflag) {
     4982 +                int i = 0;
     4983 +                conn_pid_node_t *cpn = cph->cph_cpns;
     4984 +                proc_info_t *pinfo;
     4985 +
     4986 +                do {
     4987 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     4988 +                        pinfo = get_proc_info(cpn->cpn_pid);
     4989 +
     4990 +                        (void) printf("%-20s\n%-20s %7u %08x %08x %7u %08x %08x "
     4991 +                            "%5u %5u %-11s %-8.8s %6u %s\n",
     4992 +                            pr_ap(tp->tcpConnLocalAddress,
     4993 +                            tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
     4994 +                            pr_ap(tp->tcpConnRemAddress,
     4995 +                            tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
     4996 +                            tp->tcpConnEntryInfo.ce_swnd,
     4997 +                            tp->tcpConnEntryInfo.ce_snxt,
     4998 +                            tp->tcpConnEntryInfo.ce_suna,
     4999 +                            tp->tcpConnEntryInfo.ce_rwnd,
     5000 +                            tp->tcpConnEntryInfo.ce_rnxt,
     5001 +                            tp->tcpConnEntryInfo.ce_rack,
     5002 +                            tp->tcpConnEntryInfo.ce_rto,
     5003 +                            tp->tcpConnEntryInfo.ce_mss,
     5004 +                            mitcp_state(tp->tcpConnEntryInfo.ce_state, attr),
     5005 +                            pinfo->pr_user, pid, pinfo->pr_psargs);
     5006 +                        i++; cpn++;
     5007 +                } while (i < cph->cph_pn_cnt);
     5008 +        } else if (Uflag && (!Vflag)) {
     5009 +                int sq = (int)tp->tcpConnEntryInfo.ce_snxt -
     5010 +                    (int)tp->tcpConnEntryInfo.ce_suna - 1;
     5011 +                int rq = (int)tp->tcpConnEntryInfo.ce_rnxt -
     5012 +                   (int)tp->tcpConnEntryInfo.ce_rack;
     5013 +                int i = 0;
     5014 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5015 +                proc_info_t *pinfo;
     5016 +
     5017 +                do {
     5018 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5019 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5020 +
     5021 +                        (void) printf("%-20s %-20s %-8.8s %6u %-13.13s %7u %6d %7u %6d %s\n",
     5022 +                            pr_ap(tp->tcpConnLocalAddress,
     5023 +                            tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
     5024 +                            pr_ap(tp->tcpConnRemAddress,
     5025 +                            tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
     5026 +                            pinfo->pr_user, pid, pinfo->pr_fname,
     5027 +                            tp->tcpConnEntryInfo.ce_swnd,
     5028 +                            (sq >= 0) ? sq : 0,
     5029 +                            tp->tcpConnEntryInfo.ce_rwnd,
     5030 +                            (rq >= 0) ? rq : 0,
     5031 +                            mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
     5032 +
     5033 +                        i++; cpn++;
     5034 +                } while (i < cph->cph_pn_cnt);
4897 5035          }
4898 5036  
4899 5037          print_transport_label(attr);
4900 5038  
4901 5039          return (B_FALSE);
4902 5040  }
4903 5041  
4904 5042  static boolean_t
4905      -tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6, boolean_t first,
     5043 +tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6,
     5044 +    conn_pid_node_list_hdr_t *cph, boolean_t first,
4906 5045      const mib2_transportMLPEntry_t *attr)
4907 5046  {
4908 5047          /*
4909 5048           * lname and fname below are for the hostname as well as the portname
4910 5049           * There is no limit on portname length so we assume MAXHOSTNAMELEN
4911 5050           * as the limit
4912 5051           */
4913 5052          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4914 5053          char    fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
4915 5054          char    ifname[LIFNAMSIZ + 1];
4916 5055          char    *ifnamep;
4917 5056  
4918 5057          if (!(Aflag || tp6->tcp6ConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
4919 5058                  return (first); /* Nothing to print */
4920 5059  
4921 5060          if (first) {
4922 5061                  (void) printf(tcp_hdr_v6);
4923      -                (void) printf(Vflag ? tcp_hdr_v6_verbose : tcp_hdr_v6_normal);
     5062 +                if (Uflag)
     5063 +                        (void) printf(Vflag ? tcp_hdr_v6_pid_verbose :
     5064 +                                tcp_hdr_v6_pid);
     5065 +                else
     5066 +                        (void) printf(Vflag ? tcp_hdr_v6_verbose :
     5067 +                                tcp_hdr_v6_normal);
4924 5068          }
4925 5069  
4926 5070          ifnamep = (tp6->tcp6ConnIfIndex != 0) ?
4927 5071              if_indextoname(tp6->tcp6ConnIfIndex, ifname) : NULL;
4928 5072          if (ifnamep == NULL)
4929 5073                  ifnamep = "";
4930 5074  
4931      -        if (Vflag) {
     5075 +        if ((!Uflag) && Vflag) {
4932 5076                  (void) printf("%-33s\n%-33s %5u %08x %08x %5u %08x %08x "
4933 5077                      "%5u %5u %-11s %s\n",
4934 5078                      pr_ap6(&tp6->tcp6ConnLocalAddress,
4935 5079                      tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
4936 5080                      pr_ap6(&tp6->tcp6ConnRemAddress,
4937 5081                      tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
4938 5082                      tp6->tcp6ConnEntryInfo.ce_swnd,
4939 5083                      tp6->tcp6ConnEntryInfo.ce_snxt,
4940 5084                      tp6->tcp6ConnEntryInfo.ce_suna,
4941 5085                      tp6->tcp6ConnEntryInfo.ce_rwnd,
4942 5086                      tp6->tcp6ConnEntryInfo.ce_rnxt,
4943 5087                      tp6->tcp6ConnEntryInfo.ce_rack,
4944 5088                      tp6->tcp6ConnEntryInfo.ce_rto,
4945 5089                      tp6->tcp6ConnEntryInfo.ce_mss,
4946 5090                      mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
4947 5091                      ifnamep);
4948      -        } else {
     5092 +        } else if ((!Uflag) && (!Vflag)) {
4949 5093                  int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt -
4950 5094                      (int)tp6->tcp6ConnEntryInfo.ce_suna - 1;
4951 5095                  int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt -
4952 5096                      (int)tp6->tcp6ConnEntryInfo.ce_rack;
4953 5097  
4954 5098                  (void) printf("%-33s %-33s %5u %6d %5u %6d %-11s %s\n",
4955 5099                      pr_ap6(&tp6->tcp6ConnLocalAddress,
4956 5100                      tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
4957 5101                      pr_ap6(&tp6->tcp6ConnRemAddress,
4958 5102                      tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
4959 5103                      tp6->tcp6ConnEntryInfo.ce_swnd,
4960 5104                      (sq >= 0) ? sq : 0,
4961 5105                      tp6->tcp6ConnEntryInfo.ce_rwnd,
4962 5106                      (rq >= 0) ? rq : 0,
4963 5107                      mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
4964 5108                      ifnamep);
     5109 +        } else if (Uflag && Vflag) {
     5110 +                int i = 0;
     5111 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5112 +                proc_info_t *pinfo;
     5113 +
     5114 +                do {
     5115 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5116 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5117 +
     5118 +                        (void) printf("%-33s\n%-33s %7u %08x %08x %7u %08x %08x "
     5119 +                            "%5u %5u %-11s %-5.5s %-8.8s %6u %s\n",
     5120 +                            pr_ap6(&tp6->tcp6ConnLocalAddress,
     5121 +                            tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
     5122 +                            pr_ap6(&tp6->tcp6ConnRemAddress,
     5123 +                            tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
     5124 +                            tp6->tcp6ConnEntryInfo.ce_swnd,
     5125 +                            tp6->tcp6ConnEntryInfo.ce_snxt,
     5126 +                            tp6->tcp6ConnEntryInfo.ce_suna,
     5127 +                            tp6->tcp6ConnEntryInfo.ce_rwnd,
     5128 +                            tp6->tcp6ConnEntryInfo.ce_rnxt,
     5129 +                            tp6->tcp6ConnEntryInfo.ce_rack,
     5130 +                            tp6->tcp6ConnEntryInfo.ce_rto,
     5131 +                            tp6->tcp6ConnEntryInfo.ce_mss,
     5132 +                            mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
     5133 +                            ifnamep, pinfo->pr_user, pid, pinfo->pr_psargs);
     5134 +                        i++; cpn++;
     5135 +                } while (i < cph->cph_pn_cnt);
     5136 +        } else if (Uflag && (!Vflag)) {
     5137 +                int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt -
     5138 +                    (int)tp6->tcp6ConnEntryInfo.ce_suna - 1;
     5139 +                int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt -
     5140 +                    (int)tp6->tcp6ConnEntryInfo.ce_rack;
     5141 +                int i = 0;
     5142 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5143 +                proc_info_t *pinfo;
     5144 +
     5145 +                do {
     5146 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5147 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5148 +
     5149 +                        (void) printf("%-33s %-33s %-8.8s %6u %-14.14s %7d %6u %7d %6d %-11s %s\n",
     5150 +                            pr_ap6(&tp6->tcp6ConnLocalAddress,
     5151 +                            tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
     5152 +                            pr_ap6(&tp6->tcp6ConnRemAddress,
     5153 +                            tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
     5154 +                            pinfo->pr_user, pid, pinfo->pr_fname,
     5155 +                            tp6->tcp6ConnEntryInfo.ce_swnd,
     5156 +                            (sq >= 0) ? sq : 0,
     5157 +                            tp6->tcp6ConnEntryInfo.ce_rwnd,
     5158 +                            (rq >= 0) ? rq : 0,
     5159 +                            mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
     5160 +                            ifnamep);
     5161 +
     5162 +                        i++; cpn++;
     5163 +                } while (i < cph->cph_pn_cnt);
4965 5164          }
4966 5165  
4967 5166          print_transport_label(attr);
4968 5167  
4969 5168          return (B_FALSE);
4970 5169  }
4971 5170  
4972 5171  /* ------------------------------- UDP_REPORT------------------------------- */
4973 5172  
4974 5173  static boolean_t udp_report_item_v4(const mib2_udpEntry_t *ude,
4975      -    boolean_t first, const mib2_transportMLPEntry_t *attr);
     5174 +    conn_pid_node_list_hdr_t *cph, boolean_t first,
     5175 +    const mib2_transportMLPEntry_t *attr);
4976 5176  static boolean_t udp_report_item_v6(const mib2_udp6Entry_t *ude6,
4977      -    boolean_t first, const mib2_transportMLPEntry_t *attr);
     5177 +    conn_pid_node_list_hdr_t *cph, boolean_t first,
     5178 +    const mib2_transportMLPEntry_t *attr);
4978 5179  
4979 5180  static const char udp_hdr_v4[] =
4980 5181  "   Local Address        Remote Address      State\n"
4981 5182  "-------------------- -------------------- ----------\n";
     5183 +static const char udp_hdr_v4_pid[] =
     5184 +"   Local Address        Remote Address      User    Pid   "
     5185 +"   Command       State\n"
     5186 +"-------------------- -------------------- -------- ------ "
     5187 +"-------------- ----------\n";
     5188 +static const char udp_hdr_v4_pid_verbose[] =
     5189 +"   Local Address        Remote Address      User    Pid     State    "
     5190 +"   Command\n"
     5191 +"-------------------- -------------------- -------- ------ ---------- "
     5192 +"----------------\n";
4982 5193  
4983 5194  static const char udp_hdr_v6[] =
4984 5195  "   Local Address                     Remote Address                 "
4985 5196  "  State      If\n"
4986 5197  "--------------------------------- --------------------------------- "
4987 5198  "---------- -----\n";
     5199 +static const char udp_hdr_v6_pid[] =
     5200 +"   Local Address                     Remote Address                 "
     5201 +"  User    Pid      Command       State      If\n"
     5202 +"--------------------------------- --------------------------------- "
     5203 +"-------- ------ -------------- ---------- -----\n";
     5204 +static const char udp_hdr_v6_pid_verbose[] =
     5205 +"   Local Address                     Remote Address                 "
     5206 +"  User    Pid     State      If     Command\n"
     5207 +"--------------------------------- --------------------------------- "
     5208 +"-------- ------ ---------- ----- ----------------\n";
     5209 +
4988 5210  
4989 5211  static void
4990 5212  udp_report(const mib_item_t *item)
4991 5213  {
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;
     5214 +        int                             jtemp = 0;
     5215 +        boolean_t                       print_hdr_once_v4 = B_TRUE;
     5216 +        boolean_t                       print_hdr_once_v6 = B_TRUE;
     5217 +        mib2_udpEntry_t                 *ude;
     5218 +        mib2_udp6Entry_t                *ude6;
     5219 +        mib2_transportMLPEntry_t        **v4_attrs, **v6_attrs;
     5220 +        mib2_transportMLPEntry_t        **v4a, **v6a;
     5221 +        mib2_transportMLPEntry_t        *aptr;
     5222 +        conn_pid_node_list_hdr_t        *cph;
5000 5223  
5001 5224          if (!protocol_selected(IPPROTO_UDP))
5002 5225                  return;
5003 5226  
5004 5227          /*
5005 5228           * Preparation pass: the kernel returns separate entries for UDP
5006 5229           * connection table entries and Multilevel Port attributes.  We loop
5007 5230           * through the attributes first and set up an array for each address
5008 5231           * family.
5009 5232           */
↓ open down ↓ 10 lines elided ↑ open up ↑
5020 5243                  if (Xflag) {
5021 5244                          (void) printf("\n--- Entry %d ---\n", ++jtemp);
5022 5245                          (void) printf("Group = %d, mib_id = %d, "
5023 5246                              "length = %d, valp = 0x%p\n",
5024 5247                              item->group, item->mib_id,
5025 5248                              item->length, item->valp);
5026 5249                  }
5027 5250                  if (!((item->group == MIB2_UDP &&
5028 5251                      item->mib_id == MIB2_UDP_ENTRY) ||
5029 5252                      (item->group == MIB2_UDP6 &&
5030      -                    item->mib_id == MIB2_UDP6_ENTRY)))
     5253 +                    item->mib_id == MIB2_UDP6_ENTRY) ||
     5254 +                    (item->group == MIB2_UDP &&
     5255 +                    item->mib_id == EXPER_XPORT_PROC_INFO) ||
     5256 +                    (item->group == MIB2_UDP6 &&
     5257 +                    item->mib_id == EXPER_XPORT_PROC_INFO)))
5031 5258                          continue; /* 'for' loop 1 */
5032 5259  
5033 5260                  if (item->group == MIB2_UDP && !family_selected(AF_INET))
5034 5261                          continue; /* 'for' loop 1 */
5035 5262                  else if (item->group == MIB2_UDP6 && !family_selected(AF_INET6))
5036 5263                          continue; /* 'for' loop 1 */
5037 5264  
5038 5265                  /*      xxx.xxx.xxx.xxx,pppp  sss... */
5039      -                if (item->group == MIB2_UDP) {
     5266 +                if ((!Uflag) && item->group == MIB2_UDP &&
     5267 +                    item->mib_id == MIB2_UDP_ENTRY) {
5040 5268                          for (ude = (mib2_udpEntry_t *)item->valp;
5041 5269                              (char *)ude < (char *)item->valp + item->length;
5042 5270                              /* LINTED: (note 1) */
5043 5271                              ude = (mib2_udpEntry_t *)((char *)ude +
5044 5272                              udpEntrySize)) {
5045 5273                                  aptr = v4a == NULL ? NULL : *v4a++;
5046 5274                                  print_hdr_once_v4 = udp_report_item_v4(ude,
5047      -                                    print_hdr_once_v4, aptr);
     5275 +                                    NULL, print_hdr_once_v4, aptr);
5048 5276                          }
5049      -                } else {
     5277 +                } else if ((!Uflag) && item->group == MIB2_UDP6 &&
     5278 +                     item->mib_id == MIB2_UDP6_ENTRY) {
5050 5279                          for (ude6 = (mib2_udp6Entry_t *)item->valp;
5051 5280                              (char *)ude6 < (char *)item->valp + item->length;
5052 5281                              /* LINTED: (note 1) */
5053 5282                              ude6 = (mib2_udp6Entry_t *)((char *)ude6 +
5054 5283                              udp6EntrySize)) {
5055 5284                                  aptr = v6a == NULL ? NULL : *v6a++;
5056 5285                                  print_hdr_once_v6 = udp_report_item_v6(ude6,
5057      -                                    print_hdr_once_v6, aptr);
     5286 +                                    NULL, print_hdr_once_v6, aptr);
     5287 +                        }
     5288 +                } else if ((Uflag) && item->group == MIB2_UDP &&
     5289 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5290 +                        for (ude = (mib2_udpEntry_t *)item->valp;
     5291 +                            (char *)ude < (char *)item->valp + item->length;
     5292 +                            /* LINTED: (note 1) */
     5293 +                            ude = (mib2_udpEntry_t *)((char *)cph +
     5294 +                            cph->cph_tot_size)) {
     5295 +                                aptr = v4a == NULL ? NULL : *v4a++;
     5296 +                                /* LINTED: (note 1) */
     5297 +                                cph = (conn_pid_node_list_hdr_t *)
     5298 +                                        ((char *)ude + udpEntrySize);
     5299 +                                print_hdr_once_v4 = udp_report_item_v4(ude,
     5300 +                                    cph, print_hdr_once_v4, aptr);
     5301 +                        }
     5302 +                } else if ((Uflag) && item->group == MIB2_UDP6 &&
     5303 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5304 +                        for (ude6 = (mib2_udp6Entry_t *)item->valp;
     5305 +                            (char *)ude6 < (char *)item->valp + item->length;
     5306 +                            /* LINTED: (note 1) */
     5307 +                            ude6 = (mib2_udp6Entry_t *)((char *)cph +
     5308 +                            cph->cph_tot_size)) {
     5309 +                                aptr = v6a == NULL ? NULL : *v6a++;
     5310 +                                /* LINTED: (note 1) */
     5311 +                                cph = (conn_pid_node_list_hdr_t *)
     5312 +                                        ((char *)ude6 + udp6EntrySize);
     5313 +                                print_hdr_once_v6 = udp_report_item_v6(ude6,
     5314 +                                    cph, print_hdr_once_v6, aptr);
5058 5315                          }
5059 5316                  }
5060 5317          } /* 'for' loop 1 ends */
5061 5318          (void) fflush(stdout);
5062 5319  
5063 5320          if (v4_attrs != NULL)
5064 5321                  free(v4_attrs);
5065 5322          if (v6_attrs != NULL)
5066 5323                  free(v6_attrs);
5067 5324  }
5068 5325  
5069 5326  static boolean_t
5070      -udp_report_item_v4(const mib2_udpEntry_t *ude, boolean_t first,
5071      -    const mib2_transportMLPEntry_t *attr)
     5327 +udp_report_item_v4(const mib2_udpEntry_t *ude, conn_pid_node_list_hdr_t *cph,
     5328 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
5072 5329  {
5073 5330          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5074 5331                          /* hostname + portname */
5075 5332  
5076 5333          if (!(Aflag || ude->udpEntryInfo.ue_state >= MIB2_UDP_connected))
5077 5334                  return (first); /* Nothing to print */
5078 5335  
5079 5336          if (first) {
5080 5337                  (void) printf(v4compat ? "\nUDP\n" : "\nUDP: IPv4\n");
5081      -                (void) printf(udp_hdr_v4);
     5338 +
     5339 +                if (Uflag)
     5340 +                        (void) printf(Vflag ? udp_hdr_v4_pid_verbose :
     5341 +                                udp_hdr_v4_pid);
     5342 +                else
     5343 +                        (void) printf(udp_hdr_v4);
     5344 +
5082 5345                  first = B_FALSE;
5083 5346          }
5084 5347  
5085      -        (void) printf("%-20s ",
     5348 +        (void) printf("%-20s %-20s ",
5086 5349              pr_ap(ude->udpLocalAddress, ude->udpLocalPort, "udp",
5087      -            lname, sizeof (lname)));
5088      -        (void) printf("%-20s %s\n",
     5350 +            lname, sizeof (lname)),
5089 5351              ude->udpEntryInfo.ue_state == MIB2_UDP_connected ?
5090 5352              pr_ap(ude->udpEntryInfo.ue_RemoteAddress,
5091 5353              ude->udpEntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
5092      -            "",
5093      -            miudp_state(ude->udpEntryInfo.ue_state, attr));
     5354 +            "");
     5355 +        if (!Uflag) {
     5356 +                (void) printf("%s\n",
     5357 +                    miudp_state(ude->udpEntryInfo.ue_state, attr));
     5358 +        } else {
     5359 +                int i = 0;
     5360 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5361 +                proc_info_t *pinfo;
     5362 +
     5363 +                do {
     5364 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5365 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5366 +                        (void) printf("%-8.8s %6u ", pinfo->pr_user, pid);
     5367 +
     5368 +                        if (Vflag) {
     5369 +                                (void) printf("%-10.10s %s\n",
     5370 +                                    miudp_state(ude->udpEntryInfo.ue_state,
     5371 +                                    attr),
     5372 +                                    pinfo->pr_psargs);
     5373 +                        } else {
     5374 +                                (void) printf("%-14.14s %s\n", pinfo->pr_fname,
     5375 +                                  miudp_state(ude->udpEntryInfo.ue_state,
     5376 +                                  attr));
     5377 +                        }
     5378 +                        i++; cpn++;
     5379 +                } while (i < cph->cph_pn_cnt);
     5380 +        }
5094 5381  
5095 5382          print_transport_label(attr);
5096 5383  
5097 5384          return (first);
5098 5385  }
5099 5386  
5100 5387  static boolean_t
5101      -udp_report_item_v6(const mib2_udp6Entry_t *ude6, boolean_t first,
5102      -    const mib2_transportMLPEntry_t *attr)
     5388 +udp_report_item_v6(const mib2_udp6Entry_t *ude6, conn_pid_node_list_hdr_t *cph,
     5389 +    boolean_t first, const mib2_transportMLPEntry_t *attr)
5103 5390  {
5104 5391          char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5105 5392                          /* hostname + portname */
5106 5393          char    ifname[LIFNAMSIZ + 1];
5107 5394          const char *ifnamep;
5108 5395  
5109 5396          if (!(Aflag || ude6->udp6EntryInfo.ue_state >= MIB2_UDP_connected))
5110 5397                  return (first); /* Nothing to print */
5111 5398  
5112 5399          if (first) {
5113 5400                  (void) printf("\nUDP: IPv6\n");
5114      -                (void) printf(udp_hdr_v6);
     5401 +
     5402 +                if (Uflag)
     5403 +                        (void) printf(Vflag ? udp_hdr_v6_pid_verbose :
     5404 +                                udp_hdr_v6_pid);
     5405 +                else
     5406 +                        (void) printf(udp_hdr_v6);
     5407 +
5115 5408                  first = B_FALSE;
5116 5409          }
5117 5410  
5118 5411          ifnamep = (ude6->udp6IfIndex != 0) ?
5119 5412              if_indextoname(ude6->udp6IfIndex, ifname) : NULL;
5120 5413  
5121      -        (void) printf("%-33s ",
     5414 +        (void) printf("%-33s %-33s ",
5122 5415              pr_ap6(&ude6->udp6LocalAddress,
5123      -            ude6->udp6LocalPort, "udp", lname, sizeof (lname)));
5124      -        (void) printf("%-33s %-10s %s\n",
     5416 +            ude6->udp6LocalPort, "udp", lname, sizeof (lname)),
5125 5417              ude6->udp6EntryInfo.ue_state == MIB2_UDP_connected ?
5126 5418              pr_ap6(&ude6->udp6EntryInfo.ue_RemoteAddress,
5127 5419              ude6->udp6EntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
5128      -            "",
5129      -            miudp_state(ude6->udp6EntryInfo.ue_state, attr),
5130      -            ifnamep == NULL ? "" : ifnamep);
     5420 +            "");
     5421 +        if (!Uflag) {
     5422 +                (void) printf("%-10s %s\n",
     5423 +                    miudp_state(ude6->udp6EntryInfo.ue_state, attr),
     5424 +                    ifnamep == NULL ? "" : ifnamep);
     5425 +        } else {
     5426 +                int i = 0;
     5427 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5428 +                proc_info_t *pinfo;
     5429 +
     5430 +                do {
     5431 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5432 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5433 +                        (void) printf("%-8.8s %6u ", pinfo->pr_user, pid);
     5434 +
     5435 +                        if (Vflag) {
     5436 +                                (void) printf("%-10.10s %-5.5s %s\n",
     5437 +                                    miudp_state(ude6->udp6EntryInfo.ue_state,
     5438 +                                    attr),
     5439 +                                    ifnamep == NULL ? "" : ifnamep,
     5440 +                                    pinfo->pr_psargs);
     5441 +                        } else {
     5442 +                                (void) printf("%-14.14s %-10.10s %s\n",
     5443 +                                    pinfo->pr_fname,
     5444 +                                    miudp_state(ude6->udp6EntryInfo.ue_state,
     5445 +                                    attr),
     5446 +                                    ifnamep == NULL ? "" : ifnamep);
     5447 +                        }
     5448 +                        i++; cpn++;
     5449 +                } while (i < cph->cph_pn_cnt);
     5450 +        }
5131 5451  
5132 5452          print_transport_label(attr);
5133 5453  
5134 5454          return (first);
5135 5455  }
5136 5456  
5137 5457  /* ------------------------------ SCTP_REPORT------------------------------- */
5138 5458  
5139 5459  static const char sctp_hdr[] =
5140 5460  "\nSCTP:";
5141 5461  static const char sctp_hdr_normal[] =
5142 5462  "        Local Address                   Remote Address          "
5143 5463  "Swind  Send-Q Rwind  Recv-Q StrsI/O  State\n"
5144 5464  "------------------------------- ------------------------------- "
5145 5465  "------ ------ ------ ------ ------- -----------";
     5466 +static const char sctp_hdr_pid[] =
     5467 +"        Local Address                   Remote Address          "
     5468 +"Swind  Send-Q Rwind  Recv-Q StrsI/O   User    Pid      Command      State\n"
     5469 +"------------------------------- ------------------------------- ------ "
     5470 +"------ ------ ------ ------- -------- ------ -------------- -----------";
     5471 +static const char sctp_hdr_pid_verbose[] =
     5472 +"        Local Address                   Remote Address          "
     5473 +"Swind  Send-Q Rwind  Recv-Q StrsI/O   User    Pid    State         Command\n"
     5474 +"------------------------------- ------------------------------- ------ "
     5475 +"------ ------ ------ ------- -------- ------ ----------- --------------";
5146 5476  
5147 5477  static const char *
5148 5478  nssctp_state(int state, const mib2_transportMLPEntry_t *attr)
5149 5479  {
5150 5480          static char sctpsbuf[50];
5151 5481          const char *cp;
5152 5482  
5153 5483          switch (state) {
5154 5484          case MIB2_SCTP_closed:
5155 5485                  cp = "CLOSED";
↓ open down ↓ 146 lines elided ↑ open up ↑
5302 5632                          (void) pr_addr6(addr, name, namelen);
5303 5633                  }
5304 5634                  break;
5305 5635  
5306 5636          default:
5307 5637                  (void) snprintf(name, namelen, "<unknown addr type>");
5308 5638                  break;
5309 5639          }
5310 5640  }
5311 5641  
5312      -static void
5313      -sctp_conn_report_item(const mib_item_t *head, const mib2_sctpConnEntry_t *sp,
     5642 +static boolean_t
     5643 +sctp_conn_report_item(const mib_item_t *head, conn_pid_node_list_hdr_t * cph,
     5644 +    boolean_t print_sctp_hdr, const mib2_sctpConnEntry_t *sp,
5314 5645      const mib2_transportMLPEntry_t *attr)
5315 5646  {
5316 5647          char            lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5317 5648          char            fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
5318 5649          const mib2_sctpConnRemoteEntry_t        *sre = NULL;
5319 5650          const mib2_sctpConnLocalEntry_t *sle = NULL;
5320 5651          const mib_item_t *local = head;
5321 5652          const mib_item_t *remote = head;
5322 5653          uint32_t        id = sp->sctpAssocId;
5323 5654          boolean_t       printfirst = B_TRUE;
5324 5655  
     5656 +        if (print_sctp_hdr == B_TRUE) {
     5657 +                (void) puts(sctp_hdr);
     5658 +                if (Uflag)
     5659 +                        (void) puts(Vflag? sctp_hdr_pid_verbose: sctp_hdr_pid);
     5660 +                else
     5661 +                        (void) puts(sctp_hdr_normal);
     5662 +
     5663 +                print_sctp_hdr = B_FALSE;
     5664 +        }
     5665 +
5325 5666          sctp_pr_addr(sp->sctpAssocRemPrimAddrType, fname, sizeof (fname),
5326 5667              &sp->sctpAssocRemPrimAddr, sp->sctpAssocRemPort);
5327 5668          sctp_pr_addr(sp->sctpAssocRemPrimAddrType, lname, sizeof (lname),
5328 5669              &sp->sctpAssocLocPrimAddr, sp->sctpAssocLocalPort);
5329 5670  
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));
     5671 +        if (Uflag) {
     5672 +                int i = 0;
     5673 +                conn_pid_node_t *cpn = cph->cph_cpns;
     5674 +                proc_info_t *pinfo;
     5675 +
     5676 +                do {
     5677 +                        int pid = (cph->cph_pn_cnt)?cpn->cpn_pid:0;
     5678 +                        pinfo = get_proc_info(cpn->cpn_pid);
     5679 +                        (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %-8.8s %6u ",
     5680 +                            lname, fname,
     5681 +                            sp->sctpConnEntryInfo.ce_swnd,
     5682 +                            sp->sctpConnEntryInfo.ce_sendq,
     5683 +                            sp->sctpConnEntryInfo.ce_rwnd,
     5684 +                            sp->sctpConnEntryInfo.ce_recvq,
     5685 +                            sp->sctpAssocInStreams,
     5686 +                            sp->sctpAssocOutStreams,
     5687 +                            pinfo->pr_user, pid);
     5688 +
     5689 +                        if (Vflag) {
     5690 +                                (void) printf("%-11.11s %s\n",
     5691 +                                    nssctp_state(sp->sctpAssocState, attr),
     5692 +                                    pinfo->pr_psargs);
     5693 +                        } else {
     5694 +                                (void) printf("%-14.14s %s\n",
     5695 +                                    pinfo->pr_fname,
     5696 +                                    nssctp_state(sp->sctpAssocState, attr));
     5697 +                        }
     5698 +
     5699 +                        i++; cpn++;
     5700 +                } while (i < cph->cph_pn_cnt);
     5701 +
     5702 +        } else {
     5703 +
     5704 +                (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n",
     5705 +                    lname, fname,
     5706 +                    sp->sctpConnEntryInfo.ce_swnd,
     5707 +                    sp->sctpConnEntryInfo.ce_sendq,
     5708 +                    sp->sctpConnEntryInfo.ce_rwnd,
     5709 +                    sp->sctpConnEntryInfo.ce_recvq,
     5710 +                    sp->sctpAssocInStreams, sp->sctpAssocOutStreams,
     5711 +                    nssctp_state(sp->sctpAssocState, attr));
     5712 +        }
5338 5713  
5339 5714          print_transport_label(attr);
5340 5715  
5341 5716          if (!Vflag) {
5342      -                return;
     5717 +                return (print_sctp_hdr);
5343 5718          }
5344 5719  
5345 5720          /* Print remote addresses/local addresses on following lines */
5346 5721          while ((sre = sctp_getnext_rem(&remote, sre, id)) != NULL) {
5347 5722                  if (!IN6_ARE_ADDR_EQUAL(&sre->sctpAssocRemAddr,
5348 5723                      &sp->sctpAssocRemPrimAddr)) {
5349 5724                          if (printfirst == B_TRUE) {
5350 5725                                  (void) fputs("\t<Remote: ", stdout);
5351 5726                                  printfirst = B_FALSE;
5352 5727                          } else {
↓ open down ↓ 22 lines elided ↑ open up ↑
5375 5750                                  (void) fputs(", ", stdout);
5376 5751                          }
5377 5752                          sctp_pr_addr(sle->sctpAssocLocalAddrType, lname,
5378 5753                              sizeof (lname), &sle->sctpAssocLocalAddr, -1);
5379 5754                          (void) fputs(lname, stdout);
5380 5755                  }
5381 5756          }
5382 5757          if (printfirst == B_FALSE) {
5383 5758                  (void) puts(">");
5384 5759          }
     5760 +
     5761 +        return (print_sctp_hdr);
5385 5762  }
5386 5763  
5387 5764  static void
5388 5765  sctp_report(const mib_item_t *item)
5389 5766  {
5390 5767          const mib_item_t                *head;
5391 5768          const mib2_sctpConnEntry_t      *sp;
5392      -        boolean_t               first = B_TRUE;
5393      -        mib2_transportMLPEntry_t **attrs, **aptr;
5394      -        mib2_transportMLPEntry_t *attr;
     5769 +        boolean_t                       print_sctp_hdr_once = B_TRUE;
     5770 +        mib2_transportMLPEntry_t        **attrs, **aptr;
     5771 +        mib2_transportMLPEntry_t        *attr;
     5772 +        conn_pid_node_list_hdr_t        *cph;
5395 5773  
5396 5774          /*
5397 5775           * Preparation pass: the kernel returns separate entries for SCTP
5398 5776           * connection table entries and Multilevel Port attributes.  We loop
5399 5777           * through the attributes first and set up an array for each address
5400 5778           * family.
5401 5779           */
5402 5780          attrs = RSECflag ?
5403 5781              gather_attrs(item, MIB2_SCTP, MIB2_SCTP_CONN, sctpEntrySize) :
5404 5782              NULL;
5405 5783  
5406 5784          aptr = attrs;
5407 5785          head = item;
5408 5786          for (; item != NULL; item = item->next_item) {
5409 5787  
5410      -                if (!(item->group == MIB2_SCTP &&
5411      -                    item->mib_id == MIB2_SCTP_CONN))
     5788 +                if (!((item->group == MIB2_SCTP &&
     5789 +                    item->mib_id == MIB2_SCTP_CONN) ||
     5790 +                    (item->group == MIB2_SCTP &&
     5791 +                    item->mib_id == EXPER_XPORT_PROC_INFO)))
5412 5792                          continue;
5413 5793  
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);
     5794 +                if ((!Uflag) && item->group == MIB2_SCTP
     5795 +                    && item->mib_id == MIB2_SCTP_CONN) {
     5796 +                        for (sp = item->valp;
     5797 +                            (char *)sp < (char *)item->valp + item->length;
     5798 +                            /* LINTED: (note 1) */
     5799 +                            sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
     5800 +                                if (!(Aflag ||
     5801 +                                  sp->sctpAssocState >= MIB2_SCTP_established))
     5802 +                                        continue;
     5803 +                                attr = aptr == NULL ? NULL : *aptr++;
     5804 +                                print_sctp_hdr_once = sctp_conn_report_item(head, NULL,
     5805 +                                                        print_sctp_hdr_once, sp,
     5806 +                                                        attr);
     5807 +                        }
     5808 +                } else if ((Uflag) && item->group == MIB2_SCTP &&
     5809 +                    item->mib_id == EXPER_XPORT_PROC_INFO) {
     5810 +                        for (sp = (mib2_sctpConnEntry_t *)item->valp;
     5811 +                            (char *)sp < (char *)item->valp + item->length;
     5812 +                            /* LINTED: (note 1) */
     5813 +                            sp = (mib2_sctpConnEntry_t *)((char *)cph +
     5814 +                            cph->cph_tot_size)) {
     5815 +                                /* LINTED: (note 1) */
     5816 +                                cph = (conn_pid_node_list_hdr_t *)
     5817 +                                        ((char *)sp + sctpEntrySize);
     5818 +                                if (!(Aflag ||
     5819 +                                  sp->sctpAssocState >= MIB2_SCTP_established))
     5820 +                                        continue;
     5821 +                                attr = aptr == NULL ? NULL : *aptr++;
     5822 +                                print_sctp_hdr_once =
     5823 +                                    sctp_conn_report_item(head, cph,
     5824 +                                        print_sctp_hdr_once, sp, attr);
5427 5825                          }
5428 5826                  }
5429 5827          }
5430 5828          if (attrs != NULL)
5431 5829                  free(attrs);
5432 5830  }
5433 5831  
5434 5832  static char *
5435 5833  plural(int n)
5436 5834  {
↓ open down ↓ 967 lines elided ↑ open up ↑
6404 6802  static char *
6405 6803  ifindex2str(uint_t ifindex, char *ifname)
6406 6804  {
6407 6805          if (if_indextoname(ifindex, ifname) == NULL)
6408 6806                  (void) snprintf(ifname, LIFNAMSIZ, "if#%d", ifindex);
6409 6807  
6410 6808          return (ifname);
6411 6809  }
6412 6810  
6413 6811  /*
     6812 + * get proc info (psinfo_t) given pid. It doesn't return NULL.
     6813 + */
     6814 +
     6815 +proc_info_t *
     6816 +get_proc_info(uint32_t pid)
     6817 +{
     6818 +        static uint32_t saved_pid = 0;
     6819 +        static proc_info_t saved_proc_info;
     6820 +        static proc_info_t unknown_proc_info = {"<unknown>","",""};
     6821 +        static psinfo_t pinfo;
     6822 +        char path[128];
     6823 +        int fd;
     6824 +
     6825 +        /* hardcode pid = 0 */
     6826 +        if (pid == 0) {
     6827 +                saved_proc_info.pr_user = "root";
     6828 +                saved_proc_info.pr_fname = "sched";
     6829 +                saved_proc_info.pr_psargs = "sched";
     6830 +                saved_pid = 0;
     6831 +                return &saved_proc_info;
     6832 +        }
     6833 +
     6834 +        if (pid == saved_pid)
     6835 +                return &saved_proc_info;
     6836 +        if ((snprintf(path, 128, "/proc/%u/psinfo",pid) > 0) &&
     6837 +            ((fd = open(path, O_RDONLY)) != -1)) {
     6838 +                if (read(fd, &pinfo, sizeof(pinfo)) == sizeof(pinfo)){
     6839 +                        saved_proc_info.pr_user = get_username(pinfo.pr_uid);
     6840 +                        saved_proc_info.pr_fname = pinfo.pr_fname;
     6841 +                        saved_proc_info.pr_psargs = pinfo.pr_psargs;
     6842 +                        saved_pid = pid;
     6843 +                        (void) close(fd);
     6844 +                        return &saved_proc_info;
     6845 +                } else {
     6846 +                        (void) close(fd);
     6847 +                }
     6848 +        }
     6849 +
     6850 +        return (&unknown_proc_info);
     6851 +}
     6852 +
     6853 +/*
     6854 + * get username given uid. It doesn't return NULL.
     6855 + */
     6856 +
     6857 +static char *
     6858 +get_username(uid_t u)
     6859 +{
     6860 +        static uid_t saved_uid = UINT_MAX;
     6861 +        static char  saved_username[128];
     6862 +        struct passwd *pw = NULL;
     6863 +        if (u == UINT_MAX)
     6864 +                return "<unknown>";
     6865 +        if (u == saved_uid && saved_username[0] != '\0')
     6866 +                return  (saved_username);
     6867 +        setpwent();
     6868 +        if ((pw = getpwuid(u)) != NULL)
     6869 +                (void) strlcpy(saved_username, pw->pw_name, 128);
     6870 +        else
     6871 +                (void) snprintf(saved_username, 128, "%u", u);
     6872 +        saved_uid = u;
     6873 +        return saved_username;
     6874 +}
     6875 +
     6876 +/*
6414 6877   * print the usage line
6415 6878   */
6416 6879  static void
6417 6880  usage(char *cmdname)
6418 6881  {
6419      -        (void) fprintf(stderr, "usage: %s [-anv] [-f address_family] "
     6882 +        (void) fprintf(stderr, "usage: %s [-anuv] [-f address_family] "
6420 6883              "[-T d|u]\n", cmdname);
6421 6884          (void) fprintf(stderr, "       %s [-n] [-f address_family] "
6422 6885              "[-P protocol] [-T d|u] [-g | -p | -s [interval [count]]]\n",
6423 6886              cmdname);
6424 6887          (void) fprintf(stderr, "       %s -m [-v] [-T d|u] "
6425 6888              "[interval [count]]\n", cmdname);
6426 6889          (void) fprintf(stderr, "       %s -i [-I interface] [-an] "
6427 6890              "[-f address_family] [-T d|u] [interval [count]]\n", cmdname);
6428 6891          (void) fprintf(stderr, "       %s -r [-anv] "
6429 6892              "[-f address_family|filter] [-T d|u]\n", cmdname);
↓ open down ↓ 15 lines elided ↑ open up ↑
6445 6908          va_list argp;
6446 6909  
6447 6910          if (format == NULL)
6448 6911                  return;
6449 6912  
6450 6913          va_start(argp, format);
6451 6914          (void) vfprintf(stderr, format, argp);
6452 6915          va_end(argp);
6453 6916  
6454 6917          exit(errcode);
     6918 +}
     6919 +
     6920 +
     6921 +/* -------------------UNIX Domain Sockets Report---------------------------- */
     6922 +
     6923 +
     6924 +#define NO_ADDR         "                                       "
     6925 +#define SO_PAIR         " (socketpair)                          "
     6926 +
     6927 +static char             *typetoname(t_scalar_t);
     6928 +static boolean_t        uds_report_item(struct sockinfo *, boolean_t);
     6929 +
     6930 +
     6931 +static char uds_hdr[] = "\nActive UNIX domain sockets\n";
     6932 +
     6933 +static char uds_hdr_normal[] =
     6934 +" Type       Local Adress                           "
     6935 +" Remote Address\n"
     6936 +"---------- --------------------------------------- "
     6937 +"---------------------------------------\n";
     6938 +
     6939 +static char uds_hdr_pid[] =
     6940 +" Type       User     Pid     Command       "
     6941 +" Local Address                         "
     6942 +" Remote Address\n"
     6943 +"---------- -------- ------ -------------- "
     6944 +"--------------------------------------- "
     6945 +"---------------------------------------\n";
     6946 +static char uds_hdr_pid_verbose[] =
     6947 +" Type       User     Pid    Local Address                          "
     6948 +" Remote Address                          Command\n"
     6949 +"---------- -------- ------ --------------------------------------- "
     6950 +"--------------------------------------- --------------\n";
     6951 +
     6952 +/*
     6953 + * Print a summary of connections related to a unix protocol.
     6954 + */
     6955 +static void
     6956 +uds_report(kstat_ctl_t  *kc)
     6957 +{
     6958 +        int             i;
     6959 +        kstat_t         *ksp;
     6960 +        struct sockinfo *psi;           /* ptr to current sockinfo      */
     6961 +        boolean_t       print_uds_hdr_once = B_TRUE;
     6962 +
     6963 +        if (kc == NULL) {       /* sanity check.                        */
     6964 +                fail(0, "uds_report: No kstat");
     6965 +                exit(3);
     6966 +        }
     6967 +
     6968 +        /* find the sockfs kstat:                                       */
     6969 +        if ((ksp = kstat_lookup(kc, "sockfs", 0, "sock_unix_list")) ==
     6970 +            (kstat_t *)NULL) {
     6971 +                fail(0, "kstat_data_lookup failed\n");
     6972 +        }
     6973 +
     6974 +        if (kstat_read(kc, ksp, NULL) == -1) {
     6975 +                fail(0, "kstat_read failed for sock_unix_list\n");
     6976 +        }
     6977 +
     6978 +        if (ksp->ks_ndata == 0) {
     6979 +                return;                 /* no AF_UNIX sockets found     */
     6980 +        }
     6981 +
     6982 +        /*
     6983 +         * Having ks_data set with ks_data == NULL shouldn't happen;
     6984 +         * If it does, the sockfs kstat is seriously broken.
     6985 +         */
     6986 +        if ((psi = ksp->ks_data) == NULL) {
     6987 +                fail(0, "uds_report: no kstat data\n");
     6988 +        }
     6989 +
     6990 +        /* for each sockinfo structure, display what we need:           */
     6991 +        for (i = 0; i < ksp->ks_ndata; i++) {
     6992 +
     6993 +                /* process this entry */
     6994 +                print_uds_hdr_once = uds_report_item(psi, print_uds_hdr_once);
     6995 +
     6996 +                /* if si_size didn't get filled in, then we're done     */
     6997 +                if (psi->si_size == 0 ||
     6998 +                    !IS_P2ALIGNED(psi->si_size, sizeof (psi))) {
     6999 +                        break;
     7000 +                }
     7001 +
     7002 +                /* point to the next sockinfo in the array */
     7003 +                /* LINTED: (note 1) */
     7004 +                psi = (struct sockinfo *)(((char *)psi) + psi->si_size);
     7005 +        }
     7006 +}
     7007 +
     7008 +static boolean_t
     7009 +uds_report_item(struct sockinfo *psi, boolean_t first)
     7010 +{
     7011 +        int             i = 0;
     7012 +        conn_pid_node_t *cpn;
     7013 +        proc_info_t     *pinfo;
     7014 +        char            *laddr, *raddr;
     7015 +
     7016 +        if(first) {
     7017 +                (void) printf("%s", uds_hdr);
     7018 +                if (Uflag)
     7019 +                        (void) printf("%s", Vflag?uds_hdr_pid_verbose:
     7020 +                            uds_hdr_pid);
     7021 +                else
     7022 +                        (void) printf("%s", uds_hdr_normal);
     7023 +
     7024 +                first = B_FALSE;
     7025 +        }
     7026 +
     7027 +        cpn = psi->si_pns;
     7028 +
     7029 +        do {
     7030 +                int pid = (psi->si_pn_cnt)?cpn->cpn_pid:0;
     7031 +                pinfo = get_proc_info(cpn->cpn_pid);
     7032 +                raddr = laddr = NO_ADDR;
     7033 +
     7034 +                /* laddr.soa_sa:                                        */
     7035 +                if ((psi->si_state & SS_ISBOUND) &&
     7036 +                    strlen(psi->si_laddr_sun_path) != 0 &&
     7037 +                    psi->si_laddr_soa_len != 0) {
     7038 +                        if (psi->si_faddr_noxlate) {
     7039 +                                laddr = SO_PAIR;
     7040 +                        } else {
     7041 +                                if (psi->si_laddr_soa_len >
     7042 +                                    sizeof (psi->si_laddr_family))
     7043 +                                        laddr = psi->si_laddr_sun_path;
     7044 +                        }
     7045 +                }
     7046 +
     7047 +                /* faddr.soa_sa:                                        */
     7048 +                if ((psi->si_state & SS_ISCONNECTED) &&
     7049 +                    strlen(psi->si_faddr_sun_path) != 0 &&
     7050 +                    psi->si_faddr_soa_len != 0) {
     7051 +
     7052 +                        if (psi->si_faddr_noxlate) {
     7053 +                                raddr = SO_PAIR;
     7054 +                        } else {
     7055 +                                if (psi->si_faddr_soa_len >
     7056 +                                    sizeof (psi->si_faddr_family))
     7057 +                                        raddr = psi->si_faddr_sun_path;
     7058 +                        }
     7059 +                }
     7060 +
     7061 +                if (Uflag && Vflag) {
     7062 +                        (void) printf("%-10.10s %-8.8s %6u "
     7063 +                                "%-39.39s %-39.39s %s\n",
     7064 +                                typetoname(psi->si_serv_type), pinfo->pr_user,
     7065 +                                pid, laddr, raddr, pinfo->pr_psargs);
     7066 +                } else if (Uflag && (!Vflag)) {
     7067 +                        (void) printf("%-10.10s %-8.8s %6u %-14.14s"
     7068 +                                "%-39.39s %-39.39s\n",
     7069 +                                typetoname(psi->si_serv_type), pinfo->pr_user,
     7070 +                                pid, pinfo->pr_fname, laddr, raddr);
     7071 +                } else {
     7072 +                        (void) printf("%-10.10s %s %s\n",
     7073 +                                typetoname(psi->si_serv_type), laddr, raddr);
     7074 +                }
     7075 +
     7076 +                i++; cpn++;
     7077 +        } while (i < psi->si_pn_cnt);
     7078 +
     7079 +        return (first);
     7080 +}
     7081 +
     7082 +static char *
     7083 +typetoname(t_scalar_t type)
     7084 +{
     7085 +        switch (type) {
     7086 +        case T_CLTS:
     7087 +                return ("dgram");
     7088 +
     7089 +        case T_COTS:
     7090 +                return ("stream");
     7091 +
     7092 +        case T_COTS_ORD:
     7093 +                return ("stream-ord");
     7094 +
     7095 +        default:
     7096 +                return ("");
     7097 +        }
6455 7098  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX