blob: ab33ab4e423ab861560c6530876a39b0b7b7aa32 [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"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000115#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100117#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000118#define SOL_IP IPPROTO_IP
119#endif
120
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000122#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000123#endif /* SOL_IP */
124
Roland McGrath4f6ba692004-08-31 07:01:26 +0000125#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000126#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000127#endif /* SOL_IPV6 */
128
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000130#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#endif /* SOL_IPX */
132
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000133#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000134#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000135#endif /* SOL_RAW */
136
137#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000138#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000139#endif /* SOL_PACKET */
140
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100141#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000142#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100143#endif
144
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100145#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000146#define SOL_TCP IPPROTO_TCP
147#endif
148
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000150#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#endif /* SOL_TCP */
152
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000153#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000154#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000155#endif /* SOL_RAW */
156
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000157#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000158#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000159#endif /* defined(AF_PACKET) */
160
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000162printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000164 union {
165 char pad[128];
166 struct sockaddr sa;
167 struct sockaddr_in sin;
168 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000169#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000170 struct sockaddr_in6 sa6;
171#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100172#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000173 struct sockaddr_ipx sipx;
174#endif
175#ifdef AF_PACKET
176 struct sockaddr_ll ll;
177#endif
178#ifdef AF_NETLINK
179 struct sockaddr_nl nl;
180#endif
181 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000182 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183
184 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200185 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 return;
187 }
188 if (!verbose(tcp)) {
189 tprintf("%#lx", addr);
190 return;
191 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000192
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000193 if (addrlen < 2 || addrlen > sizeof(addrbuf))
194 addrlen = sizeof(addrbuf);
195
196 memset(&addrbuf, 0, sizeof(addrbuf));
197 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200198 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199 return;
200 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000201 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000202
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200203 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000204 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200205 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000206
207 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000209 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200210 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000211 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000212 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000213 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000214 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000215 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000216 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000217 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 break;
219 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000220 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000221 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000223#ifdef HAVE_INET_NTOP
224 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000225 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000226 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
227 ntohs(addrbuf.sa6.sin6_port), string_addr,
228 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000229#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000230 {
231#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200232 int numericscope = 0;
233 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
234 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
235 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000236
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200237 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
238 numericscope++;
239 else
240 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
241 } else
242 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000243
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200244 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000245#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200246 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000247 }
248#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200249 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000250#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100251#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000253 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000254 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000255 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000256 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257 /* Yes, I know, this does not look too
258 * strace-ish, but otherwise the IPX
259 * addresses just look monstrous...
260 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000261 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000263 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200264 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000265 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
266 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 }
268 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100269#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000270#ifdef AF_PACKET
271 case AF_PACKET:
272 {
273 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000274 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000275 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000276 addrbuf.ll.sll_ifindex);
277 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
278 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000279 addrbuf.ll.sll_halen,
280 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200281 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000282 tprintf("%02x", addrbuf.ll.sll_addr[i]);
283 }
284 break;
285
Denys Vlasenko84703742012-02-25 02:38:52 +0100286#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000287#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000288 case AF_NETLINK:
289 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
290 break;
291#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000293 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294
295 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000298 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299 break;
300 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200301 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302}
303
304#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000305#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000306
307static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000308printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000309{
Roland McGrathaa524c82005-06-01 19:22:06 +0000310 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
311 NULL : malloc(len);
312 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000313 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000314 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000315 return;
316 }
317
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000318 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000319 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000321
Roland McGrathaa524c82005-06-01 19:22:06 +0000322 if (cmsg->cmsg_level == SOL_SOCKET) {
323 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000324
Roland McGrathaa524c82005-06-01 19:22:06 +0000325 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
326 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
327
328 if (cmsg->cmsg_type == SCM_RIGHTS
329 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200330 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000331 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000332
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200333 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000334 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000335 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200336 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000337 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000338 first = 0;
339 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200340 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000341 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000342 return;
343 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000344 if (cmsg->cmsg_type == SCM_CREDENTIALS
345 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200346 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000347
Roland McGrath50770822004-10-06 22:11:51 +0000348 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
349 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000350 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000351 return;
352 }
353 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000354 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200355 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000356}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357
358static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200359do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100360{
361 tprintf("{msg_name(%d)=", msg->msg_namelen);
362 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
363
364 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200365 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
366 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100367
368#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
369 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
370 if (msg->msg_controllen)
371 printcmsghdr(tcp, (unsigned long) msg->msg_control,
372 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200373 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100374 printflags(msg_flags, msg->msg_flags, "MSG_???");
375#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
376 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
377 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
378#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200379 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100380}
381
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100382struct msghdr32 {
383 uint32_t /* void* */ msg_name;
384 uint32_t /* socklen_t */msg_namelen;
385 uint32_t /* iovec* */ msg_iov;
386 uint32_t /* size_t */ msg_iovlen;
387 uint32_t /* void* */ msg_control;
388 uint32_t /* size_t */ msg_controllen;
389 uint32_t /* int */ msg_flags;
390};
391struct mmsghdr32 {
392 struct msghdr32 msg_hdr;
393 uint32_t /* unsigned */ msg_len;
394};
395
Andreas Schwab0873f292010-02-12 21:39:12 +0100396static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200397printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398{
399 struct msghdr msg;
400
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100401#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
402 if (current_wordsize == 4) {
403 struct msghdr32 msg32;
404
405 if (umove(tcp, addr, &msg32) < 0) {
406 tprintf("%#lx", addr);
407 return;
408 }
409 msg.msg_name = (void*)(long)msg32.msg_name;
410 msg.msg_namelen = msg32.msg_namelen;
411 msg.msg_iov = (void*)(long)msg32.msg_iov;
412 msg.msg_iovlen = msg32.msg_iovlen;
413 msg.msg_control = (void*)(long)msg32.msg_control;
414 msg.msg_controllen = msg32.msg_controllen;
415 msg.msg_flags = msg32.msg_flags;
416 } else
417#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000418 if (umove(tcp, addr, &msg) < 0) {
419 tprintf("%#lx", addr);
420 return;
421 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200422 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423}
424
Andreas Schwab0873f292010-02-12 21:39:12 +0100425static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000426printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100427{
428 struct mmsghdr {
429 struct msghdr msg_hdr;
430 unsigned msg_len;
431 } mmsg;
432
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100433#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
434 if (current_wordsize == 4) {
435 struct mmsghdr32 mmsg32;
436
437 addr += sizeof(mmsg32) * idx;
438 if (umove(tcp, addr, &mmsg32) < 0) {
439 tprintf("%#lx", addr);
440 return;
441 }
442 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
443 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
444 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
445 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
446 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
447 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
448 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
449 mmsg.msg_len = mmsg32.msg_len;
450 } else
451#endif
452 {
453 addr += sizeof(mmsg) * idx;
454 if (umove(tcp, addr, &mmsg) < 0) {
455 tprintf("%#lx", addr);
456 return;
457 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100458 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200459 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000460 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100461 tprintf(", %u}", mmsg.msg_len);
462}
Andreas Schwab0873f292010-02-12 21:39:12 +0100463
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000464static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000465decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000466{
467 /* mmsgvec */
468 if (syserror(tcp)) {
469 tprintf("%#lx", tcp->u_arg[1]);
470 } else {
471 unsigned int len = tcp->u_rval;
472 unsigned int i;
473
474 tprints("{");
475 for (i = 0; i < len; ++i) {
476 if (i)
477 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000478 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000479 }
480 tprints("}");
481 }
482 /* vlen */
483 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
484 /* flags */
485 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
486}
487
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488#endif /* HAVE_SENDMSG */
489
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000490/*
491 * low bits of the socket type define real socket type,
492 * other bits are socket type flags.
493 */
494static void
495tprint_sock_type(struct tcb *tcp, int flags)
496{
497 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
498
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200499 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200500 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000501 flags &= ~SOCK_TYPE_MASK;
502 if (!flags)
503 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200504 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000505 }
506 printflags(sock_type_flags, flags, "SOCK_???");
507}
508
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000510sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511{
512 if (entering(tcp)) {
513 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200514 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000515 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 switch (tcp->u_arg[0]) {
518 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000519#ifdef PF_INET6
520 case PF_INET6:
521#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900522 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 break;
524#ifdef PF_IPX
525 case PF_IPX:
526 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200527 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200529 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 break;
531#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900532#ifdef PF_NETLINK
533 case PF_NETLINK:
534 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
535 break;
536#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 default:
538 tprintf("%lu", tcp->u_arg[2]);
539 break;
540 }
541 }
542 return 0;
543}
544
John Hughesbdf48f52001-03-06 15:08:09 +0000545int
Denys Vlasenko12014262011-05-30 14:00:14 +0200546sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547{
548 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800549 printfd(tcp, tcp->u_arg[0]);
550 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000551 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 tprintf(", %lu", tcp->u_arg[2]);
553 }
554 return 0;
555}
556
557int
Denys Vlasenko12014262011-05-30 14:00:14 +0200558sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559{
560 return sys_bind(tcp);
561}
562
563int
Denys Vlasenko12014262011-05-30 14:00:14 +0200564sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565{
566 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800567 printfd(tcp, tcp->u_arg[0]);
568 tprints(", ");
569 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 }
571 return 0;
572}
573
Paolo Bonzini705ff102009-08-14 12:34:05 +0200574static int
575do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576{
577 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800578 printfd(tcp, tcp->u_arg[0]);
579 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200580 return 0;
581 }
582 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 tprintf("%#lx, NULL", tcp->u_arg[1]);
584 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000585 int len;
586 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200587 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588 tprintf("%#lx", tcp->u_arg[1]);
589 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000590 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200592 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000593 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200595 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200596 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200597 printflags(sock_type_flags, tcp->u_arg[flags_arg],
598 "SOCK_???");
599 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 return 0;
601}
602
603int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200604sys_accept(struct tcb *tcp)
605{
606 return do_accept(tcp, -1);
607}
608
Paolo Bonzini705ff102009-08-14 12:34:05 +0200609int
610sys_accept4(struct tcb *tcp)
611{
612 return do_accept(tcp, 3);
613}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200614
615int
Denys Vlasenko12014262011-05-30 14:00:14 +0200616sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617{
618 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800619 printfd(tcp, tcp->u_arg[0]);
620 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000621 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
622 tprintf(", %lu, ", tcp->u_arg[2]);
623 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000624 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625 }
626 return 0;
627}
628
629int
Denys Vlasenko12014262011-05-30 14:00:14 +0200630sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631{
632 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800633 printfd(tcp, tcp->u_arg[0]);
634 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
636 tprintf(", %lu, ", tcp->u_arg[2]);
637 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000638 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200640 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000641 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 /* to length */
643 tprintf(", %lu", tcp->u_arg[5]);
644 }
645 return 0;
646}
647
648#ifdef HAVE_SENDMSG
649
650int
Denys Vlasenko12014262011-05-30 14:00:14 +0200651sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652{
653 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800654 printfd(tcp, tcp->u_arg[0]);
655 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000656 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200658 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000659 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 }
661 return 0;
662}
663
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000664int
665sys_sendmmsg(struct tcb *tcp)
666{
667 if (entering(tcp)) {
668 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800669 printfd(tcp, tcp->u_arg[0]);
670 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000671 if (!verbose(tcp)) {
672 tprintf("%#lx, %u, ",
673 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
674 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
675 }
676 } else {
677 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000678 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000679 }
680 return 0;
681}
682
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683#endif /* HAVE_SENDMSG */
684
685int
Denys Vlasenko12014262011-05-30 14:00:14 +0200686sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687{
688 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800689 printfd(tcp, tcp->u_arg[0]);
690 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691 } else {
692 if (syserror(tcp))
693 tprintf("%#lx", tcp->u_arg[1]);
694 else
695 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
696
697 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000698 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699 }
700 return 0;
701}
702
703int
Denys Vlasenko12014262011-05-30 14:00:14 +0200704sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
706 int fromlen;
707
708 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800709 printfd(tcp, tcp->u_arg[0]);
710 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 } else {
712 if (syserror(tcp)) {
713 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
714 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
715 tcp->u_arg[4], tcp->u_arg[5]);
716 return 0;
717 }
718 /* buf */
719 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
720 /* len */
721 tprintf(", %lu, ", tcp->u_arg[2]);
722 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000723 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724 /* from address, len */
725 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
726 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200727 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000728 else
729 tprintf(", %#lx", tcp->u_arg[4]);
730 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200731 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732 else
733 tprintf(", %#lx", tcp->u_arg[5]);
734 return 0;
735 }
736 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200737 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738 return 0;
739 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200740 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000741 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742 /* from length */
743 tprintf(", [%u]", fromlen);
744 }
745 return 0;
746}
747
748#ifdef HAVE_SENDMSG
749
750int
Denys Vlasenko12014262011-05-30 14:00:14 +0200751sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752{
753 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800754 printfd(tcp, tcp->u_arg[0]);
755 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 } else {
757 if (syserror(tcp) || !verbose(tcp))
758 tprintf("%#lx", tcp->u_arg[1]);
759 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200760 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000763 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 }
765 return 0;
766}
767
Andreas Schwab0873f292010-02-12 21:39:12 +0100768int
769sys_recvmmsg(struct tcb *tcp)
770{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100771 /* +5 chars are for "left " prefix */
772 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400773
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100774 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800775 printfd(tcp, tcp->u_arg[0]);
776 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400777 if (verbose(tcp)) {
778 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100779 /* Abusing tcp->auxstr as temp storage.
780 * Will be used and freed on syscall exit.
781 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400782 tcp->auxstr = strdup(str);
783 } else {
784 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
785 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200786 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400787 print_timespec(tcp, tcp->u_arg[4]);
788 }
789 return 0;
790 } else {
791 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000792 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400793 /* timeout on entrance */
794 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
795 free((void *) tcp->auxstr);
796 tcp->auxstr = NULL;
797 }
798 if (syserror(tcp))
799 return 0;
800 if (tcp->u_rval == 0) {
801 tcp->auxstr = "Timeout";
802 return RVAL_STR;
803 }
804 if (!verbose(tcp))
805 return 0;
806 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100807 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400808 tcp->auxstr = str;
809 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100810 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100811}
Andreas Schwab0873f292010-02-12 21:39:12 +0100812
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813#endif /* HAVE_SENDMSG */
814
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000815#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100816
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817int
Denys Vlasenko12014262011-05-30 14:00:14 +0200818sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819{
820 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800821 printfd(tcp, tcp->u_arg[0]);
822 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100823 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824 }
825 return 0;
826}
827
828int
Denys Vlasenko12014262011-05-30 14:00:14 +0200829sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000830{
831 return sys_accept(tcp);
832}
833
834int
Denys Vlasenko12014262011-05-30 14:00:14 +0200835sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836{
837 return sys_accept(tcp);
838}
839
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000840static int
841do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000842{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 if (exiting(tcp)) {
844 if (syserror(tcp)) {
845 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000846 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100847#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000848 int fds[2];
849
850 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200851 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000852 else
853 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100854#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000855 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
856#else
857 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000858#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000859 }
860 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200861 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000862 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
863 }
864 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865 return 0;
866}
867
868int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000869sys_pipe(struct tcb *tcp)
870{
871 return do_pipe(tcp, -1);
872}
873
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000874int
875sys_pipe2(struct tcb *tcp)
876{
877 return do_pipe(tcp, 1);
878}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000879
880int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000881sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884
885 if (entering(tcp)) {
886 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200887 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000888 tprint_sock_type(tcp, tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000889 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890 } else {
891 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000892 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893 return 0;
894 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200896 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000897 else
898 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899 }
900 return 0;
901}
902
903int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000904sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000905{
906 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800907 printfd(tcp, tcp->u_arg[0]);
908 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000909 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200910 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911 switch (tcp->u_arg[1]) {
912 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000913 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914 break;
915#ifdef SOL_IP
916 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000918 break;
919#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000920#ifdef SOL_IPV6
921 case SOL_IPV6:
922 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
923 break;
924#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000925#ifdef SOL_IPX
926 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928 break;
929#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000930#ifdef SOL_PACKET
931 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000932 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000933 break;
934#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000935#ifdef SOL_TCP
936 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938 break;
939#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100940#ifdef SOL_SCTP
941 case SOL_SCTP:
942 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
943 break;
944#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945
946 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
947 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000948 default:
John Hughes93f7fcc2002-05-22 15:46:49 +0000949 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 break;
951 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200952 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +0000954 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200955 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +0000956 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 tcp->u_arg[3], tcp->u_arg[4]);
958 return 0;
959 }
John Hughes93f7fcc2002-05-22 15:46:49 +0000960
961 switch (tcp->u_arg[1]) {
962 case SOL_SOCKET:
963 switch (tcp->u_arg[2]) {
964#ifdef SO_LINGER
965 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200966 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +0000967 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200968 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +0000969 tcp->u_arg[3],
970 &linger) < 0)
971 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +0000972 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +0000973 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +0000974 linger.l_onoff,
975 linger.l_linger,
976 len);
977 return 0;
978 }
979 break;
980#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000981#ifdef SO_PEERCRED
982 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200983 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000984 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200985 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000986 tcp->u_arg[3],
987 &uc) < 0)
988 break;
989 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
990 "[%d]",
991 (long)uc.pid,
992 (long)uc.uid,
993 (long)uc.gid,
994 len);
995 return 0;
996 }
997 break;
998#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000999 }
1000 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001001 case SOL_PACKET:
1002 switch (tcp->u_arg[2]) {
1003#ifdef PACKET_STATISTICS
1004 case PACKET_STATISTICS:
1005 if (len == sizeof(struct tpacket_stats)) {
1006 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001007 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001008 tcp->u_arg[3],
1009 &stats) < 0)
1010 break;
1011 tprintf("{packets=%u, drops=%u}, "
1012 "[%d]",
1013 stats.tp_packets,
1014 stats.tp_drops,
1015 len);
1016 return 0;
1017 }
1018 break;
1019#endif
1020 }
1021 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001022 }
1023
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001024 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001025 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001026 }
1027 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001028 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001029 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001030 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 }
1032 return 0;
1033}
1034
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001035#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001036static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001037{
1038 struct icmp_filter filter;
1039
1040 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001041 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001042 return;
1043 }
1044 if (syserror(tcp) || !verbose(tcp)) {
1045 tprintf("%#lx", addr);
1046 return;
1047 }
1048 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001049 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001050 return;
1051 }
1052
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001053 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001054 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001055 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001056}
1057#endif /* ICMP_FILTER */
1058
John Hughes38ae88d2002-05-23 11:48:58 +00001059static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001060printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001061{
1062 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001063 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001064 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001065 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001066 printxval(sockoptions, name, "SO_???");
1067 switch (name) {
1068#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001069 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001070 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001071 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001072 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001073 break;
1074 tprintf(", {onoff=%d, linger=%d}",
1075 linger.l_onoff,
1076 linger.l_linger);
1077 return 0;
1078 }
1079 break;
1080#endif
1081 }
1082 break;
1083#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001084 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001085 printxval(sockipoptions, name, "IP_???");
1086 break;
1087#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001088#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001089 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001090 printxval(sockipv6options, name, "IPV6_???");
1091 break;
1092#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001093#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001094 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001095 printxval(sockipxoptions, name, "IPX_???");
1096 break;
1097#endif
1098#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001099 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001100 printxval(sockpacketoptions, name, "PACKET_???");
1101 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001102 switch (name) {
1103#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001104 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001105#endif
1106#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001107 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001108#endif
1109#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1110 if (len == sizeof(struct tpacket_req)) {
1111 struct tpacket_req req;
1112 if (umove(tcp, addr, &req) < 0)
1113 break;
1114 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1115 req.tp_block_size,
1116 req.tp_block_nr,
1117 req.tp_frame_size,
1118 req.tp_frame_nr);
1119 return 0;
1120 }
1121 break;
1122#endif /* PACKET_RX_RING || PACKET_TX_RING */
1123 }
John Hughes38ae88d2002-05-23 11:48:58 +00001124 break;
1125#endif
1126#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001127 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001128 printxval(socktcpoptions, name, "TCP_???");
1129 break;
1130#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001131#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001132 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001133 printxval(socksctpoptions, name, "SCTP_???");
1134 break;
1135#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001136#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001137 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001138 printxval(sockrawoptions, name, "RAW_???");
1139 switch (name) {
1140#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001141 case ICMP_FILTER:
1142 tprints(", ");
1143 printicmpfilter(tcp, addr);
1144 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001145#endif
1146 }
1147 break;
1148#endif
1149
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001151 * etc. still need work */
1152
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001153 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001154 tprintf("%u", name);
1155 }
1156
1157 /* default arg printing */
1158
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001159 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001160
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001161 if (len == sizeof(int)) {
1162 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001163 }
1164 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001165 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001166 }
1167 return 0;
1168}
1169
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001170int
Denys Vlasenko12014262011-05-30 14:00:14 +02001171sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172{
1173 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001174 printfd(tcp, tcp->u_arg[0]);
1175 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001176 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001177 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001178 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001179 }
1180 return 0;
1181}