blob: 46c491f8f6d78763c90f8fdcf20842d418c1dbae [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>
34#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000035#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# define in6_addr in6_addr_libc
37# define ipv6_mreq ipv6_mreq_libc
38# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000041#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010042# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000043#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000044#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010047#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000051#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010053#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010054# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Denys Vlasenko99aa1812013-02-08 18:49:06 +010059#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010060# if defined(HAVE_LINUX_IN6_H)
61# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
62# undef in6_addr
63# undef ipv6_mreq
64# undef sockaddr_in6
65# define in6_addr in6_addr_kernel
66# define ipv6_mreq ipv6_mreq_kernel
67# define sockaddr_in6 sockaddr_in6_kernel
68# endif
69# include <linux/in6.h>
70# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
71# undef in6_addr
72# undef ipv6_mreq
73# undef sockaddr_in6
74# define in6_addr in6_addr_libc
75# define ipv6_mreq ipv6_mreq_libc
76# define sockaddr_in6 sockaddr_in6_kernel
77# endif
78# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000079#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000080
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000081#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010082# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010085# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010088# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010091# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010094# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095#endif
96
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000097#include "xlat/domains.h"
98#include "xlat/addrfams.h"
99#include "xlat/socktypes.h"
100#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000101#ifndef SOCK_TYPE_MASK
102# define SOCK_TYPE_MASK 0xf
103#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000104#include "xlat/socketlayers.h"
John Hughes93f7fcc2002-05-22 15:46:49 +0000105/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900106 falls into "inet_protocols" array below!!!! This is intended!!! ***/
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000107#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900108
109#ifdef PF_NETLINK
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000110#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900111#endif
112
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000113#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000114#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100116#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000117#define SOL_IP IPPROTO_IP
118#endif
119
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000121#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#endif /* SOL_IP */
123
Roland McGrath4f6ba692004-08-31 07:01:26 +0000124#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000125#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000126#endif /* SOL_IPV6 */
127
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000129#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130#endif /* SOL_IPX */
131
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000132#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000133#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000134#endif /* SOL_RAW */
135
136#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000137#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000138#endif /* SOL_PACKET */
139
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100140#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000141#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100142#endif
143
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100144#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000145#define SOL_TCP IPPROTO_TCP
146#endif
147
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000149#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#endif /* SOL_TCP */
151
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000152#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000153#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000154#endif /* SOL_RAW */
155
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000156#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000157#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000158#endif /* defined(AF_PACKET) */
159
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000161printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163 union {
164 char pad[128];
165 struct sockaddr sa;
166 struct sockaddr_in sin;
167 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000168#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000169 struct sockaddr_in6 sa6;
170#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100171#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000172 struct sockaddr_ipx sipx;
173#endif
174#ifdef AF_PACKET
175 struct sockaddr_ll ll;
176#endif
177#ifdef AF_NETLINK
178 struct sockaddr_nl nl;
179#endif
180 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000181 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182
183 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200184 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 return;
186 }
187 if (!verbose(tcp)) {
188 tprintf("%#lx", addr);
189 return;
190 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000191
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000192 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000193 addrlen = sizeof(addrbuf);
194
195 memset(&addrbuf, 0, sizeof(addrbuf));
196 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200197 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198 return;
199 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000200 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000201
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200202 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000203 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200204 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000205
206 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000208 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200209 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000210 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000211 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000212 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000213 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000214 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000215 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000216 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 break;
218 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000219 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000222#ifdef HAVE_INET_NTOP
223 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000224 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000225 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
226 ntohs(addrbuf.sa6.sin6_port), string_addr,
227 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000228#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000229 {
230#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200231 int numericscope = 0;
232 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
233 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
234 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000235
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200236 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
237 numericscope++;
238 else
239 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
240 } else
241 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000242
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200243 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000244#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200245 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000246 }
247#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000249#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100250#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000252 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000254 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000255 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 /* Yes, I know, this does not look too
257 * strace-ish, but otherwise the IPX
258 * addresses just look monstrous...
259 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000260 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000262 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000264 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
265 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 }
267 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100268#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000269#ifdef AF_PACKET
270 case AF_PACKET:
271 {
272 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000273 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000274 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000275 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000276 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000277 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000278 addrbuf.ll.sll_halen,
279 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200280 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000281 tprintf("%02x", addrbuf.ll.sll_addr[i]);
282 }
283 break;
284
Denys Vlasenko84703742012-02-25 02:38:52 +0100285#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000286#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287 case AF_NETLINK:
288 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
289 break;
290#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293
294 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200295 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000297 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298 break;
299 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200300 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301}
302
303#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000304#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000305
306static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000307printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000308{
Roland McGrathaa524c82005-06-01 19:22:06 +0000309 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
310 NULL : malloc(len);
311 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000312 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000313 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000314 return;
315 }
316
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000317 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000318 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000320
Roland McGrathaa524c82005-06-01 19:22:06 +0000321 if (cmsg->cmsg_level == SOL_SOCKET) {
322 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000323
Roland McGrathaa524c82005-06-01 19:22:06 +0000324 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
325 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
326
327 if (cmsg->cmsg_type == SCM_RIGHTS
328 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200329 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000330 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000331
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200332 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000333 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000334 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200335 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000336 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000337 first = 0;
338 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200339 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000340 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000341 return;
342 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000343 if (cmsg->cmsg_type == SCM_CREDENTIALS
344 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200345 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000346
Roland McGrath50770822004-10-06 22:11:51 +0000347 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
348 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000349 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000350 return;
351 }
352 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000353 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000355}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356
357static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200358do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100359{
360 tprintf("{msg_name(%d)=", msg->msg_namelen);
361 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
362
363 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200364 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
365 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100366
367#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
368 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
369 if (msg->msg_controllen)
370 printcmsghdr(tcp, (unsigned long) msg->msg_control,
371 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200372 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100373 printflags(msg_flags, msg->msg_flags, "MSG_???");
374#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
375 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
376 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
377#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200378 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100379}
380
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100381struct msghdr32 {
382 uint32_t /* void* */ msg_name;
383 uint32_t /* socklen_t */msg_namelen;
384 uint32_t /* iovec* */ msg_iov;
385 uint32_t /* size_t */ msg_iovlen;
386 uint32_t /* void* */ msg_control;
387 uint32_t /* size_t */ msg_controllen;
388 uint32_t /* int */ msg_flags;
389};
390struct mmsghdr32 {
391 struct msghdr32 msg_hdr;
392 uint32_t /* unsigned */ msg_len;
393};
394
Andreas Schwab0873f292010-02-12 21:39:12 +0100395static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200396printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397{
398 struct msghdr msg;
399
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100400#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
401 if (current_wordsize == 4) {
402 struct msghdr32 msg32;
403
404 if (umove(tcp, addr, &msg32) < 0) {
405 tprintf("%#lx", addr);
406 return;
407 }
408 msg.msg_name = (void*)(long)msg32.msg_name;
409 msg.msg_namelen = msg32.msg_namelen;
410 msg.msg_iov = (void*)(long)msg32.msg_iov;
411 msg.msg_iovlen = msg32.msg_iovlen;
412 msg.msg_control = (void*)(long)msg32.msg_control;
413 msg.msg_controllen = msg32.msg_controllen;
414 msg.msg_flags = msg32.msg_flags;
415 } else
416#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000417 if (umove(tcp, addr, &msg) < 0) {
418 tprintf("%#lx", addr);
419 return;
420 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200421 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422}
423
Andreas Schwab0873f292010-02-12 21:39:12 +0100424static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000425printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100426{
427 struct mmsghdr {
428 struct msghdr msg_hdr;
429 unsigned msg_len;
430 } mmsg;
431
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100432#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
433 if (current_wordsize == 4) {
434 struct mmsghdr32 mmsg32;
435
436 addr += sizeof(mmsg32) * idx;
437 if (umove(tcp, addr, &mmsg32) < 0) {
438 tprintf("%#lx", addr);
439 return;
440 }
441 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
442 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
443 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
444 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
445 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
446 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
447 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
448 mmsg.msg_len = mmsg32.msg_len;
449 } else
450#endif
451 {
452 addr += sizeof(mmsg) * idx;
453 if (umove(tcp, addr, &mmsg) < 0) {
454 tprintf("%#lx", addr);
455 return;
456 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100457 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200458 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000459 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100460 tprintf(", %u}", mmsg.msg_len);
461}
Andreas Schwab0873f292010-02-12 21:39:12 +0100462
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000463static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000464decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000465{
466 /* mmsgvec */
467 if (syserror(tcp)) {
468 tprintf("%#lx", tcp->u_arg[1]);
469 } else {
470 unsigned int len = tcp->u_rval;
471 unsigned int i;
472
473 tprints("{");
474 for (i = 0; i < len; ++i) {
475 if (i)
476 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000477 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000478 }
479 tprints("}");
480 }
481 /* vlen */
482 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
483 /* flags */
484 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
485}
486
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487#endif /* HAVE_SENDMSG */
488
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000489/*
490 * low bits of the socket type define real socket type,
491 * other bits are socket type flags.
492 */
493static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000494tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000495{
496 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
497
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200498 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200499 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000500 flags &= ~SOCK_TYPE_MASK;
501 if (!flags)
502 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200503 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000504 }
505 printflags(sock_type_flags, flags, "SOCK_???");
506}
507
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000509sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510{
511 if (entering(tcp)) {
512 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000514 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200515 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 switch (tcp->u_arg[0]) {
517 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000518#ifdef PF_INET6
519 case PF_INET6:
520#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900521 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 break;
523#ifdef PF_IPX
524 case PF_IPX:
525 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200526 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200528 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 break;
530#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900531#ifdef PF_NETLINK
532 case PF_NETLINK:
533 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
534 break;
535#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 default:
537 tprintf("%lu", tcp->u_arg[2]);
538 break;
539 }
540 }
541 return 0;
542}
543
John Hughesbdf48f52001-03-06 15:08:09 +0000544int
Denys Vlasenko12014262011-05-30 14:00:14 +0200545sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546{
547 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800548 printfd(tcp, tcp->u_arg[0]);
549 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000550 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551 tprintf(", %lu", tcp->u_arg[2]);
552 }
553 return 0;
554}
555
556int
Denys Vlasenko12014262011-05-30 14:00:14 +0200557sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558{
559 return sys_bind(tcp);
560}
561
562int
Denys Vlasenko12014262011-05-30 14:00:14 +0200563sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564{
565 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800566 printfd(tcp, tcp->u_arg[0]);
567 tprints(", ");
568 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569 }
570 return 0;
571}
572
Paolo Bonzini705ff102009-08-14 12:34:05 +0200573static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000574do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575{
576 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800577 printfd(tcp, tcp->u_arg[0]);
578 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200579 return 0;
580 }
581 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 tprintf("%#lx, NULL", tcp->u_arg[1]);
583 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000584 int len;
585 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200586 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587 tprintf("%#lx", tcp->u_arg[1]);
588 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000589 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000592 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200594 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200595 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200596 printflags(sock_type_flags, tcp->u_arg[flags_arg],
597 "SOCK_???");
598 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599 return 0;
600}
601
602int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200603sys_accept(struct tcb *tcp)
604{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000605 do_sockname(tcp, -1);
606 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200607}
608
Paolo Bonzini705ff102009-08-14 12:34:05 +0200609int
610sys_accept4(struct tcb *tcp)
611{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000612 do_sockname(tcp, 3);
613 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200614}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200615
616int
Denys Vlasenko12014262011-05-30 14:00:14 +0200617sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618{
619 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800620 printfd(tcp, tcp->u_arg[0]);
621 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
623 tprintf(", %lu, ", tcp->u_arg[2]);
624 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000625 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626 }
627 return 0;
628}
629
630int
Denys Vlasenko12014262011-05-30 14:00:14 +0200631sys_sendto(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 Akkerman76baf7c1999-02-19 00:21:36 +0000636 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
637 tprintf(", %lu, ", tcp->u_arg[2]);
638 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000639 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200641 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000642 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643 /* to length */
644 tprintf(", %lu", tcp->u_arg[5]);
645 }
646 return 0;
647}
648
649#ifdef HAVE_SENDMSG
650
651int
Denys Vlasenko12014262011-05-30 14:00:14 +0200652sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653{
654 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800655 printfd(tcp, tcp->u_arg[0]);
656 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000657 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000660 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661 }
662 return 0;
663}
664
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000665int
666sys_sendmmsg(struct tcb *tcp)
667{
668 if (entering(tcp)) {
669 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800670 printfd(tcp, tcp->u_arg[0]);
671 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000672 if (!verbose(tcp)) {
673 tprintf("%#lx, %u, ",
674 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
675 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
676 }
677 } else {
678 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000679 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000680 }
681 return 0;
682}
683
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684#endif /* HAVE_SENDMSG */
685
686int
Denys Vlasenko12014262011-05-30 14:00:14 +0200687sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688{
689 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800690 printfd(tcp, tcp->u_arg[0]);
691 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 } else {
693 if (syserror(tcp))
694 tprintf("%#lx", tcp->u_arg[1]);
695 else
696 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
697
698 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000699 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700 }
701 return 0;
702}
703
704int
Denys Vlasenko12014262011-05-30 14:00:14 +0200705sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706{
707 int fromlen;
708
709 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800710 printfd(tcp, tcp->u_arg[0]);
711 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712 } else {
713 if (syserror(tcp)) {
714 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
715 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
716 tcp->u_arg[4], tcp->u_arg[5]);
717 return 0;
718 }
719 /* buf */
720 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
721 /* len */
722 tprintf(", %lu, ", tcp->u_arg[2]);
723 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000724 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725 /* from address, len */
726 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
727 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200728 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 else
730 tprintf(", %#lx", tcp->u_arg[4]);
731 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200732 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733 else
734 tprintf(", %#lx", tcp->u_arg[5]);
735 return 0;
736 }
737 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200738 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 return 0;
740 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200741 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000742 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743 /* from length */
744 tprintf(", [%u]", fromlen);
745 }
746 return 0;
747}
748
749#ifdef HAVE_SENDMSG
750
751int
Denys Vlasenko12014262011-05-30 14:00:14 +0200752sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753{
754 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800755 printfd(tcp, tcp->u_arg[0]);
756 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757 } else {
758 if (syserror(tcp) || !verbose(tcp))
759 tprintf("%#lx", tcp->u_arg[1]);
760 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200761 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200763 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000764 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765 }
766 return 0;
767}
768
Andreas Schwab0873f292010-02-12 21:39:12 +0100769int
770sys_recvmmsg(struct tcb *tcp)
771{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100772 /* +5 chars are for "left " prefix */
773 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400774
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100775 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800776 printfd(tcp, tcp->u_arg[0]);
777 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400778 if (verbose(tcp)) {
779 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100780 /* Abusing tcp->auxstr as temp storage.
781 * Will be used and freed on syscall exit.
782 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400783 tcp->auxstr = strdup(str);
784 } else {
785 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
786 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200787 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400788 print_timespec(tcp, tcp->u_arg[4]);
789 }
790 return 0;
791 } else {
792 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000793 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400794 /* timeout on entrance */
795 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
796 free((void *) tcp->auxstr);
797 tcp->auxstr = NULL;
798 }
799 if (syserror(tcp))
800 return 0;
801 if (tcp->u_rval == 0) {
802 tcp->auxstr = "Timeout";
803 return RVAL_STR;
804 }
805 if (!verbose(tcp))
806 return 0;
807 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100808 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400809 tcp->auxstr = str;
810 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100811 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100812}
Andreas Schwab0873f292010-02-12 21:39:12 +0100813
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814#endif /* HAVE_SENDMSG */
815
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000816#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100817
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818int
Denys Vlasenko12014262011-05-30 14:00:14 +0200819sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820{
821 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800822 printfd(tcp, tcp->u_arg[0]);
823 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100824 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 }
826 return 0;
827}
828
829int
Denys Vlasenko12014262011-05-30 14:00:14 +0200830sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000832 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833}
834
835int
Denys Vlasenko12014262011-05-30 14:00:14 +0200836sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000838 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839}
840
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000841static int
842do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844 if (exiting(tcp)) {
845 if (syserror(tcp)) {
846 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000847 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100848#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000849 int fds[2];
850
851 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200852 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000853 else
854 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100855#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000856 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
857#else
858 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000860 }
861 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000863 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
864 }
865 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000866 return 0;
867}
868
869int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000870sys_pipe(struct tcb *tcp)
871{
872 return do_pipe(tcp, -1);
873}
874
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000875int
876sys_pipe2(struct tcb *tcp)
877{
878 return do_pipe(tcp, 1);
879}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000880
881int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000882sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000885
886 if (entering(tcp)) {
887 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200888 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000889 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000890 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000891 } else {
892 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000893 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894 return 0;
895 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200897 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898 else
899 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000900 }
901 return 0;
902}
903
904int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000905sys_getsockopt(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(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000910 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200911 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912 switch (tcp->u_arg[1]) {
913 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915 break;
916#ifdef SOL_IP
917 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000918 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919 break;
920#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000921#ifdef SOL_IPV6
922 case SOL_IPV6:
923 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
924 break;
925#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926#ifdef SOL_IPX
927 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929 break;
930#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000931#ifdef SOL_PACKET
932 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000933 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000934 break;
935#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936#ifdef SOL_TCP
937 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939 break;
940#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100941#ifdef SOL_SCTP
942 case SOL_SCTP:
943 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
944 break;
945#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946
947 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
948 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000949 default:
John Hughes93f7fcc2002-05-22 15:46:49 +0000950 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000951 break;
952 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200953 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +0000955 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200956 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +0000957 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958 tcp->u_arg[3], tcp->u_arg[4]);
959 return 0;
960 }
John Hughes93f7fcc2002-05-22 15:46:49 +0000961
962 switch (tcp->u_arg[1]) {
963 case SOL_SOCKET:
964 switch (tcp->u_arg[2]) {
965#ifdef SO_LINGER
966 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200967 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +0000968 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200969 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +0000970 tcp->u_arg[3],
971 &linger) < 0)
972 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +0000973 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +0000974 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +0000975 linger.l_onoff,
976 linger.l_linger,
977 len);
978 return 0;
979 }
980 break;
981#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000982#ifdef SO_PEERCRED
983 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200984 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000985 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200986 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000987 tcp->u_arg[3],
988 &uc) < 0)
989 break;
990 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
991 "[%d]",
992 (long)uc.pid,
993 (long)uc.uid,
994 (long)uc.gid,
995 len);
996 return 0;
997 }
998 break;
999#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001000 }
1001 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001002 case SOL_PACKET:
1003 switch (tcp->u_arg[2]) {
1004#ifdef PACKET_STATISTICS
1005 case PACKET_STATISTICS:
1006 if (len == sizeof(struct tpacket_stats)) {
1007 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001008 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001009 tcp->u_arg[3],
1010 &stats) < 0)
1011 break;
1012 tprintf("{packets=%u, drops=%u}, "
1013 "[%d]",
1014 stats.tp_packets,
1015 stats.tp_drops,
1016 len);
1017 return 0;
1018 }
1019 break;
1020#endif
1021 }
1022 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001023 }
1024
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001025 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001026 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001027 }
1028 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001029 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001030 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001031 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 }
1033 return 0;
1034}
1035
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001036#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001037static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001038{
1039 struct icmp_filter filter;
1040
1041 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001042 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001043 return;
1044 }
1045 if (syserror(tcp) || !verbose(tcp)) {
1046 tprintf("%#lx", addr);
1047 return;
1048 }
1049 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001050 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001051 return;
1052 }
1053
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001054 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001055 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001057}
1058#endif /* ICMP_FILTER */
1059
John Hughes38ae88d2002-05-23 11:48:58 +00001060static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001061printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001062{
1063 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001064 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001065 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001066 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001067 printxval(sockoptions, name, "SO_???");
1068 switch (name) {
1069#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001070 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001071 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001072 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001073 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001074 break;
1075 tprintf(", {onoff=%d, linger=%d}",
1076 linger.l_onoff,
1077 linger.l_linger);
1078 return 0;
1079 }
1080 break;
1081#endif
1082 }
1083 break;
1084#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001085 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001086 printxval(sockipoptions, name, "IP_???");
1087 break;
1088#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001089#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001090 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001091 printxval(sockipv6options, name, "IPV6_???");
1092 break;
1093#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001094#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001095 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001096 printxval(sockipxoptions, name, "IPX_???");
1097 break;
1098#endif
1099#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001100 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001101 printxval(sockpacketoptions, name, "PACKET_???");
1102 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001103 switch (name) {
1104#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001105 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001106#endif
1107#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001108 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001109#endif
1110#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1111 if (len == sizeof(struct tpacket_req)) {
1112 struct tpacket_req req;
1113 if (umove(tcp, addr, &req) < 0)
1114 break;
1115 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1116 req.tp_block_size,
1117 req.tp_block_nr,
1118 req.tp_frame_size,
1119 req.tp_frame_nr);
1120 return 0;
1121 }
1122 break;
1123#endif /* PACKET_RX_RING || PACKET_TX_RING */
1124 }
John Hughes38ae88d2002-05-23 11:48:58 +00001125 break;
1126#endif
1127#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001128 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001129 printxval(socktcpoptions, name, "TCP_???");
1130 break;
1131#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001132#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001133 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001134 printxval(socksctpoptions, name, "SCTP_???");
1135 break;
1136#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001137#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001138 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001139 printxval(sockrawoptions, name, "RAW_???");
1140 switch (name) {
1141#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001142 case ICMP_FILTER:
1143 tprints(", ");
1144 printicmpfilter(tcp, addr);
1145 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001146#endif
1147 }
1148 break;
1149#endif
1150
Roland McGrath6d2b3492002-12-30 00:51:30 +00001151 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001152 * etc. still need work */
1153
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001154 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001155 tprintf("%u", name);
1156 }
1157
1158 /* default arg printing */
1159
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001160 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001161
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001162 if (len == sizeof(int)) {
1163 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001164 }
1165 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001166 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001167 }
1168 return 0;
1169}
1170
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171int
Denys Vlasenko12014262011-05-30 14:00:14 +02001172sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001173{
1174 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001175 printfd(tcp, tcp->u_arg[0]);
1176 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001177 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001178 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001179 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 }
1181 return 0;
1182}