blob: a0e90a8fae5f92d2dbf52ef5271f27e4b67dba4e [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
34#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000035#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# define in6_addr in6_addr_libc
37# define ipv6_mreq ipv6_mreq_libc
38# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000041#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010042# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000043#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000044#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010047#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000051#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010053#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010054# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Denys Vlasenko99aa1812013-02-08 18:49:06 +010059#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010060# if defined(HAVE_LINUX_IN6_H)
61# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
62# undef in6_addr
63# undef ipv6_mreq
64# undef sockaddr_in6
65# define in6_addr in6_addr_kernel
66# define ipv6_mreq ipv6_mreq_kernel
67# define sockaddr_in6 sockaddr_in6_kernel
68# endif
69# include <linux/in6.h>
70# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
71# undef in6_addr
72# undef ipv6_mreq
73# undef sockaddr_in6
74# define in6_addr in6_addr_libc
75# define ipv6_mreq ipv6_mreq_libc
76# define sockaddr_in6 sockaddr_in6_kernel
77# endif
78# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000079#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000080
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000081#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010082# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010085# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010088# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010091# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010094# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095#endif
96
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000097#include "xlat/domains.h"
98#include "xlat/addrfams.h"
99#include "xlat/socktypes.h"
100#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000101#ifndef SOCK_TYPE_MASK
102# define SOCK_TYPE_MASK 0xf
103#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000104#include "xlat/socketlayers.h"
John Hughes93f7fcc2002-05-22 15:46:49 +0000105/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900106 falls into "inet_protocols" array below!!!! This is intended!!! ***/
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000107#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900108
109#ifdef PF_NETLINK
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000110#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900111#endif
112
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000113#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000114#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100116#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000117#define SOL_IP IPPROTO_IP
118#endif
119
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000121#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#endif /* SOL_IP */
123
Roland McGrath4f6ba692004-08-31 07:01:26 +0000124#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000125#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000126#endif /* SOL_IPV6 */
127
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000129#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130#endif /* SOL_IPX */
131
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000132#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000133#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000134#endif /* SOL_RAW */
135
136#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000137#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000138#endif /* SOL_PACKET */
139
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100140#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000141#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100142#endif
143
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100144#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000145#define SOL_TCP IPPROTO_TCP
146#endif
147
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000149#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#endif /* SOL_TCP */
151
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000152#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000153#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000154#endif /* SOL_RAW */
155
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000156#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000157#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000158#endif /* defined(AF_PACKET) */
159
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000161printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163 union {
164 char pad[128];
165 struct sockaddr sa;
166 struct sockaddr_in sin;
167 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000168#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000169 struct sockaddr_in6 sa6;
170#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100171#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000172 struct sockaddr_ipx sipx;
173#endif
174#ifdef AF_PACKET
175 struct sockaddr_ll ll;
176#endif
177#ifdef AF_NETLINK
178 struct sockaddr_nl nl;
179#endif
180 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000181 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182
183 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200184 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 return;
186 }
187 if (!verbose(tcp)) {
188 tprintf("%#lx", addr);
189 return;
190 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000191
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000192 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000193 addrlen = sizeof(addrbuf);
194
195 memset(&addrbuf, 0, sizeof(addrbuf));
196 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200197 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198 return;
199 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000200 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000201
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200202 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000203 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200204 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000205
206 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000208 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200209 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000210 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000211 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000212 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000213 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000214 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000215 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000216 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 break;
218 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000219 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000222#ifdef HAVE_INET_NTOP
223 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000224 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000225 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
226 ntohs(addrbuf.sa6.sin6_port), string_addr,
227 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000228#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000229 {
230#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200231 int numericscope = 0;
232 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
233 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
234 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000235
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200236 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
237 numericscope++;
238 else
239 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
240 } else
241 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000242
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200243 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000244#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200245 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000246 }
247#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000249#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100250#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000252 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000254 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000255 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 /* Yes, I know, this does not look too
257 * strace-ish, but otherwise the IPX
258 * addresses just look monstrous...
259 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000260 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000262 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000264 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
265 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 }
267 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100268#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000269#ifdef AF_PACKET
270 case AF_PACKET:
271 {
272 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000273 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000274 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000275 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000276 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000277 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000278 addrbuf.ll.sll_halen,
279 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200280 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000281 tprintf("%02x", addrbuf.ll.sll_addr[i]);
282 }
283 break;
284
Denys Vlasenko84703742012-02-25 02:38:52 +0100285#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000286#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287 case AF_NETLINK:
288 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
289 break;
290#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293
294 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200295 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000297 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298 break;
299 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200300 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301}
302
303#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000304#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000305
306static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000307printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000308{
Roland McGrathaa524c82005-06-01 19:22:06 +0000309 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
310 NULL : malloc(len);
311 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000312 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000313 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000314 return;
315 }
316
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000317 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000318 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000320
Roland McGrathaa524c82005-06-01 19:22:06 +0000321 if (cmsg->cmsg_level == SOL_SOCKET) {
322 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000323
Roland McGrathaa524c82005-06-01 19:22:06 +0000324 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
325 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
326
327 if (cmsg->cmsg_type == SCM_RIGHTS
328 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200329 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000330 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000331
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200332 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000333 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000334 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200335 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000336 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000337 first = 0;
338 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200339 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000340 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000341 return;
342 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000343 if (cmsg->cmsg_type == SCM_CREDENTIALS
344 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200345 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000346
Roland McGrath50770822004-10-06 22:11:51 +0000347 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
348 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000349 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000350 return;
351 }
352 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000353 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000355}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356
357static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200358do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100359{
360 tprintf("{msg_name(%d)=", msg->msg_namelen);
361 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
362
363 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200364 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
365 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100366
367#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
368 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
369 if (msg->msg_controllen)
370 printcmsghdr(tcp, (unsigned long) msg->msg_control,
371 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200372 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100373 printflags(msg_flags, msg->msg_flags, "MSG_???");
374#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
375 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
376 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
377#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200378 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100379}
380
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100381struct msghdr32 {
382 uint32_t /* void* */ msg_name;
383 uint32_t /* socklen_t */msg_namelen;
384 uint32_t /* iovec* */ msg_iov;
385 uint32_t /* size_t */ msg_iovlen;
386 uint32_t /* void* */ msg_control;
387 uint32_t /* size_t */ msg_controllen;
388 uint32_t /* int */ msg_flags;
389};
390struct mmsghdr32 {
391 struct msghdr32 msg_hdr;
392 uint32_t /* unsigned */ msg_len;
393};
394
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900395static bool
396extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
397{
398#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
399 if (current_wordsize == 4) {
400 struct msghdr32 msg32;
401
402 if (umove(tcp, addr, &msg32) < 0)
403 return false;
404 msg->msg_name = (void*)(long)msg32.msg_name;
405 msg->msg_namelen = msg32.msg_namelen;
406 msg->msg_iov = (void*)(long)msg32.msg_iov;
407 msg->msg_iovlen = msg32.msg_iovlen;
408 msg->msg_control = (void*)(long)msg32.msg_control;
409 msg->msg_controllen = msg32.msg_controllen;
410 msg->msg_flags = msg32.msg_flags;
411 } else
412#endif
413 if (umove(tcp, addr, msg) < 0)
414 return false;
415 return true;
416}
417
Andreas Schwab0873f292010-02-12 21:39:12 +0100418static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200419printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420{
421 struct msghdr msg;
422
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900423 if (extractmsghdr(tcp, addr, &msg))
424 do_msghdr(tcp, &msg, data_size);
425 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000426 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900427}
428
429void
430dumpiov_in_msghdr(struct tcb *tcp, long addr)
431{
432 struct msghdr msg;
433
434 if (extractmsghdr(tcp, addr, &msg))
435 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436}
437
Andreas Schwab0873f292010-02-12 21:39:12 +0100438static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000439printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100440{
441 struct mmsghdr {
442 struct msghdr msg_hdr;
443 unsigned msg_len;
444 } mmsg;
445
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100446#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
447 if (current_wordsize == 4) {
448 struct mmsghdr32 mmsg32;
449
450 addr += sizeof(mmsg32) * idx;
451 if (umove(tcp, addr, &mmsg32) < 0) {
452 tprintf("%#lx", addr);
453 return;
454 }
455 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
456 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
457 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
458 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
459 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
460 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
461 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
462 mmsg.msg_len = mmsg32.msg_len;
463 } else
464#endif
465 {
466 addr += sizeof(mmsg) * idx;
467 if (umove(tcp, addr, &mmsg) < 0) {
468 tprintf("%#lx", addr);
469 return;
470 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100471 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200472 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000473 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100474 tprintf(", %u}", mmsg.msg_len);
475}
Andreas Schwab0873f292010-02-12 21:39:12 +0100476
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000477static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000478decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000479{
480 /* mmsgvec */
481 if (syserror(tcp)) {
482 tprintf("%#lx", tcp->u_arg[1]);
483 } else {
484 unsigned int len = tcp->u_rval;
485 unsigned int i;
486
487 tprints("{");
488 for (i = 0; i < len; ++i) {
489 if (i)
490 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000491 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000492 }
493 tprints("}");
494 }
495 /* vlen */
496 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
497 /* flags */
498 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
499}
500
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501#endif /* HAVE_SENDMSG */
502
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000503/*
504 * low bits of the socket type define real socket type,
505 * other bits are socket type flags.
506 */
507static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000508tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000509{
510 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
511
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200512 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200513 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000514 flags &= ~SOCK_TYPE_MASK;
515 if (!flags)
516 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200517 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000518 }
519 printflags(sock_type_flags, flags, "SOCK_???");
520}
521
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000523sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524{
525 if (entering(tcp)) {
526 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200527 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000528 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200529 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 switch (tcp->u_arg[0]) {
531 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000532#ifdef PF_INET6
533 case PF_INET6:
534#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900535 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 break;
537#ifdef PF_IPX
538 case PF_IPX:
539 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200540 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200542 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 break;
544#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900545#ifdef PF_NETLINK
546 case PF_NETLINK:
547 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
548 break;
549#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 default:
551 tprintf("%lu", tcp->u_arg[2]);
552 break;
553 }
554 }
555 return 0;
556}
557
John Hughesbdf48f52001-03-06 15:08:09 +0000558int
Denys Vlasenko12014262011-05-30 14:00:14 +0200559sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
561 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800562 printfd(tcp, tcp->u_arg[0]);
563 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000564 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 tprintf(", %lu", tcp->u_arg[2]);
566 }
567 return 0;
568}
569
570int
Denys Vlasenko12014262011-05-30 14:00:14 +0200571sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572{
573 return sys_bind(tcp);
574}
575
576int
Denys Vlasenko12014262011-05-30 14:00:14 +0200577sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578{
579 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800580 printfd(tcp, tcp->u_arg[0]);
581 tprints(", ");
582 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 }
584 return 0;
585}
586
Paolo Bonzini705ff102009-08-14 12:34:05 +0200587static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000588do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589{
590 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800591 printfd(tcp, tcp->u_arg[0]);
592 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200593 return 0;
594 }
595 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596 tprintf("%#lx, NULL", tcp->u_arg[1]);
597 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000598 int len;
599 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200600 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601 tprintf("%#lx", tcp->u_arg[1]);
602 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000603 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200605 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000606 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200608 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200609 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200610 printflags(sock_type_flags, tcp->u_arg[flags_arg],
611 "SOCK_???");
612 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613 return 0;
614}
615
616int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200617sys_accept(struct tcb *tcp)
618{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000619 do_sockname(tcp, -1);
620 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200621}
622
Paolo Bonzini705ff102009-08-14 12:34:05 +0200623int
624sys_accept4(struct tcb *tcp)
625{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000626 do_sockname(tcp, 3);
627 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200628}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200629
630int
Denys Vlasenko12014262011-05-30 14:00:14 +0200631sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632{
633 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800634 printfd(tcp, tcp->u_arg[0]);
635 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
637 tprintf(", %lu, ", tcp->u_arg[2]);
638 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000639 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 }
641 return 0;
642}
643
644int
Denys Vlasenko12014262011-05-30 14:00:14 +0200645sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646{
647 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800648 printfd(tcp, tcp->u_arg[0]);
649 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
651 tprintf(", %lu, ", tcp->u_arg[2]);
652 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000653 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200655 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000656 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 /* to length */
658 tprintf(", %lu", tcp->u_arg[5]);
659 }
660 return 0;
661}
662
663#ifdef HAVE_SENDMSG
664
665int
Denys Vlasenko12014262011-05-30 14:00:14 +0200666sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667{
668 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800669 printfd(tcp, tcp->u_arg[0]);
670 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000671 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000672 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200673 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000674 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675 }
676 return 0;
677}
678
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000679int
680sys_sendmmsg(struct tcb *tcp)
681{
682 if (entering(tcp)) {
683 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800684 printfd(tcp, tcp->u_arg[0]);
685 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000686 if (!verbose(tcp)) {
687 tprintf("%#lx, %u, ",
688 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
689 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
690 }
691 } else {
692 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000693 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000694 }
695 return 0;
696}
697
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698#endif /* HAVE_SENDMSG */
699
700int
Denys Vlasenko12014262011-05-30 14:00:14 +0200701sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702{
703 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800704 printfd(tcp, tcp->u_arg[0]);
705 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 } else {
707 if (syserror(tcp))
708 tprintf("%#lx", tcp->u_arg[1]);
709 else
710 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
711
712 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000713 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714 }
715 return 0;
716}
717
718int
Denys Vlasenko12014262011-05-30 14:00:14 +0200719sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720{
721 int fromlen;
722
723 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800724 printfd(tcp, tcp->u_arg[0]);
725 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 } else {
727 if (syserror(tcp)) {
728 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
729 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
730 tcp->u_arg[4], tcp->u_arg[5]);
731 return 0;
732 }
733 /* buf */
734 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
735 /* len */
736 tprintf(", %lu, ", tcp->u_arg[2]);
737 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000738 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 /* from address, len */
740 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
741 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200742 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743 else
744 tprintf(", %#lx", tcp->u_arg[4]);
745 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200746 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 else
748 tprintf(", %#lx", tcp->u_arg[5]);
749 return 0;
750 }
751 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200752 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753 return 0;
754 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200755 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000756 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757 /* from length */
758 tprintf(", [%u]", fromlen);
759 }
760 return 0;
761}
762
763#ifdef HAVE_SENDMSG
764
765int
Denys Vlasenko12014262011-05-30 14:00:14 +0200766sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767{
768 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800769 printfd(tcp, tcp->u_arg[0]);
770 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 } else {
772 if (syserror(tcp) || !verbose(tcp))
773 tprintf("%#lx", tcp->u_arg[1]);
774 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200775 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200777 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000778 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779 }
780 return 0;
781}
782
Andreas Schwab0873f292010-02-12 21:39:12 +0100783int
784sys_recvmmsg(struct tcb *tcp)
785{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100786 /* +5 chars are for "left " prefix */
787 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400788
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100789 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800790 printfd(tcp, tcp->u_arg[0]);
791 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400792 if (verbose(tcp)) {
793 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100794 /* Abusing tcp->auxstr as temp storage.
795 * Will be used and freed on syscall exit.
796 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400797 tcp->auxstr = strdup(str);
798 } else {
799 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
800 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400802 print_timespec(tcp, tcp->u_arg[4]);
803 }
804 return 0;
805 } else {
806 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000807 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400808 /* timeout on entrance */
809 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
810 free((void *) tcp->auxstr);
811 tcp->auxstr = NULL;
812 }
813 if (syserror(tcp))
814 return 0;
815 if (tcp->u_rval == 0) {
816 tcp->auxstr = "Timeout";
817 return RVAL_STR;
818 }
819 if (!verbose(tcp))
820 return 0;
821 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100822 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400823 tcp->auxstr = str;
824 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100825 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100826}
Andreas Schwab0873f292010-02-12 21:39:12 +0100827
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000828#endif /* HAVE_SENDMSG */
829
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000830#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100831
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832int
Denys Vlasenko12014262011-05-30 14:00:14 +0200833sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834{
835 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800836 printfd(tcp, tcp->u_arg[0]);
837 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100838 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 }
840 return 0;
841}
842
843int
Denys Vlasenko12014262011-05-30 14:00:14 +0200844sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000846 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847}
848
849int
Denys Vlasenko12014262011-05-30 14:00:14 +0200850sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000852 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853}
854
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000855static int
856do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000858 if (exiting(tcp)) {
859 if (syserror(tcp)) {
860 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000861 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100862#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000863 int fds[2];
864
865 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200866 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000867 else
868 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100869#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000870 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
871#else
872 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000874 }
875 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200876 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000877 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
878 }
879 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000880 return 0;
881}
882
883int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000884sys_pipe(struct tcb *tcp)
885{
886 return do_pipe(tcp, -1);
887}
888
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000889int
890sys_pipe2(struct tcb *tcp)
891{
892 return do_pipe(tcp, 1);
893}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000894
895int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000896sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000897{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899
900 if (entering(tcp)) {
901 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200902 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000903 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000904 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000905 } else {
906 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000907 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000908 return 0;
909 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200911 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912 else
913 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914 }
915 return 0;
916}
917
918int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000919sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920{
921 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800922 printfd(tcp, tcp->u_arg[0]);
923 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000924 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200925 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926 switch (tcp->u_arg[1]) {
927 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929 break;
930#ifdef SOL_IP
931 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000932 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933 break;
934#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000935#ifdef SOL_IPV6
936 case SOL_IPV6:
937 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
938 break;
939#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940#ifdef SOL_IPX
941 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000943 break;
944#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000945#ifdef SOL_PACKET
946 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000947 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000948 break;
949#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950#ifdef SOL_TCP
951 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 break;
954#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100955#ifdef SOL_SCTP
956 case SOL_SCTP:
957 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
958 break;
959#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960
961 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
962 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000963 default:
John Hughes93f7fcc2002-05-22 15:46:49 +0000964 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965 break;
966 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +0000969 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200970 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +0000971 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972 tcp->u_arg[3], tcp->u_arg[4]);
973 return 0;
974 }
John Hughes93f7fcc2002-05-22 15:46:49 +0000975
976 switch (tcp->u_arg[1]) {
977 case SOL_SOCKET:
978 switch (tcp->u_arg[2]) {
979#ifdef SO_LINGER
980 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200981 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +0000982 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200983 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +0000984 tcp->u_arg[3],
985 &linger) < 0)
986 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +0000987 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +0000988 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +0000989 linger.l_onoff,
990 linger.l_linger,
991 len);
992 return 0;
993 }
994 break;
995#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000996#ifdef SO_PEERCRED
997 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200998 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +0000999 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001000 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001001 tcp->u_arg[3],
1002 &uc) < 0)
1003 break;
1004 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1005 "[%d]",
1006 (long)uc.pid,
1007 (long)uc.uid,
1008 (long)uc.gid,
1009 len);
1010 return 0;
1011 }
1012 break;
1013#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001014 }
1015 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001016 case SOL_PACKET:
1017 switch (tcp->u_arg[2]) {
1018#ifdef PACKET_STATISTICS
1019 case PACKET_STATISTICS:
1020 if (len == sizeof(struct tpacket_stats)) {
1021 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001022 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001023 tcp->u_arg[3],
1024 &stats) < 0)
1025 break;
1026 tprintf("{packets=%u, drops=%u}, "
1027 "[%d]",
1028 stats.tp_packets,
1029 stats.tp_drops,
1030 len);
1031 return 0;
1032 }
1033 break;
1034#endif
1035 }
1036 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001037 }
1038
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001039 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001040 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001041 }
1042 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001043 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001044 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001045 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046 }
1047 return 0;
1048}
1049
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001050#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001051static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001052{
1053 struct icmp_filter filter;
1054
1055 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001057 return;
1058 }
1059 if (syserror(tcp) || !verbose(tcp)) {
1060 tprintf("%#lx", addr);
1061 return;
1062 }
1063 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001064 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001065 return;
1066 }
1067
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001068 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001069 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001070 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001071}
1072#endif /* ICMP_FILTER */
1073
John Hughes38ae88d2002-05-23 11:48:58 +00001074static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001075printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001076{
1077 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001078 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001079 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001080 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001081 printxval(sockoptions, name, "SO_???");
1082 switch (name) {
1083#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001084 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001085 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001086 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001087 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001088 break;
1089 tprintf(", {onoff=%d, linger=%d}",
1090 linger.l_onoff,
1091 linger.l_linger);
1092 return 0;
1093 }
1094 break;
1095#endif
1096 }
1097 break;
1098#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001099 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001100 printxval(sockipoptions, name, "IP_???");
1101 break;
1102#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001103#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001104 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001105 printxval(sockipv6options, name, "IPV6_???");
1106 break;
1107#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001108#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001109 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001110 printxval(sockipxoptions, name, "IPX_???");
1111 break;
1112#endif
1113#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001114 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001115 printxval(sockpacketoptions, name, "PACKET_???");
1116 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001117 switch (name) {
1118#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001119 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001120#endif
1121#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001122 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001123#endif
1124#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1125 if (len == sizeof(struct tpacket_req)) {
1126 struct tpacket_req req;
1127 if (umove(tcp, addr, &req) < 0)
1128 break;
1129 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1130 req.tp_block_size,
1131 req.tp_block_nr,
1132 req.tp_frame_size,
1133 req.tp_frame_nr);
1134 return 0;
1135 }
1136 break;
1137#endif /* PACKET_RX_RING || PACKET_TX_RING */
1138 }
John Hughes38ae88d2002-05-23 11:48:58 +00001139 break;
1140#endif
1141#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001142 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001143 printxval(socktcpoptions, name, "TCP_???");
1144 break;
1145#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001146#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001147 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001148 printxval(socksctpoptions, name, "SCTP_???");
1149 break;
1150#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001151#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001152 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001153 printxval(sockrawoptions, name, "RAW_???");
1154 switch (name) {
1155#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001156 case ICMP_FILTER:
1157 tprints(", ");
1158 printicmpfilter(tcp, addr);
1159 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001160#endif
1161 }
1162 break;
1163#endif
1164
Roland McGrath6d2b3492002-12-30 00:51:30 +00001165 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001166 * etc. still need work */
1167
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001168 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001169 tprintf("%u", name);
1170 }
1171
1172 /* default arg printing */
1173
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001174 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001175
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001176 if (len == sizeof(int)) {
1177 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001178 }
1179 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001180 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001181 }
1182 return 0;
1183}
1184
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185int
Denys Vlasenko12014262011-05-30 14:00:14 +02001186sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001187{
1188 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001189 printfd(tcp, tcp->u_arg[0]);
1190 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001191 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001192 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001193 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001194 }
1195 return 0;
1196}