blob: 40a18d021eddc71320a8739da3396d1b5140c19b [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. Levind9f7e7a2015-01-09 03:03:39 +0000115# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
116# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
117# endif
118# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900119#endif
120
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200121#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
122# include "xlat/bt_protocols.h"
123#endif
124
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000125#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000126#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100128#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000129#define SOL_IP IPPROTO_IP
130#endif
131
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000132#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000133#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134#endif /* SOL_IP */
135
Roland McGrath4f6ba692004-08-31 07:01:26 +0000136#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000137#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000138#endif /* SOL_IPV6 */
139
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000141#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#endif /* SOL_IPX */
143
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000144#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000145#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000146#endif /* SOL_RAW */
147
148#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000149#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000150#endif /* SOL_PACKET */
151
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100152#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000153#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100154#endif
155
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100156#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000157#define SOL_TCP IPPROTO_TCP
158#endif
159
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000161#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162#endif /* SOL_TCP */
163
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000164#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000165#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000166#endif /* SOL_RAW */
167
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000168#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000169#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000170#endif /* defined(AF_PACKET) */
171
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000173printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000175 union {
176 char pad[128];
177 struct sockaddr sa;
178 struct sockaddr_in sin;
179 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000180#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000181 struct sockaddr_in6 sa6;
182#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100183#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000184 struct sockaddr_ipx sipx;
185#endif
186#ifdef AF_PACKET
187 struct sockaddr_ll ll;
188#endif
189#ifdef AF_NETLINK
190 struct sockaddr_nl nl;
191#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200192#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
193 struct sockaddr_hci hci;
194 struct sockaddr_l2 l2;
195 struct sockaddr_rc rc;
196 struct sockaddr_sco sco;
197#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000198 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000199 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200
201 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200202 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 return;
204 }
205 if (!verbose(tcp)) {
206 tprintf("%#lx", addr);
207 return;
208 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000209
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000210 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000211 addrlen = sizeof(addrbuf);
212
213 memset(&addrbuf, 0, sizeof(addrbuf));
214 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200215 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 return;
217 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000218 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000219
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200220 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000221 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200222 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000223
224 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000226 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200227 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000228 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000229 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000230 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000231 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000232 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000233 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000234 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 break;
236 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000237 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000238 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000240#ifdef HAVE_INET_NTOP
241 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000243 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
244 ntohs(addrbuf.sa6.sin6_port), string_addr,
245 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000246#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000247 {
248#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200249 int numericscope = 0;
250 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
251 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
252 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000253
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200254 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
255 numericscope++;
256 else
257 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
258 } else
259 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000260
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200261 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000262#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000264 }
265#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200266 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000267#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100268#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000270 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000272 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000273 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 /* Yes, I know, this does not look too
275 * strace-ish, but otherwise the IPX
276 * addresses just look monstrous...
277 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000278 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000280 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200281 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000282 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
283 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 }
285 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100286#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287#ifdef AF_PACKET
288 case AF_PACKET:
289 {
290 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000291 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000293 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000294 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000295 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296 addrbuf.ll.sll_halen,
297 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200298 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000299 tprintf("%02x", addrbuf.ll.sll_addr[i]);
300 }
301 break;
302
Denys Vlasenko84703742012-02-25 02:38:52 +0100303#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000304#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000305 case AF_NETLINK:
306 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
307 break;
308#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200309#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
310 case AF_BLUETOOTH:
311 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
312 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
313 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
314 "{hci_dev=htobs(%d)}",
315 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
316 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
317 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
318 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
319 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
320 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
321 addrbuf.rc.rc_channel,
322 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
323 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
324 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
325 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
326 btohs(addrbuf.hci.hci_dev));
327 break;
328#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000330 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331
332 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200333 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336 break;
337 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200338 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339}
340
341#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000342#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000343
344static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000345printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000346{
Roland McGrathaa524c82005-06-01 19:22:06 +0000347 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
348 NULL : malloc(len);
349 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000350 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000351 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000352 return;
353 }
354
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000355 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000356 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200357 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000358
Roland McGrathaa524c82005-06-01 19:22:06 +0000359 if (cmsg->cmsg_level == SOL_SOCKET) {
360 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000361
Roland McGrathaa524c82005-06-01 19:22:06 +0000362 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
363 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
364
365 if (cmsg->cmsg_type == SCM_RIGHTS
366 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200367 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000368 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000369
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200370 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000371 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000372 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200373 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000374 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000375 first = 0;
376 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200377 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000378 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000379 return;
380 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000381 if (cmsg->cmsg_type == SCM_CREDENTIALS
382 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200383 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000384
Roland McGrath50770822004-10-06 22:11:51 +0000385 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
386 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000387 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000388 return;
389 }
390 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000391 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200392 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000393}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394
395static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200396do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100397{
398 tprintf("{msg_name(%d)=", msg->msg_namelen);
399 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
400
401 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200402 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
403 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100404
405#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
406 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
407 if (msg->msg_controllen)
408 printcmsghdr(tcp, (unsigned long) msg->msg_control,
409 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200410 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100411 printflags(msg_flags, msg->msg_flags, "MSG_???");
412#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
413 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
414 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
415#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200416 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100417}
418
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100419struct msghdr32 {
420 uint32_t /* void* */ msg_name;
421 uint32_t /* socklen_t */msg_namelen;
422 uint32_t /* iovec* */ msg_iov;
423 uint32_t /* size_t */ msg_iovlen;
424 uint32_t /* void* */ msg_control;
425 uint32_t /* size_t */ msg_controllen;
426 uint32_t /* int */ msg_flags;
427};
428struct mmsghdr32 {
429 struct msghdr32 msg_hdr;
430 uint32_t /* unsigned */ msg_len;
431};
432
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900433#ifndef HAVE_STRUCT_MMSGHDR
434struct mmsghdr {
435 struct msghdr msg_hdr;
436 unsigned msg_len;
437};
438#endif
439
Masatake YAMATOb2485432014-11-07 01:23:24 +0900440#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
441static void
442copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
443{
444 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
445 to_msg->msg_namelen = from_msg32->msg_namelen;
446 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
447 to_msg->msg_iovlen = from_msg32->msg_iovlen;
448 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
449 to_msg->msg_controllen = from_msg32->msg_controllen;
450 to_msg->msg_flags = from_msg32->msg_flags;
451}
452#endif
453
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900454static bool
455extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
456{
457#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
458 if (current_wordsize == 4) {
459 struct msghdr32 msg32;
460
461 if (umove(tcp, addr, &msg32) < 0)
462 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900463 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900464 } else
465#endif
466 if (umove(tcp, addr, msg) < 0)
467 return false;
468 return true;
469}
470
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900471static bool
472extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
473{
474#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
475 if (current_wordsize == 4) {
476 struct mmsghdr32 mmsg32;
477
478 addr += sizeof(struct mmsghdr32) * idx;
479 if (umove(tcp, addr, &mmsg32) < 0)
480 return false;
481
482 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
483 mmsg->msg_len = mmsg32.msg_len;
484 } else
485#endif
486 {
487 addr += sizeof(*mmsg) * idx;
488 if (umove(tcp, addr, mmsg) < 0)
489 return false;
490 }
491 return true;
492}
493
Andreas Schwab0873f292010-02-12 21:39:12 +0100494static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200495printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496{
497 struct msghdr msg;
498
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900499 if (extractmsghdr(tcp, addr, &msg))
500 do_msghdr(tcp, &msg, data_size);
501 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000502 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900503}
504
505void
506dumpiov_in_msghdr(struct tcb *tcp, long addr)
507{
508 struct msghdr msg;
509
510 if (extractmsghdr(tcp, addr, &msg))
511 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512}
513
Andreas Schwab0873f292010-02-12 21:39:12 +0100514static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000515printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100516{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900517 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100518
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900519 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
520 tprints("{");
521 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
522 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100523 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900524 else
525 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100526}
Andreas Schwab0873f292010-02-12 21:39:12 +0100527
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000528static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000529decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000530{
531 /* mmsgvec */
532 if (syserror(tcp)) {
533 tprintf("%#lx", tcp->u_arg[1]);
534 } else {
535 unsigned int len = tcp->u_rval;
536 unsigned int i;
537
538 tprints("{");
539 for (i = 0; i < len; ++i) {
540 if (i)
541 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000542 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000543 }
544 tprints("}");
545 }
546 /* vlen */
547 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
548 /* flags */
549 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
550}
551
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900552void
553dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
554{
555 unsigned int len = tcp->u_rval;
556 unsigned int i;
557 struct mmsghdr mmsg;
558
559 for (i = 0; i < len; ++i) {
560 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
561 tprintf(" = %lu buffers in vector %u\n",
562 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
563 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
564 (long)mmsg.msg_hdr.msg_iov);
565 }
566 }
567}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568#endif /* HAVE_SENDMSG */
569
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000570/*
571 * low bits of the socket type define real socket type,
572 * other bits are socket type flags.
573 */
574static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000575tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000576{
577 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
578
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200579 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200580 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000581 flags &= ~SOCK_TYPE_MASK;
582 if (!flags)
583 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200584 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000585 }
586 printflags(sock_type_flags, flags, "SOCK_???");
587}
588
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000590sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591{
592 if (entering(tcp)) {
593 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200594 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000595 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200596 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597 switch (tcp->u_arg[0]) {
598 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000599#ifdef PF_INET6
600 case PF_INET6:
601#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900602 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603 break;
604#ifdef PF_IPX
605 case PF_IPX:
606 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200607 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200609 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610 break;
611#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900612#ifdef PF_NETLINK
613 case PF_NETLINK:
614 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
615 break;
616#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200617#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
618 case PF_BLUETOOTH:
619 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
620 break;
621#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622 default:
623 tprintf("%lu", tcp->u_arg[2]);
624 break;
625 }
626 }
627 return 0;
628}
629
John Hughesbdf48f52001-03-06 15:08:09 +0000630int
Denys Vlasenko12014262011-05-30 14:00:14 +0200631sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632{
633 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800634 printfd(tcp, tcp->u_arg[0]);
635 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000636 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637 tprintf(", %lu", tcp->u_arg[2]);
638 }
639 return 0;
640}
641
642int
Denys Vlasenko12014262011-05-30 14:00:14 +0200643sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644{
645 return sys_bind(tcp);
646}
647
648int
Denys Vlasenko12014262011-05-30 14:00:14 +0200649sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650{
651 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800652 printfd(tcp, tcp->u_arg[0]);
653 tprints(", ");
654 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 }
656 return 0;
657}
658
Paolo Bonzini705ff102009-08-14 12:34:05 +0200659static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000660do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661{
662 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800663 printfd(tcp, tcp->u_arg[0]);
664 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200665 return 0;
666 }
667 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 tprintf("%#lx, NULL", tcp->u_arg[1]);
669 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000670 int len;
671 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200672 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 tprintf("%#lx", tcp->u_arg[1]);
674 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000675 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200677 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000678 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200680 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200681 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200682 printflags(sock_type_flags, tcp->u_arg[flags_arg],
683 "SOCK_???");
684 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685 return 0;
686}
687
688int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200689sys_accept(struct tcb *tcp)
690{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000691 do_sockname(tcp, -1);
692 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200693}
694
Paolo Bonzini705ff102009-08-14 12:34:05 +0200695int
696sys_accept4(struct tcb *tcp)
697{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000698 do_sockname(tcp, 3);
699 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200700}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200701
702int
Denys Vlasenko12014262011-05-30 14:00:14 +0200703sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704{
705 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800706 printfd(tcp, tcp->u_arg[0]);
707 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
709 tprintf(", %lu, ", tcp->u_arg[2]);
710 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000711 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712 }
713 return 0;
714}
715
716int
Denys Vlasenko12014262011-05-30 14:00:14 +0200717sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718{
719 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800720 printfd(tcp, tcp->u_arg[0]);
721 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
723 tprintf(", %lu, ", tcp->u_arg[2]);
724 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000725 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200727 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000728 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 /* to length */
730 tprintf(", %lu", tcp->u_arg[5]);
731 }
732 return 0;
733}
734
735#ifdef HAVE_SENDMSG
736
737int
Denys Vlasenko12014262011-05-30 14:00:14 +0200738sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739{
740 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800741 printfd(tcp, tcp->u_arg[0]);
742 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000743 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200745 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000746 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 }
748 return 0;
749}
750
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000751int
752sys_sendmmsg(struct tcb *tcp)
753{
754 if (entering(tcp)) {
755 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800756 printfd(tcp, tcp->u_arg[0]);
757 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000758 if (!verbose(tcp)) {
759 tprintf("%#lx, %u, ",
760 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
761 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
762 }
763 } else {
764 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000765 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000766 }
767 return 0;
768}
769
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770#endif /* HAVE_SENDMSG */
771
772int
Denys Vlasenko12014262011-05-30 14:00:14 +0200773sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774{
775 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800776 printfd(tcp, tcp->u_arg[0]);
777 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 } else {
779 if (syserror(tcp))
780 tprintf("%#lx", tcp->u_arg[1]);
781 else
782 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
783
784 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000785 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000786 }
787 return 0;
788}
789
790int
Denys Vlasenko12014262011-05-30 14:00:14 +0200791sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792{
793 int fromlen;
794
795 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800796 printfd(tcp, tcp->u_arg[0]);
797 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000798 } else {
799 if (syserror(tcp)) {
800 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
801 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
802 tcp->u_arg[4], tcp->u_arg[5]);
803 return 0;
804 }
805 /* buf */
806 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
807 /* len */
808 tprintf(", %lu, ", tcp->u_arg[2]);
809 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000810 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811 /* from address, len */
812 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
813 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200814 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815 else
816 tprintf(", %#lx", tcp->u_arg[4]);
817 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200818 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819 else
820 tprintf(", %#lx", tcp->u_arg[5]);
821 return 0;
822 }
823 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200824 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 return 0;
826 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200827 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000828 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829 /* from length */
830 tprintf(", [%u]", fromlen);
831 }
832 return 0;
833}
834
835#ifdef HAVE_SENDMSG
836
837int
Denys Vlasenko12014262011-05-30 14:00:14 +0200838sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839{
840 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800841 printfd(tcp, tcp->u_arg[0]);
842 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 } else {
844 if (syserror(tcp) || !verbose(tcp))
845 tprintf("%#lx", tcp->u_arg[1]);
846 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200847 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200849 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000850 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 }
852 return 0;
853}
854
Andreas Schwab0873f292010-02-12 21:39:12 +0100855int
856sys_recvmmsg(struct tcb *tcp)
857{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100858 /* +5 chars are for "left " prefix */
859 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400860
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100861 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800862 printfd(tcp, tcp->u_arg[0]);
863 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400864 if (verbose(tcp)) {
865 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100866 /* Abusing tcp->auxstr as temp storage.
867 * Will be used and freed on syscall exit.
868 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400869 tcp->auxstr = strdup(str);
870 } else {
871 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
872 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200873 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400874 print_timespec(tcp, tcp->u_arg[4]);
875 }
876 return 0;
877 } else {
878 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000879 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400880 /* timeout on entrance */
881 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
882 free((void *) tcp->auxstr);
883 tcp->auxstr = NULL;
884 }
885 if (syserror(tcp))
886 return 0;
887 if (tcp->u_rval == 0) {
888 tcp->auxstr = "Timeout";
889 return RVAL_STR;
890 }
891 if (!verbose(tcp))
892 return 0;
893 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100894 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400895 tcp->auxstr = str;
896 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100897 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100898}
Andreas Schwab0873f292010-02-12 21:39:12 +0100899
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000900#endif /* HAVE_SENDMSG */
901
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000902#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100903
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000904int
Denys Vlasenko12014262011-05-30 14:00:14 +0200905sys_shutdown(struct tcb *tcp)
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(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100910 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911 }
912 return 0;
913}
914
915int
Denys Vlasenko12014262011-05-30 14:00:14 +0200916sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000918 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919}
920
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000921static int
922do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924 if (exiting(tcp)) {
925 if (syserror(tcp)) {
926 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000927 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100928#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000929 int fds[2];
930
931 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200932 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000933 else
934 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100935#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000936 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
937#else
938 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000940 }
941 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200942 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000943 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
944 }
945 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946 return 0;
947}
948
949int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000950sys_pipe(struct tcb *tcp)
951{
952 return do_pipe(tcp, -1);
953}
954
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000955int
956sys_pipe2(struct tcb *tcp)
957{
958 return do_pipe(tcp, 1);
959}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000960
961int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000962sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965
966 if (entering(tcp)) {
967 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200968 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000969 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000970 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971 } else {
972 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000973 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974 return 0;
975 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200977 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 else
979 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980 }
981 return 0;
982}
983
984int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000985sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986{
987 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800988 printfd(tcp, tcp->u_arg[0]);
989 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000990 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200991 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 switch (tcp->u_arg[1]) {
993 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 break;
996#ifdef SOL_IP
997 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000998 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 break;
1000#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001001#ifdef SOL_IPV6
1002 case SOL_IPV6:
1003 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1004 break;
1005#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006#ifdef SOL_IPX
1007 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 break;
1010#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001011#ifdef SOL_PACKET
1012 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001013 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001014 break;
1015#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016#ifdef SOL_TCP
1017 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 break;
1020#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001021#ifdef SOL_SCTP
1022 case SOL_SCTP:
1023 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1024 break;
1025#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026
1027 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1028 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001029 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001030 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 break;
1032 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001033 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001035 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001036 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001037 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038 tcp->u_arg[3], tcp->u_arg[4]);
1039 return 0;
1040 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001041
1042 switch (tcp->u_arg[1]) {
1043 case SOL_SOCKET:
1044 switch (tcp->u_arg[2]) {
1045#ifdef SO_LINGER
1046 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001047 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001048 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001049 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001050 tcp->u_arg[3],
1051 &linger) < 0)
1052 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001053 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001054 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001055 linger.l_onoff,
1056 linger.l_linger,
1057 len);
1058 return 0;
1059 }
1060 break;
1061#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001062#ifdef SO_PEERCRED
1063 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001064 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001065 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001066 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001067 tcp->u_arg[3],
1068 &uc) < 0)
1069 break;
1070 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1071 "[%d]",
1072 (long)uc.pid,
1073 (long)uc.uid,
1074 (long)uc.gid,
1075 len);
1076 return 0;
1077 }
1078 break;
1079#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001080 }
1081 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001082 case SOL_PACKET:
1083 switch (tcp->u_arg[2]) {
1084#ifdef PACKET_STATISTICS
1085 case PACKET_STATISTICS:
1086 if (len == sizeof(struct tpacket_stats)) {
1087 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001088 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001089 tcp->u_arg[3],
1090 &stats) < 0)
1091 break;
1092 tprintf("{packets=%u, drops=%u}, "
1093 "[%d]",
1094 stats.tp_packets,
1095 stats.tp_drops,
1096 len);
1097 return 0;
1098 }
1099 break;
1100#endif
1101 }
1102 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001103 }
1104
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001105 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001106 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001107 }
1108 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001109 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001110 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001111 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001112 }
1113 return 0;
1114}
1115
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001116#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001117static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001118{
1119 struct icmp_filter filter;
1120
1121 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001122 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001123 return;
1124 }
1125 if (syserror(tcp) || !verbose(tcp)) {
1126 tprintf("%#lx", addr);
1127 return;
1128 }
1129 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001130 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001131 return;
1132 }
1133
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001134 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001135 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001136 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001137}
1138#endif /* ICMP_FILTER */
1139
John Hughes38ae88d2002-05-23 11:48:58 +00001140static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001141printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001142{
1143 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001144 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001145 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001146 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001147 printxval(sockoptions, name, "SO_???");
1148 switch (name) {
1149#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001150 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001151 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001152 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001153 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001154 break;
1155 tprintf(", {onoff=%d, linger=%d}",
1156 linger.l_onoff,
1157 linger.l_linger);
1158 return 0;
1159 }
1160 break;
1161#endif
1162 }
1163 break;
1164#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001165 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001166 printxval(sockipoptions, name, "IP_???");
1167 break;
1168#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001169#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001170 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001171 printxval(sockipv6options, name, "IPV6_???");
1172 break;
1173#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001174#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001175 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001176 printxval(sockipxoptions, name, "IPX_???");
1177 break;
1178#endif
1179#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001180 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001181 printxval(sockpacketoptions, name, "PACKET_???");
1182 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001183 switch (name) {
1184#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001185 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001186#endif
1187#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001188 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001189#endif
1190#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1191 if (len == sizeof(struct tpacket_req)) {
1192 struct tpacket_req req;
1193 if (umove(tcp, addr, &req) < 0)
1194 break;
1195 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1196 req.tp_block_size,
1197 req.tp_block_nr,
1198 req.tp_frame_size,
1199 req.tp_frame_nr);
1200 return 0;
1201 }
1202 break;
1203#endif /* PACKET_RX_RING || PACKET_TX_RING */
1204 }
John Hughes38ae88d2002-05-23 11:48:58 +00001205 break;
1206#endif
1207#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001208 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001209 printxval(socktcpoptions, name, "TCP_???");
1210 break;
1211#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001212#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001213 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001214 printxval(socksctpoptions, name, "SCTP_???");
1215 break;
1216#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001217#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001218 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001219 printxval(sockrawoptions, name, "RAW_???");
1220 switch (name) {
1221#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001222 case ICMP_FILTER:
1223 tprints(", ");
1224 printicmpfilter(tcp, addr);
1225 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001226#endif
1227 }
1228 break;
1229#endif
1230
Roland McGrath6d2b3492002-12-30 00:51:30 +00001231 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001232 * etc. still need work */
1233
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001234 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001235 tprintf("%u", name);
1236 }
1237
1238 /* default arg printing */
1239
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001240 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001241
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001242 if (len == sizeof(int)) {
1243 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001244 }
1245 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001246 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001247 }
1248 return 0;
1249}
1250
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251int
Denys Vlasenko12014262011-05-30 14:00:14 +02001252sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253{
1254 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001255 printfd(tcp, tcp->u_arg[0]);
1256 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001257 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001258 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001259 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 }
1261 return 0;
1262}