blob: 9e9e1591b38b32b33ea20049117c5d8864f76d2d [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
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020093#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
94# include <bluetooth/bluetooth.h>
95# include <bluetooth/hci.h>
96# include <bluetooth/l2cap.h>
97# include <bluetooth/rfcomm.h>
98# include <bluetooth/sco.h>
99#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100101# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000102#endif
103
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000104#include "xlat/domains.h"
105#include "xlat/addrfams.h"
106#include "xlat/socktypes.h"
107#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000108#ifndef SOCK_TYPE_MASK
109# define SOCK_TYPE_MASK 0xf
110#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000111#include "xlat/socketlayers.h"
John Hughes93f7fcc2002-05-22 15:46:49 +0000112/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900113 falls into "inet_protocols" array below!!!! This is intended!!! ***/
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000114#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900115
116#ifdef PF_NETLINK
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000117#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900118#endif
119
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200120#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
121# include "xlat/bt_protocols.h"
122#endif
123
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000124#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000125#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100127#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000128#define SOL_IP IPPROTO_IP
129#endif
130
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000132#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133#endif /* SOL_IP */
134
Roland McGrath4f6ba692004-08-31 07:01:26 +0000135#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000136#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000137#endif /* SOL_IPV6 */
138
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000140#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#endif /* SOL_IPX */
142
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000143#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000144#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000145#endif /* SOL_RAW */
146
147#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000148#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000149#endif /* SOL_PACKET */
150
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100151#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000152#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100153#endif
154
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100155#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000156#define SOL_TCP IPPROTO_TCP
157#endif
158
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000160#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161#endif /* SOL_TCP */
162
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000163#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000164#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000165#endif /* SOL_RAW */
166
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000167#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000168#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000169#endif /* defined(AF_PACKET) */
170
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000172printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000174 union {
175 char pad[128];
176 struct sockaddr sa;
177 struct sockaddr_in sin;
178 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000179#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000180 struct sockaddr_in6 sa6;
181#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100182#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000183 struct sockaddr_ipx sipx;
184#endif
185#ifdef AF_PACKET
186 struct sockaddr_ll ll;
187#endif
188#ifdef AF_NETLINK
189 struct sockaddr_nl nl;
190#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200191#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
192 struct sockaddr_hci hci;
193 struct sockaddr_l2 l2;
194 struct sockaddr_rc rc;
195 struct sockaddr_sco sco;
196#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000197 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000198 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199
200 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200201 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202 return;
203 }
204 if (!verbose(tcp)) {
205 tprintf("%#lx", addr);
206 return;
207 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000208
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000209 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000210 addrlen = sizeof(addrbuf);
211
212 memset(&addrbuf, 0, sizeof(addrbuf));
213 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200214 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 return;
216 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000217 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000218
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200219 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200221 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000222
223 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000225 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200226 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000227 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000228 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000229 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000230 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000231 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000232 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000233 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 break;
235 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000236 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000237 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000239#ifdef HAVE_INET_NTOP
240 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000241 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000242 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
243 ntohs(addrbuf.sa6.sin6_port), string_addr,
244 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000245#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000246 {
247#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 int numericscope = 0;
249 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
250 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
251 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000252
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200253 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
254 numericscope++;
255 else
256 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
257 } else
258 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000259
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200260 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000261#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200262 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000263 }
264#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200265 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000266#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100267#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000269 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000271 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000272 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273 /* Yes, I know, this does not look too
274 * strace-ish, but otherwise the IPX
275 * addresses just look monstrous...
276 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000277 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000279 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200280 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000281 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
282 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283 }
284 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100285#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000286#ifdef AF_PACKET
287 case AF_PACKET:
288 {
289 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000290 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000291 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000292 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000293 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000294 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000295 addrbuf.ll.sll_halen,
296 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200297 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000298 tprintf("%02x", addrbuf.ll.sll_addr[i]);
299 }
300 break;
301
Denys Vlasenko84703742012-02-25 02:38:52 +0100302#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000303#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000304 case AF_NETLINK:
305 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
306 break;
307#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200308#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
309 case AF_BLUETOOTH:
310 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
311 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
312 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
313 "{hci_dev=htobs(%d)}",
314 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
315 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
316 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
317 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
318 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
319 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
320 addrbuf.rc.rc_channel,
321 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
322 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
323 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
324 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
325 btohs(addrbuf.hci.hci_dev));
326 break;
327#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000329 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330
331 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200332 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000334 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335 break;
336 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200337 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338}
339
340#if HAVE_SENDMSG
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000341#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000342
343static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000344printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +0000345{
Roland McGrathaa524c82005-06-01 19:22:06 +0000346 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
347 NULL : malloc(len);
348 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000349 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +0000350 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000351 return;
352 }
353
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000354 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000355 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200356 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000357
Roland McGrathaa524c82005-06-01 19:22:06 +0000358 if (cmsg->cmsg_level == SOL_SOCKET) {
359 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000360
Roland McGrathaa524c82005-06-01 19:22:06 +0000361 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
362 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
363
364 if (cmsg->cmsg_type == SCM_RIGHTS
365 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200366 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000367 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +0000368
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200369 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000370 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +0000371 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200372 tprints(", ");
Dmitry V. Levinf23b0972014-05-29 21:35:34 +0000373 printfd(tcp, *fds++);
Roland McGrath50770822004-10-06 22:11:51 +0000374 first = 0;
375 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200376 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000377 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000378 return;
379 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000380 if (cmsg->cmsg_type == SCM_CREDENTIALS
381 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200382 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +0000383
Roland McGrath50770822004-10-06 22:11:51 +0000384 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
385 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +0000386 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +0000387 return;
388 }
389 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000390 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200391 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +0000392}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393
394static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200395do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100396{
397 tprintf("{msg_name(%d)=", msg->msg_namelen);
398 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
399
400 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200401 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
402 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100403
404#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
405 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
406 if (msg->msg_controllen)
407 printcmsghdr(tcp, (unsigned long) msg->msg_control,
408 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200409 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100410 printflags(msg_flags, msg->msg_flags, "MSG_???");
411#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
412 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
413 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
414#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200415 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100416}
417
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100418struct msghdr32 {
419 uint32_t /* void* */ msg_name;
420 uint32_t /* socklen_t */msg_namelen;
421 uint32_t /* iovec* */ msg_iov;
422 uint32_t /* size_t */ msg_iovlen;
423 uint32_t /* void* */ msg_control;
424 uint32_t /* size_t */ msg_controllen;
425 uint32_t /* int */ msg_flags;
426};
427struct mmsghdr32 {
428 struct msghdr32 msg_hdr;
429 uint32_t /* unsigned */ msg_len;
430};
431
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900432#ifndef HAVE_STRUCT_MMSGHDR
433struct mmsghdr {
434 struct msghdr msg_hdr;
435 unsigned msg_len;
436};
437#endif
438
Masatake YAMATOb2485432014-11-07 01:23:24 +0900439#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
440static void
441copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
442{
443 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
444 to_msg->msg_namelen = from_msg32->msg_namelen;
445 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
446 to_msg->msg_iovlen = from_msg32->msg_iovlen;
447 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
448 to_msg->msg_controllen = from_msg32->msg_controllen;
449 to_msg->msg_flags = from_msg32->msg_flags;
450}
451#endif
452
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900453static bool
454extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
455{
456#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
457 if (current_wordsize == 4) {
458 struct msghdr32 msg32;
459
460 if (umove(tcp, addr, &msg32) < 0)
461 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900462 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900463 } else
464#endif
465 if (umove(tcp, addr, msg) < 0)
466 return false;
467 return true;
468}
469
Andreas Schwab0873f292010-02-12 21:39:12 +0100470static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200471printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472{
473 struct msghdr msg;
474
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900475 if (extractmsghdr(tcp, addr, &msg))
476 do_msghdr(tcp, &msg, data_size);
477 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000478 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900479}
480
481void
482dumpiov_in_msghdr(struct tcb *tcp, long addr)
483{
484 struct msghdr msg;
485
486 if (extractmsghdr(tcp, addr, &msg))
487 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488}
489
Andreas Schwab0873f292010-02-12 21:39:12 +0100490static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000491printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100492{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900493 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100494
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100495#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
496 if (current_wordsize == 4) {
497 struct mmsghdr32 mmsg32;
498
499 addr += sizeof(mmsg32) * idx;
500 if (umove(tcp, addr, &mmsg32) < 0) {
501 tprintf("%#lx", addr);
502 return;
503 }
504 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
505 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
506 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
507 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
508 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
509 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
510 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
511 mmsg.msg_len = mmsg32.msg_len;
512 } else
513#endif
514 {
515 addr += sizeof(mmsg) * idx;
516 if (umove(tcp, addr, &mmsg) < 0) {
517 tprintf("%#lx", addr);
518 return;
519 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100520 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000522 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100523 tprintf(", %u}", mmsg.msg_len);
524}
Andreas Schwab0873f292010-02-12 21:39:12 +0100525
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000526static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000527decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000528{
529 /* mmsgvec */
530 if (syserror(tcp)) {
531 tprintf("%#lx", tcp->u_arg[1]);
532 } else {
533 unsigned int len = tcp->u_rval;
534 unsigned int i;
535
536 tprints("{");
537 for (i = 0; i < len; ++i) {
538 if (i)
539 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000540 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000541 }
542 tprints("}");
543 }
544 /* vlen */
545 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
546 /* flags */
547 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
548}
549
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550#endif /* HAVE_SENDMSG */
551
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000552/*
553 * low bits of the socket type define real socket type,
554 * other bits are socket type flags.
555 */
556static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000557tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000558{
559 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
560
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200561 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200562 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000563 flags &= ~SOCK_TYPE_MASK;
564 if (!flags)
565 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200566 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000567 }
568 printflags(sock_type_flags, flags, "SOCK_???");
569}
570
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000572sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573{
574 if (entering(tcp)) {
575 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200576 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000577 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200578 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579 switch (tcp->u_arg[0]) {
580 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000581#ifdef PF_INET6
582 case PF_INET6:
583#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900584 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 break;
586#ifdef PF_IPX
587 case PF_IPX:
588 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200589 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592 break;
593#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900594#ifdef PF_NETLINK
595 case PF_NETLINK:
596 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
597 break;
598#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200599#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
600 case PF_BLUETOOTH:
601 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
602 break;
603#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604 default:
605 tprintf("%lu", tcp->u_arg[2]);
606 break;
607 }
608 }
609 return 0;
610}
611
John Hughesbdf48f52001-03-06 15:08:09 +0000612int
Denys Vlasenko12014262011-05-30 14:00:14 +0200613sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
615 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800616 printfd(tcp, tcp->u_arg[0]);
617 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000618 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 tprintf(", %lu", tcp->u_arg[2]);
620 }
621 return 0;
622}
623
624int
Denys Vlasenko12014262011-05-30 14:00:14 +0200625sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626{
627 return sys_bind(tcp);
628}
629
630int
Denys Vlasenko12014262011-05-30 14:00:14 +0200631sys_listen(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(", ");
636 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637 }
638 return 0;
639}
640
Paolo Bonzini705ff102009-08-14 12:34:05 +0200641static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000642do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643{
644 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800645 printfd(tcp, tcp->u_arg[0]);
646 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200647 return 0;
648 }
649 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650 tprintf("%#lx, NULL", tcp->u_arg[1]);
651 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000652 int len;
653 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200654 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 tprintf("%#lx", tcp->u_arg[1]);
656 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000657 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000660 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200662 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200663 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200664 printflags(sock_type_flags, tcp->u_arg[flags_arg],
665 "SOCK_???");
666 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 return 0;
668}
669
670int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200671sys_accept(struct tcb *tcp)
672{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000673 do_sockname(tcp, -1);
674 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200675}
676
Paolo Bonzini705ff102009-08-14 12:34:05 +0200677int
678sys_accept4(struct tcb *tcp)
679{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000680 do_sockname(tcp, 3);
681 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200682}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200683
684int
Denys Vlasenko12014262011-05-30 14:00:14 +0200685sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686{
687 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800688 printfd(tcp, tcp->u_arg[0]);
689 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
691 tprintf(", %lu, ", tcp->u_arg[2]);
692 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000693 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694 }
695 return 0;
696}
697
698int
Denys Vlasenko12014262011-05-30 14:00:14 +0200699sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700{
701 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800702 printfd(tcp, tcp->u_arg[0]);
703 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
705 tprintf(", %lu, ", tcp->u_arg[2]);
706 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000707 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200709 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000710 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 /* to length */
712 tprintf(", %lu", tcp->u_arg[5]);
713 }
714 return 0;
715}
716
717#ifdef HAVE_SENDMSG
718
719int
Denys Vlasenko12014262011-05-30 14:00:14 +0200720sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000721{
722 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800723 printfd(tcp, tcp->u_arg[0]);
724 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000725 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200727 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000728 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 }
730 return 0;
731}
732
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000733int
734sys_sendmmsg(struct tcb *tcp)
735{
736 if (entering(tcp)) {
737 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800738 printfd(tcp, tcp->u_arg[0]);
739 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000740 if (!verbose(tcp)) {
741 tprintf("%#lx, %u, ",
742 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
743 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
744 }
745 } else {
746 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000747 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000748 }
749 return 0;
750}
751
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752#endif /* HAVE_SENDMSG */
753
754int
Denys Vlasenko12014262011-05-30 14:00:14 +0200755sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756{
757 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800758 printfd(tcp, tcp->u_arg[0]);
759 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 } else {
761 if (syserror(tcp))
762 tprintf("%#lx", tcp->u_arg[1]);
763 else
764 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
765
766 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000767 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 }
769 return 0;
770}
771
772int
Denys Vlasenko12014262011-05-30 14:00:14 +0200773sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774{
775 int fromlen;
776
777 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800778 printfd(tcp, tcp->u_arg[0]);
779 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780 } else {
781 if (syserror(tcp)) {
782 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
783 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
784 tcp->u_arg[4], tcp->u_arg[5]);
785 return 0;
786 }
787 /* buf */
788 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
789 /* len */
790 tprintf(", %lu, ", tcp->u_arg[2]);
791 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000792 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793 /* from address, len */
794 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
795 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000797 else
798 tprintf(", %#lx", tcp->u_arg[4]);
799 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200800 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000801 else
802 tprintf(", %#lx", tcp->u_arg[5]);
803 return 0;
804 }
805 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 return 0;
808 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200809 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000810 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811 /* from length */
812 tprintf(", [%u]", fromlen);
813 }
814 return 0;
815}
816
817#ifdef HAVE_SENDMSG
818
819int
Denys Vlasenko12014262011-05-30 14:00:14 +0200820sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821{
822 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800823 printfd(tcp, tcp->u_arg[0]);
824 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 } else {
826 if (syserror(tcp) || !verbose(tcp))
827 tprintf("%#lx", tcp->u_arg[1]);
828 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200829 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000830 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200831 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000832 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833 }
834 return 0;
835}
836
Andreas Schwab0873f292010-02-12 21:39:12 +0100837int
838sys_recvmmsg(struct tcb *tcp)
839{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100840 /* +5 chars are for "left " prefix */
841 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400842
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100843 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800844 printfd(tcp, tcp->u_arg[0]);
845 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400846 if (verbose(tcp)) {
847 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100848 /* Abusing tcp->auxstr as temp storage.
849 * Will be used and freed on syscall exit.
850 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400851 tcp->auxstr = strdup(str);
852 } else {
853 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
854 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400856 print_timespec(tcp, tcp->u_arg[4]);
857 }
858 return 0;
859 } else {
860 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000861 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400862 /* timeout on entrance */
863 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
864 free((void *) tcp->auxstr);
865 tcp->auxstr = NULL;
866 }
867 if (syserror(tcp))
868 return 0;
869 if (tcp->u_rval == 0) {
870 tcp->auxstr = "Timeout";
871 return RVAL_STR;
872 }
873 if (!verbose(tcp))
874 return 0;
875 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100876 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400877 tcp->auxstr = str;
878 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100879 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100880}
Andreas Schwab0873f292010-02-12 21:39:12 +0100881
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882#endif /* HAVE_SENDMSG */
883
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000884#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100885
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886int
Denys Vlasenko12014262011-05-30 14:00:14 +0200887sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888{
889 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800890 printfd(tcp, tcp->u_arg[0]);
891 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100892 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893 }
894 return 0;
895}
896
897int
Denys Vlasenko12014262011-05-30 14:00:14 +0200898sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000900 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901}
902
903int
Denys Vlasenko12014262011-05-30 14:00:14 +0200904sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000905{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000906 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907}
908
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000909static int
910do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912 if (exiting(tcp)) {
913 if (syserror(tcp)) {
914 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000915 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100916#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000917 int fds[2];
918
919 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200920 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000921 else
922 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100923#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000924 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
925#else
926 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000928 }
929 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200930 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000931 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
932 }
933 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934 return 0;
935}
936
937int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000938sys_pipe(struct tcb *tcp)
939{
940 return do_pipe(tcp, -1);
941}
942
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000943int
944sys_pipe2(struct tcb *tcp)
945{
946 return do_pipe(tcp, 1);
947}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000948
949int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000950sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000951{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953
954 if (entering(tcp)) {
955 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000957 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000958 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000959 } else {
960 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000961 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962 return 0;
963 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966 else
967 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 }
969 return 0;
970}
971
972int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000973sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974{
975 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800976 printfd(tcp, tcp->u_arg[0]);
977 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000978 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200979 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980 switch (tcp->u_arg[1]) {
981 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983 break;
984#ifdef SOL_IP
985 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 break;
988#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000989#ifdef SOL_IPV6
990 case SOL_IPV6:
991 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
992 break;
993#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994#ifdef SOL_IPX
995 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997 break;
998#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000999#ifdef SOL_PACKET
1000 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001001 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001002 break;
1003#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004#ifdef SOL_TCP
1005 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007 break;
1008#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001009#ifdef SOL_SCTP
1010 case SOL_SCTP:
1011 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1012 break;
1013#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014
1015 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1016 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001017 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001018 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 break;
1020 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001021 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001023 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001024 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001025 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 tcp->u_arg[3], tcp->u_arg[4]);
1027 return 0;
1028 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001029
1030 switch (tcp->u_arg[1]) {
1031 case SOL_SOCKET:
1032 switch (tcp->u_arg[2]) {
1033#ifdef SO_LINGER
1034 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001035 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001036 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001037 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001038 tcp->u_arg[3],
1039 &linger) < 0)
1040 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001041 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001042 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001043 linger.l_onoff,
1044 linger.l_linger,
1045 len);
1046 return 0;
1047 }
1048 break;
1049#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001050#ifdef SO_PEERCRED
1051 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001052 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001053 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001054 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001055 tcp->u_arg[3],
1056 &uc) < 0)
1057 break;
1058 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1059 "[%d]",
1060 (long)uc.pid,
1061 (long)uc.uid,
1062 (long)uc.gid,
1063 len);
1064 return 0;
1065 }
1066 break;
1067#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001068 }
1069 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001070 case SOL_PACKET:
1071 switch (tcp->u_arg[2]) {
1072#ifdef PACKET_STATISTICS
1073 case PACKET_STATISTICS:
1074 if (len == sizeof(struct tpacket_stats)) {
1075 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001076 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001077 tcp->u_arg[3],
1078 &stats) < 0)
1079 break;
1080 tprintf("{packets=%u, drops=%u}, "
1081 "[%d]",
1082 stats.tp_packets,
1083 stats.tp_drops,
1084 len);
1085 return 0;
1086 }
1087 break;
1088#endif
1089 }
1090 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001091 }
1092
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001093 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001094 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001095 }
1096 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001097 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001098 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001099 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 }
1101 return 0;
1102}
1103
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001104#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001105static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001106{
1107 struct icmp_filter filter;
1108
1109 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001110 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001111 return;
1112 }
1113 if (syserror(tcp) || !verbose(tcp)) {
1114 tprintf("%#lx", addr);
1115 return;
1116 }
1117 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001118 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001119 return;
1120 }
1121
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001122 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001123 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001124 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001125}
1126#endif /* ICMP_FILTER */
1127
John Hughes38ae88d2002-05-23 11:48:58 +00001128static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001129printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001130{
1131 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001132 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001133 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001134 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001135 printxval(sockoptions, name, "SO_???");
1136 switch (name) {
1137#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001138 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001139 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001140 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001141 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001142 break;
1143 tprintf(", {onoff=%d, linger=%d}",
1144 linger.l_onoff,
1145 linger.l_linger);
1146 return 0;
1147 }
1148 break;
1149#endif
1150 }
1151 break;
1152#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001153 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001154 printxval(sockipoptions, name, "IP_???");
1155 break;
1156#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001157#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001158 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001159 printxval(sockipv6options, name, "IPV6_???");
1160 break;
1161#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001162#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001163 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001164 printxval(sockipxoptions, name, "IPX_???");
1165 break;
1166#endif
1167#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001168 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001169 printxval(sockpacketoptions, name, "PACKET_???");
1170 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001171 switch (name) {
1172#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001173 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001174#endif
1175#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001176 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001177#endif
1178#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1179 if (len == sizeof(struct tpacket_req)) {
1180 struct tpacket_req req;
1181 if (umove(tcp, addr, &req) < 0)
1182 break;
1183 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1184 req.tp_block_size,
1185 req.tp_block_nr,
1186 req.tp_frame_size,
1187 req.tp_frame_nr);
1188 return 0;
1189 }
1190 break;
1191#endif /* PACKET_RX_RING || PACKET_TX_RING */
1192 }
John Hughes38ae88d2002-05-23 11:48:58 +00001193 break;
1194#endif
1195#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001196 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001197 printxval(socktcpoptions, name, "TCP_???");
1198 break;
1199#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001200#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001201 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001202 printxval(socksctpoptions, name, "SCTP_???");
1203 break;
1204#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001205#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001206 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001207 printxval(sockrawoptions, name, "RAW_???");
1208 switch (name) {
1209#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001210 case ICMP_FILTER:
1211 tprints(", ");
1212 printicmpfilter(tcp, addr);
1213 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001214#endif
1215 }
1216 break;
1217#endif
1218
Roland McGrath6d2b3492002-12-30 00:51:30 +00001219 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001220 * etc. still need work */
1221
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001222 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001223 tprintf("%u", name);
1224 }
1225
1226 /* default arg printing */
1227
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001228 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001229
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001230 if (len == sizeof(int)) {
1231 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001232 }
1233 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001234 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001235 }
1236 return 0;
1237}
1238
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239int
Denys Vlasenko12014262011-05-30 14:00:14 +02001240sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241{
1242 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001243 printfd(tcp, tcp->u_arg[0]);
1244 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001245 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001246 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001247 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 }
1249 return 0;
1250}