blob: 8703b8be60f23bce689e9a042ca61f002ac51fd1 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/stat.h>
36#include <sys/socket.h>
37#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000038
39#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40#define in6_addr in6_addr_libc
41#define ipv6_mreq ipv6_mreq_libc
42#define sockaddr_in6 sockaddr_in6_libc
43#endif
44
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000047#include <netinet/tcp.h>
48#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000049#ifdef HAVE_NETINET_UDP_H
50#include <netinet/udp.h>
51#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010052#ifdef HAVE_NETINET_SCTP_H
53#include <netinet/sctp.h>
54#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000056#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#include <asm/types.h>
58#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
59# include <netipx/ipx.h>
60#else
61# include <linux/ipx.h>
62#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063
Denys Vlasenkoc36c3522012-02-25 02:47:15 +010064#if defined(__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000065#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000066#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
67#undef in6_addr
68#undef ipv6_mreq
69#undef sockaddr_in6
70#define in6_addr in6_addr_kernel
71#define ipv6_mreq ipv6_mreq_kernel
72#define sockaddr_in6 sockaddr_in6_kernel
73#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000074#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000075#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
76#undef in6_addr
77#undef ipv6_mreq
78#undef sockaddr_in6
79#define in6_addr in6_addr_libc
80#define ipv6_mreq ipv6_mreq_libc
81#define sockaddr_in6 sockaddr_in6_kernel
82#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000083#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000084#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000085
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#if defined(HAVE_SYS_UIO_H)
87#include <sys/uio.h>
88#endif
89
90#if defined(HAVE_LINUX_NETLINK_H)
91#include <linux/netlink.h>
92#endif
93
94#if defined(HAVE_LINUX_IF_PACKET_H)
95#include <linux/if_packet.h>
96#endif
97
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000098#if defined(HAVE_LINUX_ICMP_H)
99#include <linux/icmp.h>
100#endif
101
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000102#ifndef PF_UNSPEC
103#define PF_UNSPEC AF_UNSPEC
104#endif
105
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106/* Under Linux these are enums so we can't test for them with ifdef. */
107#define IPPROTO_EGP IPPROTO_EGP
108#define IPPROTO_PUP IPPROTO_PUP
109#define IPPROTO_IDP IPPROTO_IDP
110#define IPPROTO_IGMP IPPROTO_IGMP
111#define IPPROTO_RAW IPPROTO_RAW
112#define IPPROTO_MAX IPPROTO_MAX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113
Roland McGrathd9f816f2004-09-04 03:39:20 +0000114static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000115#ifdef PF_AAL5
116 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117#endif
118#ifdef PF_APPLETALK
119 { PF_APPLETALK, "PF_APPLETALK" },
120#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000121#ifdef PF_ASH
122 { PF_ASH, "PF_ASH" },
123#endif
124#ifdef PF_ATMPVC
125 { PF_ATMPVC, "PF_ATMPVC" },
126#endif
127#ifdef PF_ATMSVC
128 { PF_ATMSVC, "PF_ATMSVC" },
129#endif
130#ifdef PF_AX25
131 { PF_AX25, "PF_AX25" },
132#endif
133#ifdef PF_BLUETOOTH
134 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135#endif
136#ifdef PF_BRIDGE
137 { PF_BRIDGE, "PF_BRIDGE" },
138#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000139#ifdef PF_DECnet
140 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#endif
142#ifdef PF_DECNET
143 { PF_DECNET, "PF_DECNET" },
144#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000145#ifdef PF_ECONET
146 { PF_ECONET, "PF_ECONET" },
147#endif
148#ifdef PF_FILE
149 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#endif
151#ifdef PF_IMPLINK
152 { PF_IMPLINK, "PF_IMPLINK" },
153#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000154#ifdef PF_INET
155 { PF_INET, "PF_INET" },
156#endif
157#ifdef PF_INET6
158 { PF_INET6, "PF_INET6" },
159#endif
160#ifdef PF_IPX
161 { PF_IPX, "PF_IPX" },
162#endif
163#ifdef PF_IRDA
164 { PF_IRDA, "PF_IRDA" },
165#endif
166#ifdef PF_ISO
167 { PF_ISO, "PF_ISO" },
168#endif
169#ifdef PF_KEY
170 { PF_KEY, "PF_KEY" },
171#endif
172#ifdef PF_UNIX
173 { PF_UNIX, "PF_UNIX" },
174#endif
175#ifdef PF_LOCAL
176 { PF_LOCAL, "PF_LOCAL" },
177#endif
178#ifdef PF_NETBEUI
179 { PF_NETBEUI, "PF_NETBEUI" },
180#endif
181#ifdef PF_NETLINK
182 { PF_NETLINK, "PF_NETLINK" },
183#endif
184#ifdef PF_NETROM
185 { PF_NETROM, "PF_NETROM" },
186#endif
187#ifdef PF_PACKET
188 { PF_PACKET, "PF_PACKET" },
189#endif
190#ifdef PF_PPPOX
191 { PF_PPPOX, "PF_PPPOX" },
192#endif
193#ifdef PF_ROSE
194 { PF_ROSE, "PF_ROSE" },
195#endif
196#ifdef PF_ROUTE
197 { PF_ROUTE, "PF_ROUTE" },
198#endif
199#ifdef PF_SECURITY
200 { PF_SECURITY, "PF_SECURITY" },
201#endif
202#ifdef PF_SNA
203 { PF_SNA, "PF_SNA" },
204#endif
205#ifdef PF_UNSPEC
206 { PF_UNSPEC, "PF_UNSPEC" },
207#endif
208#ifdef PF_WANPIPE
209 { PF_WANPIPE, "PF_WANPIPE" },
210#endif
211#ifdef PF_X25
212 { PF_X25, "PF_X25" },
213#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214 { 0, NULL },
215};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000216const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000217#ifdef AF_APPLETALK
218 { AF_APPLETALK, "AF_APPLETALK" },
219#endif
220#ifdef AF_ASH
221 { AF_ASH, "AF_ASH" },
222#endif
223#ifdef AF_ATMPVC
224 { AF_ATMPVC, "AF_ATMPVC" },
225#endif
226#ifdef AF_ATMSVC
227 { AF_ATMSVC, "AF_ATMSVC" },
228#endif
229#ifdef AF_AX25
230 { AF_AX25, "AF_AX25" },
231#endif
232#ifdef AF_BLUETOOTH
233 { AF_BLUETOOTH, "AF_BLUETOOTH" },
234#endif
235#ifdef AF_BRIDGE
236 { AF_BRIDGE, "AF_BRIDGE" },
237#endif
238#ifdef AF_DECnet
239 { AF_DECnet, "AF_DECnet" },
240#endif
241#ifdef AF_ECONET
242 { AF_ECONET, "AF_ECONET" },
243#endif
244#ifdef AF_FILE
245 { AF_FILE, "AF_FILE" },
246#endif
247#ifdef AF_IMPLINK
248 { AF_IMPLINK, "AF_IMPLINK" },
249#endif
250#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000251 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000252#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000253#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000254 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000255#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000256#ifdef AF_IPX
257 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000258#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000259#ifdef AF_IRDA
260 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000261#endif
262#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000263 { AF_ISO, "AF_ISO" },
264#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000265#ifdef AF_KEY
266 { AF_KEY, "AF_KEY" },
267#endif
268#ifdef AF_UNIX
269 { AF_UNIX, "AF_UNIX" },
270#endif
271#ifdef AF_LOCAL
272 { AF_LOCAL, "AF_LOCAL" },
273#endif
274#ifdef AF_NETBEUI
275 { AF_NETBEUI, "AF_NETBEUI" },
276#endif
277#ifdef AF_NETLINK
278 { AF_NETLINK, "AF_NETLINK" },
279#endif
280#ifdef AF_NETROM
281 { AF_NETROM, "AF_NETROM" },
282#endif
283#ifdef AF_PACKET
284 { AF_PACKET, "AF_PACKET" },
285#endif
286#ifdef AF_PPPOX
287 { AF_PPPOX, "AF_PPPOX" },
288#endif
289#ifdef AF_ROSE
290 { AF_ROSE, "AF_ROSE" },
291#endif
292#ifdef AF_ROUTE
293 { AF_ROUTE, "AF_ROUTE" },
294#endif
295#ifdef AF_SECURITY
296 { AF_SECURITY, "AF_SECURITY" },
297#endif
298#ifdef AF_SNA
299 { AF_SNA, "AF_SNA" },
300#endif
301#ifdef AF_UNSPEC
302 { AF_UNSPEC, "AF_UNSPEC" },
303#endif
304#ifdef AF_WANPIPE
305 { AF_WANPIPE, "AF_WANPIPE" },
306#endif
307#ifdef AF_X25
308 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000309#endif
310 { 0, NULL },
311};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000312static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313 { SOCK_STREAM, "SOCK_STREAM" },
314 { SOCK_DGRAM, "SOCK_DGRAM" },
315#ifdef SOCK_RAW
316 { SOCK_RAW, "SOCK_RAW" },
317#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000318#ifdef SOCK_RDM
319 { SOCK_RDM, "SOCK_RDM" },
320#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321#ifdef SOCK_SEQPACKET
322 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
323#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000324#ifdef SOCK_DCCP
325 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326#endif
327#ifdef SOCK_PACKET
328 { SOCK_PACKET, "SOCK_PACKET" },
329#endif
330 { 0, NULL },
331};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000332static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000333#ifdef SOCK_CLOEXEC
334 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
335#endif
336#ifdef SOCK_NONBLOCK
337 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
338#endif
339 { 0, NULL },
340};
341#ifndef SOCK_TYPE_MASK
342# define SOCK_TYPE_MASK 0xf
343#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000344static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000345#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000346 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000347#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000348#if defined(SOL_ICMP)
349 { SOL_ICMP, "SOL_ICMP" },
350#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000351#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000352 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000353#endif
354#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000355 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000356#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000357#if defined(SOL_IPV6)
358 { SOL_IPV6, "SOL_IPV6" },
359#endif
360#if defined(SOL_ICMPV6)
361 { SOL_ICMPV6, "SOL_ICMPV6" },
362#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100363#if defined(SOL_SCTP)
364 { SOL_SCTP, "SOL_SCTP" },
365#endif
366#if defined(SOL_UDPLITE)
367 { SOL_UDPLITE, "SOL_UDPLITE" },
368#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000369#if defined(SOL_RAW)
370 { SOL_RAW, "SOL_RAW" },
371#endif
372#if defined(SOL_IPX)
373 { SOL_IPX, "SOL_IPX" },
374#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000375#if defined(SOL_AX25)
376 { SOL_AX25, "SOL_AX25" },
377#endif
378#if defined(SOL_ATALK)
379 { SOL_ATALK, "SOL_ATALK" },
380#endif
381#if defined(SOL_NETROM)
382 { SOL_NETROM, "SOL_NETROM" },
383#endif
384#if defined(SOL_ROSE)
385 { SOL_ROSE, "SOL_ROSE" },
386#endif
387#if defined(SOL_DECNET)
388 { SOL_DECNET, "SOL_DECNET" },
389#endif
390#if defined(SOL_X25)
391 { SOL_X25, "SOL_X25" },
392#endif
393#if defined(SOL_PACKET)
394 { SOL_PACKET, "SOL_PACKET" },
395#endif
396#if defined(SOL_ATM)
397 { SOL_ATM, "SOL_ATM" },
398#endif
399#if defined(SOL_AAL)
400 { SOL_AAL, "SOL_AAL" },
401#endif
402#if defined(SOL_IRDA)
403 { SOL_IRDA, "SOL_IRDA" },
404#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100405#if defined(SOL_NETBEUI)
406 { SOL_NETBEUI, "SOL_NETBEUI" },
407#endif
408#if defined(SOL_LLC)
409 { SOL_LLC, "SOL_LLC" },
410#endif
411#if defined(SOL_DCCP)
412 { SOL_DCCP, "SOL_DCCP" },
413#endif
414#if defined(SOL_NETLINK)
415 { SOL_NETLINK, "SOL_NETLINK" },
416#endif
417#if defined(SOL_TIPC)
418 { SOL_TIPC, "SOL_TIPC" },
419#endif
420#if defined(SOL_RXRPC)
421 { SOL_RXRPC, "SOL_RXRPC" },
422#endif
423#if defined(SOL_PPPOL2TP)
424 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
425#endif
426#if defined(SOL_BLUETOOTH)
427 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
428#endif
429#if defined(SOL_PNPIPE)
430 { SOL_PNPIPE, "SOL_PNPIPE" },
431#endif
432#if defined(SOL_RDS)
433 { SOL_RDS, "SOL_RDS" },
434#endif
435#if defined(SOL_IUVC)
436 { SOL_IUCV, "SOL_IUCV" },
437#endif
438#if defined(SOL_CAIF)
439 { SOL_CAIF, "SOL_CAIF" },
440#endif
John Hughes61563572001-03-27 16:47:36 +0000441 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000442 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000443};
John Hughes93f7fcc2002-05-22 15:46:49 +0000444/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
445 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000446static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 { IPPROTO_IP, "IPPROTO_IP" },
448 { IPPROTO_ICMP, "IPPROTO_ICMP" },
449 { IPPROTO_TCP, "IPPROTO_TCP" },
450 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000451#ifdef IPPROTO_IGMP
452 { IPPROTO_IGMP, "IPPROTO_IGMP" },
453#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454#ifdef IPPROTO_GGP
455 { IPPROTO_GGP, "IPPROTO_GGP" },
456#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000457#ifdef IPPROTO_IPIP
458 { IPPROTO_IPIP, "IPPROTO_IPIP" },
459#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460#ifdef IPPROTO_EGP
461 { IPPROTO_EGP, "IPPROTO_EGP" },
462#endif
463#ifdef IPPROTO_PUP
464 { IPPROTO_PUP, "IPPROTO_PUP" },
465#endif
466#ifdef IPPROTO_IDP
467 { IPPROTO_IDP, "IPPROTO_IDP" },
468#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000469#ifdef IPPROTO_TP
470 { IPPROTO_TP, "IPPROTO_TP" },
471#endif
472#ifdef IPPROTO_DCCP
473 { IPPROTO_DCCP, "IPPROTO_DCCP" },
474#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475#ifdef IPPROTO_IPV6
476 { IPPROTO_IPV6, "IPPROTO_IPV6" },
477#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000478#ifdef IPPROTO_ROUTING
479 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000481#ifdef IPPROTO_FRAGMENT
482 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
483#endif
484#ifdef IPPROTO_RSVP
485 { IPPROTO_RSVP, "IPPROTO_RSVP" },
486#endif
487#ifdef IPPROTO_GRE
488 { IPPROTO_GRE, "IPPROTO_GRE" },
489#endif
490#ifdef IPPROTO_ESP
491 { IPPROTO_ESP, "IPPROTO_ESP" },
492#endif
493#ifdef IPPROTO_AH
494 { IPPROTO_AH, "IPPROTO_AH" },
495#endif
496#ifdef IPPROTO_ICMPV6
497 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
498#endif
499#ifdef IPPROTO_NONE
500 { IPPROTO_NONE, "IPPROTO_NONE" },
501#endif
502#ifdef IPPROTO_DSTOPTS
503 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504#endif
505#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000506 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507#endif
508#ifdef IPPROTO_ND
509 { IPPROTO_ND, "IPPROTO_ND" },
510#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000511#ifdef IPPROTO_MTP
512 { IPPROTO_MTP, "IPPROTO_MTP" },
513#endif
514#ifdef IPPROTO_ENCAP
515 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
516#endif
517#ifdef IPPROTO_PIM
518 { IPPROTO_PIM, "IPPROTO_PIM" },
519#endif
520#ifdef IPPROTO_COMP
521 { IPPROTO_COMP, "IPPROTO_COMP" },
522#endif
523#ifdef IPPROTO_SCTP
524 { IPPROTO_SCTP, "IPPROTO_SCTP" },
525#endif
526#ifdef IPPROTO_UDPLITE
527 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
528#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529#ifdef IPPROTO_RAW
530 { IPPROTO_RAW, "IPPROTO_RAW" },
531#endif
532#ifdef IPPROTO_MAX
533 { IPPROTO_MAX, "IPPROTO_MAX" },
534#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 { 0, NULL },
536};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000537static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000538 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000540 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541#endif
542#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000543 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544#endif
545#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000546 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#endif
548#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000549 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550#endif
551#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000552 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553#endif
554#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000555 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000557#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000558 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000559#endif
560#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000561 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000562#endif
563#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000564 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565#endif
566#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000567 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000568#endif
569#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000570 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000571#endif
572#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000573 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000574#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000575#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000576 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000577#endif
578#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000579 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000580#endif
581#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000582 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000583#endif
584#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000585 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000586#endif
587#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000588 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000589#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000590#ifdef MSG_WAITFORONE
591 { MSG_WAITFORONE, "MSG_WAITFORONE" },
592#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000593#ifdef MSG_CMSG_CLOEXEC
594 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
595#endif
596 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597};
598
Roland McGrathd9f816f2004-09-04 03:39:20 +0000599static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000601 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000602#endif
603#ifdef SO_ALLRAW
604 { SO_ALLRAW, "SO_ALLRAW" },
605#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000606#ifdef SO_ATTACH_FILTER
607 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
608#endif
609#ifdef SO_BINDTODEVICE
610 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
611#endif
612#ifdef SO_BROADCAST
613 { SO_BROADCAST, "SO_BROADCAST" },
614#endif
615#ifdef SO_BSDCOMPAT
616 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
617#endif
618#ifdef SO_DEBUG
619 { SO_DEBUG, "SO_DEBUG" },
620#endif
621#ifdef SO_DETACH_FILTER
622 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
623#endif
624#ifdef SO_DONTROUTE
625 { SO_DONTROUTE, "SO_DONTROUTE" },
626#endif
627#ifdef SO_ERROR
628 { SO_ERROR, "SO_ERROR" },
629#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000630#ifdef SO_ICS
631 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000633#ifdef SO_IMASOCKET
634 { SO_IMASOCKET, "SO_IMASOCKET" },
635#endif
636#ifdef SO_KEEPALIVE
637 { SO_KEEPALIVE, "SO_KEEPALIVE" },
638#endif
639#ifdef SO_LINGER
640 { SO_LINGER, "SO_LINGER" },
641#endif
642#ifdef SO_LISTENING
643 { SO_LISTENING, "SO_LISTENING" },
644#endif
645#ifdef SO_MGMT
646 { SO_MGMT, "SO_MGMT" },
647#endif
648#ifdef SO_NO_CHECK
649 { SO_NO_CHECK, "SO_NO_CHECK" },
650#endif
651#ifdef SO_OOBINLINE
652 { SO_OOBINLINE, "SO_OOBINLINE" },
653#endif
654#ifdef SO_ORDREL
655 { SO_ORDREL, "SO_ORDREL" },
656#endif
657#ifdef SO_PARALLELSVR
658 { SO_PARALLELSVR, "SO_PARALLELSVR" },
659#endif
660#ifdef SO_PASSCRED
661 { SO_PASSCRED, "SO_PASSCRED" },
662#endif
663#ifdef SO_PEERCRED
664 { SO_PEERCRED, "SO_PEERCRED" },
665#endif
666#ifdef SO_PEERNAME
667 { SO_PEERNAME, "SO_PEERNAME" },
668#endif
669#ifdef SO_PEERSEC
670 { SO_PEERSEC, "SO_PEERSEC" },
671#endif
672#ifdef SO_PRIORITY
673 { SO_PRIORITY, "SO_PRIORITY" },
674#endif
675#ifdef SO_PROTOTYPE
676 { SO_PROTOTYPE, "SO_PROTOTYPE" },
677#endif
678#ifdef SO_RCVBUF
679 { SO_RCVBUF, "SO_RCVBUF" },
680#endif
681#ifdef SO_RCVLOWAT
682 { SO_RCVLOWAT, "SO_RCVLOWAT" },
683#endif
684#ifdef SO_RCVTIMEO
685 { SO_RCVTIMEO, "SO_RCVTIMEO" },
686#endif
687#ifdef SO_RDWR
688 { SO_RDWR, "SO_RDWR" },
689#endif
690#ifdef SO_REUSEADDR
691 { SO_REUSEADDR, "SO_REUSEADDR" },
692#endif
693#ifdef SO_REUSEPORT
694 { SO_REUSEPORT, "SO_REUSEPORT" },
695#endif
696#ifdef SO_SECURITY_AUTHENTICATION
697 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
698#endif
699#ifdef SO_SECURITY_ENCRYPTION_NETWORK
700 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
701#endif
702#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
703 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
704#endif
705#ifdef SO_SEMA
706 { SO_SEMA, "SO_SEMA" },
707#endif
708#ifdef SO_SNDBUF
709 { SO_SNDBUF, "SO_SNDBUF" },
710#endif
711#ifdef SO_SNDLOWAT
712 { SO_SNDLOWAT, "SO_SNDLOWAT" },
713#endif
714#ifdef SO_SNDTIMEO
715 { SO_SNDTIMEO, "SO_SNDTIMEO" },
716#endif
717#ifdef SO_TIMESTAMP
718 { SO_TIMESTAMP, "SO_TIMESTAMP" },
719#endif
720#ifdef SO_TYPE
721 { SO_TYPE, "SO_TYPE" },
722#endif
723#ifdef SO_USELOOPBACK
724 { SO_USELOOPBACK, "SO_USELOOPBACK" },
725#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 { 0, NULL },
727};
728
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100729#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000730#define SOL_IP IPPROTO_IP
731#endif
732
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000734static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000735#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000736 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000737#endif
738#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000739 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000740#endif
741#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000742 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000744#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000745 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000747#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000748 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000749#endif
750#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000751 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
752#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000753#ifdef IP_RECVOPTS
754 { IP_RECVOPTS, "IP_RECVOPTS" },
755#endif
756#ifdef IP_RECVRETOPTS
757 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
758#endif
759#ifdef IP_RECVDSTADDR
760 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
761#endif
762#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000763 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000764#endif
765#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000766 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000767#endif
768#ifdef IP_PKTOPTIONS
769 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
770#endif
771#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000772 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000773#endif
774#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000775 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000776#endif
777#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000778 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000779#endif
780#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000781 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000782#endif
783#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000784 { IP_MTU, "IP_MTU" },
785#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000786#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000787 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000788#endif
789#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000790 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#endif
792#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000793 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000794#endif
795#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000796 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000797#endif
798#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000799 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000800#endif
801#ifdef IP_BROADCAST_IF
802 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
803#endif
804#ifdef IP_RECVIFINDEX
805 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
806#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000807#ifdef IP_MSFILTER
808 { IP_MSFILTER, "IP_MSFILTER" },
809#endif
810#ifdef MCAST_MSFILTER
811 { MCAST_MSFILTER, "MCAST_MSFILTER" },
812#endif
813#ifdef IP_FREEBIND
814 { IP_FREEBIND, "IP_FREEBIND" },
815#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000816 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817};
818#endif /* SOL_IP */
819
Roland McGrath4f6ba692004-08-31 07:01:26 +0000820#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000821static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000822#ifdef IPV6_ADDRFORM
823 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
824#endif
825#ifdef MCAST_FILTER
826 { MCAST_FILTER, "MCAST_FILTER" },
827#endif
828#ifdef IPV6_PKTOPTIONS
829 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
830#endif
831#ifdef IPV6_MTU
832 { IPV6_MTU, "IPV6_MTU" },
833#endif
834#ifdef IPV6_V6ONLY
835 { IPV6_V6ONLY, "IPV6_V6ONLY" },
836#endif
837#ifdef IPV6_PKTINFO
838 { IPV6_PKTINFO, "IPV6_PKTINFO" },
839#endif
840#ifdef IPV6_HOPLIMIT
841 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
842#endif
843#ifdef IPV6_RTHDR
844 { IPV6_RTHDR, "IPV6_RTHDR" },
845#endif
846#ifdef IPV6_HOPOPTS
847 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
848#endif
849#ifdef IPV6_DSTOPTS
850 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
851#endif
852#ifdef IPV6_FLOWINFO
853 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
854#endif
855#ifdef IPV6_UNICAST_HOPS
856 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
857#endif
858#ifdef IPV6_MULTICAST_HOPS
859 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
860#endif
861#ifdef IPV6_MULTICAST_LOOP
862 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
863#endif
864#ifdef IPV6_MULTICAST_IF
865 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
866#endif
867#ifdef IPV6_MTU_DISCOVER
868 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
869#endif
870#ifdef IPV6_RECVERR
871 { IPV6_RECVERR, "IPV6_RECVERR" },
872#endif
873#ifdef IPV6_FLOWINFO_SEND
874 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
875#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000876#ifdef IPV6_ADD_MEMBERSHIP
877 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
878#endif
879#ifdef IPV6_DROP_MEMBERSHIP
880 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
881#endif
882#ifdef IPV6_ROUTER_ALERT
883 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
884#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000885 { 0, NULL },
886};
887#endif /* SOL_IPV6 */
888
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000890static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200891 { IPX_TYPE, "IPX_TYPE" },
892 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893};
894#endif /* SOL_IPX */
895
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000896#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000897static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000898#if defined(ICMP_FILTER)
899 { ICMP_FILTER, "ICMP_FILTER" },
900#endif
901 { 0, NULL },
902};
903#endif /* SOL_RAW */
904
905#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000906static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000907#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000908 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000909#endif
910#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000911 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000912#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000913#if defined(PACKET_RECV_OUTPUT)
914 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
915#endif
916#if defined(PACKET_RX_RING)
917 { PACKET_RX_RING, "PACKET_RX_RING" },
918#endif
919#if defined(PACKET_STATISTICS)
920 { PACKET_STATISTICS, "PACKET_STATISTICS" },
921#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000922#if defined(PACKET_COPY_THRESH)
923 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
924#endif
925#if defined(PACKET_AUXDATA)
926 { PACKET_AUXDATA, "PACKET_AUXDATA" },
927#endif
928#if defined(PACKET_ORIGDEV)
929 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
930#endif
931#if defined(PACKET_VERSION)
932 { PACKET_VERSION, "PACKET_VERSION" },
933#endif
934#if defined(PACKET_HDRLEN)
935 { PACKET_HDRLEN, "PACKET_HDRLEN" },
936#endif
937#if defined(PACKET_RESERVE)
938 { PACKET_RESERVE, "PACKET_RESERVE" },
939#endif
940#if defined(PACKET_TX_RING)
941 { PACKET_TX_RING, "PACKET_TX_RING" },
942#endif
943#if defined(PACKET_LOSS)
944 { PACKET_LOSS, "PACKET_LOSS" },
945#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000946 { 0, NULL },
947};
948#endif /* SOL_PACKET */
949
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100950#ifdef SOL_SCTP
951static const struct xlat socksctpoptions[] = {
952#if defined(SCTP_RTOINFO)
953 { SCTP_RTOINFO, "SCTP_RTOINFO" },
954#endif
955#if defined(SCTP_ASSOCINFO)
956 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
957#endif
958#if defined(SCTP_INITMSG)
959 { SCTP_INITMSG, "SCTP_INITMSG" },
960#endif
961#if defined(SCTP_NODELAY)
962 { SCTP_NODELAY, "SCTP_NODELAY" },
963#endif
964#if defined(SCTP_AUTOCLOSE)
965 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
966#endif
967#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
968 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
969#endif
970#if defined(SCTP_PRIMARY_ADDR)
971 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
972#endif
973#if defined(SCTP_ADAPTATION_LAYER)
974 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
975#endif
976#if defined(SCTP_DISABLE_FRAGMENTS)
977 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
978#endif
979#if defined(SCTP_PEER_ADDR_PARAMS)
980 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
981#endif
982#if defined(SCTP_DEFAULT_SEND_PARAM)
983 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
984#endif
985#if defined(SCTP_EVENTS)
986 { SCTP_EVENTS, "SCTP_EVENTS" },
987#endif
988#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
989 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
990#endif
991#if defined(SCTP_MAXSEG)
992 { SCTP_MAXSEG, "SCTP_MAXSEG" },
993#endif
994#if defined(SCTP_STATUS)
995 { SCTP_STATUS, "SCTP_STATUS" },
996#endif
997#if defined(SCTP_GET_PEER_ADDR_INFO)
998 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
999#endif
1000#if defined(SCTP_DELAYED_ACK)
1001 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1002#endif
1003#if defined(SCTP_CONTEXT)
1004 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1005#endif
1006#if defined(SCTP_FRAGMENT_INTERLEAVE)
1007 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1008#endif
1009#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1010 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1011#endif
1012#if defined(SCTP_MAX_BURST)
1013 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1014#endif
1015#if defined(SCTP_AUTH_CHUNK)
1016 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1017#endif
1018#if defined(SCTP_HMAC_IDENT)
1019 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1020#endif
1021#if defined(SCTP_AUTH_KEY)
1022 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1023#endif
1024#if defined(SCTP_AUTH_ACTIVE_KEY)
1025 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1026#endif
1027#if defined(SCTP_AUTH_DELETE_KEY)
1028 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1029#endif
1030#if defined(SCTP_PEER_AUTH_CHUNKS)
1031 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1032#endif
1033#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1034 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1035#endif
1036#if defined(SCTP_GET_ASSOC_NUMBER)
1037 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1038#endif
1039
1040 /* linux specific things */
1041#if defined(SCTP_SOCKOPT_BINDX_ADD)
1042 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1043#endif
1044#if defined(SCTP_SOCKOPT_BINDX_REM)
1045 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1046#endif
1047#if defined(SCTP_SOCKOPT_PEELOFF)
1048 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1049#endif
1050#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1051 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1052#endif
1053#if defined(SCTP_GET_PEER_ADDRS_OLD)
1054 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1055#endif
1056#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1057 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1058#endif
1059#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1060 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1061#endif
1062#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1063 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1064#endif
1065#if defined(SCTP_GET_PEER_ADDRS)
1066 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1067#endif
1068#if defined(SCTP_GET_LOCAL_ADDRS)
1069 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1070#endif
1071
1072 { 0, NULL },
1073};
1074#endif
1075
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001076#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001077#define SOL_TCP IPPROTO_TCP
1078#endif
1079
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001081static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001082 { TCP_NODELAY, "TCP_NODELAY" },
1083 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001084#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001085 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001086#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001087#if defined(TCP_KEEPIDLE)
1088 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1089#endif
1090#if defined(TCP_KEEPINTVL)
1091 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1092#endif
1093#if defined(TCP_KEEPCNT)
1094 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1095#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001096#if defined(TCP_NKEEP)
1097 { TCP_NKEEP, "TCP_NKEEP" },
1098#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001099#if defined(TCP_SYNCNT)
1100 { TCP_SYNCNT, "TCP_SYNCNT" },
1101#endif
1102#if defined(TCP_LINGER2)
1103 { TCP_LINGER2, "TCP_LINGER2" },
1104#endif
1105#if defined(TCP_DEFER_ACCEPT)
1106 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1107#endif
1108#if defined(TCP_WINDOW_CLAMP)
1109 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1110#endif
1111#if defined(TCP_INFO)
1112 { TCP_INFO, "TCP_INFO" },
1113#endif
1114#if defined(TCP_QUICKACK)
1115 { TCP_QUICKACK, "TCP_QUICKACK" },
1116#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001117#if defined(TCP_CONGESTION)
1118 { TCP_CONGESTION, "TCP_CONGESTION" },
1119#endif
1120#if defined(TCP_MD5SIG)
1121 { TCP_MD5SIG, "TCP_MD5SIG" },
1122#endif
1123#if defined(TCP_COOKIE_TRANSACTIONS)
1124 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1125#endif
1126#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1127 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1128#endif
1129#if defined(TCP_THIN_DUPACK)
1130 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1131#endif
1132#if defined(TCP_USER_TIMEOUT)
1133 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1134#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001135 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136};
1137#endif /* SOL_TCP */
1138
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001139#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001140static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001141#if defined(ICMP_ECHOREPLY)
1142 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1143#endif
1144#if defined(ICMP_DEST_UNREACH)
1145 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1146#endif
1147#if defined(ICMP_SOURCE_QUENCH)
1148 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1149#endif
1150#if defined(ICMP_REDIRECT)
1151 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1152#endif
1153#if defined(ICMP_ECHO)
1154 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1155#endif
1156#if defined(ICMP_TIME_EXCEEDED)
1157 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1158#endif
1159#if defined(ICMP_PARAMETERPROB)
1160 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1161#endif
1162#if defined(ICMP_TIMESTAMP)
1163 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1164#endif
1165#if defined(ICMP_TIMESTAMPREPLY)
1166 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1167#endif
1168#if defined(ICMP_INFO_REQUEST)
1169 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1170#endif
1171#if defined(ICMP_INFO_REPLY)
1172 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1173#endif
1174#if defined(ICMP_ADDRESS)
1175 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1176#endif
1177#if defined(ICMP_ADDRESSREPLY)
1178 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1179#endif
1180 { 0, NULL },
1181};
1182#endif /* SOL_RAW */
1183
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001184#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001185static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001186#if defined(PACKET_HOST)
1187 { PACKET_HOST, "PACKET_HOST" },
1188#endif
1189#if defined(PACKET_BROADCAST)
1190 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1191#endif
1192#if defined(PACKET_MULTICAST)
1193 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1194#endif
1195#if defined(PACKET_OTHERHOST)
1196 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1197#endif
1198#if defined(PACKET_OUTGOING)
1199 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1200#endif
1201#if defined(PACKET_LOOPBACK)
1202 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1203#endif
1204#if defined(PACKET_FASTROUTE)
1205 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1206#endif
1207 { 0, NULL },
1208};
1209#endif /* defined(AF_PACKET) */
1210
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001212printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001213{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001214 union {
1215 char pad[128];
1216 struct sockaddr sa;
1217 struct sockaddr_in sin;
1218 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001219#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001220 struct sockaddr_in6 sa6;
1221#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001222#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001223 struct sockaddr_ipx sipx;
1224#endif
1225#ifdef AF_PACKET
1226 struct sockaddr_ll ll;
1227#endif
1228#ifdef AF_NETLINK
1229 struct sockaddr_nl nl;
1230#endif
1231 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001232 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233
1234 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001235 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 return;
1237 }
1238 if (!verbose(tcp)) {
1239 tprintf("%#lx", addr);
1240 return;
1241 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001242
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001243 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1244 addrlen = sizeof(addrbuf);
1245
1246 memset(&addrbuf, 0, sizeof(addrbuf));
1247 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001248 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 return;
1250 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001251 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001252
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001253 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001254 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001255 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001256
1257 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001258 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001259 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001260 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001261 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001262 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001263 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001264 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001265 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001266 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001267 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 break;
1269 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001270 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001271 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001273#ifdef HAVE_INET_NTOP
1274 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001275 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001276 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1277 ntohs(addrbuf.sa6.sin6_port), string_addr,
1278 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001279#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001280 {
1281#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001282 int numericscope = 0;
1283 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1284 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1285 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001286
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1288 numericscope++;
1289 else
1290 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1291 } else
1292 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001293
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001294 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001295#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001296 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001297 }
1298#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001299 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001300#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001301#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001303 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001305 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001306 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 /* Yes, I know, this does not look too
1308 * strace-ish, but otherwise the IPX
1309 * addresses just look monstrous...
1310 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001311 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001313 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001314 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001315 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1316 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001317 }
1318 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001319#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001320#ifdef AF_PACKET
1321 case AF_PACKET:
1322 {
1323 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001324 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001325 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001326 addrbuf.ll.sll_ifindex);
1327 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1328 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001329 addrbuf.ll.sll_halen,
1330 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001331 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001332 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1333 }
1334 break;
1335
Denys Vlasenko84703742012-02-25 02:38:52 +01001336#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001337#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001338 case AF_NETLINK:
1339 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1340 break;
1341#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001342 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001343 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344
1345 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001346 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001347 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001348 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349 break;
1350 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001351 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352}
1353
1354#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001355static const struct xlat scmvals[] = {
1356#ifdef SCM_RIGHTS
1357 { SCM_RIGHTS, "SCM_RIGHTS" },
1358#endif
1359#ifdef SCM_CREDENTIALS
1360 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1361#endif
1362 { 0, NULL }
1363};
1364
1365static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001366printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001367{
Roland McGrathaa524c82005-06-01 19:22:06 +00001368 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1369 NULL : malloc(len);
1370 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001371 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001372 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001373 return;
1374 }
1375
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001376 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001377 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001378 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001379
Roland McGrathaa524c82005-06-01 19:22:06 +00001380 if (cmsg->cmsg_level == SOL_SOCKET) {
1381 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001382
Roland McGrathaa524c82005-06-01 19:22:06 +00001383 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1384 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1385
1386 if (cmsg->cmsg_type == SCM_RIGHTS
1387 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001388 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001389 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001390
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001391 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001392 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001393 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001394 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001395 tprintf("%d", *fds++);
1396 first = 0;
1397 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001398 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001399 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001400 return;
1401 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001402 if (cmsg->cmsg_type == SCM_CREDENTIALS
1403 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001404 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001405
Roland McGrath50770822004-10-06 22:11:51 +00001406 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1407 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001408 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001409 return;
1410 }
1411 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001412 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001413 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001414}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415
1416static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001417do_msghdr(struct tcb *tcp, struct msghdr *msg)
1418{
1419 tprintf("{msg_name(%d)=", msg->msg_namelen);
1420 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1421
1422 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1423 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
Dmitry V. Levin88849682011-06-13 22:58:44 +00001424 (unsigned long)msg->msg_iov, 1);
Andreas Schwab0873f292010-02-12 21:39:12 +01001425
1426#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1427 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1428 if (msg->msg_controllen)
1429 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1430 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001431 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001432 printflags(msg_flags, msg->msg_flags, "MSG_???");
1433#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1434 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1435 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1436#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001437 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001438}
1439
1440static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001441printmsghdr(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442{
1443 struct msghdr msg;
1444
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001445 if (umove(tcp, addr, &msg) < 0) {
1446 tprintf("%#lx", addr);
1447 return;
1448 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001449 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450}
1451
Andreas Schwab0873f292010-02-12 21:39:12 +01001452static void
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001453printmmsghdr(struct tcb *tcp, long addr, unsigned int idx)
Andreas Schwab0873f292010-02-12 21:39:12 +01001454{
1455 struct mmsghdr {
1456 struct msghdr msg_hdr;
1457 unsigned msg_len;
1458 } mmsg;
1459
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001460 addr += sizeof(mmsg) * idx;
Andreas Schwab0873f292010-02-12 21:39:12 +01001461 if (umove(tcp, addr, &mmsg) < 0) {
1462 tprintf("%#lx", addr);
1463 return;
1464 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001465 tprints("{");
Andreas Schwab0873f292010-02-12 21:39:12 +01001466 do_msghdr(tcp, &mmsg.msg_hdr);
1467 tprintf(", %u}", mmsg.msg_len);
1468}
Andreas Schwab0873f292010-02-12 21:39:12 +01001469
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001470static void
1471decode_mmsg(struct tcb *tcp)
1472{
1473 /* mmsgvec */
1474 if (syserror(tcp)) {
1475 tprintf("%#lx", tcp->u_arg[1]);
1476 } else {
1477 unsigned int len = tcp->u_rval;
1478 unsigned int i;
1479
1480 tprints("{");
1481 for (i = 0; i < len; ++i) {
1482 if (i)
1483 tprints(", ");
1484 printmmsghdr(tcp, tcp->u_arg[1], i);
1485 }
1486 tprints("}");
1487 }
1488 /* vlen */
1489 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1490 /* flags */
1491 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1492}
1493
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494#endif /* HAVE_SENDMSG */
1495
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001496/*
1497 * low bits of the socket type define real socket type,
1498 * other bits are socket type flags.
1499 */
1500static void
1501tprint_sock_type(struct tcb *tcp, int flags)
1502{
1503 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1504
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001505 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001506 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001507 flags &= ~SOCK_TYPE_MASK;
1508 if (!flags)
1509 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001510 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001511 }
1512 printflags(sock_type_flags, flags, "SOCK_???");
1513}
1514
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001515int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001516sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001517{
1518 if (entering(tcp)) {
1519 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001520 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001521 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001522 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523 switch (tcp->u_arg[0]) {
1524 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001525#ifdef PF_INET6
1526 case PF_INET6:
1527#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001528 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1529 break;
1530#ifdef PF_IPX
1531 case PF_IPX:
1532 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001533 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001534 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001535 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001536 break;
1537#endif /* PF_IPX */
1538 default:
1539 tprintf("%lu", tcp->u_arg[2]);
1540 break;
1541 }
1542 }
1543 return 0;
1544}
1545
John Hughesbdf48f52001-03-06 15:08:09 +00001546int
Denys Vlasenko12014262011-05-30 14:00:14 +02001547sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001548{
1549 if (entering(tcp)) {
1550 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001551 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001552 tprintf(", %lu", tcp->u_arg[2]);
1553 }
1554 return 0;
1555}
1556
1557int
Denys Vlasenko12014262011-05-30 14:00:14 +02001558sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001559{
1560 return sys_bind(tcp);
1561}
1562
1563int
Denys Vlasenko12014262011-05-30 14:00:14 +02001564sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565{
1566 if (entering(tcp)) {
1567 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1568 }
1569 return 0;
1570}
1571
Paolo Bonzini705ff102009-08-14 12:34:05 +02001572static int
1573do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574{
1575 if (entering(tcp)) {
1576 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001577 return 0;
1578 }
1579 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 tprintf("%#lx, NULL", tcp->u_arg[1]);
1581 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001582 int len;
1583 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001584 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 tprintf("%#lx", tcp->u_arg[1]);
1586 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001587 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001589 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001590 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001592 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001593 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001594 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1595 "SOCK_???");
1596 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 return 0;
1598}
1599
1600int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001601sys_accept(struct tcb *tcp)
1602{
1603 return do_accept(tcp, -1);
1604}
1605
Paolo Bonzini705ff102009-08-14 12:34:05 +02001606int
1607sys_accept4(struct tcb *tcp)
1608{
1609 return do_accept(tcp, 3);
1610}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001611
1612int
Denys Vlasenko12014262011-05-30 14:00:14 +02001613sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614{
1615 if (entering(tcp)) {
1616 tprintf("%ld, ", tcp->u_arg[0]);
1617 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1618 tprintf(", %lu, ", tcp->u_arg[2]);
1619 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001620 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 }
1622 return 0;
1623}
1624
1625int
Denys Vlasenko12014262011-05-30 14:00:14 +02001626sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627{
1628 if (entering(tcp)) {
1629 tprintf("%ld, ", tcp->u_arg[0]);
1630 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1631 tprintf(", %lu, ", tcp->u_arg[2]);
1632 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001633 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001635 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001636 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637 /* to length */
1638 tprintf(", %lu", tcp->u_arg[5]);
1639 }
1640 return 0;
1641}
1642
1643#ifdef HAVE_SENDMSG
1644
1645int
Denys Vlasenko12014262011-05-30 14:00:14 +02001646sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001647{
1648 if (entering(tcp)) {
1649 tprintf("%ld, ", tcp->u_arg[0]);
1650 printmsghdr(tcp, tcp->u_arg[1]);
1651 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001652 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001653 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001654 }
1655 return 0;
1656}
1657
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001658int
1659sys_sendmmsg(struct tcb *tcp)
1660{
1661 if (entering(tcp)) {
1662 /* sockfd */
1663 tprintf("%d, ", (int) tcp->u_arg[0]);
1664 if (!verbose(tcp)) {
1665 tprintf("%#lx, %u, ",
1666 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1667 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1668 }
1669 } else {
1670 if (verbose(tcp))
1671 decode_mmsg(tcp);
1672 }
1673 return 0;
1674}
1675
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676#endif /* HAVE_SENDMSG */
1677
1678int
Denys Vlasenko12014262011-05-30 14:00:14 +02001679sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680{
1681 if (entering(tcp)) {
1682 tprintf("%ld, ", tcp->u_arg[0]);
1683 } else {
1684 if (syserror(tcp))
1685 tprintf("%#lx", tcp->u_arg[1]);
1686 else
1687 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1688
1689 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001690 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691 }
1692 return 0;
1693}
1694
1695int
Denys Vlasenko12014262011-05-30 14:00:14 +02001696sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697{
1698 int fromlen;
1699
1700 if (entering(tcp)) {
1701 tprintf("%ld, ", tcp->u_arg[0]);
1702 } else {
1703 if (syserror(tcp)) {
1704 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1705 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1706 tcp->u_arg[4], tcp->u_arg[5]);
1707 return 0;
1708 }
1709 /* buf */
1710 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1711 /* len */
1712 tprintf(", %lu, ", tcp->u_arg[2]);
1713 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001714 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001715 /* from address, len */
1716 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1717 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001718 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719 else
1720 tprintf(", %#lx", tcp->u_arg[4]);
1721 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001722 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723 else
1724 tprintf(", %#lx", tcp->u_arg[5]);
1725 return 0;
1726 }
1727 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001728 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729 return 0;
1730 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001731 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001732 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 /* from length */
1734 tprintf(", [%u]", fromlen);
1735 }
1736 return 0;
1737}
1738
1739#ifdef HAVE_SENDMSG
1740
1741int
Denys Vlasenko12014262011-05-30 14:00:14 +02001742sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001743{
1744 if (entering(tcp)) {
1745 tprintf("%ld, ", tcp->u_arg[0]);
1746 } else {
1747 if (syserror(tcp) || !verbose(tcp))
1748 tprintf("%#lx", tcp->u_arg[1]);
1749 else
1750 printmsghdr(tcp, tcp->u_arg[1]);
1751 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001752 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001753 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001754 }
1755 return 0;
1756}
1757
Andreas Schwab0873f292010-02-12 21:39:12 +01001758int
1759sys_recvmmsg(struct tcb *tcp)
1760{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001761 /* +5 chars are for "left " prefix */
1762 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001763
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001764 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001765 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001766 if (verbose(tcp)) {
1767 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001768 /* Abusing tcp->auxstr as temp storage.
1769 * Will be used and freed on syscall exit.
1770 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001771 tcp->auxstr = strdup(str);
1772 } else {
1773 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1774 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001775 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001776 print_timespec(tcp, tcp->u_arg[4]);
1777 }
1778 return 0;
1779 } else {
1780 if (verbose(tcp)) {
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001781 decode_mmsg(tcp);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001782 /* timeout on entrance */
1783 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1784 free((void *) tcp->auxstr);
1785 tcp->auxstr = NULL;
1786 }
1787 if (syserror(tcp))
1788 return 0;
1789 if (tcp->u_rval == 0) {
1790 tcp->auxstr = "Timeout";
1791 return RVAL_STR;
1792 }
1793 if (!verbose(tcp))
1794 return 0;
1795 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001796 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001797 tcp->auxstr = str;
1798 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001799 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001800}
Andreas Schwab0873f292010-02-12 21:39:12 +01001801
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802#endif /* HAVE_SENDMSG */
1803
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001804static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001805 { 0, "SHUT_RD" },
1806 { 1, "SHUT_WR" },
1807 { 2, "SHUT_RDWR" },
1808 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001809};
1810
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811int
Denys Vlasenko12014262011-05-30 14:00:14 +02001812sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813{
1814 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001815 tprintf("%ld, ", tcp->u_arg[0]);
1816 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817 }
1818 return 0;
1819}
1820
1821int
Denys Vlasenko12014262011-05-30 14:00:14 +02001822sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823{
1824 return sys_accept(tcp);
1825}
1826
1827int
Denys Vlasenko12014262011-05-30 14:00:14 +02001828sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829{
1830 return sys_accept(tcp);
1831}
1832
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001833static int
1834do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 if (exiting(tcp)) {
1837 if (syserror(tcp)) {
1838 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001839 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001840#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001841 int fds[2];
1842
1843 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001844 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001845 else
1846 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001847#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001848 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1849#else
1850 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001852 }
1853 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001854 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001855 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1856 }
1857 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858 return 0;
1859}
1860
1861int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001862sys_pipe(struct tcb *tcp)
1863{
1864 return do_pipe(tcp, -1);
1865}
1866
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001867int
1868sys_pipe2(struct tcb *tcp)
1869{
1870 return do_pipe(tcp, 1);
1871}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001872
1873int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001874sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001876 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877
1878 if (entering(tcp)) {
1879 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001880 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001881 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001882 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 switch (tcp->u_arg[0]) {
1884 case PF_INET:
1885 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1886 break;
1887#ifdef PF_IPX
1888 case PF_IPX:
1889 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001890 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001892 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 break;
1894#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001895 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001896 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 break;
1898 }
1899 } else {
1900 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001901 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001902 return 0;
1903 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001905 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906 else
1907 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001908 }
1909 return 0;
1910}
1911
1912int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001913sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914{
1915 if (entering(tcp)) {
1916 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001917 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001918 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 switch (tcp->u_arg[1]) {
1920 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922 break;
1923#ifdef SOL_IP
1924 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 break;
1927#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001928#ifdef SOL_IPV6
1929 case SOL_IPV6:
1930 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1931 break;
1932#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933#ifdef SOL_IPX
1934 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 break;
1937#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001938#ifdef SOL_PACKET
1939 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001940 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001941 break;
1942#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943#ifdef SOL_TCP
1944 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946 break;
1947#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001948#ifdef SOL_SCTP
1949 case SOL_SCTP:
1950 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1951 break;
1952#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001953
1954 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1955 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001956 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001957 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 break;
1959 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001960 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001961 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001962 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001963 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001964 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965 tcp->u_arg[3], tcp->u_arg[4]);
1966 return 0;
1967 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001968
1969 switch (tcp->u_arg[1]) {
1970 case SOL_SOCKET:
1971 switch (tcp->u_arg[2]) {
1972#ifdef SO_LINGER
1973 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001974 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001975 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001976 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001977 tcp->u_arg[3],
1978 &linger) < 0)
1979 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001980 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001981 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001982 linger.l_onoff,
1983 linger.l_linger,
1984 len);
1985 return 0;
1986 }
1987 break;
1988#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001989#ifdef SO_PEERCRED
1990 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001991 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001992 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001993 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001994 tcp->u_arg[3],
1995 &uc) < 0)
1996 break;
1997 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1998 "[%d]",
1999 (long)uc.pid,
2000 (long)uc.uid,
2001 (long)uc.gid,
2002 len);
2003 return 0;
2004 }
2005 break;
2006#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002007 }
2008 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002009 case SOL_PACKET:
2010 switch (tcp->u_arg[2]) {
2011#ifdef PACKET_STATISTICS
2012 case PACKET_STATISTICS:
2013 if (len == sizeof(struct tpacket_stats)) {
2014 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002015 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002016 tcp->u_arg[3],
2017 &stats) < 0)
2018 break;
2019 tprintf("{packets=%u, drops=%u}, "
2020 "[%d]",
2021 stats.tp_packets,
2022 stats.tp_drops,
2023 len);
2024 return 0;
2025 }
2026 break;
2027#endif
2028 }
2029 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002030 }
2031
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002032 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002033 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002034 }
2035 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002036 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002037 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002038 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002039 }
2040 return 0;
2041}
2042
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002043#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002044static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002045{
2046 struct icmp_filter filter;
2047
2048 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002050 return;
2051 }
2052 if (syserror(tcp) || !verbose(tcp)) {
2053 tprintf("%#lx", addr);
2054 return;
2055 }
2056 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002057 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002058 return;
2059 }
2060
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002061 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002062 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002063 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002064}
2065#endif /* ICMP_FILTER */
2066
John Hughes38ae88d2002-05-23 11:48:58 +00002067static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002068printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002069{
2070 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002071 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002072 switch (level) {
2073 case SOL_SOCKET:
2074 printxval(sockoptions, name, "SO_???");
2075 switch (name) {
2076#if defined(SO_LINGER)
2077 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002078 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002079 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002080 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002081 break;
2082 tprintf(", {onoff=%d, linger=%d}",
2083 linger.l_onoff,
2084 linger.l_linger);
2085 return 0;
2086 }
2087 break;
2088#endif
2089 }
2090 break;
2091#ifdef SOL_IP
2092 case SOL_IP:
2093 printxval(sockipoptions, name, "IP_???");
2094 break;
2095#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002096#ifdef SOL_IPV6
2097 case SOL_IPV6:
2098 printxval(sockipv6options, name, "IPV6_???");
2099 break;
2100#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002101#ifdef SOL_IPX
2102 case SOL_IPX:
2103 printxval(sockipxoptions, name, "IPX_???");
2104 break;
2105#endif
2106#ifdef SOL_PACKET
2107 case SOL_PACKET:
2108 printxval(sockpacketoptions, name, "PACKET_???");
2109 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002110 switch (name) {
2111#ifdef PACKET_RX_RING
2112 case PACKET_RX_RING:
2113#endif
2114#ifdef PACKET_TX_RING
2115 case PACKET_TX_RING:
2116#endif
2117#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2118 if (len == sizeof(struct tpacket_req)) {
2119 struct tpacket_req req;
2120 if (umove(tcp, addr, &req) < 0)
2121 break;
2122 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2123 req.tp_block_size,
2124 req.tp_block_nr,
2125 req.tp_frame_size,
2126 req.tp_frame_nr);
2127 return 0;
2128 }
2129 break;
2130#endif /* PACKET_RX_RING || PACKET_TX_RING */
2131 }
John Hughes38ae88d2002-05-23 11:48:58 +00002132 break;
2133#endif
2134#ifdef SOL_TCP
2135 case SOL_TCP:
2136 printxval(socktcpoptions, name, "TCP_???");
2137 break;
2138#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002139#ifdef SOL_SCTP
2140 case SOL_SCTP:
2141 printxval(socksctpoptions, name, "SCTP_???");
2142 break;
2143#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002144#ifdef SOL_RAW
2145 case SOL_RAW:
2146 printxval(sockrawoptions, name, "RAW_???");
2147 switch (name) {
2148#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002149 case ICMP_FILTER:
2150 tprints(", ");
2151 printicmpfilter(tcp, addr);
2152 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002153#endif
2154 }
2155 break;
2156#endif
2157
Roland McGrath6d2b3492002-12-30 00:51:30 +00002158 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002159 * etc. still need work */
2160
2161 default:
2162 tprintf("%u", name);
2163 }
2164
2165 /* default arg printing */
2166
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002167 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002168
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002169 if (len == sizeof(int)) {
2170 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002171 }
2172 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002173 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002174 }
2175 return 0;
2176}
2177
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002178#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002179
2180void
Denys Vlasenko12014262011-05-30 14:00:14 +02002181print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002182{
2183 int c = 0;
2184 struct opthdr hdr;
2185
John Hughes2c4e3a82002-05-24 10:19:44 +00002186 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002187 if (umove(tcp, addr, &hdr) < 0) break;
2188 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002189 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002190 }
2191 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002192 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002193 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002194 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002195 addr += sizeof hdr;
2196 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002197 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002198 if (hdr.len > 0) {
2199 addr += hdr.len;
2200 len -= hdr.len;
2201 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002202 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002203 }
2204 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002205 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002206 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002207 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002208 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002209}
2210
2211#endif
2212
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213int
Denys Vlasenko12014262011-05-30 14:00:14 +02002214sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215{
2216 if (entering(tcp)) {
2217 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002218 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002219 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002220 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 }
2222 return 0;
2223}