blob: c38b1101e011d33c5f9406f64c6285ba937f55fd [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 YAMATO02f9f6b2014-10-15 22:11:43 +0900432static bool
433extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
434{
435#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
436 if (current_wordsize == 4) {
437 struct msghdr32 msg32;
438
439 if (umove(tcp, addr, &msg32) < 0)
440 return false;
441 msg->msg_name = (void*)(long)msg32.msg_name;
442 msg->msg_namelen = msg32.msg_namelen;
443 msg->msg_iov = (void*)(long)msg32.msg_iov;
444 msg->msg_iovlen = msg32.msg_iovlen;
445 msg->msg_control = (void*)(long)msg32.msg_control;
446 msg->msg_controllen = msg32.msg_controllen;
447 msg->msg_flags = msg32.msg_flags;
448 } else
449#endif
450 if (umove(tcp, addr, msg) < 0)
451 return false;
452 return true;
453}
454
Andreas Schwab0873f292010-02-12 21:39:12 +0100455static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200456printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457{
458 struct msghdr msg;
459
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900460 if (extractmsghdr(tcp, addr, &msg))
461 do_msghdr(tcp, &msg, data_size);
462 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000463 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900464}
465
466void
467dumpiov_in_msghdr(struct tcb *tcp, long addr)
468{
469 struct msghdr msg;
470
471 if (extractmsghdr(tcp, addr, &msg))
472 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473}
474
Andreas Schwab0873f292010-02-12 21:39:12 +0100475static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000476printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100477{
478 struct mmsghdr {
479 struct msghdr msg_hdr;
480 unsigned msg_len;
481 } mmsg;
482
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100483#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
484 if (current_wordsize == 4) {
485 struct mmsghdr32 mmsg32;
486
487 addr += sizeof(mmsg32) * idx;
488 if (umove(tcp, addr, &mmsg32) < 0) {
489 tprintf("%#lx", addr);
490 return;
491 }
492 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
493 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
494 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
495 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
496 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
497 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
498 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
499 mmsg.msg_len = mmsg32.msg_len;
500 } else
501#endif
502 {
503 addr += sizeof(mmsg) * idx;
504 if (umove(tcp, addr, &mmsg) < 0) {
505 tprintf("%#lx", addr);
506 return;
507 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100508 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200509 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000510 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100511 tprintf(", %u}", mmsg.msg_len);
512}
Andreas Schwab0873f292010-02-12 21:39:12 +0100513
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000514static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000515decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000516{
517 /* mmsgvec */
518 if (syserror(tcp)) {
519 tprintf("%#lx", tcp->u_arg[1]);
520 } else {
521 unsigned int len = tcp->u_rval;
522 unsigned int i;
523
524 tprints("{");
525 for (i = 0; i < len; ++i) {
526 if (i)
527 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000528 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000529 }
530 tprints("}");
531 }
532 /* vlen */
533 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
534 /* flags */
535 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
536}
537
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538#endif /* HAVE_SENDMSG */
539
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000540/*
541 * low bits of the socket type define real socket type,
542 * other bits are socket type flags.
543 */
544static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000545tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000546{
547 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
548
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200549 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200550 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000551 flags &= ~SOCK_TYPE_MASK;
552 if (!flags)
553 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200554 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000555 }
556 printflags(sock_type_flags, flags, "SOCK_???");
557}
558
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000560sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561{
562 if (entering(tcp)) {
563 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200564 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000565 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200566 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 switch (tcp->u_arg[0]) {
568 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000569#ifdef PF_INET6
570 case PF_INET6:
571#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900572 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 break;
574#ifdef PF_IPX
575 case PF_IPX:
576 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200577 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200579 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580 break;
581#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900582#ifdef PF_NETLINK
583 case PF_NETLINK:
584 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
585 break;
586#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200587#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
588 case PF_BLUETOOTH:
589 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
590 break;
591#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592 default:
593 tprintf("%lu", tcp->u_arg[2]);
594 break;
595 }
596 }
597 return 0;
598}
599
John Hughesbdf48f52001-03-06 15:08:09 +0000600int
Denys Vlasenko12014262011-05-30 14:00:14 +0200601sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602{
603 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800604 printfd(tcp, tcp->u_arg[0]);
605 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000606 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 tprintf(", %lu", tcp->u_arg[2]);
608 }
609 return 0;
610}
611
612int
Denys Vlasenko12014262011-05-30 14:00:14 +0200613sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
615 return sys_bind(tcp);
616}
617
618int
Denys Vlasenko12014262011-05-30 14:00:14 +0200619sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620{
621 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800622 printfd(tcp, tcp->u_arg[0]);
623 tprints(", ");
624 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625 }
626 return 0;
627}
628
Paolo Bonzini705ff102009-08-14 12:34:05 +0200629static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000630do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631{
632 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800633 printfd(tcp, tcp->u_arg[0]);
634 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200635 return 0;
636 }
637 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638 tprintf("%#lx, NULL", tcp->u_arg[1]);
639 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000640 int len;
641 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200642 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643 tprintf("%#lx", tcp->u_arg[1]);
644 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000645 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200647 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000648 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200650 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200651 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200652 printflags(sock_type_flags, tcp->u_arg[flags_arg],
653 "SOCK_???");
654 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 return 0;
656}
657
658int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200659sys_accept(struct tcb *tcp)
660{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000661 do_sockname(tcp, -1);
662 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200663}
664
Paolo Bonzini705ff102009-08-14 12:34:05 +0200665int
666sys_accept4(struct tcb *tcp)
667{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000668 do_sockname(tcp, 3);
669 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200670}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200671
672int
Denys Vlasenko12014262011-05-30 14:00:14 +0200673sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674{
675 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800676 printfd(tcp, tcp->u_arg[0]);
677 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
679 tprintf(", %lu, ", tcp->u_arg[2]);
680 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000681 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682 }
683 return 0;
684}
685
686int
Denys Vlasenko12014262011-05-30 14:00:14 +0200687sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688{
689 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800690 printfd(tcp, tcp->u_arg[0]);
691 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
693 tprintf(", %lu, ", tcp->u_arg[2]);
694 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000695 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200697 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000698 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699 /* to length */
700 tprintf(", %lu", tcp->u_arg[5]);
701 }
702 return 0;
703}
704
705#ifdef HAVE_SENDMSG
706
707int
Denys Vlasenko12014262011-05-30 14:00:14 +0200708sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709{
710 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800711 printfd(tcp, tcp->u_arg[0]);
712 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000713 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200715 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000716 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717 }
718 return 0;
719}
720
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000721int
722sys_sendmmsg(struct tcb *tcp)
723{
724 if (entering(tcp)) {
725 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800726 printfd(tcp, tcp->u_arg[0]);
727 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000728 if (!verbose(tcp)) {
729 tprintf("%#lx, %u, ",
730 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
731 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
732 }
733 } else {
734 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000735 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000736 }
737 return 0;
738}
739
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740#endif /* HAVE_SENDMSG */
741
742int
Denys Vlasenko12014262011-05-30 14:00:14 +0200743sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744{
745 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800746 printfd(tcp, tcp->u_arg[0]);
747 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748 } else {
749 if (syserror(tcp))
750 tprintf("%#lx", tcp->u_arg[1]);
751 else
752 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
753
754 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000755 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 }
757 return 0;
758}
759
760int
Denys Vlasenko12014262011-05-30 14:00:14 +0200761sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762{
763 int fromlen;
764
765 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800766 printfd(tcp, tcp->u_arg[0]);
767 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 } else {
769 if (syserror(tcp)) {
770 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
771 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
772 tcp->u_arg[4], tcp->u_arg[5]);
773 return 0;
774 }
775 /* buf */
776 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
777 /* len */
778 tprintf(", %lu, ", tcp->u_arg[2]);
779 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000780 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781 /* from address, len */
782 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
783 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200784 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000785 else
786 tprintf(", %#lx", tcp->u_arg[4]);
787 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200788 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789 else
790 tprintf(", %#lx", tcp->u_arg[5]);
791 return 0;
792 }
793 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200794 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795 return 0;
796 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200797 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000798 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799 /* from length */
800 tprintf(", [%u]", fromlen);
801 }
802 return 0;
803}
804
805#ifdef HAVE_SENDMSG
806
807int
Denys Vlasenko12014262011-05-30 14:00:14 +0200808sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809{
810 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800811 printfd(tcp, tcp->u_arg[0]);
812 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813 } else {
814 if (syserror(tcp) || !verbose(tcp))
815 tprintf("%#lx", tcp->u_arg[1]);
816 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200817 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200819 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000820 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 }
822 return 0;
823}
824
Andreas Schwab0873f292010-02-12 21:39:12 +0100825int
826sys_recvmmsg(struct tcb *tcp)
827{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100828 /* +5 chars are for "left " prefix */
829 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400830
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100831 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800832 printfd(tcp, tcp->u_arg[0]);
833 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400834 if (verbose(tcp)) {
835 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100836 /* Abusing tcp->auxstr as temp storage.
837 * Will be used and freed on syscall exit.
838 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400839 tcp->auxstr = strdup(str);
840 } else {
841 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
842 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200843 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400844 print_timespec(tcp, tcp->u_arg[4]);
845 }
846 return 0;
847 } else {
848 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000849 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400850 /* timeout on entrance */
851 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
852 free((void *) tcp->auxstr);
853 tcp->auxstr = NULL;
854 }
855 if (syserror(tcp))
856 return 0;
857 if (tcp->u_rval == 0) {
858 tcp->auxstr = "Timeout";
859 return RVAL_STR;
860 }
861 if (!verbose(tcp))
862 return 0;
863 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100864 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400865 tcp->auxstr = str;
866 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100867 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100868}
Andreas Schwab0873f292010-02-12 21:39:12 +0100869
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870#endif /* HAVE_SENDMSG */
871
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000872#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100873
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874int
Denys Vlasenko12014262011-05-30 14:00:14 +0200875sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876{
877 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800878 printfd(tcp, tcp->u_arg[0]);
879 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100880 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881 }
882 return 0;
883}
884
885int
Denys Vlasenko12014262011-05-30 14:00:14 +0200886sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000888 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889}
890
891int
Denys Vlasenko12014262011-05-30 14:00:14 +0200892sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000894 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895}
896
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000897static int
898do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000900 if (exiting(tcp)) {
901 if (syserror(tcp)) {
902 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000903 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +0100904#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000905 int fds[2];
906
907 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000909 else
910 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +0100911#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000912 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
913#else
914 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000916 }
917 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200918 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000919 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
920 }
921 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922 return 0;
923}
924
925int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000926sys_pipe(struct tcb *tcp)
927{
928 return do_pipe(tcp, -1);
929}
930
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000931int
932sys_pipe2(struct tcb *tcp)
933{
934 return do_pipe(tcp, 1);
935}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000936
937int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000938sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000939{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941
942 if (entering(tcp)) {
943 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200944 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000945 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000946 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947 } else {
948 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000949 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 return 0;
951 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200953 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954 else
955 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 }
957 return 0;
958}
959
960int
Dmitry V. Levin31289192009-11-06 18:05:40 +0000961sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962{
963 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800964 printfd(tcp, tcp->u_arg[0]);
965 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +0000966 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 switch (tcp->u_arg[1]) {
969 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971 break;
972#ifdef SOL_IP
973 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 break;
976#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000977#ifdef SOL_IPV6
978 case SOL_IPV6:
979 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
980 break;
981#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982#ifdef SOL_IPX
983 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985 break;
986#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000987#ifdef SOL_PACKET
988 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000989 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000990 break;
991#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992#ifdef SOL_TCP
993 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 break;
996#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100997#ifdef SOL_SCTP
998 case SOL_SCTP:
999 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1000 break;
1001#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002
1003 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1004 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001005 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001006 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007 break;
1008 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001009 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001011 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001012 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001013 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014 tcp->u_arg[3], tcp->u_arg[4]);
1015 return 0;
1016 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001017
1018 switch (tcp->u_arg[1]) {
1019 case SOL_SOCKET:
1020 switch (tcp->u_arg[2]) {
1021#ifdef SO_LINGER
1022 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001023 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001024 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001025 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001026 tcp->u_arg[3],
1027 &linger) < 0)
1028 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001029 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001030 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001031 linger.l_onoff,
1032 linger.l_linger,
1033 len);
1034 return 0;
1035 }
1036 break;
1037#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001038#ifdef SO_PEERCRED
1039 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001040 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001041 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001042 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001043 tcp->u_arg[3],
1044 &uc) < 0)
1045 break;
1046 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1047 "[%d]",
1048 (long)uc.pid,
1049 (long)uc.uid,
1050 (long)uc.gid,
1051 len);
1052 return 0;
1053 }
1054 break;
1055#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001056 }
1057 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001058 case SOL_PACKET:
1059 switch (tcp->u_arg[2]) {
1060#ifdef PACKET_STATISTICS
1061 case PACKET_STATISTICS:
1062 if (len == sizeof(struct tpacket_stats)) {
1063 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001064 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001065 tcp->u_arg[3],
1066 &stats) < 0)
1067 break;
1068 tprintf("{packets=%u, drops=%u}, "
1069 "[%d]",
1070 stats.tp_packets,
1071 stats.tp_drops,
1072 len);
1073 return 0;
1074 }
1075 break;
1076#endif
1077 }
1078 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001079 }
1080
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001081 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001082 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001083 }
1084 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001085 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001086 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001087 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 }
1089 return 0;
1090}
1091
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001092#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001093static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001094{
1095 struct icmp_filter filter;
1096
1097 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001098 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001099 return;
1100 }
1101 if (syserror(tcp) || !verbose(tcp)) {
1102 tprintf("%#lx", addr);
1103 return;
1104 }
1105 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001106 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001107 return;
1108 }
1109
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001110 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001111 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001112 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001113}
1114#endif /* ICMP_FILTER */
1115
John Hughes38ae88d2002-05-23 11:48:58 +00001116static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001117printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001118{
1119 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001120 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001121 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001122 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001123 printxval(sockoptions, name, "SO_???");
1124 switch (name) {
1125#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001126 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001127 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001128 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001129 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001130 break;
1131 tprintf(", {onoff=%d, linger=%d}",
1132 linger.l_onoff,
1133 linger.l_linger);
1134 return 0;
1135 }
1136 break;
1137#endif
1138 }
1139 break;
1140#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001141 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001142 printxval(sockipoptions, name, "IP_???");
1143 break;
1144#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001145#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001146 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001147 printxval(sockipv6options, name, "IPV6_???");
1148 break;
1149#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001150#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001151 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001152 printxval(sockipxoptions, name, "IPX_???");
1153 break;
1154#endif
1155#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001156 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001157 printxval(sockpacketoptions, name, "PACKET_???");
1158 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001159 switch (name) {
1160#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001161 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001162#endif
1163#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001164 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001165#endif
1166#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1167 if (len == sizeof(struct tpacket_req)) {
1168 struct tpacket_req req;
1169 if (umove(tcp, addr, &req) < 0)
1170 break;
1171 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1172 req.tp_block_size,
1173 req.tp_block_nr,
1174 req.tp_frame_size,
1175 req.tp_frame_nr);
1176 return 0;
1177 }
1178 break;
1179#endif /* PACKET_RX_RING || PACKET_TX_RING */
1180 }
John Hughes38ae88d2002-05-23 11:48:58 +00001181 break;
1182#endif
1183#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001184 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001185 printxval(socktcpoptions, name, "TCP_???");
1186 break;
1187#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001188#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001189 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001190 printxval(socksctpoptions, name, "SCTP_???");
1191 break;
1192#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001193#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001194 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001195 printxval(sockrawoptions, name, "RAW_???");
1196 switch (name) {
1197#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001198 case ICMP_FILTER:
1199 tprints(", ");
1200 printicmpfilter(tcp, addr);
1201 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001202#endif
1203 }
1204 break;
1205#endif
1206
Roland McGrath6d2b3492002-12-30 00:51:30 +00001207 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001208 * etc. still need work */
1209
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001210 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001211 tprintf("%u", name);
1212 }
1213
1214 /* default arg printing */
1215
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001216 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001217
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001218 if (len == sizeof(int)) {
1219 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001220 }
1221 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001222 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001223 }
1224 return 0;
1225}
1226
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227int
Denys Vlasenko12014262011-05-30 14:00:14 +02001228sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229{
1230 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001231 printfd(tcp, tcp->u_arg[0]);
1232 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001233 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001234 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001235 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 }
1237 return 0;
1238}