blob: 0f88c4295d9cd0d05a5e59c6af3b5f7550165da3 [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>
Wichert Akkermanf1850652001-02-16 20:29:03 +000036#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010037# define in6_addr in6_addr_libc
38# define ipv6_mreq ipv6_mreq_libc
39# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000040#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010043# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000044#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000045#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010046# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000047#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010048#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010049# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010050#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000052#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010054#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010055# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010057# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Denys Vlasenko99aa1812013-02-08 18:49:06 +010060#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010061# 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
Wichert Akkerman2f473da1999-11-01 19:53:31 +000080#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000081
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000082#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010083# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010086# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000088#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010089# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020091#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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010099# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100#endif
101
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000102#include "xlat/domains.h"
103#include "xlat/addrfams.h"
104#include "xlat/socktypes.h"
105#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000106#ifndef SOCK_TYPE_MASK
107# define SOCK_TYPE_MASK 0xf
108#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000109#include "xlat/socketlayers.h"
John Hughes93f7fcc2002-05-22 15:46:49 +0000110/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900111 falls into "inet_protocols" array below!!!! This is intended!!! ***/
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000112#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900113
114#ifdef PF_NETLINK
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000115#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900116#endif
117
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200118#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
119# include "xlat/bt_protocols.h"
120#endif
121
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000122#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000123#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100125#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000126#define SOL_IP IPPROTO_IP
127#endif
128
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000130#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#endif /* SOL_IP */
132
Roland McGrath4f6ba692004-08-31 07:01:26 +0000133#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000134#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000135#endif /* SOL_IPV6 */
136
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000138#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#endif /* SOL_IPX */
140
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000141#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000142#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000143#endif /* SOL_RAW */
144
145#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000146#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000147#endif /* SOL_PACKET */
148
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100149#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000150#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100151#endif
152
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100153#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000154#define SOL_TCP IPPROTO_TCP
155#endif
156
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000158#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159#endif /* SOL_TCP */
160
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000161#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000162#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000163#endif /* SOL_RAW */
164
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000165#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000166#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000167#endif /* defined(AF_PACKET) */
168
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000170printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000172 union {
173 char pad[128];
174 struct sockaddr sa;
175 struct sockaddr_in sin;
176 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000177#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000178 struct sockaddr_in6 sa6;
179#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100180#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000181 struct sockaddr_ipx sipx;
182#endif
183#ifdef AF_PACKET
184 struct sockaddr_ll ll;
185#endif
186#ifdef AF_NETLINK
187 struct sockaddr_nl nl;
188#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200189#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
190 struct sockaddr_hci hci;
191 struct sockaddr_l2 l2;
192 struct sockaddr_rc rc;
193 struct sockaddr_sco sco;
194#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000195 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000196 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197
198 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200199 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200 return;
201 }
202 if (!verbose(tcp)) {
203 tprintf("%#lx", addr);
204 return;
205 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000206
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000207 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000208 addrlen = sizeof(addrbuf);
209
210 memset(&addrbuf, 0, sizeof(addrbuf));
211 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200212 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213 return;
214 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000215 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000216
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200217 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000218 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200219 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220
221 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000223 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200224 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000225 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000226 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000227 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000228 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000229 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000230 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000231 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232 break;
233 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000234 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000235 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000237#ifdef HAVE_INET_NTOP
238 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000239 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000240 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
241 ntohs(addrbuf.sa6.sin6_port), string_addr,
242 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000243#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000244 {
245#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200246 int numericscope = 0;
247 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
248 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
249 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000250
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200251 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
252 numericscope++;
253 else
254 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
255 } else
256 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000257
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200258 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000259#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200260 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000261 }
262#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000264#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100265#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000267 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000269 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000270 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271 /* Yes, I know, this does not look too
272 * strace-ish, but otherwise the IPX
273 * addresses just look monstrous...
274 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000275 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000277 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200278 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000279 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
280 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281 }
282 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100283#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000284#ifdef AF_PACKET
285 case AF_PACKET:
286 {
287 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000288 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000289 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000290 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000291 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000292 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000293 addrbuf.ll.sll_halen,
294 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200295 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296 tprintf("%02x", addrbuf.ll.sll_addr[i]);
297 }
298 break;
299
Denys Vlasenko84703742012-02-25 02:38:52 +0100300#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000301#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000302 case AF_NETLINK:
303 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
304 break;
305#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200306#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
307 case AF_BLUETOOTH:
308 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
309 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
310 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
311 "{hci_dev=htobs(%d)}",
312 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
313 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
314 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
315 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
316 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
317 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
318 addrbuf.rc.rc_channel,
319 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
320 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
321 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
322 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
323 btohs(addrbuf.hci.hci_dev));
324 break;
325#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000327 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328
329 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000332 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 break;
334 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200335 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336}
337
338#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000339#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000340
341static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000342printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000343{
Roland McGrathaa524c82005-06-01 19:22:06 +0000344 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
345 NULL : malloc(len);
346 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000347 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000348 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000349 return;
350 }
351
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000352 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000353 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000355
Roland McGrathaa524c82005-06-01 19:22:06 +0000356 if (cmsg->cmsg_level == SOL_SOCKET) {
357 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000358
Roland McGrathaa524c82005-06-01 19:22:06 +0000359 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
360 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
361
362 if (cmsg->cmsg_type == SCM_RIGHTS
363 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200364 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000365 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000366
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200367 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000368 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000369 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200370 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000371 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000372 first = 0;
373 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000375 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000376 return;
377 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000378 if (cmsg->cmsg_type == SCM_CREDENTIALS
379 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200380 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000381
Roland McGrath50770822004-10-06 22:11:51 +0000382 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
383 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000384 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000385 return;
386 }
387 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000388 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200389 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000390}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391
392static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200393do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100394{
395 tprintf("{msg_name(%d)=", msg->msg_namelen);
396 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
397
398 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200399 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
400 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100401
402#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
403 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
404 if (msg->msg_controllen)
405 printcmsghdr(tcp, (unsigned long) msg->msg_control,
406 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200407 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100408 printflags(msg_flags, msg->msg_flags, "MSG_???");
409#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
410 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
411 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
412#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200413 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100414}
415
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100416struct msghdr32 {
417 uint32_t /* void* */ msg_name;
418 uint32_t /* socklen_t */msg_namelen;
419 uint32_t /* iovec* */ msg_iov;
420 uint32_t /* size_t */ msg_iovlen;
421 uint32_t /* void* */ msg_control;
422 uint32_t /* size_t */ msg_controllen;
423 uint32_t /* int */ msg_flags;
424};
425struct mmsghdr32 {
426 struct msghdr32 msg_hdr;
427 uint32_t /* unsigned */ msg_len;
428};
429
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900430#ifndef HAVE_STRUCT_MMSGHDR
431struct mmsghdr {
432 struct msghdr msg_hdr;
433 unsigned msg_len;
434};
435#endif
436
Masatake YAMATOb2485432014-11-07 01:23:24 +0900437#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
438static void
439copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
440{
441 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
442 to_msg->msg_namelen = from_msg32->msg_namelen;
443 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
444 to_msg->msg_iovlen = from_msg32->msg_iovlen;
445 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
446 to_msg->msg_controllen = from_msg32->msg_controllen;
447 to_msg->msg_flags = from_msg32->msg_flags;
448}
449#endif
450
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900451static bool
452extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
453{
454#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
455 if (current_wordsize == 4) {
456 struct msghdr32 msg32;
457
458 if (umove(tcp, addr, &msg32) < 0)
459 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900460 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900461 } else
462#endif
463 if (umove(tcp, addr, msg) < 0)
464 return false;
465 return true;
466}
467
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900468static bool
469extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
470{
471#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
472 if (current_wordsize == 4) {
473 struct mmsghdr32 mmsg32;
474
475 addr += sizeof(struct mmsghdr32) * idx;
476 if (umove(tcp, addr, &mmsg32) < 0)
477 return false;
478
479 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
480 mmsg->msg_len = mmsg32.msg_len;
481 } else
482#endif
483 {
484 addr += sizeof(*mmsg) * idx;
485 if (umove(tcp, addr, mmsg) < 0)
486 return false;
487 }
488 return true;
489}
490
Andreas Schwab0873f292010-02-12 21:39:12 +0100491static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200492printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493{
494 struct msghdr msg;
495
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900496 if (extractmsghdr(tcp, addr, &msg))
497 do_msghdr(tcp, &msg, data_size);
498 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000499 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900500}
501
502void
503dumpiov_in_msghdr(struct tcb *tcp, long addr)
504{
505 struct msghdr msg;
506
507 if (extractmsghdr(tcp, addr, &msg))
508 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509}
510
Andreas Schwab0873f292010-02-12 21:39:12 +0100511static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000512printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100513{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900514 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100515
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900516 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
517 tprints("{");
518 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
519 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100520 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900521 else
522 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100523}
Andreas Schwab0873f292010-02-12 21:39:12 +0100524
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000525static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000526decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000527{
528 /* mmsgvec */
529 if (syserror(tcp)) {
530 tprintf("%#lx", tcp->u_arg[1]);
531 } else {
532 unsigned int len = tcp->u_rval;
533 unsigned int i;
534
535 tprints("{");
536 for (i = 0; i < len; ++i) {
537 if (i)
538 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000539 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000540 }
541 tprints("}");
542 }
543 /* vlen */
544 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
545 /* flags */
546 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
547}
548
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900549void
550dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
551{
552 unsigned int len = tcp->u_rval;
553 unsigned int i;
554 struct mmsghdr mmsg;
555
556 for (i = 0; i < len; ++i) {
557 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
558 tprintf(" = %lu buffers in vector %u\n",
559 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
560 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
561 (long)mmsg.msg_hdr.msg_iov);
562 }
563 }
564}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565#endif /* HAVE_SENDMSG */
566
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000567/*
568 * low bits of the socket type define real socket type,
569 * other bits are socket type flags.
570 */
571static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000572tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000573{
574 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
575
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200576 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200577 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000578 flags &= ~SOCK_TYPE_MASK;
579 if (!flags)
580 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200581 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000582 }
583 printflags(sock_type_flags, flags, "SOCK_???");
584}
585
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000587sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588{
589 if (entering(tcp)) {
590 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000592 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200593 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594 switch (tcp->u_arg[0]) {
595 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000596#ifdef PF_INET6
597 case PF_INET6:
598#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900599 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 break;
601#ifdef PF_IPX
602 case PF_IPX:
603 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200604 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000605 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200606 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 break;
608#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900609#ifdef PF_NETLINK
610 case PF_NETLINK:
611 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
612 break;
613#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200614#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
615 case PF_BLUETOOTH:
616 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
617 break;
618#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 default:
620 tprintf("%lu", tcp->u_arg[2]);
621 break;
622 }
623 }
624 return 0;
625}
626
John Hughesbdf48f52001-03-06 15:08:09 +0000627int
Denys Vlasenko12014262011-05-30 14:00:14 +0200628sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629{
630 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800631 printfd(tcp, tcp->u_arg[0]);
632 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000633 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 tprintf(", %lu", tcp->u_arg[2]);
635 }
636 return 0;
637}
638
639int
Denys Vlasenko12014262011-05-30 14:00:14 +0200640sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641{
642 return sys_bind(tcp);
643}
644
645int
Denys Vlasenko12014262011-05-30 14:00:14 +0200646sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647{
648 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800649 printfd(tcp, tcp->u_arg[0]);
650 tprints(", ");
651 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652 }
653 return 0;
654}
655
Paolo Bonzini705ff102009-08-14 12:34:05 +0200656static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000657do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658{
659 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800660 printfd(tcp, tcp->u_arg[0]);
661 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200662 return 0;
663 }
664 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 tprintf("%#lx, NULL", tcp->u_arg[1]);
666 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000667 int len;
668 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200669 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670 tprintf("%#lx", tcp->u_arg[1]);
671 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000672 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200674 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000675 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200677 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200678 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200679 printflags(sock_type_flags, tcp->u_arg[flags_arg],
680 "SOCK_???");
681 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682 return 0;
683}
684
685int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200686sys_accept(struct tcb *tcp)
687{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000688 do_sockname(tcp, -1);
689 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200690}
691
Paolo Bonzini705ff102009-08-14 12:34:05 +0200692int
693sys_accept4(struct tcb *tcp)
694{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000695 do_sockname(tcp, 3);
696 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200697}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200698
699int
Denys Vlasenko12014262011-05-30 14:00:14 +0200700sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701{
702 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800703 printfd(tcp, tcp->u_arg[0]);
704 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
706 tprintf(", %lu, ", tcp->u_arg[2]);
707 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000708 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709 }
710 return 0;
711}
712
713int
Denys Vlasenko12014262011-05-30 14:00:14 +0200714sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000715{
716 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800717 printfd(tcp, tcp->u_arg[0]);
718 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
720 tprintf(", %lu, ", tcp->u_arg[2]);
721 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000722 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200724 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000725 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 /* to length */
727 tprintf(", %lu", tcp->u_arg[5]);
728 }
729 return 0;
730}
731
732#ifdef HAVE_SENDMSG
733
734int
Denys Vlasenko12014262011-05-30 14:00:14 +0200735sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736{
737 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800738 printfd(tcp, tcp->u_arg[0]);
739 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000740 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200742 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000743 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744 }
745 return 0;
746}
747
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000748int
749sys_sendmmsg(struct tcb *tcp)
750{
751 if (entering(tcp)) {
752 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800753 printfd(tcp, tcp->u_arg[0]);
754 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000755 if (!verbose(tcp)) {
756 tprintf("%#lx, %u, ",
757 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
758 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
759 }
760 } else {
761 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000762 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000763 }
764 return 0;
765}
766
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767#endif /* HAVE_SENDMSG */
768
769int
Denys Vlasenko12014262011-05-30 14:00:14 +0200770sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771{
772 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800773 printfd(tcp, tcp->u_arg[0]);
774 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000775 } else {
776 if (syserror(tcp))
777 tprintf("%#lx", tcp->u_arg[1]);
778 else
779 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
780
781 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000782 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783 }
784 return 0;
785}
786
787int
Denys Vlasenko12014262011-05-30 14:00:14 +0200788sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789{
790 int fromlen;
791
792 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800793 printfd(tcp, tcp->u_arg[0]);
794 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795 } else {
796 if (syserror(tcp)) {
797 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
798 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
799 tcp->u_arg[4], tcp->u_arg[5]);
800 return 0;
801 }
802 /* buf */
803 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
804 /* len */
805 tprintf(", %lu, ", tcp->u_arg[2]);
806 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000807 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808 /* from address, len */
809 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
810 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200811 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812 else
813 tprintf(", %#lx", tcp->u_arg[4]);
814 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200815 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 else
817 tprintf(", %#lx", tcp->u_arg[5]);
818 return 0;
819 }
820 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200821 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822 return 0;
823 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200824 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000825 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826 /* from length */
827 tprintf(", [%u]", fromlen);
828 }
829 return 0;
830}
831
832#ifdef HAVE_SENDMSG
833
834int
Denys Vlasenko12014262011-05-30 14:00:14 +0200835sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836{
837 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800838 printfd(tcp, tcp->u_arg[0]);
839 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840 } else {
841 if (syserror(tcp) || !verbose(tcp))
842 tprintf("%#lx", tcp->u_arg[1]);
843 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200844 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200846 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000847 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848 }
849 return 0;
850}
851
Andreas Schwab0873f292010-02-12 21:39:12 +0100852int
853sys_recvmmsg(struct tcb *tcp)
854{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100855 /* +5 chars are for "left " prefix */
856 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400857
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100858 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800859 printfd(tcp, tcp->u_arg[0]);
860 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400861 if (verbose(tcp)) {
862 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100863 /* Abusing tcp->auxstr as temp storage.
864 * Will be used and freed on syscall exit.
865 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400866 tcp->auxstr = strdup(str);
867 } else {
868 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
869 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200870 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400871 print_timespec(tcp, tcp->u_arg[4]);
872 }
873 return 0;
874 } else {
875 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000876 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400877 /* timeout on entrance */
878 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
879 free((void *) tcp->auxstr);
880 tcp->auxstr = NULL;
881 }
882 if (syserror(tcp))
883 return 0;
884 if (tcp->u_rval == 0) {
885 tcp->auxstr = "Timeout";
886 return RVAL_STR;
887 }
888 if (!verbose(tcp))
889 return 0;
890 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100891 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400892 tcp->auxstr = str;
893 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100894 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100895}
Andreas Schwab0873f292010-02-12 21:39:12 +0100896
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000897#endif /* HAVE_SENDMSG */
898
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000899#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100900
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901int
Denys Vlasenko12014262011-05-30 14:00:14 +0200902sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000903{
904 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800905 printfd(tcp, tcp->u_arg[0]);
906 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100907 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000908 }
909 return 0;
910}
911
912int
Denys Vlasenko12014262011-05-30 14:00:14 +0200913sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000915 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916}
917
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000918static int
919do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000921 if (exiting(tcp)) {
922 if (syserror(tcp)) {
923 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000924 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100925#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000926 int fds[2];
927
928 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200929 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000930 else
931 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100932#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000933 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
934#else
935 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000937 }
938 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200939 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000940 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
941 }
942 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000943 return 0;
944}
945
946int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000947sys_pipe(struct tcb *tcp)
948{
949 return do_pipe(tcp, -1);
950}
951
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000952int
953sys_pipe2(struct tcb *tcp)
954{
955 return do_pipe(tcp, 1);
956}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000957
958int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000959sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962
963 if (entering(tcp)) {
964 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000966 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000967 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 } else {
969 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000970 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971 return 0;
972 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200974 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 else
976 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977 }
978 return 0;
979}
980
981int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000982sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983{
984 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800985 printfd(tcp, tcp->u_arg[0]);
986 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000987 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200988 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 switch (tcp->u_arg[1]) {
990 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 break;
993#ifdef SOL_IP
994 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996 break;
997#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000998#ifdef SOL_IPV6
999 case SOL_IPV6:
1000 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1001 break;
1002#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001003#ifdef SOL_IPX
1004 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006 break;
1007#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001008#ifdef SOL_PACKET
1009 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001010 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001011 break;
1012#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013#ifdef SOL_TCP
1014 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 break;
1017#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001018#ifdef SOL_SCTP
1019 case SOL_SCTP:
1020 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1021 break;
1022#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023
1024 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1025 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001026 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001027 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028 break;
1029 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001030 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001032 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001033 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001034 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001035 tcp->u_arg[3], tcp->u_arg[4]);
1036 return 0;
1037 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001038
1039 switch (tcp->u_arg[1]) {
1040 case SOL_SOCKET:
1041 switch (tcp->u_arg[2]) {
1042#ifdef SO_LINGER
1043 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001044 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001045 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001046 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001047 tcp->u_arg[3],
1048 &linger) < 0)
1049 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001050 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001051 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001052 linger.l_onoff,
1053 linger.l_linger,
1054 len);
1055 return 0;
1056 }
1057 break;
1058#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001059#ifdef SO_PEERCRED
1060 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001061 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001062 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001063 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001064 tcp->u_arg[3],
1065 &uc) < 0)
1066 break;
1067 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1068 "[%d]",
1069 (long)uc.pid,
1070 (long)uc.uid,
1071 (long)uc.gid,
1072 len);
1073 return 0;
1074 }
1075 break;
1076#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001077 }
1078 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001079 case SOL_PACKET:
1080 switch (tcp->u_arg[2]) {
1081#ifdef PACKET_STATISTICS
1082 case PACKET_STATISTICS:
1083 if (len == sizeof(struct tpacket_stats)) {
1084 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001085 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001086 tcp->u_arg[3],
1087 &stats) < 0)
1088 break;
1089 tprintf("{packets=%u, drops=%u}, "
1090 "[%d]",
1091 stats.tp_packets,
1092 stats.tp_drops,
1093 len);
1094 return 0;
1095 }
1096 break;
1097#endif
1098 }
1099 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001100 }
1101
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001102 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001103 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001104 }
1105 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001106 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001107 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001108 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109 }
1110 return 0;
1111}
1112
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001113#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001114static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001115{
1116 struct icmp_filter filter;
1117
1118 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001119 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001120 return;
1121 }
1122 if (syserror(tcp) || !verbose(tcp)) {
1123 tprintf("%#lx", addr);
1124 return;
1125 }
1126 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001127 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001128 return;
1129 }
1130
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001131 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001132 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001133 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001134}
1135#endif /* ICMP_FILTER */
1136
John Hughes38ae88d2002-05-23 11:48:58 +00001137static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001138printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001139{
1140 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001141 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001142 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001143 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001144 printxval(sockoptions, name, "SO_???");
1145 switch (name) {
1146#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001147 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001148 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001149 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001150 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001151 break;
1152 tprintf(", {onoff=%d, linger=%d}",
1153 linger.l_onoff,
1154 linger.l_linger);
1155 return 0;
1156 }
1157 break;
1158#endif
1159 }
1160 break;
1161#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001162 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001163 printxval(sockipoptions, name, "IP_???");
1164 break;
1165#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001166#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001167 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001168 printxval(sockipv6options, name, "IPV6_???");
1169 break;
1170#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001171#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001172 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001173 printxval(sockipxoptions, name, "IPX_???");
1174 break;
1175#endif
1176#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001177 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001178 printxval(sockpacketoptions, name, "PACKET_???");
1179 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001180 switch (name) {
1181#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001182 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001183#endif
1184#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001185 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001186#endif
1187#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1188 if (len == sizeof(struct tpacket_req)) {
1189 struct tpacket_req req;
1190 if (umove(tcp, addr, &req) < 0)
1191 break;
1192 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1193 req.tp_block_size,
1194 req.tp_block_nr,
1195 req.tp_frame_size,
1196 req.tp_frame_nr);
1197 return 0;
1198 }
1199 break;
1200#endif /* PACKET_RX_RING || PACKET_TX_RING */
1201 }
John Hughes38ae88d2002-05-23 11:48:58 +00001202 break;
1203#endif
1204#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001205 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001206 printxval(socktcpoptions, name, "TCP_???");
1207 break;
1208#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001209#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001210 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001211 printxval(socksctpoptions, name, "SCTP_???");
1212 break;
1213#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001214#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001215 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001216 printxval(sockrawoptions, name, "RAW_???");
1217 switch (name) {
1218#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001219 case ICMP_FILTER:
1220 tprints(", ");
1221 printicmpfilter(tcp, addr);
1222 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001223#endif
1224 }
1225 break;
1226#endif
1227
Roland McGrath6d2b3492002-12-30 00:51:30 +00001228 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001229 * etc. still need work */
1230
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001231 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001232 tprintf("%u", name);
1233 }
1234
1235 /* default arg printing */
1236
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001237 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001238
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001239 if (len == sizeof(int)) {
1240 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001241 }
1242 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001243 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001244 }
1245 return 0;
1246}
1247
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248int
Denys Vlasenko12014262011-05-30 14:00:14 +02001249sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001250{
1251 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001252 printfd(tcp, tcp->u_arg[0]);
1253 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001254 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001255 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001256 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 }
1258 return 0;
1259}