blob: 41c55c667fad34cf1b8c820161f81aadb3f7e095 [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 YAMATOb2485432014-11-07 01:23:24 +0900432#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
433static void
434copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
435{
436 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
437 to_msg->msg_namelen = from_msg32->msg_namelen;
438 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
439 to_msg->msg_iovlen = from_msg32->msg_iovlen;
440 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
441 to_msg->msg_controllen = from_msg32->msg_controllen;
442 to_msg->msg_flags = from_msg32->msg_flags;
443}
444#endif
445
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900446static bool
447extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
448{
449#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
450 if (current_wordsize == 4) {
451 struct msghdr32 msg32;
452
453 if (umove(tcp, addr, &msg32) < 0)
454 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900455 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900456 } else
457#endif
458 if (umove(tcp, addr, msg) < 0)
459 return false;
460 return true;
461}
462
Andreas Schwab0873f292010-02-12 21:39:12 +0100463static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200464printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465{
466 struct msghdr msg;
467
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900468 if (extractmsghdr(tcp, addr, &msg))
469 do_msghdr(tcp, &msg, data_size);
470 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000471 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900472}
473
474void
475dumpiov_in_msghdr(struct tcb *tcp, long addr)
476{
477 struct msghdr msg;
478
479 if (extractmsghdr(tcp, addr, &msg))
480 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481}
482
Andreas Schwab0873f292010-02-12 21:39:12 +0100483static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000484printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100485{
486 struct mmsghdr {
487 struct msghdr msg_hdr;
488 unsigned msg_len;
489 } mmsg;
490
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100491#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
492 if (current_wordsize == 4) {
493 struct mmsghdr32 mmsg32;
494
495 addr += sizeof(mmsg32) * idx;
496 if (umove(tcp, addr, &mmsg32) < 0) {
497 tprintf("%#lx", addr);
498 return;
499 }
500 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
501 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
502 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
503 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
504 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
505 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
506 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
507 mmsg.msg_len = mmsg32.msg_len;
508 } else
509#endif
510 {
511 addr += sizeof(mmsg) * idx;
512 if (umove(tcp, addr, &mmsg) < 0) {
513 tprintf("%#lx", addr);
514 return;
515 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100516 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200517 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000518 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100519 tprintf(", %u}", mmsg.msg_len);
520}
Andreas Schwab0873f292010-02-12 21:39:12 +0100521
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000522static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000523decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000524{
525 /* mmsgvec */
526 if (syserror(tcp)) {
527 tprintf("%#lx", tcp->u_arg[1]);
528 } else {
529 unsigned int len = tcp->u_rval;
530 unsigned int i;
531
532 tprints("{");
533 for (i = 0; i < len; ++i) {
534 if (i)
535 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000536 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000537 }
538 tprints("}");
539 }
540 /* vlen */
541 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
542 /* flags */
543 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
544}
545
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546#endif /* HAVE_SENDMSG */
547
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000548/*
549 * low bits of the socket type define real socket type,
550 * other bits are socket type flags.
551 */
552static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000553tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000554{
555 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
556
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200557 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200558 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000559 flags &= ~SOCK_TYPE_MASK;
560 if (!flags)
561 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200562 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000563 }
564 printflags(sock_type_flags, flags, "SOCK_???");
565}
566
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000568sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569{
570 if (entering(tcp)) {
571 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200572 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000573 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200574 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 switch (tcp->u_arg[0]) {
576 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000577#ifdef PF_INET6
578 case PF_INET6:
579#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900580 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 break;
582#ifdef PF_IPX
583 case PF_IPX:
584 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200585 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200587 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588 break;
589#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900590#ifdef PF_NETLINK
591 case PF_NETLINK:
592 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
593 break;
594#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200595#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
596 case PF_BLUETOOTH:
597 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
598 break;
599#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 default:
601 tprintf("%lu", tcp->u_arg[2]);
602 break;
603 }
604 }
605 return 0;
606}
607
John Hughesbdf48f52001-03-06 15:08:09 +0000608int
Denys Vlasenko12014262011-05-30 14:00:14 +0200609sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610{
611 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800612 printfd(tcp, tcp->u_arg[0]);
613 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000614 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615 tprintf(", %lu", tcp->u_arg[2]);
616 }
617 return 0;
618}
619
620int
Denys Vlasenko12014262011-05-30 14:00:14 +0200621sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622{
623 return sys_bind(tcp);
624}
625
626int
Denys Vlasenko12014262011-05-30 14:00:14 +0200627sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628{
629 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800630 printfd(tcp, tcp->u_arg[0]);
631 tprints(", ");
632 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633 }
634 return 0;
635}
636
Paolo Bonzini705ff102009-08-14 12:34:05 +0200637static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000638do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639{
640 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800641 printfd(tcp, tcp->u_arg[0]);
642 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200643 return 0;
644 }
645 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646 tprintf("%#lx, NULL", tcp->u_arg[1]);
647 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000648 int len;
649 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200650 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651 tprintf("%#lx", tcp->u_arg[1]);
652 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000653 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200655 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000656 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200658 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200660 printflags(sock_type_flags, tcp->u_arg[flags_arg],
661 "SOCK_???");
662 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 return 0;
664}
665
666int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200667sys_accept(struct tcb *tcp)
668{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000669 do_sockname(tcp, -1);
670 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200671}
672
Paolo Bonzini705ff102009-08-14 12:34:05 +0200673int
674sys_accept4(struct tcb *tcp)
675{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000676 do_sockname(tcp, 3);
677 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200678}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200679
680int
Denys Vlasenko12014262011-05-30 14:00:14 +0200681sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682{
683 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800684 printfd(tcp, tcp->u_arg[0]);
685 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
687 tprintf(", %lu, ", tcp->u_arg[2]);
688 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000689 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690 }
691 return 0;
692}
693
694int
Denys Vlasenko12014262011-05-30 14:00:14 +0200695sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696{
697 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800698 printfd(tcp, tcp->u_arg[0]);
699 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
701 tprintf(", %lu, ", tcp->u_arg[2]);
702 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000703 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200705 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000706 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000707 /* to length */
708 tprintf(", %lu", tcp->u_arg[5]);
709 }
710 return 0;
711}
712
713#ifdef HAVE_SENDMSG
714
715int
Denys Vlasenko12014262011-05-30 14:00:14 +0200716sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717{
718 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800719 printfd(tcp, tcp->u_arg[0]);
720 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000721 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200723 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000724 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725 }
726 return 0;
727}
728
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000729int
730sys_sendmmsg(struct tcb *tcp)
731{
732 if (entering(tcp)) {
733 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800734 printfd(tcp, tcp->u_arg[0]);
735 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000736 if (!verbose(tcp)) {
737 tprintf("%#lx, %u, ",
738 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
739 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
740 }
741 } else {
742 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000743 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000744 }
745 return 0;
746}
747
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748#endif /* HAVE_SENDMSG */
749
750int
Denys Vlasenko12014262011-05-30 14:00:14 +0200751sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752{
753 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800754 printfd(tcp, tcp->u_arg[0]);
755 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 } else {
757 if (syserror(tcp))
758 tprintf("%#lx", tcp->u_arg[1]);
759 else
760 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
761
762 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000763 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 }
765 return 0;
766}
767
768int
Denys Vlasenko12014262011-05-30 14:00:14 +0200769sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770{
771 int fromlen;
772
773 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800774 printfd(tcp, tcp->u_arg[0]);
775 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776 } else {
777 if (syserror(tcp)) {
778 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
779 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
780 tcp->u_arg[4], tcp->u_arg[5]);
781 return 0;
782 }
783 /* buf */
784 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
785 /* len */
786 tprintf(", %lu, ", tcp->u_arg[2]);
787 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000788 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789 /* from address, len */
790 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
791 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200792 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793 else
794 tprintf(", %#lx", tcp->u_arg[4]);
795 if (tcp->u_arg[5] == 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[5]);
799 return 0;
800 }
801 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200802 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000803 return 0;
804 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200805 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000806 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 /* from length */
808 tprintf(", [%u]", fromlen);
809 }
810 return 0;
811}
812
813#ifdef HAVE_SENDMSG
814
815int
Denys Vlasenko12014262011-05-30 14:00:14 +0200816sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817{
818 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800819 printfd(tcp, tcp->u_arg[0]);
820 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 } else {
822 if (syserror(tcp) || !verbose(tcp))
823 tprintf("%#lx", tcp->u_arg[1]);
824 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200825 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200827 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000828 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829 }
830 return 0;
831}
832
Andreas Schwab0873f292010-02-12 21:39:12 +0100833int
834sys_recvmmsg(struct tcb *tcp)
835{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100836 /* +5 chars are for "left " prefix */
837 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400838
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100839 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800840 printfd(tcp, tcp->u_arg[0]);
841 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400842 if (verbose(tcp)) {
843 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100844 /* Abusing tcp->auxstr as temp storage.
845 * Will be used and freed on syscall exit.
846 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400847 tcp->auxstr = strdup(str);
848 } else {
849 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
850 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200851 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400852 print_timespec(tcp, tcp->u_arg[4]);
853 }
854 return 0;
855 } else {
856 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000857 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400858 /* timeout on entrance */
859 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
860 free((void *) tcp->auxstr);
861 tcp->auxstr = NULL;
862 }
863 if (syserror(tcp))
864 return 0;
865 if (tcp->u_rval == 0) {
866 tcp->auxstr = "Timeout";
867 return RVAL_STR;
868 }
869 if (!verbose(tcp))
870 return 0;
871 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100872 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400873 tcp->auxstr = str;
874 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100875 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100876}
Andreas Schwab0873f292010-02-12 21:39:12 +0100877
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878#endif /* HAVE_SENDMSG */
879
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000880#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100881
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882int
Denys Vlasenko12014262011-05-30 14:00:14 +0200883sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884{
885 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800886 printfd(tcp, tcp->u_arg[0]);
887 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100888 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889 }
890 return 0;
891}
892
893int
Denys Vlasenko12014262011-05-30 14:00:14 +0200894sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000896 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000897}
898
899int
Denys Vlasenko12014262011-05-30 14:00:14 +0200900sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000902 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000903}
904
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000905static int
906do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000908 if (exiting(tcp)) {
909 if (syserror(tcp)) {
910 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000911 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100912#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000913 int fds[2];
914
915 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200916 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000917 else
918 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100919#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000920 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
921#else
922 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000924 }
925 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000927 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
928 }
929 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930 return 0;
931}
932
933int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000934sys_pipe(struct tcb *tcp)
935{
936 return do_pipe(tcp, -1);
937}
938
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000939int
940sys_pipe2(struct tcb *tcp)
941{
942 return do_pipe(tcp, 1);
943}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000944
945int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000946sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949
950 if (entering(tcp)) {
951 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200952 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000953 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000954 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955 } else {
956 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000957 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958 return 0;
959 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200961 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962 else
963 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 }
965 return 0;
966}
967
968int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000969sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970{
971 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800972 printfd(tcp, tcp->u_arg[0]);
973 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000974 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200975 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976 switch (tcp->u_arg[1]) {
977 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 break;
980#ifdef SOL_IP
981 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983 break;
984#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000985#ifdef SOL_IPV6
986 case SOL_IPV6:
987 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
988 break;
989#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990#ifdef SOL_IPX
991 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993 break;
994#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000995#ifdef SOL_PACKET
996 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000997 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000998 break;
999#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000#ifdef SOL_TCP
1001 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001003 break;
1004#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001005#ifdef SOL_SCTP
1006 case SOL_SCTP:
1007 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1008 break;
1009#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010
1011 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1012 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001013 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001014 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 break;
1016 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001019 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001020 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001021 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 tcp->u_arg[3], tcp->u_arg[4]);
1023 return 0;
1024 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001025
1026 switch (tcp->u_arg[1]) {
1027 case SOL_SOCKET:
1028 switch (tcp->u_arg[2]) {
1029#ifdef SO_LINGER
1030 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001031 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001032 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001033 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001034 tcp->u_arg[3],
1035 &linger) < 0)
1036 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001037 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001038 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001039 linger.l_onoff,
1040 linger.l_linger,
1041 len);
1042 return 0;
1043 }
1044 break;
1045#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001046#ifdef SO_PEERCRED
1047 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001048 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001049 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001050 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001051 tcp->u_arg[3],
1052 &uc) < 0)
1053 break;
1054 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1055 "[%d]",
1056 (long)uc.pid,
1057 (long)uc.uid,
1058 (long)uc.gid,
1059 len);
1060 return 0;
1061 }
1062 break;
1063#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001064 }
1065 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001066 case SOL_PACKET:
1067 switch (tcp->u_arg[2]) {
1068#ifdef PACKET_STATISTICS
1069 case PACKET_STATISTICS:
1070 if (len == sizeof(struct tpacket_stats)) {
1071 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001072 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001073 tcp->u_arg[3],
1074 &stats) < 0)
1075 break;
1076 tprintf("{packets=%u, drops=%u}, "
1077 "[%d]",
1078 stats.tp_packets,
1079 stats.tp_drops,
1080 len);
1081 return 0;
1082 }
1083 break;
1084#endif
1085 }
1086 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001087 }
1088
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001089 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001090 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001091 }
1092 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001093 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001094 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001095 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096 }
1097 return 0;
1098}
1099
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001100#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001101static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001102{
1103 struct icmp_filter filter;
1104
1105 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001106 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001107 return;
1108 }
1109 if (syserror(tcp) || !verbose(tcp)) {
1110 tprintf("%#lx", addr);
1111 return;
1112 }
1113 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001114 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001115 return;
1116 }
1117
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001118 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001119 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001120 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001121}
1122#endif /* ICMP_FILTER */
1123
John Hughes38ae88d2002-05-23 11:48:58 +00001124static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001125printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001126{
1127 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001128 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001129 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001130 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001131 printxval(sockoptions, name, "SO_???");
1132 switch (name) {
1133#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001134 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001135 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001136 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001137 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001138 break;
1139 tprintf(", {onoff=%d, linger=%d}",
1140 linger.l_onoff,
1141 linger.l_linger);
1142 return 0;
1143 }
1144 break;
1145#endif
1146 }
1147 break;
1148#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001149 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001150 printxval(sockipoptions, name, "IP_???");
1151 break;
1152#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001153#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001154 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001155 printxval(sockipv6options, name, "IPV6_???");
1156 break;
1157#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001158#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001159 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001160 printxval(sockipxoptions, name, "IPX_???");
1161 break;
1162#endif
1163#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001164 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001165 printxval(sockpacketoptions, name, "PACKET_???");
1166 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001167 switch (name) {
1168#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001169 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001170#endif
1171#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001172 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001173#endif
1174#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1175 if (len == sizeof(struct tpacket_req)) {
1176 struct tpacket_req req;
1177 if (umove(tcp, addr, &req) < 0)
1178 break;
1179 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1180 req.tp_block_size,
1181 req.tp_block_nr,
1182 req.tp_frame_size,
1183 req.tp_frame_nr);
1184 return 0;
1185 }
1186 break;
1187#endif /* PACKET_RX_RING || PACKET_TX_RING */
1188 }
John Hughes38ae88d2002-05-23 11:48:58 +00001189 break;
1190#endif
1191#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001192 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001193 printxval(socktcpoptions, name, "TCP_???");
1194 break;
1195#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001196#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001197 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001198 printxval(socksctpoptions, name, "SCTP_???");
1199 break;
1200#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001201#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001202 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001203 printxval(sockrawoptions, name, "RAW_???");
1204 switch (name) {
1205#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001206 case ICMP_FILTER:
1207 tprints(", ");
1208 printicmpfilter(tcp, addr);
1209 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001210#endif
1211 }
1212 break;
1213#endif
1214
Roland McGrath6d2b3492002-12-30 00:51:30 +00001215 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001216 * etc. still need work */
1217
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001218 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001219 tprintf("%u", name);
1220 }
1221
1222 /* default arg printing */
1223
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001224 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001225
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001226 if (len == sizeof(int)) {
1227 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001228 }
1229 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001230 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001231 }
1232 return 0;
1233}
1234
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235int
Denys Vlasenko12014262011-05-30 14:00:14 +02001236sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237{
1238 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001239 printfd(tcp, tcp->u_arg[0]);
1240 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001241 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001242 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001243 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 }
1245 return 0;
1246}