Print this page
4142 truss should expand connect() arguments

@@ -80,10 +80,12 @@
 #include <sys/tsol/tndb.h>
 #include <sys/rctl.h>
 #include <sys/rctl_impl.h>
 #include <sys/fork.h>
 #include <sys/task.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
 #include "ramdata.h"
 #include "print.h"
 #include "proto.h"
 #include "systable.h"
 

@@ -1784,10 +1786,100 @@
         default:                prt_dec(pri, 0, val);           break;
         }
 }
 
 /*
+ * Print connect() 2nd and 3rd arguments.
+ */
+/*ARGSUSED*/
+void
+prt_sad(private_t *pri, int raw, long addr, long len)
+{
+        /*
+         * A buffer large enough for PATH_MAX size AF_UNIX address, which is
+         * also large enough to store a sockaddr_in or a sockaddr_in6.
+         */
+        struct sockaddr_storage buf;
+
+        struct sockaddr *sa = (struct sockaddr *)&buf;
+        struct sockaddr_in *sin = (struct sockaddr_in *)&buf;
+        struct sockaddr_un *soun = (struct sockaddr_un *)&buf;
+        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&buf;
+        char addrbuf[INET6_ADDRSTRLEN];
+        char scope[16] = "";
+        long rlen = len;
+
+        GROW(20);
+        if (data_model == PR_MODEL_ILP32) {
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    "0x%.8X", (int)addr);
+        } else {
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    "0x%.8lX", addr);
+        }
+
+        if (raw != 0)
+                return;
+
+        if (rlen >= sizeof (buf))       /* protect against ridiculous length */
+                rlen = sizeof (buf) - 1;
+        if (Pread(Proc, (void*)&buf, rlen, addr) != rlen)
+                return;
+
+        GROW(175);
+
+        switch (sa->sa_family) {
+        case AF_INET6:
+                if (ntohl(sin6->sin6_scope_id) != 0) {
+                    sprintf(scope, "%%%u", ntohl(sin6->sin6_scope_id));
+                }
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    " AF_INET6 to = [%s]%s:%u",
+                    inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf,
+                    sizeof (addrbuf)),
+                    scope, ntohs(sin6->sin6_port));
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    " source id = 0x%x"
+                    " flow class = 0x%02x flow label = 0x%05x",
+                    ntohl(sin6->__sin6_src_id),
+                    ntohl((sin6->sin6_flowinfo & IPV6_FLOWINFO_TCLASS) >> 20),
+                    ntohl(sin6->sin6_flowinfo & IPV6_FLOWINFO_FLOWLABEL));
+                break;
+        case AF_INET:
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    " AF_INET to = %s:%u",
+                    inet_ntop(AF_INET, &sin->sin_addr, addrbuf,
+                    sizeof (addrbuf)),
+                    ntohs(sin->sin_port));
+                break;
+        case AF_UNIX:
+                rlen -= sizeof (soun->sun_family);
+                if (rlen >= 0) {
+                        /* Null terminate */
+                        soun->sun_path[rlen] = NULL;
+                        pri->sys_leng += sprintf(
+                            pri->sys_string + pri->sys_leng,
+                            " AF_UNIX to = %s", soun->sun_path);
+                }
+                break;
+        }
+
+        /*
+         * print the third argument len
+         */
+        if (data_model == PR_MODEL_ILP32) {
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    ", %d", (int)len);
+        } else {
+                pri->sys_leng += sprintf(pri->sys_string + pri->sys_leng,
+                    ", %ld", len);
+        }
+
+}
+
+
+/*
  * Print accept4() flags argument.
  */
 void
 prt_acf(private_t *pri, int raw, long val)
 {

@@ -2813,10 +2905,11 @@
         prt_mif,        /* MIF -- print meminfo() arguments */
         prt_pfm,        /* PFM -- print so_socket() proto-family (1st) arg */
         prt_skt,        /* SKT -- print so_socket() socket-type (2nd) arg */
         prt_skp,        /* SKP -- print so_socket() protocol (3rd) arg */
         prt_skv,        /* SKV -- print socket version arg */
+        prt_sad,        /* SAD -- print connect 2nd and 3rd arguments */
         prt_sol,        /* SOL -- print [sg]etsockopt() level (2nd) arg */
         prt_son,        /* SON -- print [sg]etsockopt() opt-name (3rd) arg */
         prt_utt,        /* UTT -- print utrap type */
         prt_uth,        /* UTH -- print utrap handler */
         prt_acc,        /* ACC -- print access() flags */