blob: 08341adcf75e45968e101f3687ca1e997c9ee19b [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. Levinb6c32f42007-10-08 23:31:19 +0000192 if (addrlen < 2 || addrlen > sizeof(addrbuf))
193 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);
276 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
277 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
494tprint_sock_type(struct tcb *tcp, int flags)
495{
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. Levin8a550d72008-11-10 17:21:23 +0000514 tprint_sock_type(tcp, 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
574do_accept(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{
605 return do_accept(tcp, -1);
606}
607
Paolo Bonzini705ff102009-08-14 12:34:05 +0200608int
609sys_accept4(struct tcb *tcp)
610{
611 return do_accept(tcp, 3);
612}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200613
614int
Denys Vlasenko12014262011-05-30 14:00:14 +0200615sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616{
617 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800618 printfd(tcp, tcp->u_arg[0]);
619 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
621 tprintf(", %lu, ", tcp->u_arg[2]);
622 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000623 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624 }
625 return 0;
626}
627
628int
Denys Vlasenko12014262011-05-30 14:00:14 +0200629sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630{
631 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800632 printfd(tcp, tcp->u_arg[0]);
633 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
635 tprintf(", %lu, ", tcp->u_arg[2]);
636 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000637 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200639 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000640 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641 /* to length */
642 tprintf(", %lu", tcp->u_arg[5]);
643 }
644 return 0;
645}
646
647#ifdef HAVE_SENDMSG
648
649int
Denys Vlasenko12014262011-05-30 14:00:14 +0200650sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651{
652 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800653 printfd(tcp, tcp->u_arg[0]);
654 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000655 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200657 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000658 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 }
660 return 0;
661}
662
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000663int
664sys_sendmmsg(struct tcb *tcp)
665{
666 if (entering(tcp)) {
667 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800668 printfd(tcp, tcp->u_arg[0]);
669 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000670 if (!verbose(tcp)) {
671 tprintf("%#lx, %u, ",
672 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
673 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
674 }
675 } else {
676 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000677 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000678 }
679 return 0;
680}
681
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682#endif /* HAVE_SENDMSG */
683
684int
Denys Vlasenko12014262011-05-30 14:00:14 +0200685sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686{
687 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800688 printfd(tcp, tcp->u_arg[0]);
689 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690 } else {
691 if (syserror(tcp))
692 tprintf("%#lx", tcp->u_arg[1]);
693 else
694 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
695
696 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000697 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698 }
699 return 0;
700}
701
702int
Denys Vlasenko12014262011-05-30 14:00:14 +0200703sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704{
705 int fromlen;
706
707 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800708 printfd(tcp, tcp->u_arg[0]);
709 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 } else {
711 if (syserror(tcp)) {
712 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
713 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
714 tcp->u_arg[4], tcp->u_arg[5]);
715 return 0;
716 }
717 /* buf */
718 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
719 /* len */
720 tprintf(", %lu, ", tcp->u_arg[2]);
721 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000722 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723 /* from address, len */
724 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
725 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200726 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727 else
728 tprintf(", %#lx", tcp->u_arg[4]);
729 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200730 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 else
732 tprintf(", %#lx", tcp->u_arg[5]);
733 return 0;
734 }
735 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200736 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737 return 0;
738 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200739 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000740 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741 /* from length */
742 tprintf(", [%u]", fromlen);
743 }
744 return 0;
745}
746
747#ifdef HAVE_SENDMSG
748
749int
Denys Vlasenko12014262011-05-30 14:00:14 +0200750sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751{
752 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800753 printfd(tcp, tcp->u_arg[0]);
754 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755 } else {
756 if (syserror(tcp) || !verbose(tcp))
757 tprintf("%#lx", tcp->u_arg[1]);
758 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200759 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200761 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000762 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 }
764 return 0;
765}
766
Andreas Schwab0873f292010-02-12 21:39:12 +0100767int
768sys_recvmmsg(struct tcb *tcp)
769{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100770 /* +5 chars are for "left " prefix */
771 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400772
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100773 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800774 printfd(tcp, tcp->u_arg[0]);
775 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400776 if (verbose(tcp)) {
777 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100778 /* Abusing tcp->auxstr as temp storage.
779 * Will be used and freed on syscall exit.
780 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400781 tcp->auxstr = strdup(str);
782 } else {
783 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
784 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200785 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400786 print_timespec(tcp, tcp->u_arg[4]);
787 }
788 return 0;
789 } else {
790 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000791 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400792 /* timeout on entrance */
793 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
794 free((void *) tcp->auxstr);
795 tcp->auxstr = NULL;
796 }
797 if (syserror(tcp))
798 return 0;
799 if (tcp->u_rval == 0) {
800 tcp->auxstr = "Timeout";
801 return RVAL_STR;
802 }
803 if (!verbose(tcp))
804 return 0;
805 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100806 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400807 tcp->auxstr = str;
808 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100809 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100810}
Andreas Schwab0873f292010-02-12 21:39:12 +0100811
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812#endif /* HAVE_SENDMSG */
813
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000814#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100815
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816int
Denys Vlasenko12014262011-05-30 14:00:14 +0200817sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818{
819 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800820 printfd(tcp, tcp->u_arg[0]);
821 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100822 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000823 }
824 return 0;
825}
826
827int
Denys Vlasenko12014262011-05-30 14:00:14 +0200828sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829{
830 return sys_accept(tcp);
831}
832
833int
Denys Vlasenko12014262011-05-30 14:00:14 +0200834sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835{
836 return sys_accept(tcp);
837}
838
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000839static int
840do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000842 if (exiting(tcp)) {
843 if (syserror(tcp)) {
844 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000845 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100846#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000847 int fds[2];
848
849 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200850 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000851 else
852 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100853#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000854 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
855#else
856 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000858 }
859 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200860 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000861 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
862 }
863 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864 return 0;
865}
866
867int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000868sys_pipe(struct tcb *tcp)
869{
870 return do_pipe(tcp, -1);
871}
872
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000873int
874sys_pipe2(struct tcb *tcp)
875{
876 return do_pipe(tcp, 1);
877}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000878
879int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000880sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883
884 if (entering(tcp)) {
885 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200886 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000887 tprint_sock_type(tcp, tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000888 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889 } else {
890 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000891 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000892 return 0;
893 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896 else
897 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898 }
899 return 0;
900}
901
902int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000903sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000904{
905 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800906 printfd(tcp, tcp->u_arg[0]);
907 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000908 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200909 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910 switch (tcp->u_arg[1]) {
911 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000913 break;
914#ifdef SOL_IP
915 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917 break;
918#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000919#ifdef SOL_IPV6
920 case SOL_IPV6:
921 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
922 break;
923#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924#ifdef SOL_IPX
925 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927 break;
928#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000929#ifdef SOL_PACKET
930 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000931 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000932 break;
933#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934#ifdef SOL_TCP
935 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937 break;
938#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100939#ifdef SOL_SCTP
940 case SOL_SCTP:
941 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
942 break;
943#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944
945 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
946 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000947 default:
John Hughes93f7fcc2002-05-22 15:46:49 +0000948 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949 break;
950 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200951 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +0000953 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200954 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +0000955 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 tcp->u_arg[3], tcp->u_arg[4]);
957 return 0;
958 }
John Hughes93f7fcc2002-05-22 15:46:49 +0000959
960 switch (tcp->u_arg[1]) {
961 case SOL_SOCKET:
962 switch (tcp->u_arg[2]) {
963#ifdef SO_LINGER
964 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200965 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +0000966 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200967 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +0000968 tcp->u_arg[3],
969 &linger) < 0)
970 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +0000971 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +0000972 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +0000973 linger.l_onoff,
974 linger.l_linger,
975 len);
976 return 0;
977 }
978 break;
979#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000980#ifdef SO_PEERCRED
981 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200982 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000983 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200984 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000985 tcp->u_arg[3],
986 &uc) < 0)
987 break;
988 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
989 "[%d]",
990 (long)uc.pid,
991 (long)uc.uid,
992 (long)uc.gid,
993 len);
994 return 0;
995 }
996 break;
997#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000998 }
999 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001000 case SOL_PACKET:
1001 switch (tcp->u_arg[2]) {
1002#ifdef PACKET_STATISTICS
1003 case PACKET_STATISTICS:
1004 if (len == sizeof(struct tpacket_stats)) {
1005 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001006 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001007 tcp->u_arg[3],
1008 &stats) < 0)
1009 break;
1010 tprintf("{packets=%u, drops=%u}, "
1011 "[%d]",
1012 stats.tp_packets,
1013 stats.tp_drops,
1014 len);
1015 return 0;
1016 }
1017 break;
1018#endif
1019 }
1020 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001021 }
1022
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001023 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001024 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001025 }
1026 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001027 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001028 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001029 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030 }
1031 return 0;
1032}
1033
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001034#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001035static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001036{
1037 struct icmp_filter filter;
1038
1039 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001040 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001041 return;
1042 }
1043 if (syserror(tcp) || !verbose(tcp)) {
1044 tprintf("%#lx", addr);
1045 return;
1046 }
1047 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001048 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001049 return;
1050 }
1051
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001052 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001053 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001054 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001055}
1056#endif /* ICMP_FILTER */
1057
John Hughes38ae88d2002-05-23 11:48:58 +00001058static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001059printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001060{
1061 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001062 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001063 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001064 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001065 printxval(sockoptions, name, "SO_???");
1066 switch (name) {
1067#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001068 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001069 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001070 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001071 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001072 break;
1073 tprintf(", {onoff=%d, linger=%d}",
1074 linger.l_onoff,
1075 linger.l_linger);
1076 return 0;
1077 }
1078 break;
1079#endif
1080 }
1081 break;
1082#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001083 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001084 printxval(sockipoptions, name, "IP_???");
1085 break;
1086#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001087#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001088 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001089 printxval(sockipv6options, name, "IPV6_???");
1090 break;
1091#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001092#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001093 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001094 printxval(sockipxoptions, name, "IPX_???");
1095 break;
1096#endif
1097#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001098 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001099 printxval(sockpacketoptions, name, "PACKET_???");
1100 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001101 switch (name) {
1102#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001103 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001104#endif
1105#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001106 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001107#endif
1108#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1109 if (len == sizeof(struct tpacket_req)) {
1110 struct tpacket_req req;
1111 if (umove(tcp, addr, &req) < 0)
1112 break;
1113 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1114 req.tp_block_size,
1115 req.tp_block_nr,
1116 req.tp_frame_size,
1117 req.tp_frame_nr);
1118 return 0;
1119 }
1120 break;
1121#endif /* PACKET_RX_RING || PACKET_TX_RING */
1122 }
John Hughes38ae88d2002-05-23 11:48:58 +00001123 break;
1124#endif
1125#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001126 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001127 printxval(socktcpoptions, name, "TCP_???");
1128 break;
1129#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001130#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001131 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001132 printxval(socksctpoptions, name, "SCTP_???");
1133 break;
1134#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001135#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001136 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001137 printxval(sockrawoptions, name, "RAW_???");
1138 switch (name) {
1139#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001140 case ICMP_FILTER:
1141 tprints(", ");
1142 printicmpfilter(tcp, addr);
1143 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001144#endif
1145 }
1146 break;
1147#endif
1148
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001150 * etc. still need work */
1151
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001152 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001153 tprintf("%u", name);
1154 }
1155
1156 /* default arg printing */
1157
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001158 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001159
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001160 if (len == sizeof(int)) {
1161 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001162 }
1163 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001164 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001165 }
1166 return 0;
1167}
1168
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169int
Denys Vlasenko12014262011-05-30 14:00:14 +02001170sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171{
1172 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001173 printfd(tcp, tcp->u_arg[0]);
1174 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001175 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001176 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001177 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178 }
1179 return 0;
1180}