blob: c235116c5abe264eac4e4c82c5dd62f04b1ed334 [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
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000344#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
345struct cmsghdr32 {
346 uint32_t cmsg_len;
347 int cmsg_level;
348 int cmsg_type;
349};
350#endif
351
352typedef union {
353 char *buf;
354 struct cmsghdr *cmsg;
355#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
356 struct cmsghdr32 *cmsg32;
357#endif
358} union_cmsghdr;
359
Roland McGrath50770822004-10-06 22:11:51 +0000360static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000361printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000362{
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000363 union_cmsghdr u;
364 size_t cmsg_size;
365 unsigned long cmsg_len;
366 int cmsg_level;
367 int cmsg_type;
368
369 cmsg_size =
370#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
371 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
372#endif
373 sizeof(struct cmsghdr);
374
375 u.buf = len < cmsg_size ? NULL : malloc(len);
376 if (!u.buf || umoven(tcp, addr, len, u.buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000377 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000378 free(u.buf);
Roland McGrath50770822004-10-06 22:11:51 +0000379 return;
380 }
381
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000382 cmsg_len =
383#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
384 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
385#endif
386 u.cmsg->cmsg_len;
387 cmsg_level =
388#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
389 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
390#endif
391 u.cmsg->cmsg_level;
392 cmsg_type =
393#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
394 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
395#endif
396 u.cmsg->cmsg_type;
397
398 tprintf(", {cmsg_len=%lu, cmsg_level=", cmsg_len);
399 printxval(socketlayers, cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200400 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000401
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000402 if (cmsg_len > len)
403 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000404
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000405 if (cmsg_level == SOL_SOCKET) {
406 printxval(scmvals, cmsg_type, "SCM_???");
Roland McGrathaa524c82005-06-01 19:22:06 +0000407
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000408 if (cmsg_type == SCM_RIGHTS
409 && cmsg_size + sizeof(int) <= cmsg_len) {
410 int *fds = (int *) (u.buf + cmsg_size);
Roland McGrath50770822004-10-06 22:11:51 +0000411 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000412
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200413 tprints(", {");
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000414 while ((char *) fds < (u.buf + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000415 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200416 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000417 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000418 first = 0;
419 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200420 tprints("}}");
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000421 free(u.buf);
Roland McGrath50770822004-10-06 22:11:51 +0000422 return;
423 }
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000424 if (cmsg_type == SCM_CREDENTIALS
425 && cmsg_size + sizeof(struct ucred) <= cmsg_len) {
426 struct ucred *uc = (void *) (u.buf + cmsg_size);
Roland McGrathaa524c82005-06-01 19:22:06 +0000427
Roland McGrath50770822004-10-06 22:11:51 +0000428 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
429 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000430 free(u.buf);
Roland McGrath50770822004-10-06 22:11:51 +0000431 return;
432 }
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000433 } else {
434 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000435 }
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000436 free(u.buf);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200437 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000438}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439
440static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200441do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100442{
443 tprintf("{msg_name(%d)=", msg->msg_namelen);
444 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
445
446 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200447 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
448 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100449
450#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
451 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
452 if (msg->msg_controllen)
453 printcmsghdr(tcp, (unsigned long) msg->msg_control,
454 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200455 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100456 printflags(msg_flags, msg->msg_flags, "MSG_???");
457#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
458 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
459 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
460#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200461 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100462}
463
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100464struct msghdr32 {
465 uint32_t /* void* */ msg_name;
466 uint32_t /* socklen_t */msg_namelen;
467 uint32_t /* iovec* */ msg_iov;
468 uint32_t /* size_t */ msg_iovlen;
469 uint32_t /* void* */ msg_control;
470 uint32_t /* size_t */ msg_controllen;
471 uint32_t /* int */ msg_flags;
472};
473struct mmsghdr32 {
474 struct msghdr32 msg_hdr;
475 uint32_t /* unsigned */ msg_len;
476};
477
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900478#ifndef HAVE_STRUCT_MMSGHDR
479struct mmsghdr {
480 struct msghdr msg_hdr;
481 unsigned msg_len;
482};
483#endif
484
Masatake YAMATOb2485432014-11-07 01:23:24 +0900485#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
486static void
487copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
488{
489 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
490 to_msg->msg_namelen = from_msg32->msg_namelen;
491 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
492 to_msg->msg_iovlen = from_msg32->msg_iovlen;
493 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
494 to_msg->msg_controllen = from_msg32->msg_controllen;
495 to_msg->msg_flags = from_msg32->msg_flags;
496}
497#endif
498
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900499static bool
500extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
501{
502#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
503 if (current_wordsize == 4) {
504 struct msghdr32 msg32;
505
506 if (umove(tcp, addr, &msg32) < 0)
507 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900508 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900509 } else
510#endif
511 if (umove(tcp, addr, msg) < 0)
512 return false;
513 return true;
514}
515
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900516static bool
517extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
518{
519#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
520 if (current_wordsize == 4) {
521 struct mmsghdr32 mmsg32;
522
523 addr += sizeof(struct mmsghdr32) * idx;
524 if (umove(tcp, addr, &mmsg32) < 0)
525 return false;
526
527 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
528 mmsg->msg_len = mmsg32.msg_len;
529 } else
530#endif
531 {
532 addr += sizeof(*mmsg) * idx;
533 if (umove(tcp, addr, mmsg) < 0)
534 return false;
535 }
536 return true;
537}
538
Andreas Schwab0873f292010-02-12 21:39:12 +0100539static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200540printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541{
542 struct msghdr msg;
543
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900544 if (extractmsghdr(tcp, addr, &msg))
545 do_msghdr(tcp, &msg, data_size);
546 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000547 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900548}
549
550void
551dumpiov_in_msghdr(struct tcb *tcp, long addr)
552{
553 struct msghdr msg;
554
555 if (extractmsghdr(tcp, addr, &msg))
556 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557}
558
Andreas Schwab0873f292010-02-12 21:39:12 +0100559static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000560printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100561{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900562 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100563
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900564 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
565 tprints("{");
566 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
567 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100568 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900569 else
570 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100571}
Andreas Schwab0873f292010-02-12 21:39:12 +0100572
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000573static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000574decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000575{
576 /* mmsgvec */
577 if (syserror(tcp)) {
578 tprintf("%#lx", tcp->u_arg[1]);
579 } else {
580 unsigned int len = tcp->u_rval;
581 unsigned int i;
582
583 tprints("{");
584 for (i = 0; i < len; ++i) {
585 if (i)
586 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000587 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000588 }
589 tprints("}");
590 }
591 /* vlen */
592 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
593 /* flags */
594 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
595}
596
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900597void
598dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
599{
600 unsigned int len = tcp->u_rval;
601 unsigned int i;
602 struct mmsghdr mmsg;
603
604 for (i = 0; i < len; ++i) {
605 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
606 tprintf(" = %lu buffers in vector %u\n",
607 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
608 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
609 (long)mmsg.msg_hdr.msg_iov);
610 }
611 }
612}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613#endif /* HAVE_SENDMSG */
614
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000615/*
616 * low bits of the socket type define real socket type,
617 * other bits are socket type flags.
618 */
619static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000620tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000621{
622 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
623
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200624 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200625 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000626 flags &= ~SOCK_TYPE_MASK;
627 if (!flags)
628 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200629 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000630 }
631 printflags(sock_type_flags, flags, "SOCK_???");
632}
633
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000635sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636{
637 if (entering(tcp)) {
638 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200639 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000640 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200641 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 switch (tcp->u_arg[0]) {
643 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000644#ifdef PF_INET6
645 case PF_INET6:
646#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900647 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 break;
649#ifdef PF_IPX
650 case PF_IPX:
651 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200652 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200654 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 break;
656#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900657#ifdef PF_NETLINK
658 case PF_NETLINK:
659 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
660 break;
661#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200662#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
663 case PF_BLUETOOTH:
664 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
665 break;
666#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 default:
668 tprintf("%lu", tcp->u_arg[2]);
669 break;
670 }
671 }
672 return 0;
673}
674
John Hughesbdf48f52001-03-06 15:08:09 +0000675int
Denys Vlasenko12014262011-05-30 14:00:14 +0200676sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677{
678 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800679 printfd(tcp, tcp->u_arg[0]);
680 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000681 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682 tprintf(", %lu", tcp->u_arg[2]);
683 }
684 return 0;
685}
686
687int
Denys Vlasenko12014262011-05-30 14:00:14 +0200688sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689{
690 return sys_bind(tcp);
691}
692
693int
Denys Vlasenko12014262011-05-30 14:00:14 +0200694sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695{
696 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800697 printfd(tcp, tcp->u_arg[0]);
698 tprints(", ");
699 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700 }
701 return 0;
702}
703
Paolo Bonzini705ff102009-08-14 12:34:05 +0200704static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000705do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706{
707 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800708 printfd(tcp, tcp->u_arg[0]);
709 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200710 return 0;
711 }
712 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713 tprintf("%#lx, NULL", tcp->u_arg[1]);
714 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000715 int len;
716 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200717 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718 tprintf("%#lx", tcp->u_arg[1]);
719 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000720 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000721 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200722 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000723 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200725 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200726 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200727 printflags(sock_type_flags, tcp->u_arg[flags_arg],
728 "SOCK_???");
729 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730 return 0;
731}
732
733int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200734sys_accept(struct tcb *tcp)
735{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000736 do_sockname(tcp, -1);
737 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200738}
739
Paolo Bonzini705ff102009-08-14 12:34:05 +0200740int
741sys_accept4(struct tcb *tcp)
742{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000743 do_sockname(tcp, 3);
744 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200745}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200746
747int
Denys Vlasenko12014262011-05-30 14:00:14 +0200748sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000749{
750 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800751 printfd(tcp, tcp->u_arg[0]);
752 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
754 tprintf(", %lu, ", tcp->u_arg[2]);
755 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000756 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757 }
758 return 0;
759}
760
761int
Denys Vlasenko12014262011-05-30 14:00:14 +0200762sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763{
764 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800765 printfd(tcp, tcp->u_arg[0]);
766 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
768 tprintf(", %lu, ", tcp->u_arg[2]);
769 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000770 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000773 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774 /* to length */
775 tprintf(", %lu", tcp->u_arg[5]);
776 }
777 return 0;
778}
779
780#ifdef HAVE_SENDMSG
781
782int
Denys Vlasenko12014262011-05-30 14:00:14 +0200783sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000784{
785 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800786 printfd(tcp, tcp->u_arg[0]);
787 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000788 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000791 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792 }
793 return 0;
794}
795
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000796int
797sys_sendmmsg(struct tcb *tcp)
798{
799 if (entering(tcp)) {
800 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800801 printfd(tcp, tcp->u_arg[0]);
802 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000803 if (!verbose(tcp)) {
804 tprintf("%#lx, %u, ",
805 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
806 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
807 }
808 } else {
809 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000810 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000811 }
812 return 0;
813}
814
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815#endif /* HAVE_SENDMSG */
816
817int
Denys Vlasenko12014262011-05-30 14:00:14 +0200818sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819{
820 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800821 printfd(tcp, tcp->u_arg[0]);
822 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000823 } else {
824 if (syserror(tcp))
825 tprintf("%#lx", tcp->u_arg[1]);
826 else
827 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
828
829 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000830 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831 }
832 return 0;
833}
834
835int
Denys Vlasenko12014262011-05-30 14:00:14 +0200836sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837{
838 int fromlen;
839
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)) {
845 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
846 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
847 tcp->u_arg[4], tcp->u_arg[5]);
848 return 0;
849 }
850 /* buf */
851 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
852 /* len */
853 tprintf(", %lu, ", tcp->u_arg[2]);
854 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000855 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 /* from address, len */
857 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
858 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000860 else
861 tprintf(", %#lx", tcp->u_arg[4]);
862 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200863 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864 else
865 tprintf(", %#lx", tcp->u_arg[5]);
866 return 0;
867 }
868 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870 return 0;
871 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200872 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000873 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874 /* from length */
875 tprintf(", [%u]", fromlen);
876 }
877 return 0;
878}
879
880#ifdef HAVE_SENDMSG
881
882int
Denys Vlasenko12014262011-05-30 14:00:14 +0200883sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884{
885 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800886 printfd(tcp, tcp->u_arg[0]);
887 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888 } else {
889 if (syserror(tcp) || !verbose(tcp))
890 tprintf("%#lx", tcp->u_arg[1]);
891 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200892 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000895 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896 }
897 return 0;
898}
899
Andreas Schwab0873f292010-02-12 21:39:12 +0100900int
901sys_recvmmsg(struct tcb *tcp)
902{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100903 /* +5 chars are for "left " prefix */
904 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400905
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100906 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800907 printfd(tcp, tcp->u_arg[0]);
908 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400909 if (verbose(tcp)) {
910 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100911 /* Abusing tcp->auxstr as temp storage.
912 * Will be used and freed on syscall exit.
913 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400914 tcp->auxstr = strdup(str);
915 } else {
916 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
917 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200918 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400919 print_timespec(tcp, tcp->u_arg[4]);
920 }
921 return 0;
922 } else {
923 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000924 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400925 /* timeout on entrance */
926 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
927 free((void *) tcp->auxstr);
928 tcp->auxstr = NULL;
929 }
930 if (syserror(tcp))
931 return 0;
932 if (tcp->u_rval == 0) {
933 tcp->auxstr = "Timeout";
934 return RVAL_STR;
935 }
936 if (!verbose(tcp))
937 return 0;
938 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100939 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400940 tcp->auxstr = str;
941 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100942 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100943}
Andreas Schwab0873f292010-02-12 21:39:12 +0100944
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945#endif /* HAVE_SENDMSG */
946
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000947#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100948
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949int
Denys Vlasenko12014262011-05-30 14:00:14 +0200950sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000951{
952 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800953 printfd(tcp, tcp->u_arg[0]);
954 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100955 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 }
957 return 0;
958}
959
960int
Denys Vlasenko12014262011-05-30 14:00:14 +0200961sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000963 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964}
965
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000966static int
967do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969 if (exiting(tcp)) {
970 if (syserror(tcp)) {
971 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000972 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100973#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000974 int fds[2];
975
976 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200977 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000978 else
979 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100980#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000981 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
982#else
983 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000985 }
986 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200987 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000988 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
989 }
990 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991 return 0;
992}
993
994int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000995sys_pipe(struct tcb *tcp)
996{
997 return do_pipe(tcp, -1);
998}
999
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001000int
1001sys_pipe2(struct tcb *tcp)
1002{
1003 return do_pipe(tcp, 1);
1004}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001005
1006int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001007sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010
1011 if (entering(tcp)) {
1012 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001013 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001014 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001015 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 } else {
1017 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001018 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 return 0;
1020 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001022 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 else
1024 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 }
1026 return 0;
1027}
1028
1029int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001030sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031{
1032 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001033 printfd(tcp, tcp->u_arg[0]);
1034 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +00001035 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001036 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037 switch (tcp->u_arg[1]) {
1038 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 break;
1041#ifdef SOL_IP
1042 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044 break;
1045#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001046#ifdef SOL_IPV6
1047 case SOL_IPV6:
1048 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1049 break;
1050#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051#ifdef SOL_IPX
1052 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 break;
1055#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001056#ifdef SOL_PACKET
1057 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001058 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001059 break;
1060#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061#ifdef SOL_TCP
1062 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064 break;
1065#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001066#ifdef SOL_SCTP
1067 case SOL_SCTP:
1068 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1069 break;
1070#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071
1072 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1073 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001074 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001075 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076 break;
1077 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001078 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001080 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001081 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001082 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 tcp->u_arg[3], tcp->u_arg[4]);
1084 return 0;
1085 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001086
1087 switch (tcp->u_arg[1]) {
1088 case SOL_SOCKET:
1089 switch (tcp->u_arg[2]) {
1090#ifdef SO_LINGER
1091 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001092 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001093 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001094 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001095 tcp->u_arg[3],
1096 &linger) < 0)
1097 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001098 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001099 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001100 linger.l_onoff,
1101 linger.l_linger,
1102 len);
1103 return 0;
1104 }
1105 break;
1106#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001107#ifdef SO_PEERCRED
1108 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001109 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001110 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001111 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001112 tcp->u_arg[3],
1113 &uc) < 0)
1114 break;
1115 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1116 "[%d]",
1117 (long)uc.pid,
1118 (long)uc.uid,
1119 (long)uc.gid,
1120 len);
1121 return 0;
1122 }
1123 break;
1124#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001125 }
1126 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001127 case SOL_PACKET:
1128 switch (tcp->u_arg[2]) {
1129#ifdef PACKET_STATISTICS
1130 case PACKET_STATISTICS:
1131 if (len == sizeof(struct tpacket_stats)) {
1132 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001133 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001134 tcp->u_arg[3],
1135 &stats) < 0)
1136 break;
1137 tprintf("{packets=%u, drops=%u}, "
1138 "[%d]",
1139 stats.tp_packets,
1140 stats.tp_drops,
1141 len);
1142 return 0;
1143 }
1144 break;
1145#endif
1146 }
1147 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001148 }
1149
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001150 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001151 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001152 }
1153 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001154 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001155 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001156 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157 }
1158 return 0;
1159}
1160
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001161#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001162static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001163{
1164 struct icmp_filter filter;
1165
1166 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001167 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001168 return;
1169 }
1170 if (syserror(tcp) || !verbose(tcp)) {
1171 tprintf("%#lx", addr);
1172 return;
1173 }
1174 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001175 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001176 return;
1177 }
1178
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001179 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001180 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001181 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001182}
1183#endif /* ICMP_FILTER */
1184
John Hughes38ae88d2002-05-23 11:48:58 +00001185static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001186printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001187{
1188 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001189 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001190 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001191 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001192 printxval(sockoptions, name, "SO_???");
1193 switch (name) {
1194#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001195 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001196 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001197 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001198 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001199 break;
1200 tprintf(", {onoff=%d, linger=%d}",
1201 linger.l_onoff,
1202 linger.l_linger);
1203 return 0;
1204 }
1205 break;
1206#endif
1207 }
1208 break;
1209#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001210 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001211 printxval(sockipoptions, name, "IP_???");
1212 break;
1213#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001214#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001215 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001216 printxval(sockipv6options, name, "IPV6_???");
1217 break;
1218#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001219#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001220 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001221 printxval(sockipxoptions, name, "IPX_???");
1222 break;
1223#endif
1224#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001225 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001226 printxval(sockpacketoptions, name, "PACKET_???");
1227 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001228 switch (name) {
1229#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001230 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001231#endif
1232#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001233 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001234#endif
1235#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1236 if (len == sizeof(struct tpacket_req)) {
1237 struct tpacket_req req;
1238 if (umove(tcp, addr, &req) < 0)
1239 break;
1240 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1241 req.tp_block_size,
1242 req.tp_block_nr,
1243 req.tp_frame_size,
1244 req.tp_frame_nr);
1245 return 0;
1246 }
1247 break;
1248#endif /* PACKET_RX_RING || PACKET_TX_RING */
1249 }
John Hughes38ae88d2002-05-23 11:48:58 +00001250 break;
1251#endif
1252#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001253 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001254 printxval(socktcpoptions, name, "TCP_???");
1255 break;
1256#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001257#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001258 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001259 printxval(socksctpoptions, name, "SCTP_???");
1260 break;
1261#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001262#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001263 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001264 printxval(sockrawoptions, name, "RAW_???");
1265 switch (name) {
1266#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001267 case ICMP_FILTER:
1268 tprints(", ");
1269 printicmpfilter(tcp, addr);
1270 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001271#endif
1272 }
1273 break;
1274#endif
1275
Roland McGrath6d2b3492002-12-30 00:51:30 +00001276 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001277 * etc. still need work */
1278
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001279 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001280 tprintf("%u", name);
1281 }
1282
1283 /* default arg printing */
1284
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001285 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001286
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 if (len == sizeof(int)) {
1288 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001289 }
1290 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001291 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001292 }
1293 return 0;
1294}
1295
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296int
Denys Vlasenko12014262011-05-30 14:00:14 +02001297sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298{
1299 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001300 printfd(tcp, tcp->u_arg[0]);
1301 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001302 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001303 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001304 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 }
1306 return 0;
1307}