blob: 2ed950de316eec5a2506260862b48b67ce209d39 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
Dmitry V. Levinb2fa2be2014-11-21 20:46:16 +000034#include <sys/uio.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/un.h>
36#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000037#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010038# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000039#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000040#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010041# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010043#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010044# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010045#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000047#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010049#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010050# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010052# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000055#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000057#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000058#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010059# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000060#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000061#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010062# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000063#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020064#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
65# include <bluetooth/bluetooth.h>
66# include <bluetooth/hci.h>
67# include <bluetooth/l2cap.h>
68# include <bluetooth/rfcomm.h>
69# include <bluetooth/sco.h>
70#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010072# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073#endif
74
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000075#include "xlat/domains.h"
76#include "xlat/addrfams.h"
77#include "xlat/socktypes.h"
78#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000079#ifndef SOCK_TYPE_MASK
80# define SOCK_TYPE_MASK 0xf
81#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000082
83#ifndef SOL_IP
84# define SOL_IP 0
85#endif
86#ifndef SOL_TCP
87# define SOL_TCP 6
88#endif
89#ifndef SOL_UDP
90# define SOL_UDP 17
91#endif
92#ifndef SOL_IPV6
93# define SOL_IPV6 41
94#endif
95#ifndef SOL_ICMPV6
96# define SOL_ICMPV6 58
97#endif
98#ifndef SOL_SCTP
99# define SOL_SCTP 132
100#endif
101#ifndef SOL_UDPLITE
102# define SOL_UDPLITE 136
103#endif
104#ifndef SOL_RAW
105# define SOL_RAW 255
106#endif
107#ifndef SOL_IPX
108# define SOL_IPX 256
109#endif
110#ifndef SOL_AX25
111# define SOL_AX25 257
112#endif
113#ifndef SOL_ATALK
114# define SOL_ATALK 258
115#endif
116#ifndef SOL_NETROM
117# define SOL_NETROM 259
118#endif
119#ifndef SOL_ROSE
120# define SOL_ROSE 260
121#endif
122#ifndef SOL_DECNET
123# define SOL_DECNET 261
124#endif
125#ifndef SOL_X25
126# define SOL_X25 262
127#endif
128#ifndef SOL_PACKET
129# define SOL_PACKET 263
130#endif
131#ifndef SOL_ATM
132# define SOL_ATM 264
133#endif
134#ifndef SOL_AAL
135# define SOL_AAL 265
136#endif
137#ifndef SOL_IRDA
138# define SOL_IRDA 266
139#endif
140#ifndef SOL_NETBEUI
141# define SOL_NETBEUI 267
142#endif
143#ifndef SOL_LLC
144# define SOL_LLC 268
145#endif
146#ifndef SOL_DCCP
147# define SOL_DCCP 269
148#endif
149#ifndef SOL_NETLINK
150# define SOL_NETLINK 270
151#endif
152#ifndef SOL_TIPC
153# define SOL_TIPC 271
154#endif
155#ifndef SOL_RXRPC
156# define SOL_RXRPC 272
157#endif
158#ifndef SOL_PPPOL2TP
159# define SOL_PPPOL2TP 273
160#endif
161#ifndef SOL_BLUETOOTH
162# define SOL_BLUETOOTH 274
163#endif
164#ifndef SOL_PNPIPE
165# define SOL_PNPIPE 275
166#endif
167#ifndef SOL_RDS
168# define SOL_RDS 276
169#endif
170#ifndef SOL_IUCV
171# define SOL_IUCV 277
172#endif
173#ifndef SOL_CAIF
174# define SOL_CAIF 278
175#endif
176#ifndef SOL_ALG
177# define SOL_ALG 279
178#endif
179#ifndef SOL_NFC
180# define SOL_NFC 280
181#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000182#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000183
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000184#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900185
186#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +0000187# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
188# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
189# endif
190# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900191#endif
192
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200193#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
194# include "xlat/bt_protocols.h"
195#endif
196
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000197#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000198
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000199#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000200# include "xlat/af_packet_types.h"
201#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000202
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000204printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000206 union {
207 char pad[128];
208 struct sockaddr sa;
209 struct sockaddr_in sin;
210 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000211#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000212 struct sockaddr_in6 sa6;
213#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100214#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000215 struct sockaddr_ipx sipx;
216#endif
217#ifdef AF_PACKET
218 struct sockaddr_ll ll;
219#endif
220#ifdef AF_NETLINK
221 struct sockaddr_nl nl;
222#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200223#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
224 struct sockaddr_hci hci;
225 struct sockaddr_l2 l2;
226 struct sockaddr_rc rc;
227 struct sockaddr_sco sco;
228#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000229 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000230 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231
232 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200233 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 return;
235 }
236 if (!verbose(tcp)) {
237 tprintf("%#lx", addr);
238 return;
239 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000240
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000241 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000242 addrlen = sizeof(addrbuf);
243
244 memset(&addrbuf, 0, sizeof(addrbuf));
245 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200246 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247 return;
248 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000249 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000250
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200251 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000252 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200253 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000254
255 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000257 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200258 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000260 tprints("sun_path=");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000261 print_quoted_string(addrbuf.sau.sun_path,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000262 sizeof(addrbuf.sau.sun_path) + 1,
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000263 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000264 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000265 tprints("sun_path=@");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000266 print_quoted_string(addrbuf.sau.sun_path + 1,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000267 sizeof(addrbuf.sau.sun_path),
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000268 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000269 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 break;
271 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000272 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000273 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000275#ifdef HAVE_INET_NTOP
276 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000277 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000278 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
279 ntohs(addrbuf.sa6.sin6_port), string_addr,
280 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000281#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000282 {
283#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200284 int numericscope = 0;
285 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
286 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
287 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000288
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200289 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
290 numericscope++;
Dmitry V. Levin0e9d5942015-01-24 20:23:02 +0000291 else {
292 tprints(", sin6_scope_id=if_nametoindex(");
293 print_quoted_string(scopebuf,
294 sizeof(scopebuf),
295 QUOTE_0_TERMINATED);
296 tprints(")");
297 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200298 } else
299 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000300
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200301 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000302#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200303 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000304 }
305#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200306 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000307#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100308#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000310 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000312 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000313 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314 /* Yes, I know, this does not look too
315 * strace-ish, but otherwise the IPX
316 * addresses just look monstrous...
317 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000318 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000320 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200321 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000322 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
323 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 }
325 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100326#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000327#ifdef AF_PACKET
328 case AF_PACKET:
329 {
330 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000331 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000332 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000333 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000334 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000335 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000336 addrbuf.ll.sll_halen,
337 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200338 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000339 tprintf("%02x", addrbuf.ll.sll_addr[i]);
340 }
341 break;
342
Denys Vlasenko84703742012-02-25 02:38:52 +0100343#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000344#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000345 case AF_NETLINK:
346 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
347 break;
348#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200349#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
350 case AF_BLUETOOTH:
351 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
352 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
353 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
354 "{hci_dev=htobs(%d)}",
355 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
356 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
357 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
358 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
359 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
360 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
361 addrbuf.rc.rc_channel,
362 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
363 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
364 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
365 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
366 btohs(addrbuf.hci.hci_dev));
367 break;
368#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000370 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371
372 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200373 tprints("sa_data=");
Dmitry V. Levind0dceaf2015-01-30 13:36:49 +0000374 print_quoted_string(addrbuf.sa.sa_data,
375 sizeof(addrbuf.sa.sa_data), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376 break;
377 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200378 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379}
380
381#if HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000382# ifndef SCM_SECURITY
383# define SCM_SECURITY 0x03
384# endif
385# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000386
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000387#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
388struct cmsghdr32 {
389 uint32_t cmsg_len;
390 int cmsg_level;
391 int cmsg_type;
392};
393#endif
394
395typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000396 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000397 struct cmsghdr *cmsg;
398#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
399 struct cmsghdr32 *cmsg32;
400#endif
401} union_cmsghdr;
402
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000403static bool
404print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000405{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000406 if (cmsg_size + sizeof(int) > cmsg_len)
407 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000408
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000409 int *fds = (int *) (ptr + cmsg_size);
410 bool seen = false;
411
412 tprints(", [");
413 while ((char *) fds < (ptr + cmsg_len)) {
414 if (seen)
415 tprints(", ");
416 else
417 seen = true;
418 printfd(tcp, *fds++);
419 }
420 tprints("]}");
421 return true;
422}
423
424static bool
425print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
426{
427 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
428 return false;
429
430 const struct ucred *uc = (void *) (ptr + cmsg_size);
431
432 tprintf(", {pid=%u, uid=%u, gid=%u}}",
433 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
434 return true;
435}
436
437static bool
438print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
439{
440 if (cmsg_size + sizeof(char) > cmsg_len)
441 return false;
442
443 const char *label = (const char *) (ptr + cmsg_size);
444 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000445
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000446 tprints(", ");
447 print_quoted_string(label, label_len, 0);
448 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000449
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000450 return true;
451}
452
453static void
454printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
455{
456 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000457#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
458 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
459#endif
460 sizeof(struct cmsghdr);
461
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000462 char *buf = len < cmsg_size ? NULL : malloc(len);
463 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000464 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000465 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000466 return;
467 }
468
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000469 union_cmsghdr u = { .ptr = buf };
470
471 tprints(", [");
472 while (len >= cmsg_size) {
473 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000474#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000475 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000476#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000477 u.cmsg->cmsg_len;
478 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000479#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000480 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000481#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000482 u.cmsg->cmsg_level;
483 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000484#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000485 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000486#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000487 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000488
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000489 if (u.ptr != buf)
490 tprints(", ");
491 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
492 printxval(socketlayers, cmsg_level, "SOL_???");
493 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000494
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000495 if (cmsg_len > len)
496 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000497
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000498 if (cmsg_level == SOL_SOCKET) {
499 printxval(scmvals, cmsg_type, "SCM_???");
500 switch (cmsg_type) {
501 case SCM_RIGHTS:
502 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
503 goto next_cmsg;
504 break;
505 case SCM_CREDENTIALS:
506 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
507 goto next_cmsg;
508 break;
509 case SCM_SECURITY:
510 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
511 goto next_cmsg;
512 break;
Roland McGrath50770822004-10-06 22:11:51 +0000513 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000514 } else {
515 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000516 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000517 tprints(", ...}");
518next_cmsg:
519 if (cmsg_len < cmsg_size) {
520 len -= cmsg_size;
521 break;
Roland McGrath50770822004-10-06 22:11:51 +0000522 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000523 cmsg_len = (cmsg_len + current_wordsize - 1) &
524 (size_t) ~(current_wordsize - 1);
525 if (cmsg_len >= len) {
526 len = 0;
527 break;
528 }
529 u.ptr += cmsg_len;
530 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000531 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000532 if (len)
533 tprints(", ...");
534 tprints("]");
535 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000536}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537
538static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200539do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100540{
541 tprintf("{msg_name(%d)=", msg->msg_namelen);
542 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
543
544 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200545 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
546 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100547
548#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
549 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
550 if (msg->msg_controllen)
551 printcmsghdr(tcp, (unsigned long) msg->msg_control,
552 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200553 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100554 printflags(msg_flags, msg->msg_flags, "MSG_???");
555#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
556 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
557 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
558#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200559 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100560}
561
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100562struct msghdr32 {
563 uint32_t /* void* */ msg_name;
564 uint32_t /* socklen_t */msg_namelen;
565 uint32_t /* iovec* */ msg_iov;
566 uint32_t /* size_t */ msg_iovlen;
567 uint32_t /* void* */ msg_control;
568 uint32_t /* size_t */ msg_controllen;
569 uint32_t /* int */ msg_flags;
570};
571struct mmsghdr32 {
572 struct msghdr32 msg_hdr;
573 uint32_t /* unsigned */ msg_len;
574};
575
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900576#ifndef HAVE_STRUCT_MMSGHDR
577struct mmsghdr {
578 struct msghdr msg_hdr;
579 unsigned msg_len;
580};
581#endif
582
Masatake YAMATOb2485432014-11-07 01:23:24 +0900583#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
584static void
585copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
586{
587 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
588 to_msg->msg_namelen = from_msg32->msg_namelen;
589 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
590 to_msg->msg_iovlen = from_msg32->msg_iovlen;
591 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
592 to_msg->msg_controllen = from_msg32->msg_controllen;
593 to_msg->msg_flags = from_msg32->msg_flags;
594}
595#endif
596
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900597static bool
598extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
599{
600#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
601 if (current_wordsize == 4) {
602 struct msghdr32 msg32;
603
604 if (umove(tcp, addr, &msg32) < 0)
605 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900606 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900607 } else
608#endif
609 if (umove(tcp, addr, msg) < 0)
610 return false;
611 return true;
612}
613
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900614static bool
615extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
616{
617#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
618 if (current_wordsize == 4) {
619 struct mmsghdr32 mmsg32;
620
621 addr += sizeof(struct mmsghdr32) * idx;
622 if (umove(tcp, addr, &mmsg32) < 0)
623 return false;
624
625 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
626 mmsg->msg_len = mmsg32.msg_len;
627 } else
628#endif
629 {
630 addr += sizeof(*mmsg) * idx;
631 if (umove(tcp, addr, mmsg) < 0)
632 return false;
633 }
634 return true;
635}
636
Andreas Schwab0873f292010-02-12 21:39:12 +0100637static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200638printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639{
640 struct msghdr msg;
641
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000642 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900643 do_msghdr(tcp, &msg, data_size);
644 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000645 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900646}
647
648void
649dumpiov_in_msghdr(struct tcb *tcp, long addr)
650{
651 struct msghdr msg;
652
653 if (extractmsghdr(tcp, addr, &msg))
654 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655}
656
Andreas Schwab0873f292010-02-12 21:39:12 +0100657static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000658printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100659{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900660 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100661
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900662 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
663 tprints("{");
664 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
665 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100666 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900667 else
668 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100669}
Andreas Schwab0873f292010-02-12 21:39:12 +0100670
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000671static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000672decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000673{
674 /* mmsgvec */
675 if (syserror(tcp)) {
676 tprintf("%#lx", tcp->u_arg[1]);
677 } else {
678 unsigned int len = tcp->u_rval;
679 unsigned int i;
680
681 tprints("{");
682 for (i = 0; i < len; ++i) {
683 if (i)
684 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000685 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000686 }
687 tprints("}");
688 }
689 /* vlen */
690 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
691 /* flags */
692 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
693}
694
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900695void
696dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
697{
698 unsigned int len = tcp->u_rval;
699 unsigned int i;
700 struct mmsghdr mmsg;
701
702 for (i = 0; i < len; ++i) {
703 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
704 tprintf(" = %lu buffers in vector %u\n",
705 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
706 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
707 (long)mmsg.msg_hdr.msg_iov);
708 }
709 }
710}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711#endif /* HAVE_SENDMSG */
712
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000713/*
714 * low bits of the socket type define real socket type,
715 * other bits are socket type flags.
716 */
717static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000718tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000719{
720 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
721
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200722 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200723 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000724 flags &= ~SOCK_TYPE_MASK;
725 if (!flags)
726 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200727 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000728 }
729 printflags(sock_type_flags, flags, "SOCK_???");
730}
731
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000732SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733{
734 if (entering(tcp)) {
735 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200736 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000737 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200738 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 switch (tcp->u_arg[0]) {
740 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000741#ifdef PF_INET6
742 case PF_INET6:
743#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900744 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000745 break;
746#ifdef PF_IPX
747 case PF_IPX:
748 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200749 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200751 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752 break;
753#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900754#ifdef PF_NETLINK
755 case PF_NETLINK:
756 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
757 break;
758#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200759#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
760 case PF_BLUETOOTH:
761 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
762 break;
763#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 default:
765 tprintf("%lu", tcp->u_arg[2]);
766 break;
767 }
768 }
769 return 0;
770}
771
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000772SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000773{
774 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800775 printfd(tcp, tcp->u_arg[0]);
776 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000777 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 tprintf(", %lu", tcp->u_arg[2]);
779 }
780 return 0;
781}
782
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000783SYS_FUNC(connect)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000784{
785 return sys_bind(tcp);
786}
787
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000788SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789{
790 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800791 printfd(tcp, tcp->u_arg[0]);
792 tprints(", ");
793 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794 }
795 return 0;
796}
797
Paolo Bonzini705ff102009-08-14 12:34:05 +0200798static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000799do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800{
801 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800802 printfd(tcp, tcp->u_arg[0]);
803 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200804 return 0;
805 }
806 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 tprintf("%#lx, NULL", tcp->u_arg[1]);
808 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000809 int len;
810 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200811 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812 tprintf("%#lx", tcp->u_arg[1]);
813 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000814 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200816 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000817 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200819 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200820 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200821 printflags(sock_type_flags, tcp->u_arg[flags_arg],
822 "SOCK_???");
823 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824 return 0;
825}
826
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000827SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200828{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000829 do_sockname(tcp, -1);
830 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200831}
832
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000833SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200834{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000835 do_sockname(tcp, 3);
836 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200837}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200838
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000839SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840{
841 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800842 printfd(tcp, tcp->u_arg[0]);
843 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
845 tprintf(", %lu, ", tcp->u_arg[2]);
846 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000847 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848 }
849 return 0;
850}
851
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000852SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853{
854 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800855 printfd(tcp, tcp->u_arg[0]);
856 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
858 tprintf(", %lu, ", tcp->u_arg[2]);
859 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000860 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000863 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864 /* to length */
865 tprintf(", %lu", tcp->u_arg[5]);
866 }
867 return 0;
868}
869
870#ifdef HAVE_SENDMSG
871
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000872SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873{
874 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800875 printfd(tcp, tcp->u_arg[0]);
876 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000877 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200879 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000880 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881 }
882 return 0;
883}
884
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000885SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000886{
887 if (entering(tcp)) {
888 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800889 printfd(tcp, tcp->u_arg[0]);
890 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000891 if (!verbose(tcp)) {
892 tprintf("%#lx, %u, ",
893 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
894 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
895 }
896 } else {
897 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000898 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000899 }
900 return 0;
901}
902
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000903#endif /* HAVE_SENDMSG */
904
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000905SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000906{
907 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800908 printfd(tcp, tcp->u_arg[0]);
909 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910 } else {
911 if (syserror(tcp))
912 tprintf("%#lx", tcp->u_arg[1]);
913 else
914 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
915
916 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000917 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000918 }
919 return 0;
920}
921
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000922SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923{
924 int fromlen;
925
926 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800927 printfd(tcp, tcp->u_arg[0]);
928 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929 } else {
930 if (syserror(tcp)) {
931 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
932 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
933 tcp->u_arg[4], tcp->u_arg[5]);
934 return 0;
935 }
936 /* buf */
937 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
938 /* len */
939 tprintf(", %lu, ", tcp->u_arg[2]);
940 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000941 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942 /* from address, len */
943 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
944 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200945 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946 else
947 tprintf(", %#lx", tcp->u_arg[4]);
948 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200949 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 else
951 tprintf(", %#lx", tcp->u_arg[5]);
952 return 0;
953 }
954 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200955 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 return 0;
957 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200958 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000959 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960 /* from length */
961 tprintf(", [%u]", fromlen);
962 }
963 return 0;
964}
965
966#ifdef HAVE_SENDMSG
967
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000968SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969{
970 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800971 printfd(tcp, tcp->u_arg[0]);
972 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000974 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 tprintf("%#lx", tcp->u_arg[1]);
976 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200977 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200979 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000980 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 }
982 return 0;
983}
984
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000985SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100986{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100987 /* +5 chars are for "left " prefix */
988 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400989
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100990 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800991 printfd(tcp, tcp->u_arg[0]);
992 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400993 if (verbose(tcp)) {
994 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100995 /* Abusing tcp->auxstr as temp storage.
996 * Will be used and freed on syscall exit.
997 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400998 tcp->auxstr = strdup(str);
999 } else {
1000 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1001 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001002 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001003 print_timespec(tcp, tcp->u_arg[4]);
1004 }
1005 return 0;
1006 } else {
1007 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001008 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001009 /* timeout on entrance */
1010 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1011 free((void *) tcp->auxstr);
1012 tcp->auxstr = NULL;
1013 }
1014 if (syserror(tcp))
1015 return 0;
1016 if (tcp->u_rval == 0) {
1017 tcp->auxstr = "Timeout";
1018 return RVAL_STR;
1019 }
1020 if (!verbose(tcp))
1021 return 0;
1022 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001023 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001024 tcp->auxstr = str;
1025 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001026 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001027}
Andreas Schwab0873f292010-02-12 21:39:12 +01001028
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029#endif /* HAVE_SENDMSG */
1030
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001031#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001032
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001033SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034{
1035 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001036 printfd(tcp, tcp->u_arg[0]);
1037 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001038 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039 }
1040 return 0;
1041}
1042
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001043SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001045 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046}
1047
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001048static int
1049do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 if (exiting(tcp)) {
1052 if (syserror(tcp)) {
1053 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001054 } else {
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +00001055#ifdef HAVE_GETRVAL2
1056 if (flags_arg < 0) {
1057 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1058 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059#endif
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +00001060 {
1061 int fds[2];
1062
1063 if (umove(tcp, tcp->u_arg[0], &fds) < 0)
1064 tprintf("%#lx", tcp->u_arg[0]);
1065 else
1066 tprintf("[%u, %u]", fds[0], fds[1]);
1067 }
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001068 }
1069 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001070 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001071 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1072 }
1073 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074 return 0;
1075}
1076
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001077SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001078{
1079 return do_pipe(tcp, -1);
1080}
1081
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001082SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001083{
1084 return do_pipe(tcp, 1);
1085}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001086
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001087SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090
1091 if (entering(tcp)) {
1092 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001093 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001094 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001095 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096 } else {
1097 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001098 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 return 0;
1100 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +01001101 if (umoven(tcp, tcp->u_arg[3], sizeof fds, fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001102 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 else
1104 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 }
1106 return 0;
1107}
1108
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001109#include "xlat/sockoptions.h"
1110#include "xlat/sockipoptions.h"
1111#include "xlat/sockipv6options.h"
1112#include "xlat/sockipxoptions.h"
1113#include "xlat/sockrawoptions.h"
1114#include "xlat/sockpacketoptions.h"
1115#include "xlat/socksctpoptions.h"
1116#include "xlat/socktcpoptions.h"
1117
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001118static void
1119print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001121 printfd(tcp, fd);
1122 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001123 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001124 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001125
John Hughes38ae88d2002-05-23 11:48:58 +00001126 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001127 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001128 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001129 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001130 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001131 printxval(sockipoptions, name, "IP_???");
1132 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001133 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001134 printxval(sockipv6options, name, "IPV6_???");
1135 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001136 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001137 printxval(sockipxoptions, name, "IPX_???");
1138 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001139 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001140 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001141 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001142 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001143 printxval(socktcpoptions, name, "TCP_???");
1144 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001145 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001146 printxval(socksctpoptions, name, "SCTP_???");
1147 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001148 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001149 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001150 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001151
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001152 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001153
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001154 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001155 tprintf("%u", name);
1156 }
1157
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001158 tprints(", ");
1159}
1160
1161#ifdef SO_LINGER
1162static void
1163print_linger(struct tcb *tcp, long addr, int len)
1164{
1165 struct linger linger;
1166
1167 if (len != sizeof(linger) ||
1168 umove(tcp, addr, &linger) < 0) {
1169 tprintf("%#lx", addr);
1170 return;
1171 }
1172
1173 tprintf("{onoff=%d, linger=%d}",
1174 linger.l_onoff,
1175 linger.l_linger);
1176}
1177#endif /* SO_LINGER */
1178
1179#ifdef SO_PEERCRED
1180static void
1181print_ucred(struct tcb *tcp, long addr, int len)
1182{
1183 struct ucred uc;
1184
1185 if (len != sizeof(uc) ||
1186 umove(tcp, addr, &uc) < 0) {
1187 tprintf("%#lx", addr);
1188 } else {
1189 tprintf("{pid=%u, uid=%u, gid=%u}",
1190 (unsigned) uc.pid,
1191 (unsigned) uc.uid,
1192 (unsigned) uc.gid);
1193 }
1194}
1195#endif /* SO_PEERCRED */
1196
1197#ifdef PACKET_STATISTICS
1198static void
1199print_tpacket_stats(struct tcb *tcp, long addr, int len)
1200{
1201 struct tpacket_stats stats;
1202
1203 if (len != sizeof(stats) ||
1204 umove(tcp, addr, &stats) < 0) {
1205 tprintf("%#lx", addr);
1206 } else {
1207 tprintf("{packets=%u, drops=%u}",
1208 stats.tp_packets,
1209 stats.tp_drops);
1210 }
1211}
1212#endif /* PACKET_STATISTICS */
1213
1214#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001215# include "xlat/icmpfilterflags.h"
1216
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001217static void
1218print_icmp_filter(struct tcb *tcp, long addr, int len)
1219{
1220 struct icmp_filter filter;
1221
1222 if (len != sizeof(filter) ||
1223 umove(tcp, addr, &filter) < 0) {
1224 tprintf("%#lx", addr);
1225 return;
1226 }
1227
1228 tprints("~(");
1229 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1230 tprints(")");
1231}
1232#endif /* ICMP_FILTER */
1233
1234static void
1235print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1236{
1237 if (addr && verbose(tcp))
1238 switch (level) {
1239 case SOL_SOCKET:
1240 switch (name) {
1241#ifdef SO_LINGER
1242 case SO_LINGER:
1243 print_linger(tcp, addr, len);
1244 goto done;
1245#endif
1246#ifdef SO_PEERCRED
1247 case SO_PEERCRED:
1248 print_ucred(tcp, addr, len);
1249 goto done;
1250#endif
1251 }
1252 break;
1253
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001254 case SOL_PACKET:
1255 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001256#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001257 case PACKET_STATISTICS:
1258 print_tpacket_stats(tcp, addr, len);
1259 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001260#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001261 }
1262 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001263
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001264 case SOL_RAW:
1265 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001266#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001267 case ICMP_FILTER:
1268 print_icmp_filter(tcp, addr, len);
1269 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001270#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001271 }
1272 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001273 }
1274
John Hughes38ae88d2002-05-23 11:48:58 +00001275 /* default arg printing */
1276
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001277 if (verbose(tcp)) {
1278 if (len == sizeof(int)) {
1279 printnum_int(tcp, addr, "%d");
1280 } else {
1281 printstr(tcp, addr, len);
1282 }
1283 } else {
1284 tprintf("%#lx", addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001285 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001286done:
1287 tprintf(", [%d]", len);
1288}
1289
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001290SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001291{
1292 if (entering(tcp)) {
1293 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1294 tcp->u_arg[1], tcp->u_arg[2]);
1295 } else {
1296 int len;
1297
1298 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1299 tprintf("%#lx, %#lx",
1300 tcp->u_arg[3], tcp->u_arg[4]);
1301 } else {
1302 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1303 tcp->u_arg[3], len);
1304 }
John Hughes38ae88d2002-05-23 11:48:58 +00001305 }
1306 return 0;
1307}
1308
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001309#ifdef MCAST_JOIN_GROUP
1310static void
1311print_group_req(struct tcb *tcp, long addr, int len)
1312{
1313 struct group_req greq;
1314
1315 if (len != sizeof(greq) ||
1316 umove(tcp, addr, &greq) < 0) {
1317 tprintf("%#lx", addr);
1318 return;
1319 }
1320
1321 union {
1322 struct sockaddr *sa;
1323 struct sockaddr_in *sin;
1324#ifdef HAVE_INET_NTOP
1325 struct sockaddr_in6 *sin6;
1326#endif
1327 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1328#ifdef HAVE_INET_NTOP
1329 char str[INET6_ADDRSTRLEN];
1330#endif
1331
1332 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1333 printxval(addrfams, a.sa->sa_family, "AF_???");
1334
1335 switch (a.sa->sa_family) {
1336 case AF_INET:
1337 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1338 ntohs(a.sin->sin_port),
1339 inet_ntoa(a.sin->sin_addr));
1340 return;
1341#ifdef HAVE_INET_NTOP
1342 case AF_INET6:
1343 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1344 break;
1345 tprintf(", sin6_port=htons(%u)"
1346 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1347 ntohs(a.sin6->sin6_port), str);
1348 return;
1349#endif /* HAVE_INET_NTOP */
1350 }
1351
1352 tprints(", sa_data=");
1353 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1354 tprintf("}}");
1355
1356}
1357#endif /* MCAST_JOIN_GROUP */
1358
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001359#ifdef PACKET_RX_RING
1360static void
1361print_tpacket_req(struct tcb *tcp, long addr, int len)
1362{
1363 struct tpacket_req req;
1364
1365 if (len != sizeof(req) ||
1366 umove(tcp, addr, &req) < 0) {
1367 tprintf("%#lx", addr);
1368 } else {
1369 tprintf("{block_size=%u, block_nr=%u, "
1370 "frame_size=%u, frame_nr=%u}",
1371 req.tp_block_size,
1372 req.tp_block_nr,
1373 req.tp_frame_size,
1374 req.tp_frame_nr);
1375 }
1376}
1377#endif /* PACKET_RX_RING */
1378
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001379#ifdef PACKET_ADD_MEMBERSHIP
1380# include "xlat/packet_mreq_type.h"
1381
1382static void
1383print_packet_mreq(struct tcb *tcp, long addr, int len)
1384{
1385 struct packet_mreq mreq;
1386
1387 if (len != sizeof(mreq) ||
1388 umove(tcp, addr, &mreq) < 0) {
1389 tprintf("%#lx", addr);
1390 } else {
1391 unsigned int i;
1392
1393 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1394 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1395 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1396 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1397 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1398 for (i = 0; i < mreq.mr_alen; ++i)
1399 tprintf("%02x", mreq.mr_address[i]);
1400 tprints("}");
1401 }
1402}
1403#endif /* PACKET_ADD_MEMBERSHIP */
1404
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001405static void
1406print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1407{
1408 if (addr && verbose(tcp))
1409 switch (level) {
1410 case SOL_SOCKET:
1411 switch (name) {
1412#ifdef SO_LINGER
1413 case SO_LINGER:
1414 print_linger(tcp, addr, len);
1415 goto done;
1416#endif
1417 }
1418 break;
1419
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001420 case SOL_IP:
1421 switch (name) {
1422#ifdef MCAST_JOIN_GROUP
1423 case MCAST_JOIN_GROUP:
1424 case MCAST_LEAVE_GROUP:
1425 print_group_req(tcp, addr, len);
1426 goto done;
1427#endif /* MCAST_JOIN_GROUP */
1428 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001429 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001430
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001431 case SOL_PACKET:
1432 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001433#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001434 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001435# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001436 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001437# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001438 print_tpacket_req(tcp, addr, len);
1439 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001440#endif /* PACKET_RX_RING */
1441#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001442 case PACKET_ADD_MEMBERSHIP:
1443 case PACKET_DROP_MEMBERSHIP:
1444 print_packet_mreq(tcp, addr, len);
1445 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001446#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001447 }
1448 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001449
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001450 case SOL_RAW:
1451 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001452#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001453 case ICMP_FILTER:
1454 print_icmp_filter(tcp, addr, len);
1455 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001456#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001457 }
1458 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001459 }
1460
1461 /* default arg printing */
1462
1463 if (verbose(tcp)) {
1464 if (len == sizeof(int)) {
1465 printnum_int(tcp, addr, "%d");
1466 } else {
1467 printstr(tcp, addr, len);
1468 }
1469 } else {
1470 tprintf("%#lx", addr);
1471 }
1472done:
1473 tprintf(", %d", len);
1474}
1475
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001476SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477{
1478 if (entering(tcp)) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001479 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1480 tcp->u_arg[1], tcp->u_arg[2]);
1481 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1482 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001483 }
1484 return 0;
1485}