]> granicus.if.org Git - strace/blob - net.c
getsockopt, setsockopt: do not decode structures in non-verbose mode
[strace] / net.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "defs.h"
32 #include <sys/stat.h>
33 #include <sys/socket.h>
34 #include <sys/uio.h>
35 #include <sys/un.h>
36 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
37 # define in6_addr in6_addr_libc
38 # define ipv6_mreq ipv6_mreq_libc
39 # define sockaddr_in6 sockaddr_in6_libc
40 #endif
41 #include <netinet/in.h>
42 #ifdef HAVE_NETINET_TCP_H
43 # include <netinet/tcp.h>
44 #endif
45 #ifdef HAVE_NETINET_UDP_H
46 # include <netinet/udp.h>
47 #endif
48 #ifdef HAVE_NETINET_SCTP_H
49 # include <netinet/sctp.h>
50 #endif
51 #include <arpa/inet.h>
52 #include <net/if.h>
53 #include <asm/types.h>
54 #if defined(__GLIBC__)
55 # include <netipx/ipx.h>
56 #else
57 # include <linux/ipx.h>
58 #endif
59
60 #if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
61 # if defined(HAVE_LINUX_IN6_H)
62 #  if defined(HAVE_SIN6_SCOPE_ID_LINUX)
63 #   undef in6_addr
64 #   undef ipv6_mreq
65 #   undef sockaddr_in6
66 #   define in6_addr in6_addr_kernel
67 #   define ipv6_mreq ipv6_mreq_kernel
68 #   define sockaddr_in6 sockaddr_in6_kernel
69 #  endif
70 #  include <linux/in6.h>
71 #  if defined(HAVE_SIN6_SCOPE_ID_LINUX)
72 #   undef in6_addr
73 #   undef ipv6_mreq
74 #   undef sockaddr_in6
75 #   define in6_addr in6_addr_libc
76 #   define ipv6_mreq ipv6_mreq_libc
77 #   define sockaddr_in6 sockaddr_in6_kernel
78 #  endif
79 # endif
80 #endif
81
82 #if defined(HAVE_LINUX_NETLINK_H)
83 # include <linux/netlink.h>
84 #endif
85 #if defined(HAVE_LINUX_IF_PACKET_H)
86 # include <linux/if_packet.h>
87 #endif
88 #if defined(HAVE_LINUX_ICMP_H)
89 # include <linux/icmp.h>
90 #endif
91 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
92 # include <bluetooth/bluetooth.h>
93 # include <bluetooth/hci.h>
94 # include <bluetooth/l2cap.h>
95 # include <bluetooth/rfcomm.h>
96 # include <bluetooth/sco.h>
97 #endif
98 #ifndef PF_UNSPEC
99 # define PF_UNSPEC AF_UNSPEC
100 #endif
101
102 #include "xlat/domains.h"
103 #include "xlat/addrfams.h"
104 #include "xlat/socktypes.h"
105 #include "xlat/sock_type_flags.h"
106 #ifndef SOCK_TYPE_MASK
107 # define SOCK_TYPE_MASK 0xf
108 #endif
109 #include "xlat/socketlayers.h"
110 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
111      falls into "inet_protocols" array below!!!!   This is intended!!! ***/
112 #include "xlat/inet_protocols.h"
113
114 #ifdef PF_NETLINK
115 # if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
116 #  define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
117 # endif
118 # include "xlat/netlink_protocols.h"
119 #endif
120
121 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
122 # include "xlat/bt_protocols.h"
123 #endif
124
125 #include "xlat/msg_flags.h"
126 #include "xlat/sockoptions.h"
127
128 #if !defined(SOL_IP) && defined(IPPROTO_IP)
129 #define SOL_IP IPPROTO_IP
130 #endif
131
132 #ifdef SOL_IP
133 #include "xlat/sockipoptions.h"
134 #endif /* SOL_IP */
135
136 #ifdef SOL_IPV6
137 #include "xlat/sockipv6options.h"
138 #endif /* SOL_IPV6 */
139
140 #ifdef SOL_IPX
141 #include "xlat/sockipxoptions.h"
142 #endif /* SOL_IPX */
143
144 #ifdef SOL_RAW
145 #include "xlat/sockrawoptions.h"
146 #endif /* SOL_RAW */
147
148 #ifdef SOL_PACKET
149 #include "xlat/sockpacketoptions.h"
150 #endif /* SOL_PACKET */
151
152 #ifdef SOL_SCTP
153 #include "xlat/socksctpoptions.h"
154 #endif
155
156 #if !defined(SOL_TCP) && defined(IPPROTO_TCP)
157 #define SOL_TCP IPPROTO_TCP
158 #endif
159
160 #ifdef SOL_TCP
161 #include "xlat/socktcpoptions.h"
162 #endif /* SOL_TCP */
163
164 #ifdef SOL_RAW
165 #include "xlat/icmpfilterflags.h"
166 #endif /* SOL_RAW */
167
168 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
169 #include "xlat/af_packet_types.h"
170 #endif /* defined(AF_PACKET) */
171
172 void
173 printsock(struct tcb *tcp, long addr, int addrlen)
174 {
175         union {
176                 char pad[128];
177                 struct sockaddr sa;
178                 struct sockaddr_in sin;
179                 struct sockaddr_un sau;
180 #ifdef HAVE_INET_NTOP
181                 struct sockaddr_in6 sa6;
182 #endif
183 #if defined(AF_IPX)
184                 struct sockaddr_ipx sipx;
185 #endif
186 #ifdef AF_PACKET
187                 struct sockaddr_ll ll;
188 #endif
189 #ifdef AF_NETLINK
190                 struct sockaddr_nl nl;
191 #endif
192 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
193                 struct sockaddr_hci hci;
194                 struct sockaddr_l2 l2;
195                 struct sockaddr_rc rc;
196                 struct sockaddr_sco sco;
197 #endif
198         } addrbuf;
199         char string_addr[100];
200
201         if (addr == 0) {
202                 tprints("NULL");
203                 return;
204         }
205         if (!verbose(tcp)) {
206                 tprintf("%#lx", addr);
207                 return;
208         }
209
210         if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
211                 addrlen = sizeof(addrbuf);
212
213         memset(&addrbuf, 0, sizeof(addrbuf));
214         if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
215                 tprints("{...}");
216                 return;
217         }
218         addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
219
220         tprints("{sa_family=");
221         printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
222         tprints(", ");
223
224         switch (addrbuf.sa.sa_family) {
225         case AF_UNIX:
226                 if (addrlen == 2) {
227                         tprints("NULL");
228                 } else if (addrbuf.sau.sun_path[0]) {
229                         tprints("sun_path=");
230                         printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
231                 } else {
232                         tprints("sun_path=@");
233                         printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
234                 }
235                 break;
236         case AF_INET:
237                 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
238                         ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
239                 break;
240 #ifdef HAVE_INET_NTOP
241         case AF_INET6:
242                 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
243                 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
244                                 ntohs(addrbuf.sa6.sin6_port), string_addr,
245                                 addrbuf.sa6.sin6_flowinfo);
246 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
247                 {
248 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
249                         int numericscope = 0;
250                         if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
251                             || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
252                                 char scopebuf[IFNAMSIZ + 1];
253
254                                 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
255                                         numericscope++;
256                                 else {
257                                         tprints(", sin6_scope_id=if_nametoindex(");
258                                         print_quoted_string(scopebuf,
259                                                             sizeof(scopebuf),
260                                                             QUOTE_0_TERMINATED);
261                                         tprints(")");
262                                 }
263                         } else
264                                 numericscope++;
265
266                         if (numericscope)
267 #endif
268                                 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
269                 }
270 #endif
271                 break;
272 #endif
273 #if defined(AF_IPX)
274         case AF_IPX:
275                 {
276                         int i;
277                         tprintf("sipx_port=htons(%u), ",
278                                         ntohs(addrbuf.sipx.sipx_port));
279                         /* Yes, I know, this does not look too
280                          * strace-ish, but otherwise the IPX
281                          * addresses just look monstrous...
282                          * Anyways, feel free if you don't like
283                          * this way.. :)
284                          */
285                         tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
286                         for (i = 0; i < IPX_NODE_LEN; i++)
287                                 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
288                         tprintf("/[%02x]", addrbuf.sipx.sipx_type);
289                 }
290                 break;
291 #endif /* AF_IPX */
292 #ifdef AF_PACKET
293         case AF_PACKET:
294                 {
295                         int i;
296                         tprintf("proto=%#04x, if%d, pkttype=",
297                                         ntohs(addrbuf.ll.sll_protocol),
298                                         addrbuf.ll.sll_ifindex);
299                         printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
300                         tprintf(", addr(%d)={%d, ",
301                                         addrbuf.ll.sll_halen,
302                                         addrbuf.ll.sll_hatype);
303                         for (i = 0; i < addrbuf.ll.sll_halen; i++)
304                                 tprintf("%02x", addrbuf.ll.sll_addr[i]);
305                 }
306                 break;
307
308 #endif /* AF_PACKET */
309 #ifdef AF_NETLINK
310         case AF_NETLINK:
311                 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
312                 break;
313 #endif /* AF_NETLINK */
314 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
315         case AF_BLUETOOTH:
316                 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
317                         "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
318                         "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
319                         "{hci_dev=htobs(%d)}",
320                         addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
321                         addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
322                         addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
323                         addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
324                         addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
325                         addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
326                         addrbuf.rc.rc_channel,
327                         btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
328                         addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
329                         addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
330                         addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
331                         btohs(addrbuf.hci.hci_dev));
332                 break;
333 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
334         /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
335         AF_X25 AF_ROSE etc. still need to be done */
336
337         default:
338                 tprints("sa_data=");
339                 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
340                         sizeof addrbuf.sa.sa_data);
341                 break;
342         }
343         tprints("}");
344 }
345
346 #if HAVE_SENDMSG
347 # ifndef SCM_SECURITY
348 #  define SCM_SECURITY 0x03
349 # endif
350 # include "xlat/scmvals.h"
351
352 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
353 struct cmsghdr32 {
354         uint32_t cmsg_len;
355         int cmsg_level;
356         int cmsg_type;
357 };
358 #endif
359
360 typedef union {
361         char *ptr;
362         struct cmsghdr *cmsg;
363 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
364         struct cmsghdr32 *cmsg32;
365 #endif
366 } union_cmsghdr;
367
368 static bool
369 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
370 {
371         if (cmsg_size + sizeof(int) > cmsg_len)
372                 return false;
373
374         int *fds = (int *) (ptr + cmsg_size);
375         bool seen = false;
376
377         tprints(", [");
378         while ((char *) fds < (ptr + cmsg_len)) {
379                 if (seen)
380                         tprints(", ");
381                 else
382                         seen = true;
383                 printfd(tcp, *fds++);
384         }
385         tprints("]}");
386         return true;
387 }
388
389 static bool
390 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
391 {
392         if (cmsg_size + sizeof(struct ucred) > cmsg_len)
393                 return false;
394
395         const struct ucred *uc = (void *) (ptr + cmsg_size);
396
397         tprintf(", {pid=%u, uid=%u, gid=%u}}",
398                 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
399         return true;
400 }
401
402 static bool
403 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
404 {
405         if (cmsg_size + sizeof(char) > cmsg_len)
406                 return false;
407
408         const char *label = (const char *) (ptr + cmsg_size);
409         const size_t label_len = cmsg_len - cmsg_size;
410
411         tprints(", ");
412         print_quoted_string(label, label_len, 0);
413         tprints("}");
414
415         return true;
416 }
417
418 static void
419 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
420 {
421         const size_t cmsg_size =
422 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
423                 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
424 #endif
425                         sizeof(struct cmsghdr);
426
427         char *buf = len < cmsg_size ? NULL : malloc(len);
428         if (!buf || umoven(tcp, addr, len, buf) < 0) {
429                 tprintf(", msg_control=%#lx", addr);
430                 free(buf);
431                 return;
432         }
433
434         union_cmsghdr u = { .ptr = buf };
435
436         tprints(", [");
437         while (len >= cmsg_size) {
438                 size_t cmsg_len =
439 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
440                         (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
441 #endif
442                                 u.cmsg->cmsg_len;
443                 int cmsg_level =
444 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
445                         (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
446 #endif
447                                 u.cmsg->cmsg_level;
448                 int cmsg_type =
449 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
450                         (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
451 #endif
452                                 u.cmsg->cmsg_type;
453
454                 if (u.ptr != buf)
455                         tprints(", ");
456                 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
457                 printxval(socketlayers, cmsg_level, "SOL_???");
458                 tprints(", cmsg_type=");
459
460                 if (cmsg_len > len)
461                         cmsg_len = len;
462
463                 if (cmsg_level == SOL_SOCKET) {
464                         printxval(scmvals, cmsg_type, "SCM_???");
465                         switch (cmsg_type) {
466                         case SCM_RIGHTS:
467                                 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
468                                         goto next_cmsg;
469                                 break;
470                         case SCM_CREDENTIALS:
471                                 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
472                                         goto next_cmsg;
473                                 break;
474                         case SCM_SECURITY:
475                                 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
476                                         goto next_cmsg;
477                                 break;
478                         }
479                 } else {
480                         tprintf("%u", cmsg_type);
481                 }
482                 tprints(", ...}");
483 next_cmsg:
484                 if (cmsg_len < cmsg_size) {
485                         len -= cmsg_size;
486                         break;
487                 }
488                 cmsg_len = (cmsg_len + current_wordsize - 1) &
489                         (size_t) ~(current_wordsize - 1);
490                 if (cmsg_len >= len) {
491                         len = 0;
492                         break;
493                 }
494                 u.ptr += cmsg_len;
495                 len -= cmsg_len;
496         }
497         if (len)
498                 tprints(", ...");
499         tprints("]");
500         free(buf);
501 }
502
503 static void
504 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
505 {
506         tprintf("{msg_name(%d)=", msg->msg_namelen);
507         printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
508
509         tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
510         tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
511                    (unsigned long)msg->msg_iov, 1, data_size);
512
513 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
514         tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
515         if (msg->msg_controllen)
516                 printcmsghdr(tcp, (unsigned long) msg->msg_control,
517                              msg->msg_controllen);
518         tprints(", msg_flags=");
519         printflags(msg_flags, msg->msg_flags, "MSG_???");
520 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
521         tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
522                 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
523 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
524         tprints("}");
525 }
526
527 struct msghdr32 {
528         uint32_t /* void* */    msg_name;
529         uint32_t /* socklen_t */msg_namelen;
530         uint32_t /* iovec* */   msg_iov;
531         uint32_t /* size_t */   msg_iovlen;
532         uint32_t /* void* */    msg_control;
533         uint32_t /* size_t */   msg_controllen;
534         uint32_t /* int */      msg_flags;
535 };
536 struct mmsghdr32 {
537         struct msghdr32         msg_hdr;
538         uint32_t /* unsigned */ msg_len;
539 };
540
541 #ifndef HAVE_STRUCT_MMSGHDR
542 struct mmsghdr {
543         struct msghdr msg_hdr;
544         unsigned msg_len;
545 };
546 #endif
547
548 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
549 static void
550 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
551 {
552         to_msg->msg_name       = (void*)(long)from_msg32->msg_name;
553         to_msg->msg_namelen    =              from_msg32->msg_namelen;
554         to_msg->msg_iov        = (void*)(long)from_msg32->msg_iov;
555         to_msg->msg_iovlen     =              from_msg32->msg_iovlen;
556         to_msg->msg_control    = (void*)(long)from_msg32->msg_control;
557         to_msg->msg_controllen =              from_msg32->msg_controllen;
558         to_msg->msg_flags      =              from_msg32->msg_flags;
559 }
560 #endif
561
562 static bool
563 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
564 {
565 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
566         if (current_wordsize == 4) {
567                 struct msghdr32 msg32;
568
569                 if (umove(tcp, addr, &msg32) < 0)
570                         return false;
571                 copy_from_msghdr32(msg, &msg32);
572         } else
573 #endif
574         if (umove(tcp, addr, msg) < 0)
575                 return false;
576         return true;
577 }
578
579 static bool
580 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
581 {
582 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
583         if (current_wordsize == 4) {
584                 struct mmsghdr32 mmsg32;
585
586                 addr += sizeof(struct mmsghdr32) * idx;
587                 if (umove(tcp, addr, &mmsg32) < 0)
588                         return false;
589
590                 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
591                 mmsg->msg_len = mmsg32.msg_len;
592         } else
593 #endif
594         {
595                 addr += sizeof(*mmsg) * idx;
596                 if (umove(tcp, addr, mmsg) < 0)
597                         return false;
598         }
599         return true;
600 }
601
602 static void
603 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
604 {
605         struct msghdr msg;
606
607         if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
608                 do_msghdr(tcp, &msg, data_size);
609         else
610                 tprintf("%#lx", addr);
611 }
612
613 void
614 dumpiov_in_msghdr(struct tcb *tcp, long addr)
615 {
616         struct msghdr msg;
617
618         if (extractmsghdr(tcp, addr, &msg))
619                 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
620 }
621
622 static void
623 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
624 {
625         struct mmsghdr mmsg;
626
627         if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
628                 tprints("{");
629                 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
630                 tprintf(", %u}", mmsg.msg_len);
631         }
632         else
633                 tprintf("%#lx", addr);
634 }
635
636 static void
637 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
638 {
639         /* mmsgvec */
640         if (syserror(tcp)) {
641                 tprintf("%#lx", tcp->u_arg[1]);
642         } else {
643                 unsigned int len = tcp->u_rval;
644                 unsigned int i;
645
646                 tprints("{");
647                 for (i = 0; i < len; ++i) {
648                         if (i)
649                                 tprints(", ");
650                         printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
651                 }
652                 tprints("}");
653         }
654         /* vlen */
655         tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
656         /* flags */
657         printflags(msg_flags, tcp->u_arg[3], "MSG_???");
658 }
659
660 void
661 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
662 {
663         unsigned int len = tcp->u_rval;
664         unsigned int i;
665         struct mmsghdr mmsg;
666
667         for (i = 0; i < len; ++i) {
668                 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
669                         tprintf(" = %lu buffers in vector %u\n",
670                                 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
671                         dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
672                                 (long)mmsg.msg_hdr.msg_iov);
673                 }
674         }
675 }
676 #endif /* HAVE_SENDMSG */
677
678 /*
679  * low bits of the socket type define real socket type,
680  * other bits are socket type flags.
681  */
682 static void
683 tprint_sock_type(int flags)
684 {
685         const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
686
687         if (str) {
688                 tprints(str);
689                 flags &= ~SOCK_TYPE_MASK;
690                 if (!flags)
691                         return;
692                 tprints("|");
693         }
694         printflags(sock_type_flags, flags, "SOCK_???");
695 }
696
697 int
698 sys_socket(struct tcb *tcp)
699 {
700         if (entering(tcp)) {
701                 printxval(domains, tcp->u_arg[0], "PF_???");
702                 tprints(", ");
703                 tprint_sock_type(tcp->u_arg[1]);
704                 tprints(", ");
705                 switch (tcp->u_arg[0]) {
706                 case PF_INET:
707 #ifdef PF_INET6
708                 case PF_INET6:
709 #endif
710                         printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
711                         break;
712 #ifdef PF_IPX
713                 case PF_IPX:
714                         /* BTW: I don't believe this.. */
715                         tprints("[");
716                         printxval(domains, tcp->u_arg[2], "PF_???");
717                         tprints("]");
718                         break;
719 #endif /* PF_IPX */
720 #ifdef PF_NETLINK
721                 case PF_NETLINK:
722                         printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
723                         break;
724 #endif
725 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
726                 case PF_BLUETOOTH:
727                         printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
728                         break;
729 #endif
730                 default:
731                         tprintf("%lu", tcp->u_arg[2]);
732                         break;
733                 }
734         }
735         return 0;
736 }
737
738 int
739 sys_bind(struct tcb *tcp)
740 {
741         if (entering(tcp)) {
742                 printfd(tcp, tcp->u_arg[0]);
743                 tprints(", ");
744                 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
745                 tprintf(", %lu", tcp->u_arg[2]);
746         }
747         return 0;
748 }
749
750 int
751 sys_connect(struct tcb *tcp)
752 {
753         return sys_bind(tcp);
754 }
755
756 int
757 sys_listen(struct tcb *tcp)
758 {
759         if (entering(tcp)) {
760                 printfd(tcp, tcp->u_arg[0]);
761                 tprints(", ");
762                 tprintf("%lu", tcp->u_arg[1]);
763         }
764         return 0;
765 }
766
767 static int
768 do_sockname(struct tcb *tcp, int flags_arg)
769 {
770         if (entering(tcp)) {
771                 printfd(tcp, tcp->u_arg[0]);
772                 tprints(", ");
773                 return 0;
774         }
775         if (!tcp->u_arg[2])
776                 tprintf("%#lx, NULL", tcp->u_arg[1]);
777         else {
778                 int len;
779                 if (tcp->u_arg[1] == 0 || syserror(tcp)
780                     || umove(tcp, tcp->u_arg[2], &len) < 0) {
781                         tprintf("%#lx", tcp->u_arg[1]);
782                 } else {
783                         printsock(tcp, tcp->u_arg[1], len);
784                 }
785                 tprints(", ");
786                 printnum_int(tcp, tcp->u_arg[2], "%u");
787         }
788         if (flags_arg >= 0) {
789                 tprints(", ");
790                 printflags(sock_type_flags, tcp->u_arg[flags_arg],
791                            "SOCK_???");
792         }
793         return 0;
794 }
795
796 int
797 sys_accept(struct tcb *tcp)
798 {
799         do_sockname(tcp, -1);
800         return RVAL_FD;
801 }
802
803 int
804 sys_accept4(struct tcb *tcp)
805 {
806         do_sockname(tcp, 3);
807         return RVAL_FD;
808 }
809
810 int
811 sys_send(struct tcb *tcp)
812 {
813         if (entering(tcp)) {
814                 printfd(tcp, tcp->u_arg[0]);
815                 tprints(", ");
816                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
817                 tprintf(", %lu, ", tcp->u_arg[2]);
818                 /* flags */
819                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
820         }
821         return 0;
822 }
823
824 int
825 sys_sendto(struct tcb *tcp)
826 {
827         if (entering(tcp)) {
828                 printfd(tcp, tcp->u_arg[0]);
829                 tprints(", ");
830                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
831                 tprintf(", %lu, ", tcp->u_arg[2]);
832                 /* flags */
833                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
834                 /* to address */
835                 tprints(", ");
836                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
837                 /* to length */
838                 tprintf(", %lu", tcp->u_arg[5]);
839         }
840         return 0;
841 }
842
843 #ifdef HAVE_SENDMSG
844
845 int
846 sys_sendmsg(struct tcb *tcp)
847 {
848         if (entering(tcp)) {
849                 printfd(tcp, tcp->u_arg[0]);
850                 tprints(", ");
851                 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
852                 /* flags */
853                 tprints(", ");
854                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
855         }
856         return 0;
857 }
858
859 int
860 sys_sendmmsg(struct tcb *tcp)
861 {
862         if (entering(tcp)) {
863                 /* sockfd */
864                 printfd(tcp, tcp->u_arg[0]);
865                 tprints(", ");
866                 if (!verbose(tcp)) {
867                         tprintf("%#lx, %u, ",
868                                 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
869                         printflags(msg_flags, tcp->u_arg[3], "MSG_???");
870                 }
871         } else {
872                 if (verbose(tcp))
873                         decode_mmsg(tcp, (unsigned long) -1L);
874         }
875         return 0;
876 }
877
878 #endif /* HAVE_SENDMSG */
879
880 int
881 sys_recv(struct tcb *tcp)
882 {
883         if (entering(tcp)) {
884                 printfd(tcp, tcp->u_arg[0]);
885                 tprints(", ");
886         } else {
887                 if (syserror(tcp))
888                         tprintf("%#lx", tcp->u_arg[1]);
889                 else
890                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
891
892                 tprintf(", %lu, ", tcp->u_arg[2]);
893                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
894         }
895         return 0;
896 }
897
898 int
899 sys_recvfrom(struct tcb *tcp)
900 {
901         int fromlen;
902
903         if (entering(tcp)) {
904                 printfd(tcp, tcp->u_arg[0]);
905                 tprints(", ");
906         } else {
907                 if (syserror(tcp)) {
908                         tprintf("%#lx, %lu, %lu, %#lx, %#lx",
909                                 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
910                                 tcp->u_arg[4], tcp->u_arg[5]);
911                         return 0;
912                 }
913                 /* buf */
914                 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
915                 /* len */
916                 tprintf(", %lu, ", tcp->u_arg[2]);
917                 /* flags */
918                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
919                 /* from address, len */
920                 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
921                         if (tcp->u_arg[4] == 0)
922                                 tprints(", NULL");
923                         else
924                                 tprintf(", %#lx", tcp->u_arg[4]);
925                         if (tcp->u_arg[5] == 0)
926                                 tprints(", NULL");
927                         else
928                                 tprintf(", %#lx", tcp->u_arg[5]);
929                         return 0;
930                 }
931                 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
932                         tprints(", {...}, [?]");
933                         return 0;
934                 }
935                 tprints(", ");
936                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
937                 /* from length */
938                 tprintf(", [%u]", fromlen);
939         }
940         return 0;
941 }
942
943 #ifdef HAVE_SENDMSG
944
945 int
946 sys_recvmsg(struct tcb *tcp)
947 {
948         if (entering(tcp)) {
949                 printfd(tcp, tcp->u_arg[0]);
950                 tprints(", ");
951         } else {
952                 if (syserror(tcp))
953                         tprintf("%#lx", tcp->u_arg[1]);
954                 else
955                         printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
956                 /* flags */
957                 tprints(", ");
958                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
959         }
960         return 0;
961 }
962
963 int
964 sys_recvmmsg(struct tcb *tcp)
965 {
966         /* +5 chars are for "left " prefix */
967         static char str[5 + TIMESPEC_TEXT_BUFSIZE];
968
969         if (entering(tcp)) {
970                 printfd(tcp, tcp->u_arg[0]);
971                 tprints(", ");
972                 if (verbose(tcp)) {
973                         sprint_timespec(str, tcp, tcp->u_arg[4]);
974                         /* Abusing tcp->auxstr as temp storage.
975                          * Will be used and freed on syscall exit.
976                          */
977                         tcp->auxstr = strdup(str);
978                 } else {
979                         tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
980                         printflags(msg_flags, tcp->u_arg[3], "MSG_???");
981                         tprints(", ");
982                         print_timespec(tcp, tcp->u_arg[4]);
983                 }
984                 return 0;
985         } else {
986                 if (verbose(tcp)) {
987                         decode_mmsg(tcp, 0);
988                         /* timeout on entrance */
989                         tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
990                         free((void *) tcp->auxstr);
991                         tcp->auxstr = NULL;
992                 }
993                 if (syserror(tcp))
994                         return 0;
995                 if (tcp->u_rval == 0) {
996                         tcp->auxstr = "Timeout";
997                         return RVAL_STR;
998                 }
999                 if (!verbose(tcp))
1000                         return 0;
1001                 /* timeout on exit */
1002                 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
1003                 tcp->auxstr = str;
1004                 return RVAL_STR;
1005         }
1006 }
1007
1008 #endif /* HAVE_SENDMSG */
1009
1010 #include "xlat/shutdown_modes.h"
1011
1012 int
1013 sys_shutdown(struct tcb *tcp)
1014 {
1015         if (entering(tcp)) {
1016                 printfd(tcp, tcp->u_arg[0]);
1017                 tprints(", ");
1018                 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1019         }
1020         return 0;
1021 }
1022
1023 int
1024 sys_getsockname(struct tcb *tcp)
1025 {
1026         return do_sockname(tcp, -1);
1027 }
1028
1029 static int
1030 do_pipe(struct tcb *tcp, int flags_arg)
1031 {
1032         if (exiting(tcp)) {
1033                 if (syserror(tcp)) {
1034                         tprintf("%#lx", tcp->u_arg[0]);
1035                 } else {
1036 #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1037                         int fds[2];
1038
1039                         if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1040                                 tprints("[...]");
1041                         else
1042                                 tprintf("[%u, %u]", fds[0], fds[1]);
1043 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
1044                         tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1045 #else
1046                         tprintf("%#lx", tcp->u_arg[0]);
1047 #endif
1048                 }
1049                 if (flags_arg >= 0) {
1050                         tprints(", ");
1051                         printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1052                 }
1053         }
1054         return 0;
1055 }
1056
1057 int
1058 sys_pipe(struct tcb *tcp)
1059 {
1060         return do_pipe(tcp, -1);
1061 }
1062
1063 int
1064 sys_pipe2(struct tcb *tcp)
1065 {
1066         return do_pipe(tcp, 1);
1067 }
1068
1069 int
1070 sys_socketpair(struct tcb *tcp)
1071 {
1072         int fds[2];
1073
1074         if (entering(tcp)) {
1075                 printxval(domains, tcp->u_arg[0], "PF_???");
1076                 tprints(", ");
1077                 tprint_sock_type(tcp->u_arg[1]);
1078                 tprintf(", %lu", tcp->u_arg[2]);
1079         } else {
1080                 if (syserror(tcp)) {
1081                         tprintf(", %#lx", tcp->u_arg[3]);
1082                         return 0;
1083                 }
1084                 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1085                         tprints(", [...]");
1086                 else
1087                         tprintf(", [%u, %u]", fds[0], fds[1]);
1088         }
1089         return 0;
1090 }
1091
1092 static void
1093 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
1094 {
1095         printfd(tcp, fd);
1096         tprints(", ");
1097         printxval(socketlayers, level, "SOL_??");
1098         tprints(", ");
1099
1100         switch (level) {
1101         case SOL_SOCKET:
1102                 printxval(sockoptions, name, "SO_???");
1103                 break;
1104 #ifdef SOL_IP
1105         case SOL_IP:
1106                 printxval(sockipoptions, name, "IP_???");
1107                 break;
1108 #endif
1109 #ifdef SOL_IPV6
1110         case SOL_IPV6:
1111                 printxval(sockipv6options, name, "IPV6_???");
1112                 break;
1113 #endif
1114 #ifdef SOL_IPX
1115         case SOL_IPX:
1116                 printxval(sockipxoptions, name, "IPX_???");
1117                 break;
1118 #endif
1119 #ifdef SOL_PACKET
1120         case SOL_PACKET:
1121                 printxval(sockpacketoptions, name, "PACKET_???");
1122                 break;
1123 #endif
1124 #ifdef SOL_TCP
1125         case SOL_TCP:
1126                 printxval(socktcpoptions, name, "TCP_???");
1127                 break;
1128 #endif
1129 #ifdef SOL_SCTP
1130         case SOL_SCTP:
1131                 printxval(socksctpoptions, name, "SCTP_???");
1132                 break;
1133 #endif
1134 #ifdef SOL_RAW
1135         case SOL_RAW:
1136                 printxval(sockrawoptions, name, "RAW_???");
1137                 break;
1138 #endif
1139
1140                 /* Other SOL_* protocol levels still need work. */
1141
1142         default:
1143                 tprintf("%u", name);
1144         }
1145
1146         tprints(", ");
1147 }
1148
1149 #ifdef SO_LINGER
1150 static void
1151 print_linger(struct tcb *tcp, long addr, int len)
1152 {
1153         struct linger linger;
1154
1155         if (len != sizeof(linger) ||
1156             umove(tcp, addr, &linger) < 0) {
1157                 tprintf("%#lx", addr);
1158                 return;
1159         }
1160
1161         tprintf("{onoff=%d, linger=%d}",
1162                 linger.l_onoff,
1163                 linger.l_linger);
1164 }
1165 #endif /* SO_LINGER */
1166
1167 #ifdef SO_PEERCRED
1168 static void
1169 print_ucred(struct tcb *tcp, long addr, int len)
1170 {
1171         struct ucred uc;
1172
1173         if (len != sizeof(uc) ||
1174             umove(tcp, addr, &uc) < 0) {
1175                 tprintf("%#lx", addr);
1176         } else {
1177                 tprintf("{pid=%u, uid=%u, gid=%u}",
1178                         (unsigned) uc.pid,
1179                         (unsigned) uc.uid,
1180                         (unsigned) uc.gid);
1181         }
1182 }
1183 #endif /* SO_PEERCRED */
1184
1185 #ifdef PACKET_STATISTICS
1186 static void
1187 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1188 {
1189         struct tpacket_stats stats;
1190
1191         if (len != sizeof(stats) ||
1192             umove(tcp, addr, &stats) < 0) {
1193                 tprintf("%#lx", addr);
1194         } else {
1195                 tprintf("{packets=%u, drops=%u}",
1196                         stats.tp_packets,
1197                         stats.tp_drops);
1198         }
1199 }
1200 #endif /* PACKET_STATISTICS */
1201
1202 #ifdef ICMP_FILTER
1203 static void
1204 print_icmp_filter(struct tcb *tcp, long addr, int len)
1205 {
1206         struct icmp_filter      filter;
1207
1208         if (len != sizeof(filter) ||
1209             umove(tcp, addr, &filter) < 0) {
1210                 tprintf("%#lx", addr);
1211                 return;
1212         }
1213
1214         tprints("~(");
1215         printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1216         tprints(")");
1217 }
1218 #endif /* ICMP_FILTER */
1219
1220 static void
1221 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1222 {
1223         if (addr && verbose(tcp))
1224         switch (level) {
1225         case SOL_SOCKET:
1226                 switch (name) {
1227 #ifdef SO_LINGER
1228                 case SO_LINGER:
1229                         print_linger(tcp, addr, len);
1230                         goto done;
1231 #endif
1232 #ifdef SO_PEERCRED
1233                 case SO_PEERCRED:
1234                         print_ucred(tcp, addr, len);
1235                         goto done;
1236 #endif
1237                 }
1238                 break;
1239
1240 #ifdef SOL_PACKET
1241         case SOL_PACKET:
1242                 switch (name) {
1243 # ifdef PACKET_STATISTICS
1244                 case PACKET_STATISTICS:
1245                         print_tpacket_stats(tcp, addr, len);
1246                         goto done;
1247 # endif
1248                 }
1249                 break;
1250 #endif /* SOL_PACKET */
1251
1252 #ifdef SOL_RAW
1253         case SOL_RAW:
1254                 switch (name) {
1255 # ifdef ICMP_FILTER
1256                 case ICMP_FILTER:
1257                         print_icmp_filter(tcp, addr, len);
1258                         goto done;
1259 # endif
1260                 }
1261                 break;
1262 #endif /* SOL_RAW */
1263         }
1264
1265         /* default arg printing */
1266
1267         if (verbose(tcp)) {
1268                 if (len == sizeof(int)) {
1269                         printnum_int(tcp, addr, "%d");
1270                 } else {
1271                         printstr(tcp, addr, len);
1272                 }
1273         } else {
1274                 tprintf("%#lx", addr);
1275         }
1276 done:
1277         tprintf(", [%d]", len);
1278 }
1279
1280 int
1281 sys_getsockopt(struct tcb *tcp)
1282 {
1283         if (entering(tcp)) {
1284                 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1285                                             tcp->u_arg[1], tcp->u_arg[2]);
1286         } else {
1287                 int len;
1288
1289                 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1290                         tprintf("%#lx, %#lx",
1291                                 tcp->u_arg[3], tcp->u_arg[4]);
1292                 } else {
1293                         print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1294                                          tcp->u_arg[3], len);
1295                 }
1296         }
1297         return 0;
1298 }
1299
1300 #ifdef PACKET_RX_RING
1301 static void
1302 print_tpacket_req(struct tcb *tcp, long addr, int len)
1303 {
1304         struct tpacket_req req;
1305
1306         if (len != sizeof(req) ||
1307             umove(tcp, addr, &req) < 0) {
1308                 tprintf("%#lx", addr);
1309         } else {
1310                 tprintf("{block_size=%u, block_nr=%u, "
1311                         "frame_size=%u, frame_nr=%u}",
1312                         req.tp_block_size,
1313                         req.tp_block_nr,
1314                         req.tp_frame_size,
1315                         req.tp_frame_nr);
1316         }
1317 }
1318 #endif /* PACKET_RX_RING */
1319
1320 static void
1321 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1322 {
1323         if (addr && verbose(tcp))
1324         switch (level) {
1325         case SOL_SOCKET:
1326                 switch (name) {
1327 #ifdef SO_LINGER
1328                 case SO_LINGER:
1329                         print_linger(tcp, addr, len);
1330                         goto done;
1331 #endif
1332                 }
1333                 break;
1334
1335 #ifdef SOL_PACKET
1336         case SOL_PACKET:
1337                 switch (name) {
1338 # ifdef PACKET_RX_RING
1339                 case PACKET_RX_RING:
1340 #  ifdef PACKET_TX_RING
1341                 case PACKET_TX_RING:
1342 #  endif
1343                         print_tpacket_req(tcp, addr, len);
1344                         goto done;
1345 # endif /* PACKET_RX_RING */
1346                 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1347                 }
1348                 break;
1349 #endif /* SOL_PACKET */
1350
1351 #ifdef SOL_RAW
1352         case SOL_RAW:
1353                 switch (name) {
1354 # ifdef ICMP_FILTER
1355                 case ICMP_FILTER:
1356                         print_icmp_filter(tcp, addr, len);
1357                         goto done;
1358 # endif
1359                 }
1360                 break;
1361 #endif /* SOL_RAW */
1362         }
1363
1364         /* default arg printing */
1365
1366         if (verbose(tcp)) {
1367                 if (len == sizeof(int)) {
1368                         printnum_int(tcp, addr, "%d");
1369                 } else {
1370                         printstr(tcp, addr, len);
1371                 }
1372         } else {
1373                 tprintf("%#lx", addr);
1374         }
1375 done:
1376         tprintf(", %d", len);
1377 }
1378
1379 int
1380 sys_setsockopt(struct tcb *tcp)
1381 {
1382         if (entering(tcp)) {
1383                 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1384                                             tcp->u_arg[1], tcp->u_arg[2]);
1385                 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1386                                  tcp->u_arg[3], tcp->u_arg[4]);
1387         }
1388         return 0;
1389 }