blob: e7c7b2bbcbf65a83453f5a5de74605aabac66e1e [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
Roland McGrath71d3d662007-08-07 01:00:26 +0000590#ifdef MSG_CMSG_CLOEXEC
591 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
592#endif
593 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594};
595
Roland McGrathd9f816f2004-09-04 03:39:20 +0000596static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000598 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000599#endif
600#ifdef SO_ALLRAW
601 { SO_ALLRAW, "SO_ALLRAW" },
602#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000603#ifdef SO_ATTACH_FILTER
604 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
605#endif
606#ifdef SO_BINDTODEVICE
607 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
608#endif
609#ifdef SO_BROADCAST
610 { SO_BROADCAST, "SO_BROADCAST" },
611#endif
612#ifdef SO_BSDCOMPAT
613 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
614#endif
615#ifdef SO_DEBUG
616 { SO_DEBUG, "SO_DEBUG" },
617#endif
618#ifdef SO_DETACH_FILTER
619 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
620#endif
621#ifdef SO_DONTROUTE
622 { SO_DONTROUTE, "SO_DONTROUTE" },
623#endif
624#ifdef SO_ERROR
625 { SO_ERROR, "SO_ERROR" },
626#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000627#ifdef SO_ICS
628 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000630#ifdef SO_IMASOCKET
631 { SO_IMASOCKET, "SO_IMASOCKET" },
632#endif
633#ifdef SO_KEEPALIVE
634 { SO_KEEPALIVE, "SO_KEEPALIVE" },
635#endif
636#ifdef SO_LINGER
637 { SO_LINGER, "SO_LINGER" },
638#endif
639#ifdef SO_LISTENING
640 { SO_LISTENING, "SO_LISTENING" },
641#endif
642#ifdef SO_MGMT
643 { SO_MGMT, "SO_MGMT" },
644#endif
645#ifdef SO_NO_CHECK
646 { SO_NO_CHECK, "SO_NO_CHECK" },
647#endif
648#ifdef SO_OOBINLINE
649 { SO_OOBINLINE, "SO_OOBINLINE" },
650#endif
651#ifdef SO_ORDREL
652 { SO_ORDREL, "SO_ORDREL" },
653#endif
654#ifdef SO_PARALLELSVR
655 { SO_PARALLELSVR, "SO_PARALLELSVR" },
656#endif
657#ifdef SO_PASSCRED
658 { SO_PASSCRED, "SO_PASSCRED" },
659#endif
660#ifdef SO_PEERCRED
661 { SO_PEERCRED, "SO_PEERCRED" },
662#endif
663#ifdef SO_PEERNAME
664 { SO_PEERNAME, "SO_PEERNAME" },
665#endif
666#ifdef SO_PEERSEC
667 { SO_PEERSEC, "SO_PEERSEC" },
668#endif
669#ifdef SO_PRIORITY
670 { SO_PRIORITY, "SO_PRIORITY" },
671#endif
672#ifdef SO_PROTOTYPE
673 { SO_PROTOTYPE, "SO_PROTOTYPE" },
674#endif
675#ifdef SO_RCVBUF
676 { SO_RCVBUF, "SO_RCVBUF" },
677#endif
678#ifdef SO_RCVLOWAT
679 { SO_RCVLOWAT, "SO_RCVLOWAT" },
680#endif
681#ifdef SO_RCVTIMEO
682 { SO_RCVTIMEO, "SO_RCVTIMEO" },
683#endif
684#ifdef SO_RDWR
685 { SO_RDWR, "SO_RDWR" },
686#endif
687#ifdef SO_REUSEADDR
688 { SO_REUSEADDR, "SO_REUSEADDR" },
689#endif
690#ifdef SO_REUSEPORT
691 { SO_REUSEPORT, "SO_REUSEPORT" },
692#endif
693#ifdef SO_SECURITY_AUTHENTICATION
694 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
695#endif
696#ifdef SO_SECURITY_ENCRYPTION_NETWORK
697 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
698#endif
699#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
700 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
701#endif
702#ifdef SO_SEMA
703 { SO_SEMA, "SO_SEMA" },
704#endif
705#ifdef SO_SNDBUF
706 { SO_SNDBUF, "SO_SNDBUF" },
707#endif
708#ifdef SO_SNDLOWAT
709 { SO_SNDLOWAT, "SO_SNDLOWAT" },
710#endif
711#ifdef SO_SNDTIMEO
712 { SO_SNDTIMEO, "SO_SNDTIMEO" },
713#endif
714#ifdef SO_TIMESTAMP
715 { SO_TIMESTAMP, "SO_TIMESTAMP" },
716#endif
717#ifdef SO_TYPE
718 { SO_TYPE, "SO_TYPE" },
719#endif
720#ifdef SO_USELOOPBACK
721 { SO_USELOOPBACK, "SO_USELOOPBACK" },
722#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723 { 0, NULL },
724};
725
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100726#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000727#define SOL_IP IPPROTO_IP
728#endif
729
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000731static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000732#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000733 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000734#endif
735#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000736 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000737#endif
738#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000739 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000741#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000742 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000744#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000745 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000746#endif
747#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000748 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
749#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000750#ifdef IP_RECVOPTS
751 { IP_RECVOPTS, "IP_RECVOPTS" },
752#endif
753#ifdef IP_RECVRETOPTS
754 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
755#endif
756#ifdef IP_RECVDSTADDR
757 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
758#endif
759#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000760 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000761#endif
762#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000763 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000764#endif
765#ifdef IP_PKTOPTIONS
766 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
767#endif
768#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000769 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000770#endif
771#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000772 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000773#endif
774#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000775 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000776#endif
777#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000778 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000779#endif
780#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000781 { IP_MTU, "IP_MTU" },
782#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000783#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000784 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000785#endif
786#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000787 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000788#endif
789#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000790 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#endif
792#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000793 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000794#endif
795#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000796 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000797#endif
798#ifdef IP_BROADCAST_IF
799 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
800#endif
801#ifdef IP_RECVIFINDEX
802 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
803#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000804#ifdef IP_MSFILTER
805 { IP_MSFILTER, "IP_MSFILTER" },
806#endif
807#ifdef MCAST_MSFILTER
808 { MCAST_MSFILTER, "MCAST_MSFILTER" },
809#endif
810#ifdef IP_FREEBIND
811 { IP_FREEBIND, "IP_FREEBIND" },
812#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000813 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814};
815#endif /* SOL_IP */
816
Roland McGrath4f6ba692004-08-31 07:01:26 +0000817#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000818static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000819#ifdef IPV6_ADDRFORM
820 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
821#endif
822#ifdef MCAST_FILTER
823 { MCAST_FILTER, "MCAST_FILTER" },
824#endif
825#ifdef IPV6_PKTOPTIONS
826 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
827#endif
828#ifdef IPV6_MTU
829 { IPV6_MTU, "IPV6_MTU" },
830#endif
831#ifdef IPV6_V6ONLY
832 { IPV6_V6ONLY, "IPV6_V6ONLY" },
833#endif
834#ifdef IPV6_PKTINFO
835 { IPV6_PKTINFO, "IPV6_PKTINFO" },
836#endif
837#ifdef IPV6_HOPLIMIT
838 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
839#endif
840#ifdef IPV6_RTHDR
841 { IPV6_RTHDR, "IPV6_RTHDR" },
842#endif
843#ifdef IPV6_HOPOPTS
844 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
845#endif
846#ifdef IPV6_DSTOPTS
847 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
848#endif
849#ifdef IPV6_FLOWINFO
850 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
851#endif
852#ifdef IPV6_UNICAST_HOPS
853 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
854#endif
855#ifdef IPV6_MULTICAST_HOPS
856 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
857#endif
858#ifdef IPV6_MULTICAST_LOOP
859 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
860#endif
861#ifdef IPV6_MULTICAST_IF
862 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
863#endif
864#ifdef IPV6_MTU_DISCOVER
865 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
866#endif
867#ifdef IPV6_RECVERR
868 { IPV6_RECVERR, "IPV6_RECVERR" },
869#endif
870#ifdef IPV6_FLOWINFO_SEND
871 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
872#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000873#ifdef IPV6_ADD_MEMBERSHIP
874 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
875#endif
876#ifdef IPV6_DROP_MEMBERSHIP
877 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
878#endif
879#ifdef IPV6_ROUTER_ALERT
880 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
881#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000882 { 0, NULL },
883};
884#endif /* SOL_IPV6 */
885
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000887static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200888 { IPX_TYPE, "IPX_TYPE" },
889 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890};
891#endif /* SOL_IPX */
892
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000893#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000894static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000895#if defined(ICMP_FILTER)
896 { ICMP_FILTER, "ICMP_FILTER" },
897#endif
898 { 0, NULL },
899};
900#endif /* SOL_RAW */
901
902#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000903static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000904#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000905 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000906#endif
907#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000908 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000909#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000910#if defined(PACKET_RECV_OUTPUT)
911 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
912#endif
913#if defined(PACKET_RX_RING)
914 { PACKET_RX_RING, "PACKET_RX_RING" },
915#endif
916#if defined(PACKET_STATISTICS)
917 { PACKET_STATISTICS, "PACKET_STATISTICS" },
918#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000919#if defined(PACKET_COPY_THRESH)
920 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
921#endif
922#if defined(PACKET_AUXDATA)
923 { PACKET_AUXDATA, "PACKET_AUXDATA" },
924#endif
925#if defined(PACKET_ORIGDEV)
926 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
927#endif
928#if defined(PACKET_VERSION)
929 { PACKET_VERSION, "PACKET_VERSION" },
930#endif
931#if defined(PACKET_HDRLEN)
932 { PACKET_HDRLEN, "PACKET_HDRLEN" },
933#endif
934#if defined(PACKET_RESERVE)
935 { PACKET_RESERVE, "PACKET_RESERVE" },
936#endif
937#if defined(PACKET_TX_RING)
938 { PACKET_TX_RING, "PACKET_TX_RING" },
939#endif
940#if defined(PACKET_LOSS)
941 { PACKET_LOSS, "PACKET_LOSS" },
942#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000943 { 0, NULL },
944};
945#endif /* SOL_PACKET */
946
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100947#ifdef SOL_SCTP
948static const struct xlat socksctpoptions[] = {
949#if defined(SCTP_RTOINFO)
950 { SCTP_RTOINFO, "SCTP_RTOINFO" },
951#endif
952#if defined(SCTP_ASSOCINFO)
953 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
954#endif
955#if defined(SCTP_INITMSG)
956 { SCTP_INITMSG, "SCTP_INITMSG" },
957#endif
958#if defined(SCTP_NODELAY)
959 { SCTP_NODELAY, "SCTP_NODELAY" },
960#endif
961#if defined(SCTP_AUTOCLOSE)
962 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
963#endif
964#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
965 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
966#endif
967#if defined(SCTP_PRIMARY_ADDR)
968 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
969#endif
970#if defined(SCTP_ADAPTATION_LAYER)
971 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
972#endif
973#if defined(SCTP_DISABLE_FRAGMENTS)
974 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
975#endif
976#if defined(SCTP_PEER_ADDR_PARAMS)
977 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
978#endif
979#if defined(SCTP_DEFAULT_SEND_PARAM)
980 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
981#endif
982#if defined(SCTP_EVENTS)
983 { SCTP_EVENTS, "SCTP_EVENTS" },
984#endif
985#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
986 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
987#endif
988#if defined(SCTP_MAXSEG)
989 { SCTP_MAXSEG, "SCTP_MAXSEG" },
990#endif
991#if defined(SCTP_STATUS)
992 { SCTP_STATUS, "SCTP_STATUS" },
993#endif
994#if defined(SCTP_GET_PEER_ADDR_INFO)
995 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
996#endif
997#if defined(SCTP_DELAYED_ACK)
998 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
999#endif
1000#if defined(SCTP_CONTEXT)
1001 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1002#endif
1003#if defined(SCTP_FRAGMENT_INTERLEAVE)
1004 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1005#endif
1006#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1007 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1008#endif
1009#if defined(SCTP_MAX_BURST)
1010 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1011#endif
1012#if defined(SCTP_AUTH_CHUNK)
1013 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1014#endif
1015#if defined(SCTP_HMAC_IDENT)
1016 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1017#endif
1018#if defined(SCTP_AUTH_KEY)
1019 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1020#endif
1021#if defined(SCTP_AUTH_ACTIVE_KEY)
1022 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1023#endif
1024#if defined(SCTP_AUTH_DELETE_KEY)
1025 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1026#endif
1027#if defined(SCTP_PEER_AUTH_CHUNKS)
1028 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1029#endif
1030#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1031 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1032#endif
1033#if defined(SCTP_GET_ASSOC_NUMBER)
1034 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1035#endif
1036
1037 /* linux specific things */
1038#if defined(SCTP_SOCKOPT_BINDX_ADD)
1039 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1040#endif
1041#if defined(SCTP_SOCKOPT_BINDX_REM)
1042 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1043#endif
1044#if defined(SCTP_SOCKOPT_PEELOFF)
1045 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1046#endif
1047#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1048 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1049#endif
1050#if defined(SCTP_GET_PEER_ADDRS_OLD)
1051 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1052#endif
1053#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1054 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1055#endif
1056#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1057 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1058#endif
1059#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1060 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1061#endif
1062#if defined(SCTP_GET_PEER_ADDRS)
1063 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1064#endif
1065#if defined(SCTP_GET_LOCAL_ADDRS)
1066 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1067#endif
1068
1069 { 0, NULL },
1070};
1071#endif
1072
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001073#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001074#define SOL_TCP IPPROTO_TCP
1075#endif
1076
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001078static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001079 { TCP_NODELAY, "TCP_NODELAY" },
1080 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001081#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001082 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001083#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001084#if defined(TCP_KEEPIDLE)
1085 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1086#endif
1087#if defined(TCP_KEEPINTVL)
1088 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1089#endif
1090#if defined(TCP_KEEPCNT)
1091 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1092#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001093#if defined(TCP_NKEEP)
1094 { TCP_NKEEP, "TCP_NKEEP" },
1095#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001096#if defined(TCP_SYNCNT)
1097 { TCP_SYNCNT, "TCP_SYNCNT" },
1098#endif
1099#if defined(TCP_LINGER2)
1100 { TCP_LINGER2, "TCP_LINGER2" },
1101#endif
1102#if defined(TCP_DEFER_ACCEPT)
1103 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1104#endif
1105#if defined(TCP_WINDOW_CLAMP)
1106 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1107#endif
1108#if defined(TCP_INFO)
1109 { TCP_INFO, "TCP_INFO" },
1110#endif
1111#if defined(TCP_QUICKACK)
1112 { TCP_QUICKACK, "TCP_QUICKACK" },
1113#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001114#if defined(TCP_CONGESTION)
1115 { TCP_CONGESTION, "TCP_CONGESTION" },
1116#endif
1117#if defined(TCP_MD5SIG)
1118 { TCP_MD5SIG, "TCP_MD5SIG" },
1119#endif
1120#if defined(TCP_COOKIE_TRANSACTIONS)
1121 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1122#endif
1123#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1124 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1125#endif
1126#if defined(TCP_THIN_DUPACK)
1127 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1128#endif
1129#if defined(TCP_USER_TIMEOUT)
1130 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1131#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001132 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133};
1134#endif /* SOL_TCP */
1135
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001136#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001137static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001138#if defined(ICMP_ECHOREPLY)
1139 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1140#endif
1141#if defined(ICMP_DEST_UNREACH)
1142 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1143#endif
1144#if defined(ICMP_SOURCE_QUENCH)
1145 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1146#endif
1147#if defined(ICMP_REDIRECT)
1148 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1149#endif
1150#if defined(ICMP_ECHO)
1151 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1152#endif
1153#if defined(ICMP_TIME_EXCEEDED)
1154 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1155#endif
1156#if defined(ICMP_PARAMETERPROB)
1157 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1158#endif
1159#if defined(ICMP_TIMESTAMP)
1160 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1161#endif
1162#if defined(ICMP_TIMESTAMPREPLY)
1163 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1164#endif
1165#if defined(ICMP_INFO_REQUEST)
1166 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1167#endif
1168#if defined(ICMP_INFO_REPLY)
1169 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1170#endif
1171#if defined(ICMP_ADDRESS)
1172 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1173#endif
1174#if defined(ICMP_ADDRESSREPLY)
1175 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1176#endif
1177 { 0, NULL },
1178};
1179#endif /* SOL_RAW */
1180
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001181#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001182static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001183#if defined(PACKET_HOST)
1184 { PACKET_HOST, "PACKET_HOST" },
1185#endif
1186#if defined(PACKET_BROADCAST)
1187 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1188#endif
1189#if defined(PACKET_MULTICAST)
1190 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1191#endif
1192#if defined(PACKET_OTHERHOST)
1193 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1194#endif
1195#if defined(PACKET_OUTGOING)
1196 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1197#endif
1198#if defined(PACKET_LOOPBACK)
1199 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1200#endif
1201#if defined(PACKET_FASTROUTE)
1202 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1203#endif
1204 { 0, NULL },
1205};
1206#endif /* defined(AF_PACKET) */
1207
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001208void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001209printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001210{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001211 union {
1212 char pad[128];
1213 struct sockaddr sa;
1214 struct sockaddr_in sin;
1215 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001216#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001217 struct sockaddr_in6 sa6;
1218#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001219#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001220 struct sockaddr_ipx sipx;
1221#endif
1222#ifdef AF_PACKET
1223 struct sockaddr_ll ll;
1224#endif
1225#ifdef AF_NETLINK
1226 struct sockaddr_nl nl;
1227#endif
1228 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001229 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230
1231 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001232 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233 return;
1234 }
1235 if (!verbose(tcp)) {
1236 tprintf("%#lx", addr);
1237 return;
1238 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001239
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001240 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1241 addrlen = sizeof(addrbuf);
1242
1243 memset(&addrbuf, 0, sizeof(addrbuf));
1244 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001245 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 return;
1247 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001248 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001249
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001250 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001251 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001252 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001253
1254 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001256 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001257 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001258 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001259 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001260 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001261 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001262 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001263 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001264 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 break;
1266 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001267 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001268 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001270#ifdef HAVE_INET_NTOP
1271 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001272 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001273 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1274 ntohs(addrbuf.sa6.sin6_port), string_addr,
1275 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001276#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001277 {
1278#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001279 int numericscope = 0;
1280 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1281 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1282 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001283
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001284 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1285 numericscope++;
1286 else
1287 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1288 } else
1289 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001290
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001291 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001292#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001293 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001294 }
1295#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001296 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001297#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001298#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001300 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001302 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001303 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 /* Yes, I know, this does not look too
1305 * strace-ish, but otherwise the IPX
1306 * addresses just look monstrous...
1307 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001308 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001310 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001311 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001312 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1313 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 }
1315 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001316#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001317#ifdef AF_PACKET
1318 case AF_PACKET:
1319 {
1320 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001321 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001322 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001323 addrbuf.ll.sll_ifindex);
1324 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1325 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001326 addrbuf.ll.sll_halen,
1327 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001328 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001329 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1330 }
1331 break;
1332
Denys Vlasenko84703742012-02-25 02:38:52 +01001333#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001334#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001335 case AF_NETLINK:
1336 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1337 break;
1338#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001339 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001340 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001341
1342 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001343 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001345 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346 break;
1347 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001348 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349}
1350
1351#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001352static const struct xlat scmvals[] = {
1353#ifdef SCM_RIGHTS
1354 { SCM_RIGHTS, "SCM_RIGHTS" },
1355#endif
1356#ifdef SCM_CREDENTIALS
1357 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1358#endif
1359 { 0, NULL }
1360};
1361
1362static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001363printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001364{
Roland McGrathaa524c82005-06-01 19:22:06 +00001365 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1366 NULL : malloc(len);
1367 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001368 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001369 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001370 return;
1371 }
1372
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001373 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001374 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001375 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001376
Roland McGrathaa524c82005-06-01 19:22:06 +00001377 if (cmsg->cmsg_level == SOL_SOCKET) {
1378 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001379
Roland McGrathaa524c82005-06-01 19:22:06 +00001380 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1381 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1382
1383 if (cmsg->cmsg_type == SCM_RIGHTS
1384 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001385 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001386 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001387
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001388 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001389 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001390 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001391 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001392 tprintf("%d", *fds++);
1393 first = 0;
1394 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001395 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001396 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001397 return;
1398 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001399 if (cmsg->cmsg_type == SCM_CREDENTIALS
1400 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001401 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001402
Roland McGrath50770822004-10-06 22:11:51 +00001403 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1404 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001405 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001406 return;
1407 }
1408 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001409 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001410 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001411}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412
1413static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001414do_msghdr(struct tcb *tcp, struct msghdr *msg)
1415{
1416 tprintf("{msg_name(%d)=", msg->msg_namelen);
1417 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1418
1419 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1420 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
Dmitry V. Levin88849682011-06-13 22:58:44 +00001421 (unsigned long)msg->msg_iov, 1);
Andreas Schwab0873f292010-02-12 21:39:12 +01001422
1423#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1424 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1425 if (msg->msg_controllen)
1426 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1427 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001428 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001429 printflags(msg_flags, msg->msg_flags, "MSG_???");
1430#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1431 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1432 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1433#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001434 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001435}
1436
1437static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001438printmsghdr(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001439{
1440 struct msghdr msg;
1441
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001442 if (umove(tcp, addr, &msg) < 0) {
1443 tprintf("%#lx", addr);
1444 return;
1445 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001446 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447}
1448
Andreas Schwab0873f292010-02-12 21:39:12 +01001449static void
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001450printmmsghdr(struct tcb *tcp, long addr, unsigned int idx)
Andreas Schwab0873f292010-02-12 21:39:12 +01001451{
1452 struct mmsghdr {
1453 struct msghdr msg_hdr;
1454 unsigned msg_len;
1455 } mmsg;
1456
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001457 addr += sizeof(mmsg) * idx;
Andreas Schwab0873f292010-02-12 21:39:12 +01001458 if (umove(tcp, addr, &mmsg) < 0) {
1459 tprintf("%#lx", addr);
1460 return;
1461 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001462 tprints("{");
Andreas Schwab0873f292010-02-12 21:39:12 +01001463 do_msghdr(tcp, &mmsg.msg_hdr);
1464 tprintf(", %u}", mmsg.msg_len);
1465}
Andreas Schwab0873f292010-02-12 21:39:12 +01001466
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001467static void
1468decode_mmsg(struct tcb *tcp)
1469{
1470 /* mmsgvec */
1471 if (syserror(tcp)) {
1472 tprintf("%#lx", tcp->u_arg[1]);
1473 } else {
1474 unsigned int len = tcp->u_rval;
1475 unsigned int i;
1476
1477 tprints("{");
1478 for (i = 0; i < len; ++i) {
1479 if (i)
1480 tprints(", ");
1481 printmmsghdr(tcp, tcp->u_arg[1], i);
1482 }
1483 tprints("}");
1484 }
1485 /* vlen */
1486 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1487 /* flags */
1488 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1489}
1490
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491#endif /* HAVE_SENDMSG */
1492
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001493/*
1494 * low bits of the socket type define real socket type,
1495 * other bits are socket type flags.
1496 */
1497static void
1498tprint_sock_type(struct tcb *tcp, int flags)
1499{
1500 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1501
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001502 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001503 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001504 flags &= ~SOCK_TYPE_MASK;
1505 if (!flags)
1506 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001507 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001508 }
1509 printflags(sock_type_flags, flags, "SOCK_???");
1510}
1511
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001513sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001514{
1515 if (entering(tcp)) {
1516 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001517 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001518 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001519 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 switch (tcp->u_arg[0]) {
1521 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001522#ifdef PF_INET6
1523 case PF_INET6:
1524#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1526 break;
1527#ifdef PF_IPX
1528 case PF_IPX:
1529 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001530 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001532 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533 break;
1534#endif /* PF_IPX */
1535 default:
1536 tprintf("%lu", tcp->u_arg[2]);
1537 break;
1538 }
1539 }
1540 return 0;
1541}
1542
John Hughesbdf48f52001-03-06 15:08:09 +00001543int
Denys Vlasenko12014262011-05-30 14:00:14 +02001544sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545{
1546 if (entering(tcp)) {
1547 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001548 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001549 tprintf(", %lu", tcp->u_arg[2]);
1550 }
1551 return 0;
1552}
1553
1554int
Denys Vlasenko12014262011-05-30 14:00:14 +02001555sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556{
1557 return sys_bind(tcp);
1558}
1559
1560int
Denys Vlasenko12014262011-05-30 14:00:14 +02001561sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562{
1563 if (entering(tcp)) {
1564 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1565 }
1566 return 0;
1567}
1568
Paolo Bonzini705ff102009-08-14 12:34:05 +02001569static int
1570do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571{
1572 if (entering(tcp)) {
1573 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001574 return 0;
1575 }
1576 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577 tprintf("%#lx, NULL", tcp->u_arg[1]);
1578 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001579 int len;
1580 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001581 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001582 tprintf("%#lx", tcp->u_arg[1]);
1583 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001584 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001586 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001587 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001589 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001590 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001591 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1592 "SOCK_???");
1593 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 return 0;
1595}
1596
1597int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001598sys_accept(struct tcb *tcp)
1599{
1600 return do_accept(tcp, -1);
1601}
1602
Paolo Bonzini705ff102009-08-14 12:34:05 +02001603int
1604sys_accept4(struct tcb *tcp)
1605{
1606 return do_accept(tcp, 3);
1607}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001608
1609int
Denys Vlasenko12014262011-05-30 14:00:14 +02001610sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611{
1612 if (entering(tcp)) {
1613 tprintf("%ld, ", tcp->u_arg[0]);
1614 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1615 tprintf(", %lu, ", tcp->u_arg[2]);
1616 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001617 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 }
1619 return 0;
1620}
1621
1622int
Denys Vlasenko12014262011-05-30 14:00:14 +02001623sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624{
1625 if (entering(tcp)) {
1626 tprintf("%ld, ", tcp->u_arg[0]);
1627 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1628 tprintf(", %lu, ", tcp->u_arg[2]);
1629 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001630 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001632 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001633 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634 /* to length */
1635 tprintf(", %lu", tcp->u_arg[5]);
1636 }
1637 return 0;
1638}
1639
1640#ifdef HAVE_SENDMSG
1641
1642int
Denys Vlasenko12014262011-05-30 14:00:14 +02001643sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644{
1645 if (entering(tcp)) {
1646 tprintf("%ld, ", tcp->u_arg[0]);
1647 printmsghdr(tcp, tcp->u_arg[1]);
1648 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001649 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001650 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651 }
1652 return 0;
1653}
1654
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001655int
1656sys_sendmmsg(struct tcb *tcp)
1657{
1658 if (entering(tcp)) {
1659 /* sockfd */
1660 tprintf("%d, ", (int) tcp->u_arg[0]);
1661 if (!verbose(tcp)) {
1662 tprintf("%#lx, %u, ",
1663 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1664 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1665 }
1666 } else {
1667 if (verbose(tcp))
1668 decode_mmsg(tcp);
1669 }
1670 return 0;
1671}
1672
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673#endif /* HAVE_SENDMSG */
1674
1675int
Denys Vlasenko12014262011-05-30 14:00:14 +02001676sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001677{
1678 if (entering(tcp)) {
1679 tprintf("%ld, ", tcp->u_arg[0]);
1680 } else {
1681 if (syserror(tcp))
1682 tprintf("%#lx", tcp->u_arg[1]);
1683 else
1684 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1685
1686 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001687 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688 }
1689 return 0;
1690}
1691
1692int
Denys Vlasenko12014262011-05-30 14:00:14 +02001693sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694{
1695 int fromlen;
1696
1697 if (entering(tcp)) {
1698 tprintf("%ld, ", tcp->u_arg[0]);
1699 } else {
1700 if (syserror(tcp)) {
1701 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1702 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1703 tcp->u_arg[4], tcp->u_arg[5]);
1704 return 0;
1705 }
1706 /* buf */
1707 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1708 /* len */
1709 tprintf(", %lu, ", tcp->u_arg[2]);
1710 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001711 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712 /* from address, len */
1713 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1714 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001715 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716 else
1717 tprintf(", %#lx", tcp->u_arg[4]);
1718 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001719 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 else
1721 tprintf(", %#lx", tcp->u_arg[5]);
1722 return 0;
1723 }
1724 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001725 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726 return 0;
1727 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001728 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001729 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730 /* from length */
1731 tprintf(", [%u]", fromlen);
1732 }
1733 return 0;
1734}
1735
1736#ifdef HAVE_SENDMSG
1737
1738int
Denys Vlasenko12014262011-05-30 14:00:14 +02001739sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740{
1741 if (entering(tcp)) {
1742 tprintf("%ld, ", tcp->u_arg[0]);
1743 } else {
1744 if (syserror(tcp) || !verbose(tcp))
1745 tprintf("%#lx", tcp->u_arg[1]);
1746 else
1747 printmsghdr(tcp, tcp->u_arg[1]);
1748 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001749 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001750 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751 }
1752 return 0;
1753}
1754
Andreas Schwab0873f292010-02-12 21:39:12 +01001755int
1756sys_recvmmsg(struct tcb *tcp)
1757{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001758 /* +5 chars are for "left " prefix */
1759 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001760
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001761 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001762 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001763 if (verbose(tcp)) {
1764 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001765 /* Abusing tcp->auxstr as temp storage.
1766 * Will be used and freed on syscall exit.
1767 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001768 tcp->auxstr = strdup(str);
1769 } else {
1770 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1771 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001772 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001773 print_timespec(tcp, tcp->u_arg[4]);
1774 }
1775 return 0;
1776 } else {
1777 if (verbose(tcp)) {
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001778 decode_mmsg(tcp);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001779 /* timeout on entrance */
1780 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1781 free((void *) tcp->auxstr);
1782 tcp->auxstr = NULL;
1783 }
1784 if (syserror(tcp))
1785 return 0;
1786 if (tcp->u_rval == 0) {
1787 tcp->auxstr = "Timeout";
1788 return RVAL_STR;
1789 }
1790 if (!verbose(tcp))
1791 return 0;
1792 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001793 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001794 tcp->auxstr = str;
1795 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001796 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001797}
Andreas Schwab0873f292010-02-12 21:39:12 +01001798
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799#endif /* HAVE_SENDMSG */
1800
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001801static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001802 { 0, "SHUT_RD" },
1803 { 1, "SHUT_WR" },
1804 { 2, "SHUT_RDWR" },
1805 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001806};
1807
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808int
Denys Vlasenko12014262011-05-30 14:00:14 +02001809sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810{
1811 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001812 tprintf("%ld, ", tcp->u_arg[0]);
1813 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814 }
1815 return 0;
1816}
1817
1818int
Denys Vlasenko12014262011-05-30 14:00:14 +02001819sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001820{
1821 return sys_accept(tcp);
1822}
1823
1824int
Denys Vlasenko12014262011-05-30 14:00:14 +02001825sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826{
1827 return sys_accept(tcp);
1828}
1829
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001830static int
1831do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 if (exiting(tcp)) {
1834 if (syserror(tcp)) {
1835 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001836 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001837#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001838 int fds[2];
1839
1840 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001841 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001842 else
1843 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001844#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001845 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1846#else
1847 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001848#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001849 }
1850 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001851 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001852 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1853 }
1854 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 return 0;
1856}
1857
1858int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001859sys_pipe(struct tcb *tcp)
1860{
1861 return do_pipe(tcp, -1);
1862}
1863
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001864int
1865sys_pipe2(struct tcb *tcp)
1866{
1867 return do_pipe(tcp, 1);
1868}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001869
1870int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001871sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001872{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874
1875 if (entering(tcp)) {
1876 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001878 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001879 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880 switch (tcp->u_arg[0]) {
1881 case PF_INET:
1882 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1883 break;
1884#ifdef PF_IPX
1885 case PF_IPX:
1886 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001887 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001889 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890 break;
1891#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001892 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001893 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894 break;
1895 }
1896 } else {
1897 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001898 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899 return 0;
1900 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001902 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001903 else
1904 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905 }
1906 return 0;
1907}
1908
1909int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001910sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911{
1912 if (entering(tcp)) {
1913 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001914 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001915 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 switch (tcp->u_arg[1]) {
1917 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 break;
1920#ifdef SOL_IP
1921 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923 break;
1924#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001925#ifdef SOL_IPV6
1926 case SOL_IPV6:
1927 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1928 break;
1929#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001930#ifdef SOL_IPX
1931 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933 break;
1934#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001935#ifdef SOL_PACKET
1936 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001937 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001938 break;
1939#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940#ifdef SOL_TCP
1941 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943 break;
1944#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001945#ifdef SOL_SCTP
1946 case SOL_SCTP:
1947 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1948 break;
1949#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950
1951 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1952 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001953 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001954 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001955 break;
1956 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001957 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001959 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001960 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001961 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962 tcp->u_arg[3], tcp->u_arg[4]);
1963 return 0;
1964 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001965
1966 switch (tcp->u_arg[1]) {
1967 case SOL_SOCKET:
1968 switch (tcp->u_arg[2]) {
1969#ifdef SO_LINGER
1970 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001971 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001972 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001973 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001974 tcp->u_arg[3],
1975 &linger) < 0)
1976 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001977 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001978 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001979 linger.l_onoff,
1980 linger.l_linger,
1981 len);
1982 return 0;
1983 }
1984 break;
1985#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001986#ifdef SO_PEERCRED
1987 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001988 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001989 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001990 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001991 tcp->u_arg[3],
1992 &uc) < 0)
1993 break;
1994 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1995 "[%d]",
1996 (long)uc.pid,
1997 (long)uc.uid,
1998 (long)uc.gid,
1999 len);
2000 return 0;
2001 }
2002 break;
2003#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002004 }
2005 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002006 case SOL_PACKET:
2007 switch (tcp->u_arg[2]) {
2008#ifdef PACKET_STATISTICS
2009 case PACKET_STATISTICS:
2010 if (len == sizeof(struct tpacket_stats)) {
2011 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002012 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002013 tcp->u_arg[3],
2014 &stats) < 0)
2015 break;
2016 tprintf("{packets=%u, drops=%u}, "
2017 "[%d]",
2018 stats.tp_packets,
2019 stats.tp_drops,
2020 len);
2021 return 0;
2022 }
2023 break;
2024#endif
2025 }
2026 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002027 }
2028
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002029 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002030 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002031 }
2032 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002033 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002034 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002035 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002036 }
2037 return 0;
2038}
2039
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002040#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002041static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002042{
2043 struct icmp_filter filter;
2044
2045 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002046 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002047 return;
2048 }
2049 if (syserror(tcp) || !verbose(tcp)) {
2050 tprintf("%#lx", addr);
2051 return;
2052 }
2053 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002054 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002055 return;
2056 }
2057
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002058 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002059 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002060 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002061}
2062#endif /* ICMP_FILTER */
2063
John Hughes38ae88d2002-05-23 11:48:58 +00002064static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002065printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002066{
2067 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002068 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002069 switch (level) {
2070 case SOL_SOCKET:
2071 printxval(sockoptions, name, "SO_???");
2072 switch (name) {
2073#if defined(SO_LINGER)
2074 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002075 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002076 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002077 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002078 break;
2079 tprintf(", {onoff=%d, linger=%d}",
2080 linger.l_onoff,
2081 linger.l_linger);
2082 return 0;
2083 }
2084 break;
2085#endif
2086 }
2087 break;
2088#ifdef SOL_IP
2089 case SOL_IP:
2090 printxval(sockipoptions, name, "IP_???");
2091 break;
2092#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002093#ifdef SOL_IPV6
2094 case SOL_IPV6:
2095 printxval(sockipv6options, name, "IPV6_???");
2096 break;
2097#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002098#ifdef SOL_IPX
2099 case SOL_IPX:
2100 printxval(sockipxoptions, name, "IPX_???");
2101 break;
2102#endif
2103#ifdef SOL_PACKET
2104 case SOL_PACKET:
2105 printxval(sockpacketoptions, name, "PACKET_???");
2106 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002107 switch (name) {
2108#ifdef PACKET_RX_RING
2109 case PACKET_RX_RING:
2110#endif
2111#ifdef PACKET_TX_RING
2112 case PACKET_TX_RING:
2113#endif
2114#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2115 if (len == sizeof(struct tpacket_req)) {
2116 struct tpacket_req req;
2117 if (umove(tcp, addr, &req) < 0)
2118 break;
2119 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2120 req.tp_block_size,
2121 req.tp_block_nr,
2122 req.tp_frame_size,
2123 req.tp_frame_nr);
2124 return 0;
2125 }
2126 break;
2127#endif /* PACKET_RX_RING || PACKET_TX_RING */
2128 }
John Hughes38ae88d2002-05-23 11:48:58 +00002129 break;
2130#endif
2131#ifdef SOL_TCP
2132 case SOL_TCP:
2133 printxval(socktcpoptions, name, "TCP_???");
2134 break;
2135#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002136#ifdef SOL_SCTP
2137 case SOL_SCTP:
2138 printxval(socksctpoptions, name, "SCTP_???");
2139 break;
2140#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002141#ifdef SOL_RAW
2142 case SOL_RAW:
2143 printxval(sockrawoptions, name, "RAW_???");
2144 switch (name) {
2145#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002146 case ICMP_FILTER:
2147 tprints(", ");
2148 printicmpfilter(tcp, addr);
2149 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002150#endif
2151 }
2152 break;
2153#endif
2154
Roland McGrath6d2b3492002-12-30 00:51:30 +00002155 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002156 * etc. still need work */
2157
2158 default:
2159 tprintf("%u", name);
2160 }
2161
2162 /* default arg printing */
2163
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002164 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002165
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002166 if (len == sizeof(int)) {
2167 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002168 }
2169 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002170 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002171 }
2172 return 0;
2173}
2174
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002175#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002176
2177void
Denys Vlasenko12014262011-05-30 14:00:14 +02002178print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002179{
2180 int c = 0;
2181 struct opthdr hdr;
2182
John Hughes2c4e3a82002-05-24 10:19:44 +00002183 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002184 if (umove(tcp, addr, &hdr) < 0) break;
2185 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002186 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002187 }
2188 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002189 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002190 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002191 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002192 addr += sizeof hdr;
2193 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002194 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002195 if (hdr.len > 0) {
2196 addr += hdr.len;
2197 len -= hdr.len;
2198 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002199 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002200 }
2201 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002202 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002203 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002204 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002205 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002206}
2207
2208#endif
2209
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210int
Denys Vlasenko12014262011-05-30 14:00:14 +02002211sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212{
2213 if (entering(tcp)) {
2214 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002215 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002216 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002217 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002218 }
2219 return 0;
2220}