blob: c7f0b9709012e23142f4c32c897eb5ddc7397c24 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
34#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000035#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# define in6_addr in6_addr_libc
37# define ipv6_mreq ipv6_mreq_libc
38# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000041#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010042# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000043#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000044#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010047#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000051#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <asm/types.h>
53#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010054# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Denys Vlasenkoc36c3522012-02-25 02:47:15 +010059#if defined(__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010060# if defined(HAVE_LINUX_IN6_H)
61# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
62# undef in6_addr
63# undef ipv6_mreq
64# undef sockaddr_in6
65# define in6_addr in6_addr_kernel
66# define ipv6_mreq ipv6_mreq_kernel
67# define sockaddr_in6 sockaddr_in6_kernel
68# endif
69# include <linux/in6.h>
70# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
71# undef in6_addr
72# undef ipv6_mreq
73# undef sockaddr_in6
74# define in6_addr in6_addr_libc
75# define ipv6_mreq ipv6_mreq_libc
76# define sockaddr_in6 sockaddr_in6_kernel
77# endif
78# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000079#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000080
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000081#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010082# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010085# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010088# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010091# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010094# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095#endif
96
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097/* Under Linux these are enums so we can't test for them with ifdef. */
98#define IPPROTO_EGP IPPROTO_EGP
99#define IPPROTO_PUP IPPROTO_PUP
100#define IPPROTO_IDP IPPROTO_IDP
101#define IPPROTO_IGMP IPPROTO_IGMP
102#define IPPROTO_RAW IPPROTO_RAW
103#define IPPROTO_MAX IPPROTO_MAX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104
Roland McGrathd9f816f2004-09-04 03:39:20 +0000105static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000106#ifdef PF_AAL5
107 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#endif
109#ifdef PF_APPLETALK
110 { PF_APPLETALK, "PF_APPLETALK" },
111#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000112#ifdef PF_ASH
113 { PF_ASH, "PF_ASH" },
114#endif
115#ifdef PF_ATMPVC
116 { PF_ATMPVC, "PF_ATMPVC" },
117#endif
118#ifdef PF_ATMSVC
119 { PF_ATMSVC, "PF_ATMSVC" },
120#endif
121#ifdef PF_AX25
122 { PF_AX25, "PF_AX25" },
123#endif
124#ifdef PF_BLUETOOTH
125 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#endif
127#ifdef PF_BRIDGE
128 { PF_BRIDGE, "PF_BRIDGE" },
129#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000130#ifdef PF_DECnet
131 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000132#endif
133#ifdef PF_DECNET
134 { PF_DECNET, "PF_DECNET" },
135#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000136#ifdef PF_ECONET
137 { PF_ECONET, "PF_ECONET" },
138#endif
139#ifdef PF_FILE
140 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#endif
142#ifdef PF_IMPLINK
143 { PF_IMPLINK, "PF_IMPLINK" },
144#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000145#ifdef PF_INET
146 { PF_INET, "PF_INET" },
147#endif
148#ifdef PF_INET6
149 { PF_INET6, "PF_INET6" },
150#endif
151#ifdef PF_IPX
152 { PF_IPX, "PF_IPX" },
153#endif
154#ifdef PF_IRDA
155 { PF_IRDA, "PF_IRDA" },
156#endif
157#ifdef PF_ISO
158 { PF_ISO, "PF_ISO" },
159#endif
160#ifdef PF_KEY
161 { PF_KEY, "PF_KEY" },
162#endif
163#ifdef PF_UNIX
164 { PF_UNIX, "PF_UNIX" },
165#endif
166#ifdef PF_LOCAL
167 { PF_LOCAL, "PF_LOCAL" },
168#endif
169#ifdef PF_NETBEUI
170 { PF_NETBEUI, "PF_NETBEUI" },
171#endif
172#ifdef PF_NETLINK
173 { PF_NETLINK, "PF_NETLINK" },
174#endif
175#ifdef PF_NETROM
176 { PF_NETROM, "PF_NETROM" },
177#endif
178#ifdef PF_PACKET
179 { PF_PACKET, "PF_PACKET" },
180#endif
181#ifdef PF_PPPOX
182 { PF_PPPOX, "PF_PPPOX" },
183#endif
184#ifdef PF_ROSE
185 { PF_ROSE, "PF_ROSE" },
186#endif
187#ifdef PF_ROUTE
188 { PF_ROUTE, "PF_ROUTE" },
189#endif
190#ifdef PF_SECURITY
191 { PF_SECURITY, "PF_SECURITY" },
192#endif
193#ifdef PF_SNA
194 { PF_SNA, "PF_SNA" },
195#endif
196#ifdef PF_UNSPEC
197 { PF_UNSPEC, "PF_UNSPEC" },
198#endif
199#ifdef PF_WANPIPE
200 { PF_WANPIPE, "PF_WANPIPE" },
201#endif
202#ifdef PF_X25
203 { PF_X25, "PF_X25" },
204#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 { 0, NULL },
206};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000207const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000208#ifdef AF_APPLETALK
209 { AF_APPLETALK, "AF_APPLETALK" },
210#endif
211#ifdef AF_ASH
212 { AF_ASH, "AF_ASH" },
213#endif
214#ifdef AF_ATMPVC
215 { AF_ATMPVC, "AF_ATMPVC" },
216#endif
217#ifdef AF_ATMSVC
218 { AF_ATMSVC, "AF_ATMSVC" },
219#endif
220#ifdef AF_AX25
221 { AF_AX25, "AF_AX25" },
222#endif
223#ifdef AF_BLUETOOTH
224 { AF_BLUETOOTH, "AF_BLUETOOTH" },
225#endif
226#ifdef AF_BRIDGE
227 { AF_BRIDGE, "AF_BRIDGE" },
228#endif
229#ifdef AF_DECnet
230 { AF_DECnet, "AF_DECnet" },
231#endif
232#ifdef AF_ECONET
233 { AF_ECONET, "AF_ECONET" },
234#endif
235#ifdef AF_FILE
236 { AF_FILE, "AF_FILE" },
237#endif
238#ifdef AF_IMPLINK
239 { AF_IMPLINK, "AF_IMPLINK" },
240#endif
241#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000243#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000244#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000245 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000246#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000247#ifdef AF_IPX
248 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000249#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000250#ifdef AF_IRDA
251 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000252#endif
253#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000254 { AF_ISO, "AF_ISO" },
255#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000256#ifdef AF_KEY
257 { AF_KEY, "AF_KEY" },
258#endif
259#ifdef AF_UNIX
260 { AF_UNIX, "AF_UNIX" },
261#endif
262#ifdef AF_LOCAL
263 { AF_LOCAL, "AF_LOCAL" },
264#endif
265#ifdef AF_NETBEUI
266 { AF_NETBEUI, "AF_NETBEUI" },
267#endif
268#ifdef AF_NETLINK
269 { AF_NETLINK, "AF_NETLINK" },
270#endif
271#ifdef AF_NETROM
272 { AF_NETROM, "AF_NETROM" },
273#endif
274#ifdef AF_PACKET
275 { AF_PACKET, "AF_PACKET" },
276#endif
277#ifdef AF_PPPOX
278 { AF_PPPOX, "AF_PPPOX" },
279#endif
280#ifdef AF_ROSE
281 { AF_ROSE, "AF_ROSE" },
282#endif
283#ifdef AF_ROUTE
284 { AF_ROUTE, "AF_ROUTE" },
285#endif
286#ifdef AF_SECURITY
287 { AF_SECURITY, "AF_SECURITY" },
288#endif
289#ifdef AF_SNA
290 { AF_SNA, "AF_SNA" },
291#endif
292#ifdef AF_UNSPEC
293 { AF_UNSPEC, "AF_UNSPEC" },
294#endif
295#ifdef AF_WANPIPE
296 { AF_WANPIPE, "AF_WANPIPE" },
297#endif
298#ifdef AF_X25
299 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300#endif
301 { 0, NULL },
302};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000303static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304 { SOCK_STREAM, "SOCK_STREAM" },
305 { SOCK_DGRAM, "SOCK_DGRAM" },
306#ifdef SOCK_RAW
307 { SOCK_RAW, "SOCK_RAW" },
308#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000309#ifdef SOCK_RDM
310 { SOCK_RDM, "SOCK_RDM" },
311#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312#ifdef SOCK_SEQPACKET
313 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
314#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000315#ifdef SOCK_DCCP
316 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317#endif
318#ifdef SOCK_PACKET
319 { SOCK_PACKET, "SOCK_PACKET" },
320#endif
321 { 0, NULL },
322};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000323static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000324#ifdef SOCK_CLOEXEC
325 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
326#endif
327#ifdef SOCK_NONBLOCK
328 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
329#endif
330 { 0, NULL },
331};
332#ifndef SOCK_TYPE_MASK
333# define SOCK_TYPE_MASK 0xf
334#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000335static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000336#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000337 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000338#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000339#if defined(SOL_ICMP)
340 { SOL_ICMP, "SOL_ICMP" },
341#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000342#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000343 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000344#endif
345#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000346 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000347#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000348#if defined(SOL_IPV6)
349 { SOL_IPV6, "SOL_IPV6" },
350#endif
351#if defined(SOL_ICMPV6)
352 { SOL_ICMPV6, "SOL_ICMPV6" },
353#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100354#if defined(SOL_SCTP)
355 { SOL_SCTP, "SOL_SCTP" },
356#endif
357#if defined(SOL_UDPLITE)
358 { SOL_UDPLITE, "SOL_UDPLITE" },
359#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360#if defined(SOL_RAW)
361 { SOL_RAW, "SOL_RAW" },
362#endif
363#if defined(SOL_IPX)
364 { SOL_IPX, "SOL_IPX" },
365#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000366#if defined(SOL_AX25)
367 { SOL_AX25, "SOL_AX25" },
368#endif
369#if defined(SOL_ATALK)
370 { SOL_ATALK, "SOL_ATALK" },
371#endif
372#if defined(SOL_NETROM)
373 { SOL_NETROM, "SOL_NETROM" },
374#endif
375#if defined(SOL_ROSE)
376 { SOL_ROSE, "SOL_ROSE" },
377#endif
378#if defined(SOL_DECNET)
379 { SOL_DECNET, "SOL_DECNET" },
380#endif
381#if defined(SOL_X25)
382 { SOL_X25, "SOL_X25" },
383#endif
384#if defined(SOL_PACKET)
385 { SOL_PACKET, "SOL_PACKET" },
386#endif
387#if defined(SOL_ATM)
388 { SOL_ATM, "SOL_ATM" },
389#endif
390#if defined(SOL_AAL)
391 { SOL_AAL, "SOL_AAL" },
392#endif
393#if defined(SOL_IRDA)
394 { SOL_IRDA, "SOL_IRDA" },
395#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100396#if defined(SOL_NETBEUI)
397 { SOL_NETBEUI, "SOL_NETBEUI" },
398#endif
399#if defined(SOL_LLC)
400 { SOL_LLC, "SOL_LLC" },
401#endif
402#if defined(SOL_DCCP)
403 { SOL_DCCP, "SOL_DCCP" },
404#endif
405#if defined(SOL_NETLINK)
406 { SOL_NETLINK, "SOL_NETLINK" },
407#endif
408#if defined(SOL_TIPC)
409 { SOL_TIPC, "SOL_TIPC" },
410#endif
411#if defined(SOL_RXRPC)
412 { SOL_RXRPC, "SOL_RXRPC" },
413#endif
414#if defined(SOL_PPPOL2TP)
415 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
416#endif
417#if defined(SOL_BLUETOOTH)
418 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
419#endif
420#if defined(SOL_PNPIPE)
421 { SOL_PNPIPE, "SOL_PNPIPE" },
422#endif
423#if defined(SOL_RDS)
424 { SOL_RDS, "SOL_RDS" },
425#endif
426#if defined(SOL_IUVC)
427 { SOL_IUCV, "SOL_IUCV" },
428#endif
429#if defined(SOL_CAIF)
430 { SOL_CAIF, "SOL_CAIF" },
431#endif
John Hughes61563572001-03-27 16:47:36 +0000432 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000433 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000434};
John Hughes93f7fcc2002-05-22 15:46:49 +0000435/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
436 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000437static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 { IPPROTO_IP, "IPPROTO_IP" },
439 { IPPROTO_ICMP, "IPPROTO_ICMP" },
440 { IPPROTO_TCP, "IPPROTO_TCP" },
441 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000442#ifdef IPPROTO_IGMP
443 { IPPROTO_IGMP, "IPPROTO_IGMP" },
444#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445#ifdef IPPROTO_GGP
446 { IPPROTO_GGP, "IPPROTO_GGP" },
447#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000448#ifdef IPPROTO_IPIP
449 { IPPROTO_IPIP, "IPPROTO_IPIP" },
450#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451#ifdef IPPROTO_EGP
452 { IPPROTO_EGP, "IPPROTO_EGP" },
453#endif
454#ifdef IPPROTO_PUP
455 { IPPROTO_PUP, "IPPROTO_PUP" },
456#endif
457#ifdef IPPROTO_IDP
458 { IPPROTO_IDP, "IPPROTO_IDP" },
459#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000460#ifdef IPPROTO_TP
461 { IPPROTO_TP, "IPPROTO_TP" },
462#endif
463#ifdef IPPROTO_DCCP
464 { IPPROTO_DCCP, "IPPROTO_DCCP" },
465#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466#ifdef IPPROTO_IPV6
467 { IPPROTO_IPV6, "IPPROTO_IPV6" },
468#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000469#ifdef IPPROTO_ROUTING
470 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000472#ifdef IPPROTO_FRAGMENT
473 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
474#endif
475#ifdef IPPROTO_RSVP
476 { IPPROTO_RSVP, "IPPROTO_RSVP" },
477#endif
478#ifdef IPPROTO_GRE
479 { IPPROTO_GRE, "IPPROTO_GRE" },
480#endif
481#ifdef IPPROTO_ESP
482 { IPPROTO_ESP, "IPPROTO_ESP" },
483#endif
484#ifdef IPPROTO_AH
485 { IPPROTO_AH, "IPPROTO_AH" },
486#endif
487#ifdef IPPROTO_ICMPV6
488 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
489#endif
490#ifdef IPPROTO_NONE
491 { IPPROTO_NONE, "IPPROTO_NONE" },
492#endif
493#ifdef IPPROTO_DSTOPTS
494 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495#endif
496#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000497 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498#endif
499#ifdef IPPROTO_ND
500 { IPPROTO_ND, "IPPROTO_ND" },
501#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000502#ifdef IPPROTO_MTP
503 { IPPROTO_MTP, "IPPROTO_MTP" },
504#endif
505#ifdef IPPROTO_ENCAP
506 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
507#endif
508#ifdef IPPROTO_PIM
509 { IPPROTO_PIM, "IPPROTO_PIM" },
510#endif
511#ifdef IPPROTO_COMP
512 { IPPROTO_COMP, "IPPROTO_COMP" },
513#endif
514#ifdef IPPROTO_SCTP
515 { IPPROTO_SCTP, "IPPROTO_SCTP" },
516#endif
517#ifdef IPPROTO_UDPLITE
518 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520#ifdef IPPROTO_RAW
521 { IPPROTO_RAW, "IPPROTO_RAW" },
522#endif
523#ifdef IPPROTO_MAX
524 { IPPROTO_MAX, "IPPROTO_MAX" },
525#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 { 0, NULL },
527};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000528static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000529 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000531 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532#endif
533#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000534 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535#endif
536#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000537 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538#endif
539#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000540 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541#endif
542#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000543 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544#endif
545#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000546 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000548#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000549 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000550#endif
551#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000552 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000553#endif
554#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000555 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000556#endif
557#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000558 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000559#endif
560#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000561 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000562#endif
563#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000564 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000566#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000567 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000568#endif
569#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000570 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000571#endif
572#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000573 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000574#endif
575#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000576 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000577#endif
578#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000579 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000580#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000581#ifdef MSG_WAITFORONE
582 { MSG_WAITFORONE, "MSG_WAITFORONE" },
583#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000584#ifdef MSG_CMSG_CLOEXEC
585 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
586#endif
587 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588};
589
Roland McGrathd9f816f2004-09-04 03:39:20 +0000590static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000592 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000593#endif
594#ifdef SO_ALLRAW
595 { SO_ALLRAW, "SO_ALLRAW" },
596#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000597#ifdef SO_ATTACH_FILTER
598 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
599#endif
600#ifdef SO_BINDTODEVICE
601 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
602#endif
603#ifdef SO_BROADCAST
604 { SO_BROADCAST, "SO_BROADCAST" },
605#endif
606#ifdef SO_BSDCOMPAT
607 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
608#endif
609#ifdef SO_DEBUG
610 { SO_DEBUG, "SO_DEBUG" },
611#endif
612#ifdef SO_DETACH_FILTER
613 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
614#endif
615#ifdef SO_DONTROUTE
616 { SO_DONTROUTE, "SO_DONTROUTE" },
617#endif
618#ifdef SO_ERROR
619 { SO_ERROR, "SO_ERROR" },
620#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000621#ifdef SO_ICS
622 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000624#ifdef SO_IMASOCKET
625 { SO_IMASOCKET, "SO_IMASOCKET" },
626#endif
627#ifdef SO_KEEPALIVE
628 { SO_KEEPALIVE, "SO_KEEPALIVE" },
629#endif
630#ifdef SO_LINGER
631 { SO_LINGER, "SO_LINGER" },
632#endif
633#ifdef SO_LISTENING
634 { SO_LISTENING, "SO_LISTENING" },
635#endif
636#ifdef SO_MGMT
637 { SO_MGMT, "SO_MGMT" },
638#endif
639#ifdef SO_NO_CHECK
640 { SO_NO_CHECK, "SO_NO_CHECK" },
641#endif
642#ifdef SO_OOBINLINE
643 { SO_OOBINLINE, "SO_OOBINLINE" },
644#endif
645#ifdef SO_ORDREL
646 { SO_ORDREL, "SO_ORDREL" },
647#endif
648#ifdef SO_PARALLELSVR
649 { SO_PARALLELSVR, "SO_PARALLELSVR" },
650#endif
651#ifdef SO_PASSCRED
652 { SO_PASSCRED, "SO_PASSCRED" },
653#endif
654#ifdef SO_PEERCRED
655 { SO_PEERCRED, "SO_PEERCRED" },
656#endif
657#ifdef SO_PEERNAME
658 { SO_PEERNAME, "SO_PEERNAME" },
659#endif
660#ifdef SO_PEERSEC
661 { SO_PEERSEC, "SO_PEERSEC" },
662#endif
663#ifdef SO_PRIORITY
664 { SO_PRIORITY, "SO_PRIORITY" },
665#endif
666#ifdef SO_PROTOTYPE
667 { SO_PROTOTYPE, "SO_PROTOTYPE" },
668#endif
669#ifdef SO_RCVBUF
670 { SO_RCVBUF, "SO_RCVBUF" },
671#endif
672#ifdef SO_RCVLOWAT
673 { SO_RCVLOWAT, "SO_RCVLOWAT" },
674#endif
675#ifdef SO_RCVTIMEO
676 { SO_RCVTIMEO, "SO_RCVTIMEO" },
677#endif
678#ifdef SO_RDWR
679 { SO_RDWR, "SO_RDWR" },
680#endif
681#ifdef SO_REUSEADDR
682 { SO_REUSEADDR, "SO_REUSEADDR" },
683#endif
684#ifdef SO_REUSEPORT
685 { SO_REUSEPORT, "SO_REUSEPORT" },
686#endif
687#ifdef SO_SECURITY_AUTHENTICATION
688 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
689#endif
690#ifdef SO_SECURITY_ENCRYPTION_NETWORK
691 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
692#endif
693#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
694 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
695#endif
696#ifdef SO_SEMA
697 { SO_SEMA, "SO_SEMA" },
698#endif
699#ifdef SO_SNDBUF
700 { SO_SNDBUF, "SO_SNDBUF" },
701#endif
702#ifdef SO_SNDLOWAT
703 { SO_SNDLOWAT, "SO_SNDLOWAT" },
704#endif
705#ifdef SO_SNDTIMEO
706 { SO_SNDTIMEO, "SO_SNDTIMEO" },
707#endif
708#ifdef SO_TIMESTAMP
709 { SO_TIMESTAMP, "SO_TIMESTAMP" },
710#endif
711#ifdef SO_TYPE
712 { SO_TYPE, "SO_TYPE" },
713#endif
714#ifdef SO_USELOOPBACK
715 { SO_USELOOPBACK, "SO_USELOOPBACK" },
716#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717 { 0, NULL },
718};
719
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100720#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000721#define SOL_IP IPPROTO_IP
722#endif
723
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000725static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000726#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000727 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000728#endif
729#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000730 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000731#endif
732#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000733 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000735#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000736 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000738#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000739 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000740#endif
741#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000742 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
743#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000744#ifdef IP_RECVOPTS
745 { IP_RECVOPTS, "IP_RECVOPTS" },
746#endif
747#ifdef IP_RECVRETOPTS
748 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
749#endif
750#ifdef IP_RECVDSTADDR
751 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
752#endif
753#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000754 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000755#endif
756#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000757 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000758#endif
759#ifdef IP_PKTOPTIONS
760 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
761#endif
762#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000763 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000764#endif
765#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000766 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000767#endif
768#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000769 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000770#endif
771#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000772 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000773#endif
774#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000775 { IP_MTU, "IP_MTU" },
776#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000777#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000778 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000779#endif
780#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000781 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000782#endif
783#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000784 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000785#endif
786#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000787 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000788#endif
789#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000790 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#endif
792#ifdef IP_BROADCAST_IF
793 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
794#endif
795#ifdef IP_RECVIFINDEX
796 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
797#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000798#ifdef IP_MSFILTER
799 { IP_MSFILTER, "IP_MSFILTER" },
800#endif
801#ifdef MCAST_MSFILTER
802 { MCAST_MSFILTER, "MCAST_MSFILTER" },
803#endif
804#ifdef IP_FREEBIND
805 { IP_FREEBIND, "IP_FREEBIND" },
806#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000807 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808};
809#endif /* SOL_IP */
810
Roland McGrath4f6ba692004-08-31 07:01:26 +0000811#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000812static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000813#ifdef IPV6_ADDRFORM
814 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
815#endif
816#ifdef MCAST_FILTER
817 { MCAST_FILTER, "MCAST_FILTER" },
818#endif
819#ifdef IPV6_PKTOPTIONS
820 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
821#endif
822#ifdef IPV6_MTU
823 { IPV6_MTU, "IPV6_MTU" },
824#endif
825#ifdef IPV6_V6ONLY
826 { IPV6_V6ONLY, "IPV6_V6ONLY" },
827#endif
828#ifdef IPV6_PKTINFO
829 { IPV6_PKTINFO, "IPV6_PKTINFO" },
830#endif
831#ifdef IPV6_HOPLIMIT
832 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
833#endif
834#ifdef IPV6_RTHDR
835 { IPV6_RTHDR, "IPV6_RTHDR" },
836#endif
837#ifdef IPV6_HOPOPTS
838 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
839#endif
840#ifdef IPV6_DSTOPTS
841 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
842#endif
843#ifdef IPV6_FLOWINFO
844 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
845#endif
846#ifdef IPV6_UNICAST_HOPS
847 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
848#endif
849#ifdef IPV6_MULTICAST_HOPS
850 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
851#endif
852#ifdef IPV6_MULTICAST_LOOP
853 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
854#endif
855#ifdef IPV6_MULTICAST_IF
856 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
857#endif
858#ifdef IPV6_MTU_DISCOVER
859 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
860#endif
861#ifdef IPV6_RECVERR
862 { IPV6_RECVERR, "IPV6_RECVERR" },
863#endif
864#ifdef IPV6_FLOWINFO_SEND
865 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
866#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000867#ifdef IPV6_ADD_MEMBERSHIP
868 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
869#endif
870#ifdef IPV6_DROP_MEMBERSHIP
871 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
872#endif
873#ifdef IPV6_ROUTER_ALERT
874 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
875#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000876 { 0, NULL },
877};
878#endif /* SOL_IPV6 */
879
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000880#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000881static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200882 { IPX_TYPE, "IPX_TYPE" },
883 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884};
885#endif /* SOL_IPX */
886
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000887#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000888static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000889#if defined(ICMP_FILTER)
890 { ICMP_FILTER, "ICMP_FILTER" },
891#endif
892 { 0, NULL },
893};
894#endif /* SOL_RAW */
895
896#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000897static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000898#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000899 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000900#endif
901#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000902 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000903#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000904#if defined(PACKET_RECV_OUTPUT)
905 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
906#endif
907#if defined(PACKET_RX_RING)
908 { PACKET_RX_RING, "PACKET_RX_RING" },
909#endif
910#if defined(PACKET_STATISTICS)
911 { PACKET_STATISTICS, "PACKET_STATISTICS" },
912#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000913#if defined(PACKET_COPY_THRESH)
914 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
915#endif
916#if defined(PACKET_AUXDATA)
917 { PACKET_AUXDATA, "PACKET_AUXDATA" },
918#endif
919#if defined(PACKET_ORIGDEV)
920 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
921#endif
922#if defined(PACKET_VERSION)
923 { PACKET_VERSION, "PACKET_VERSION" },
924#endif
925#if defined(PACKET_HDRLEN)
926 { PACKET_HDRLEN, "PACKET_HDRLEN" },
927#endif
928#if defined(PACKET_RESERVE)
929 { PACKET_RESERVE, "PACKET_RESERVE" },
930#endif
931#if defined(PACKET_TX_RING)
932 { PACKET_TX_RING, "PACKET_TX_RING" },
933#endif
934#if defined(PACKET_LOSS)
935 { PACKET_LOSS, "PACKET_LOSS" },
936#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000937 { 0, NULL },
938};
939#endif /* SOL_PACKET */
940
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100941#ifdef SOL_SCTP
942static const struct xlat socksctpoptions[] = {
943#if defined(SCTP_RTOINFO)
944 { SCTP_RTOINFO, "SCTP_RTOINFO" },
945#endif
946#if defined(SCTP_ASSOCINFO)
947 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
948#endif
949#if defined(SCTP_INITMSG)
950 { SCTP_INITMSG, "SCTP_INITMSG" },
951#endif
952#if defined(SCTP_NODELAY)
953 { SCTP_NODELAY, "SCTP_NODELAY" },
954#endif
955#if defined(SCTP_AUTOCLOSE)
956 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
957#endif
958#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
959 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
960#endif
961#if defined(SCTP_PRIMARY_ADDR)
962 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
963#endif
964#if defined(SCTP_ADAPTATION_LAYER)
965 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
966#endif
967#if defined(SCTP_DISABLE_FRAGMENTS)
968 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
969#endif
970#if defined(SCTP_PEER_ADDR_PARAMS)
971 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
972#endif
973#if defined(SCTP_DEFAULT_SEND_PARAM)
974 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
975#endif
976#if defined(SCTP_EVENTS)
977 { SCTP_EVENTS, "SCTP_EVENTS" },
978#endif
979#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
980 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
981#endif
982#if defined(SCTP_MAXSEG)
983 { SCTP_MAXSEG, "SCTP_MAXSEG" },
984#endif
985#if defined(SCTP_STATUS)
986 { SCTP_STATUS, "SCTP_STATUS" },
987#endif
988#if defined(SCTP_GET_PEER_ADDR_INFO)
989 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
990#endif
991#if defined(SCTP_DELAYED_ACK)
992 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
993#endif
994#if defined(SCTP_CONTEXT)
995 { SCTP_CONTEXT, "SCTP_CONTEXT" },
996#endif
997#if defined(SCTP_FRAGMENT_INTERLEAVE)
998 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
999#endif
1000#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1001 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1002#endif
1003#if defined(SCTP_MAX_BURST)
1004 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1005#endif
1006#if defined(SCTP_AUTH_CHUNK)
1007 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1008#endif
1009#if defined(SCTP_HMAC_IDENT)
1010 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1011#endif
1012#if defined(SCTP_AUTH_KEY)
1013 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1014#endif
1015#if defined(SCTP_AUTH_ACTIVE_KEY)
1016 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1017#endif
1018#if defined(SCTP_AUTH_DELETE_KEY)
1019 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1020#endif
1021#if defined(SCTP_PEER_AUTH_CHUNKS)
1022 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1023#endif
1024#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1025 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1026#endif
1027#if defined(SCTP_GET_ASSOC_NUMBER)
1028 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1029#endif
1030
1031 /* linux specific things */
1032#if defined(SCTP_SOCKOPT_BINDX_ADD)
1033 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1034#endif
1035#if defined(SCTP_SOCKOPT_BINDX_REM)
1036 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1037#endif
1038#if defined(SCTP_SOCKOPT_PEELOFF)
1039 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1040#endif
1041#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1042 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1043#endif
1044#if defined(SCTP_GET_PEER_ADDRS_OLD)
1045 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1046#endif
1047#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1048 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1049#endif
1050#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1051 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1052#endif
1053#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1054 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1055#endif
1056#if defined(SCTP_GET_PEER_ADDRS)
1057 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1058#endif
1059#if defined(SCTP_GET_LOCAL_ADDRS)
1060 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1061#endif
1062
1063 { 0, NULL },
1064};
1065#endif
1066
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001067#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001068#define SOL_TCP IPPROTO_TCP
1069#endif
1070
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001072static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001073 { TCP_NODELAY, "TCP_NODELAY" },
1074 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001075#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001076 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001077#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001078#if defined(TCP_KEEPIDLE)
1079 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1080#endif
1081#if defined(TCP_KEEPINTVL)
1082 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1083#endif
1084#if defined(TCP_KEEPCNT)
1085 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1086#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001087#if defined(TCP_NKEEP)
1088 { TCP_NKEEP, "TCP_NKEEP" },
1089#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001090#if defined(TCP_SYNCNT)
1091 { TCP_SYNCNT, "TCP_SYNCNT" },
1092#endif
1093#if defined(TCP_LINGER2)
1094 { TCP_LINGER2, "TCP_LINGER2" },
1095#endif
1096#if defined(TCP_DEFER_ACCEPT)
1097 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1098#endif
1099#if defined(TCP_WINDOW_CLAMP)
1100 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1101#endif
1102#if defined(TCP_INFO)
1103 { TCP_INFO, "TCP_INFO" },
1104#endif
1105#if defined(TCP_QUICKACK)
1106 { TCP_QUICKACK, "TCP_QUICKACK" },
1107#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001108#if defined(TCP_CONGESTION)
1109 { TCP_CONGESTION, "TCP_CONGESTION" },
1110#endif
1111#if defined(TCP_MD5SIG)
1112 { TCP_MD5SIG, "TCP_MD5SIG" },
1113#endif
1114#if defined(TCP_COOKIE_TRANSACTIONS)
1115 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1116#endif
1117#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1118 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1119#endif
1120#if defined(TCP_THIN_DUPACK)
1121 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1122#endif
1123#if defined(TCP_USER_TIMEOUT)
1124 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1125#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001126 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127};
1128#endif /* SOL_TCP */
1129
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001130#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001131static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001132#if defined(ICMP_ECHOREPLY)
1133 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1134#endif
1135#if defined(ICMP_DEST_UNREACH)
1136 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1137#endif
1138#if defined(ICMP_SOURCE_QUENCH)
1139 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1140#endif
1141#if defined(ICMP_REDIRECT)
1142 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1143#endif
1144#if defined(ICMP_ECHO)
1145 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1146#endif
1147#if defined(ICMP_TIME_EXCEEDED)
1148 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1149#endif
1150#if defined(ICMP_PARAMETERPROB)
1151 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1152#endif
1153#if defined(ICMP_TIMESTAMP)
1154 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1155#endif
1156#if defined(ICMP_TIMESTAMPREPLY)
1157 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1158#endif
1159#if defined(ICMP_INFO_REQUEST)
1160 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1161#endif
1162#if defined(ICMP_INFO_REPLY)
1163 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1164#endif
1165#if defined(ICMP_ADDRESS)
1166 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1167#endif
1168#if defined(ICMP_ADDRESSREPLY)
1169 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1170#endif
1171 { 0, NULL },
1172};
1173#endif /* SOL_RAW */
1174
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001175#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001176static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001177#if defined(PACKET_HOST)
1178 { PACKET_HOST, "PACKET_HOST" },
1179#endif
1180#if defined(PACKET_BROADCAST)
1181 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1182#endif
1183#if defined(PACKET_MULTICAST)
1184 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1185#endif
1186#if defined(PACKET_OTHERHOST)
1187 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1188#endif
1189#if defined(PACKET_OUTGOING)
1190 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1191#endif
1192#if defined(PACKET_LOOPBACK)
1193 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1194#endif
1195#if defined(PACKET_FASTROUTE)
1196 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1197#endif
1198 { 0, NULL },
1199};
1200#endif /* defined(AF_PACKET) */
1201
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001203printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001204{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001205 union {
1206 char pad[128];
1207 struct sockaddr sa;
1208 struct sockaddr_in sin;
1209 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001210#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001211 struct sockaddr_in6 sa6;
1212#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001213#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001214 struct sockaddr_ipx sipx;
1215#endif
1216#ifdef AF_PACKET
1217 struct sockaddr_ll ll;
1218#endif
1219#ifdef AF_NETLINK
1220 struct sockaddr_nl nl;
1221#endif
1222 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001223 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224
1225 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001226 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227 return;
1228 }
1229 if (!verbose(tcp)) {
1230 tprintf("%#lx", addr);
1231 return;
1232 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001233
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001234 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1235 addrlen = sizeof(addrbuf);
1236
1237 memset(&addrbuf, 0, sizeof(addrbuf));
1238 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001239 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240 return;
1241 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001242 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001243
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001244 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001245 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001246 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001247
1248 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001250 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001251 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001252 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001253 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001254 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001255 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001256 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001257 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001258 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259 break;
1260 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001261 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001262 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001264#ifdef HAVE_INET_NTOP
1265 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001266 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001267 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1268 ntohs(addrbuf.sa6.sin6_port), string_addr,
1269 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001270#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001271 {
1272#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001273 int numericscope = 0;
1274 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1275 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1276 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001277
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001278 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1279 numericscope++;
1280 else
1281 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1282 } else
1283 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001284
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001285 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001286#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001288 }
1289#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001290 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001291#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001292#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001294 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001296 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001297 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 /* Yes, I know, this does not look too
1299 * strace-ish, but otherwise the IPX
1300 * addresses just look monstrous...
1301 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001302 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001304 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001305 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001306 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1307 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 }
1309 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001310#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001311#ifdef AF_PACKET
1312 case AF_PACKET:
1313 {
1314 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001315 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001316 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001317 addrbuf.ll.sll_ifindex);
1318 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1319 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001320 addrbuf.ll.sll_halen,
1321 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001322 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001323 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1324 }
1325 break;
1326
Denys Vlasenko84703742012-02-25 02:38:52 +01001327#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001328#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001329 case AF_NETLINK:
1330 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1331 break;
1332#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001333 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001334 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335
1336 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001337 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001339 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 break;
1341 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001342 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343}
1344
1345#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001346static const struct xlat scmvals[] = {
1347#ifdef SCM_RIGHTS
1348 { SCM_RIGHTS, "SCM_RIGHTS" },
1349#endif
1350#ifdef SCM_CREDENTIALS
1351 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1352#endif
1353 { 0, NULL }
1354};
1355
1356static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001357printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001358{
Roland McGrathaa524c82005-06-01 19:22:06 +00001359 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1360 NULL : malloc(len);
1361 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001362 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001363 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001364 return;
1365 }
1366
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001367 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001368 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001370
Roland McGrathaa524c82005-06-01 19:22:06 +00001371 if (cmsg->cmsg_level == SOL_SOCKET) {
1372 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001373
Roland McGrathaa524c82005-06-01 19:22:06 +00001374 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1375 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1376
1377 if (cmsg->cmsg_type == SCM_RIGHTS
1378 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001379 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001380 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001381
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001382 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001383 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001384 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001386 tprintf("%d", *fds++);
1387 first = 0;
1388 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001389 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001390 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001391 return;
1392 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001393 if (cmsg->cmsg_type == SCM_CREDENTIALS
1394 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001395 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001396
Roland McGrath50770822004-10-06 22:11:51 +00001397 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1398 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001399 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001400 return;
1401 }
1402 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001403 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001404 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001405}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406
1407static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001408do_msghdr(struct tcb *tcp, struct msghdr *msg)
1409{
1410 tprintf("{msg_name(%d)=", msg->msg_namelen);
1411 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1412
1413 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1414 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
Dmitry V. Levin88849682011-06-13 22:58:44 +00001415 (unsigned long)msg->msg_iov, 1);
Andreas Schwab0873f292010-02-12 21:39:12 +01001416
1417#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1418 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1419 if (msg->msg_controllen)
1420 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1421 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001422 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001423 printflags(msg_flags, msg->msg_flags, "MSG_???");
1424#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1425 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1426 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1427#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001428 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001429}
1430
1431static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001432printmsghdr(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433{
1434 struct msghdr msg;
1435
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001436 if (umove(tcp, addr, &msg) < 0) {
1437 tprintf("%#lx", addr);
1438 return;
1439 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001440 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441}
1442
Andreas Schwab0873f292010-02-12 21:39:12 +01001443static void
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001444printmmsghdr(struct tcb *tcp, long addr, unsigned int idx)
Andreas Schwab0873f292010-02-12 21:39:12 +01001445{
1446 struct mmsghdr {
1447 struct msghdr msg_hdr;
1448 unsigned msg_len;
1449 } mmsg;
1450
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001451 addr += sizeof(mmsg) * idx;
Andreas Schwab0873f292010-02-12 21:39:12 +01001452 if (umove(tcp, addr, &mmsg) < 0) {
1453 tprintf("%#lx", addr);
1454 return;
1455 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001456 tprints("{");
Andreas Schwab0873f292010-02-12 21:39:12 +01001457 do_msghdr(tcp, &mmsg.msg_hdr);
1458 tprintf(", %u}", mmsg.msg_len);
1459}
Andreas Schwab0873f292010-02-12 21:39:12 +01001460
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001461static void
1462decode_mmsg(struct tcb *tcp)
1463{
1464 /* mmsgvec */
1465 if (syserror(tcp)) {
1466 tprintf("%#lx", tcp->u_arg[1]);
1467 } else {
1468 unsigned int len = tcp->u_rval;
1469 unsigned int i;
1470
1471 tprints("{");
1472 for (i = 0; i < len; ++i) {
1473 if (i)
1474 tprints(", ");
1475 printmmsghdr(tcp, tcp->u_arg[1], i);
1476 }
1477 tprints("}");
1478 }
1479 /* vlen */
1480 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1481 /* flags */
1482 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1483}
1484
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001485#endif /* HAVE_SENDMSG */
1486
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001487/*
1488 * low bits of the socket type define real socket type,
1489 * other bits are socket type flags.
1490 */
1491static void
1492tprint_sock_type(struct tcb *tcp, int flags)
1493{
1494 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1495
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001496 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001497 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001498 flags &= ~SOCK_TYPE_MASK;
1499 if (!flags)
1500 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001501 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001502 }
1503 printflags(sock_type_flags, flags, "SOCK_???");
1504}
1505
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001506int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001507sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508{
1509 if (entering(tcp)) {
1510 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001511 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001512 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001513 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001514 switch (tcp->u_arg[0]) {
1515 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001516#ifdef PF_INET6
1517 case PF_INET6:
1518#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1520 break;
1521#ifdef PF_IPX
1522 case PF_IPX:
1523 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001524 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001526 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527 break;
1528#endif /* PF_IPX */
1529 default:
1530 tprintf("%lu", tcp->u_arg[2]);
1531 break;
1532 }
1533 }
1534 return 0;
1535}
1536
John Hughesbdf48f52001-03-06 15:08:09 +00001537int
Denys Vlasenko12014262011-05-30 14:00:14 +02001538sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001539{
1540 if (entering(tcp)) {
1541 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001542 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543 tprintf(", %lu", tcp->u_arg[2]);
1544 }
1545 return 0;
1546}
1547
1548int
Denys Vlasenko12014262011-05-30 14:00:14 +02001549sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001550{
1551 return sys_bind(tcp);
1552}
1553
1554int
Denys Vlasenko12014262011-05-30 14:00:14 +02001555sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001556{
1557 if (entering(tcp)) {
1558 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1559 }
1560 return 0;
1561}
1562
Paolo Bonzini705ff102009-08-14 12:34:05 +02001563static int
1564do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565{
1566 if (entering(tcp)) {
1567 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001568 return 0;
1569 }
1570 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571 tprintf("%#lx, NULL", tcp->u_arg[1]);
1572 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001573 int len;
1574 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001575 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576 tprintf("%#lx", tcp->u_arg[1]);
1577 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001578 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001579 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001580 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001581 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001582 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001583 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001584 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001585 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1586 "SOCK_???");
1587 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 return 0;
1589}
1590
1591int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001592sys_accept(struct tcb *tcp)
1593{
1594 return do_accept(tcp, -1);
1595}
1596
Paolo Bonzini705ff102009-08-14 12:34:05 +02001597int
1598sys_accept4(struct tcb *tcp)
1599{
1600 return do_accept(tcp, 3);
1601}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001602
1603int
Denys Vlasenko12014262011-05-30 14:00:14 +02001604sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605{
1606 if (entering(tcp)) {
1607 tprintf("%ld, ", tcp->u_arg[0]);
1608 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1609 tprintf(", %lu, ", tcp->u_arg[2]);
1610 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001611 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 }
1613 return 0;
1614}
1615
1616int
Denys Vlasenko12014262011-05-30 14:00:14 +02001617sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618{
1619 if (entering(tcp)) {
1620 tprintf("%ld, ", tcp->u_arg[0]);
1621 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1622 tprintf(", %lu, ", tcp->u_arg[2]);
1623 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001624 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001626 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001627 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628 /* to length */
1629 tprintf(", %lu", tcp->u_arg[5]);
1630 }
1631 return 0;
1632}
1633
1634#ifdef HAVE_SENDMSG
1635
1636int
Denys Vlasenko12014262011-05-30 14:00:14 +02001637sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638{
1639 if (entering(tcp)) {
1640 tprintf("%ld, ", tcp->u_arg[0]);
1641 printmsghdr(tcp, tcp->u_arg[1]);
1642 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001643 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001644 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001645 }
1646 return 0;
1647}
1648
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001649int
1650sys_sendmmsg(struct tcb *tcp)
1651{
1652 if (entering(tcp)) {
1653 /* sockfd */
1654 tprintf("%d, ", (int) tcp->u_arg[0]);
1655 if (!verbose(tcp)) {
1656 tprintf("%#lx, %u, ",
1657 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1658 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1659 }
1660 } else {
1661 if (verbose(tcp))
1662 decode_mmsg(tcp);
1663 }
1664 return 0;
1665}
1666
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667#endif /* HAVE_SENDMSG */
1668
1669int
Denys Vlasenko12014262011-05-30 14:00:14 +02001670sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671{
1672 if (entering(tcp)) {
1673 tprintf("%ld, ", tcp->u_arg[0]);
1674 } else {
1675 if (syserror(tcp))
1676 tprintf("%#lx", tcp->u_arg[1]);
1677 else
1678 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1679
1680 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001681 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682 }
1683 return 0;
1684}
1685
1686int
Denys Vlasenko12014262011-05-30 14:00:14 +02001687sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688{
1689 int fromlen;
1690
1691 if (entering(tcp)) {
1692 tprintf("%ld, ", tcp->u_arg[0]);
1693 } else {
1694 if (syserror(tcp)) {
1695 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1696 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1697 tcp->u_arg[4], tcp->u_arg[5]);
1698 return 0;
1699 }
1700 /* buf */
1701 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1702 /* len */
1703 tprintf(", %lu, ", tcp->u_arg[2]);
1704 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001705 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706 /* from address, len */
1707 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1708 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710 else
1711 tprintf(", %#lx", tcp->u_arg[4]);
1712 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001713 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001714 else
1715 tprintf(", %#lx", tcp->u_arg[5]);
1716 return 0;
1717 }
1718 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001719 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720 return 0;
1721 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001722 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001723 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001724 /* from length */
1725 tprintf(", [%u]", fromlen);
1726 }
1727 return 0;
1728}
1729
1730#ifdef HAVE_SENDMSG
1731
1732int
Denys Vlasenko12014262011-05-30 14:00:14 +02001733sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734{
1735 if (entering(tcp)) {
1736 tprintf("%ld, ", tcp->u_arg[0]);
1737 } else {
1738 if (syserror(tcp) || !verbose(tcp))
1739 tprintf("%#lx", tcp->u_arg[1]);
1740 else
1741 printmsghdr(tcp, tcp->u_arg[1]);
1742 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001743 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001744 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001745 }
1746 return 0;
1747}
1748
Andreas Schwab0873f292010-02-12 21:39:12 +01001749int
1750sys_recvmmsg(struct tcb *tcp)
1751{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001752 /* +5 chars are for "left " prefix */
1753 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001754
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001755 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001756 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001757 if (verbose(tcp)) {
1758 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001759 /* Abusing tcp->auxstr as temp storage.
1760 * Will be used and freed on syscall exit.
1761 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001762 tcp->auxstr = strdup(str);
1763 } else {
1764 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1765 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001766 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001767 print_timespec(tcp, tcp->u_arg[4]);
1768 }
1769 return 0;
1770 } else {
1771 if (verbose(tcp)) {
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001772 decode_mmsg(tcp);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001773 /* timeout on entrance */
1774 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1775 free((void *) tcp->auxstr);
1776 tcp->auxstr = NULL;
1777 }
1778 if (syserror(tcp))
1779 return 0;
1780 if (tcp->u_rval == 0) {
1781 tcp->auxstr = "Timeout";
1782 return RVAL_STR;
1783 }
1784 if (!verbose(tcp))
1785 return 0;
1786 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001787 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001788 tcp->auxstr = str;
1789 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001790 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001791}
Andreas Schwab0873f292010-02-12 21:39:12 +01001792
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001793#endif /* HAVE_SENDMSG */
1794
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001795static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001796 { 0, "SHUT_RD" },
1797 { 1, "SHUT_WR" },
1798 { 2, "SHUT_RDWR" },
1799 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001800};
1801
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802int
Denys Vlasenko12014262011-05-30 14:00:14 +02001803sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804{
1805 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001806 tprintf("%ld, ", tcp->u_arg[0]);
1807 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808 }
1809 return 0;
1810}
1811
1812int
Denys Vlasenko12014262011-05-30 14:00:14 +02001813sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814{
1815 return sys_accept(tcp);
1816}
1817
1818int
Denys Vlasenko12014262011-05-30 14:00:14 +02001819sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001820{
1821 return sys_accept(tcp);
1822}
1823
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001824static int
1825do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 if (exiting(tcp)) {
1828 if (syserror(tcp)) {
1829 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001830 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001831#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001832 int fds[2];
1833
1834 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001835 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001836 else
1837 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001838#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001839 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1840#else
1841 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001843 }
1844 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001845 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001846 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1847 }
1848 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 return 0;
1850}
1851
1852int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001853sys_pipe(struct tcb *tcp)
1854{
1855 return do_pipe(tcp, -1);
1856}
1857
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001858int
1859sys_pipe2(struct tcb *tcp)
1860{
1861 return do_pipe(tcp, 1);
1862}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001863
1864int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001865sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868
1869 if (entering(tcp)) {
1870 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001871 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001872 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001873 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874 switch (tcp->u_arg[0]) {
1875 case PF_INET:
1876 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1877 break;
1878#ifdef PF_IPX
1879 case PF_IPX:
1880 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001881 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001883 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 break;
1885#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001886 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001887 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888 break;
1889 }
1890 } else {
1891 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001892 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 return 0;
1894 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001895 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001896 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 else
1898 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899 }
1900 return 0;
1901}
1902
1903int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001904sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905{
1906 if (entering(tcp)) {
1907 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001908 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001909 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 switch (tcp->u_arg[1]) {
1911 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001913 break;
1914#ifdef SOL_IP
1915 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 break;
1918#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001919#ifdef SOL_IPV6
1920 case SOL_IPV6:
1921 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1922 break;
1923#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924#ifdef SOL_IPX
1925 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 break;
1928#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001929#ifdef SOL_PACKET
1930 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001931 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001932 break;
1933#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934#ifdef SOL_TCP
1935 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 break;
1938#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001939#ifdef SOL_SCTP
1940 case SOL_SCTP:
1941 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1942 break;
1943#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944
1945 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1946 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001947 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001948 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001949 break;
1950 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001951 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001953 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001954 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001955 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 tcp->u_arg[3], tcp->u_arg[4]);
1957 return 0;
1958 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001959
1960 switch (tcp->u_arg[1]) {
1961 case SOL_SOCKET:
1962 switch (tcp->u_arg[2]) {
1963#ifdef SO_LINGER
1964 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001965 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001966 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001967 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001968 tcp->u_arg[3],
1969 &linger) < 0)
1970 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001971 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001972 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001973 linger.l_onoff,
1974 linger.l_linger,
1975 len);
1976 return 0;
1977 }
1978 break;
1979#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001980#ifdef SO_PEERCRED
1981 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001982 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001983 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001984 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001985 tcp->u_arg[3],
1986 &uc) < 0)
1987 break;
1988 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1989 "[%d]",
1990 (long)uc.pid,
1991 (long)uc.uid,
1992 (long)uc.gid,
1993 len);
1994 return 0;
1995 }
1996 break;
1997#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001998 }
1999 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002000 case SOL_PACKET:
2001 switch (tcp->u_arg[2]) {
2002#ifdef PACKET_STATISTICS
2003 case PACKET_STATISTICS:
2004 if (len == sizeof(struct tpacket_stats)) {
2005 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002006 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002007 tcp->u_arg[3],
2008 &stats) < 0)
2009 break;
2010 tprintf("{packets=%u, drops=%u}, "
2011 "[%d]",
2012 stats.tp_packets,
2013 stats.tp_drops,
2014 len);
2015 return 0;
2016 }
2017 break;
2018#endif
2019 }
2020 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002021 }
2022
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002023 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002024 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002025 }
2026 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002027 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002028 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002029 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030 }
2031 return 0;
2032}
2033
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002034#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002035static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002036{
2037 struct icmp_filter filter;
2038
2039 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002040 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002041 return;
2042 }
2043 if (syserror(tcp) || !verbose(tcp)) {
2044 tprintf("%#lx", addr);
2045 return;
2046 }
2047 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002048 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002049 return;
2050 }
2051
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002052 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002053 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002054 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002055}
2056#endif /* ICMP_FILTER */
2057
John Hughes38ae88d2002-05-23 11:48:58 +00002058static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002059printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002060{
2061 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002062 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002063 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002064 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002065 printxval(sockoptions, name, "SO_???");
2066 switch (name) {
2067#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002068 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002069 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002070 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002071 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002072 break;
2073 tprintf(", {onoff=%d, linger=%d}",
2074 linger.l_onoff,
2075 linger.l_linger);
2076 return 0;
2077 }
2078 break;
2079#endif
2080 }
2081 break;
2082#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002083 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00002084 printxval(sockipoptions, name, "IP_???");
2085 break;
2086#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002087#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002088 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00002089 printxval(sockipv6options, name, "IPV6_???");
2090 break;
2091#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002092#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002093 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00002094 printxval(sockipxoptions, name, "IPX_???");
2095 break;
2096#endif
2097#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002098 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002099 printxval(sockpacketoptions, name, "PACKET_???");
2100 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002101 switch (name) {
2102#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002103 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002104#endif
2105#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002106 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002107#endif
2108#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2109 if (len == sizeof(struct tpacket_req)) {
2110 struct tpacket_req req;
2111 if (umove(tcp, addr, &req) < 0)
2112 break;
2113 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2114 req.tp_block_size,
2115 req.tp_block_nr,
2116 req.tp_frame_size,
2117 req.tp_frame_nr);
2118 return 0;
2119 }
2120 break;
2121#endif /* PACKET_RX_RING || PACKET_TX_RING */
2122 }
John Hughes38ae88d2002-05-23 11:48:58 +00002123 break;
2124#endif
2125#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002126 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00002127 printxval(socktcpoptions, name, "TCP_???");
2128 break;
2129#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002130#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002131 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002132 printxval(socksctpoptions, name, "SCTP_???");
2133 break;
2134#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002135#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002136 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00002137 printxval(sockrawoptions, name, "RAW_???");
2138 switch (name) {
2139#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002140 case ICMP_FILTER:
2141 tprints(", ");
2142 printicmpfilter(tcp, addr);
2143 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002144#endif
2145 }
2146 break;
2147#endif
2148
Roland McGrath6d2b3492002-12-30 00:51:30 +00002149 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002150 * etc. still need work */
2151
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002152 default:
John Hughes38ae88d2002-05-23 11:48:58 +00002153 tprintf("%u", name);
2154 }
2155
2156 /* default arg printing */
2157
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002158 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002159
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002160 if (len == sizeof(int)) {
2161 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002162 }
2163 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002164 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002165 }
2166 return 0;
2167}
2168
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002169#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002170
2171void
Denys Vlasenko12014262011-05-30 14:00:14 +02002172print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002173{
2174 int c = 0;
2175 struct opthdr hdr;
2176
John Hughes2c4e3a82002-05-24 10:19:44 +00002177 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002178 if (umove(tcp, addr, &hdr) < 0) break;
2179 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002180 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002181 }
2182 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002183 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002184 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002185 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002186 addr += sizeof hdr;
2187 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002188 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002189 if (hdr.len > 0) {
2190 addr += hdr.len;
2191 len -= hdr.len;
2192 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002193 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002194 }
2195 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002196 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002197 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002198 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002199 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002200}
2201
2202#endif
2203
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204int
Denys Vlasenko12014262011-05-30 14:00:14 +02002205sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206{
2207 if (entering(tcp)) {
2208 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002209 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002210 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002211 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 }
2213 return 0;
2214}