blob: 9ae783a9345b518c296db0f2faba1ed42efd03d8 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
34#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000035#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# define in6_addr in6_addr_libc
37# define ipv6_mreq ipv6_mreq_libc
38# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000041#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010042# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000043#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000044#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010047#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000051#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010053#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010054# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Denys Vlasenko99aa1812013-02-08 18:49:06 +010059#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010060# if defined(HAVE_LINUX_IN6_H)
61# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
62# undef in6_addr
63# undef ipv6_mreq
64# undef sockaddr_in6
65# define in6_addr in6_addr_kernel
66# define ipv6_mreq ipv6_mreq_kernel
67# define sockaddr_in6 sockaddr_in6_kernel
68# endif
69# include <linux/in6.h>
70# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
71# undef in6_addr
72# undef ipv6_mreq
73# undef sockaddr_in6
74# define in6_addr in6_addr_libc
75# define ipv6_mreq ipv6_mreq_libc
76# define sockaddr_in6 sockaddr_in6_kernel
77# endif
78# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000079#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000080
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000081#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010082# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010085# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010088# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010091# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000092#endif
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[] = {
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000106#ifdef PF_UNSPEC
107 { PF_UNSPEC, "PF_UNSPEC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000108#endif
109#ifdef PF_LOCAL
110 { PF_LOCAL, "PF_LOCAL" },
111#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000112#ifdef PF_UNIX
113 { PF_UNIX, "PF_UNIX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000114#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000115#ifdef PF_INET
116 { PF_INET, "PF_INET" },
117#endif
118#ifdef PF_AX25
119 { PF_AX25, "PF_AX25" },
120#endif
121#ifdef PF_IPX
122 { PF_IPX, "PF_IPX" },
123#endif
124#ifdef PF_APPLETALK
125 { PF_APPLETALK, "PF_APPLETALK" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000126#endif
127#ifdef PF_NETROM
128 { PF_NETROM, "PF_NETROM" },
129#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000130#ifdef PF_BRIDGE
131 { PF_BRIDGE, "PF_BRIDGE" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000132#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000133#ifdef PF_ATMPVC
134 { PF_ATMPVC, "PF_ATMPVC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000135#endif
136#ifdef PF_X25
137 { PF_X25, "PF_X25" },
138#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000139#ifdef PF_INET6
140 { PF_INET6, "PF_INET6" },
141#endif
142#ifdef PF_ROSE
143 { PF_ROSE, "PF_ROSE" },
144#endif
145#ifdef PF_DECnet
146 { PF_DECnet, "PF_DECnet" },
147#endif
148#ifdef PF_NETBEUI
149 { PF_NETBEUI, "PF_NETBEUI" },
150#endif
151#ifdef PF_SECURITY
152 { PF_SECURITY, "PF_SECURITY" },
153#endif
154#ifdef PF_KEY
155 { PF_KEY, "PF_KEY" },
156#endif
157#ifdef PF_NETLINK
158 { PF_NETLINK, "PF_NETLINK" },
159#endif
160#ifdef PF_ROUTE
161 { PF_ROUTE, "PF_ROUTE" },
162#endif
163#ifdef PF_PACKET
164 { PF_PACKET, "PF_PACKET" },
165#endif
166#ifdef PF_ASH
167 { PF_ASH, "PF_ASH" },
168#endif
169#ifdef PF_ECONET
170 { PF_ECONET, "PF_ECONET" },
171#endif
172#ifdef PF_ATMSVC
173 { PF_ATMSVC, "PF_ATMSVC" },
174#endif
175#ifdef PF_RDS
176 { PF_RDS, "PF_RDS" },
177#endif
178#ifdef PF_SNA
179 { PF_SNA, "PF_SNA" },
180#endif
181#ifdef PF_IRDA
182 { PF_IRDA, "PF_IRDA" },
183#endif
184#ifdef PF_PPPOX
185 { PF_PPPOX, "PF_PPPOX" },
186#endif
187#ifdef PF_WANPIPE
188 { PF_WANPIPE, "PF_WANPIPE" },
189#endif
190#ifdef PF_LLC
191 { PF_LLC, "PF_LLC" },
192#endif
193#ifdef PF_CAN
194 { PF_CAN, "PF_CAN" },
195#endif
196#ifdef PF_TIPC
197 { PF_TIPC, "PF_TIPC" },
198#endif
199#ifdef PF_BLUETOOTH
200 { PF_BLUETOOTH, "PF_BLUETOOTH" },
201#endif
202#ifdef PF_IUCV
203 { PF_IUCV, "PF_IUCV" },
204#endif
205#ifdef PF_RXRPC
206 { PF_RXRPC, "PF_RXRPC" },
207#endif
208#ifdef PF_ISDN
209 { PF_ISDN, "PF_ISDN" },
210#endif
211#ifdef PF_PHONET
212 { PF_PHONET, "PF_PHONET" },
213#endif
214#ifdef PF_IEEE802154
215 { PF_IEEE802154,"PF_IEEE802154" },
216#endif
217#ifdef PF_CAIF
218 { PF_CAIF, "PF_CAIF" },
219#endif
220#ifdef PF_ALG
221 { PF_ALG, "PF_ALG" },
222#endif
223#ifdef PF_NFC
224 { PF_NFC, "PF_NFC" },
225#endif
226#ifdef PF_VSOCK
227 { PF_VSOCK, "PF_VSOCK" },
228#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 { 0, NULL },
230};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000231const struct xlat addrfams[] = {
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000232#ifdef AF_UNSPEC
233 { AF_UNSPEC, "AF_UNSPEC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000234#endif
235#ifdef AF_LOCAL
236 { AF_LOCAL, "AF_LOCAL" },
237#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000238#ifdef AF_UNIX
239 { AF_UNIX, "AF_UNIX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000240#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000241#ifdef AF_INET
242 { AF_INET, "AF_INET" },
243#endif
244#ifdef AF_AX25
245 { AF_AX25, "AF_AX25" },
246#endif
247#ifdef AF_IPX
248 { AF_IPX, "AF_IPX" },
249#endif
250#ifdef AF_APPLETALK
251 { AF_APPLETALK, "AF_APPLETALK" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000252#endif
253#ifdef AF_NETROM
254 { AF_NETROM, "AF_NETROM" },
255#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000256#ifdef AF_BRIDGE
257 { AF_BRIDGE, "AF_BRIDGE" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000258#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000259#ifdef AF_ATMPVC
260 { AF_ATMPVC, "AF_ATMPVC" },
261#endif
262#ifdef AF_X25
263 { AF_X25, "AF_X25" },
264#endif
265#ifdef AF_INET6
266 { AF_INET6, "AF_INET6" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000267#endif
268#ifdef AF_ROSE
269 { AF_ROSE, "AF_ROSE" },
270#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000271#ifdef AF_DECnet
272 { AF_DECnet, "AF_DECnet" },
273#endif
274#ifdef AF_NETBEUI
275 { AF_NETBEUI, "AF_NETBEUI" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000276#endif
277#ifdef AF_SECURITY
278 { AF_SECURITY, "AF_SECURITY" },
279#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000280#ifdef AF_KEY
281 { AF_KEY, "AF_KEY" },
282#endif
283#ifdef AF_NETLINK
284 { AF_NETLINK, "AF_NETLINK" },
285#endif
286#ifdef AF_ROUTE
287 { AF_ROUTE, "AF_ROUTE" },
288#endif
289#ifdef AF_PACKET
290 { AF_PACKET, "AF_PACKET" },
291#endif
292#ifdef AF_ASH
293 { AF_ASH, "AF_ASH" },
294#endif
295#ifdef AF_ECONET
296 { AF_ECONET, "AF_ECONET" },
297#endif
298#ifdef AF_ATMSVC
299 { AF_ATMSVC, "AF_ATMSVC" },
300#endif
301#ifdef AF_RDS
302 { AF_RDS, "AF_RDS" },
303#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000304#ifdef AF_SNA
305 { AF_SNA, "AF_SNA" },
306#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000307#ifdef AF_IRDA
308 { AF_IRDA, "AF_IRDA" },
309#endif
310#ifdef AF_PPPOX
311 { AF_PPPOX, "AF_PPPOX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000312#endif
313#ifdef AF_WANPIPE
314 { AF_WANPIPE, "AF_WANPIPE" },
315#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000316#ifdef AF_LLC
317 { AF_LLC, "AF_LLC" },
318#endif
319#ifdef AF_CAN
320 { AF_CAN, "AF_CAN" },
321#endif
322#ifdef AF_TIPC
323 { AF_TIPC, "AF_TIPC" },
324#endif
325#ifdef AF_BLUETOOTH
326 { AF_BLUETOOTH, "AF_BLUETOOTH" },
327#endif
328#ifdef AF_IUCV
329 { AF_IUCV, "AF_IUCV" },
330#endif
331#ifdef AF_RXRPC
332 { AF_RXRPC, "AF_RXRPC" },
333#endif
334#ifdef AF_ISDN
335 { AF_ISDN, "AF_ISDN" },
336#endif
337#ifdef AF_PHONET
338 { AF_PHONET, "AF_PHONET" },
339#endif
340#ifdef AF_IEEE802154
341 { AF_IEEE802154,"AF_IEEE802154" },
342#endif
343#ifdef AF_CAIF
344 { AF_CAIF, "AF_CAIF" },
345#endif
346#ifdef AF_ALG
347 { AF_ALG, "AF_ALG" },
348#endif
349#ifdef AF_NFC
350 { AF_NFC, "AF_NFC" },
351#endif
352#ifdef AF_VSOCK
353 { AF_VSOCK, "AF_VSOCK" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000354#endif
355 { 0, NULL },
356};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000357static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 { SOCK_STREAM, "SOCK_STREAM" },
359 { SOCK_DGRAM, "SOCK_DGRAM" },
360#ifdef SOCK_RAW
361 { SOCK_RAW, "SOCK_RAW" },
362#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000363#ifdef SOCK_RDM
364 { SOCK_RDM, "SOCK_RDM" },
365#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366#ifdef SOCK_SEQPACKET
367 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
368#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000369#ifdef SOCK_DCCP
370 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371#endif
372#ifdef SOCK_PACKET
373 { SOCK_PACKET, "SOCK_PACKET" },
374#endif
375 { 0, NULL },
376};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000377static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000378#ifdef SOCK_CLOEXEC
379 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
380#endif
381#ifdef SOCK_NONBLOCK
382 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
383#endif
384 { 0, NULL },
385};
386#ifndef SOCK_TYPE_MASK
387# define SOCK_TYPE_MASK 0xf
388#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000389static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000390#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000391 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000392#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000393#if defined(SOL_ICMP)
394 { SOL_ICMP, "SOL_ICMP" },
395#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000396#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000397 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000398#endif
399#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000400 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000401#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000402#if defined(SOL_IPV6)
403 { SOL_IPV6, "SOL_IPV6" },
404#endif
405#if defined(SOL_ICMPV6)
406 { SOL_ICMPV6, "SOL_ICMPV6" },
407#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100408#if defined(SOL_SCTP)
409 { SOL_SCTP, "SOL_SCTP" },
410#endif
411#if defined(SOL_UDPLITE)
412 { SOL_UDPLITE, "SOL_UDPLITE" },
413#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000414#if defined(SOL_RAW)
415 { SOL_RAW, "SOL_RAW" },
416#endif
417#if defined(SOL_IPX)
418 { SOL_IPX, "SOL_IPX" },
419#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000420#if defined(SOL_AX25)
421 { SOL_AX25, "SOL_AX25" },
422#endif
423#if defined(SOL_ATALK)
424 { SOL_ATALK, "SOL_ATALK" },
425#endif
426#if defined(SOL_NETROM)
427 { SOL_NETROM, "SOL_NETROM" },
428#endif
429#if defined(SOL_ROSE)
430 { SOL_ROSE, "SOL_ROSE" },
431#endif
432#if defined(SOL_DECNET)
433 { SOL_DECNET, "SOL_DECNET" },
434#endif
435#if defined(SOL_X25)
436 { SOL_X25, "SOL_X25" },
437#endif
438#if defined(SOL_PACKET)
439 { SOL_PACKET, "SOL_PACKET" },
440#endif
441#if defined(SOL_ATM)
442 { SOL_ATM, "SOL_ATM" },
443#endif
444#if defined(SOL_AAL)
445 { SOL_AAL, "SOL_AAL" },
446#endif
447#if defined(SOL_IRDA)
448 { SOL_IRDA, "SOL_IRDA" },
449#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100450#if defined(SOL_NETBEUI)
451 { SOL_NETBEUI, "SOL_NETBEUI" },
452#endif
453#if defined(SOL_LLC)
454 { SOL_LLC, "SOL_LLC" },
455#endif
456#if defined(SOL_DCCP)
457 { SOL_DCCP, "SOL_DCCP" },
458#endif
459#if defined(SOL_NETLINK)
460 { SOL_NETLINK, "SOL_NETLINK" },
461#endif
462#if defined(SOL_TIPC)
463 { SOL_TIPC, "SOL_TIPC" },
464#endif
465#if defined(SOL_RXRPC)
466 { SOL_RXRPC, "SOL_RXRPC" },
467#endif
468#if defined(SOL_PPPOL2TP)
469 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
470#endif
471#if defined(SOL_BLUETOOTH)
472 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
473#endif
474#if defined(SOL_PNPIPE)
475 { SOL_PNPIPE, "SOL_PNPIPE" },
476#endif
477#if defined(SOL_RDS)
478 { SOL_RDS, "SOL_RDS" },
479#endif
480#if defined(SOL_IUVC)
481 { SOL_IUCV, "SOL_IUCV" },
482#endif
483#if defined(SOL_CAIF)
484 { SOL_CAIF, "SOL_CAIF" },
485#endif
John Hughes61563572001-03-27 16:47:36 +0000486 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000487 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000488};
John Hughes93f7fcc2002-05-22 15:46:49 +0000489/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
490 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000491static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 { IPPROTO_IP, "IPPROTO_IP" },
493 { IPPROTO_ICMP, "IPPROTO_ICMP" },
494 { IPPROTO_TCP, "IPPROTO_TCP" },
495 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000496#ifdef IPPROTO_IGMP
497 { IPPROTO_IGMP, "IPPROTO_IGMP" },
498#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499#ifdef IPPROTO_GGP
500 { IPPROTO_GGP, "IPPROTO_GGP" },
501#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000502#ifdef IPPROTO_IPIP
503 { IPPROTO_IPIP, "IPPROTO_IPIP" },
504#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505#ifdef IPPROTO_EGP
506 { IPPROTO_EGP, "IPPROTO_EGP" },
507#endif
508#ifdef IPPROTO_PUP
509 { IPPROTO_PUP, "IPPROTO_PUP" },
510#endif
511#ifdef IPPROTO_IDP
512 { IPPROTO_IDP, "IPPROTO_IDP" },
513#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000514#ifdef IPPROTO_TP
515 { IPPROTO_TP, "IPPROTO_TP" },
516#endif
517#ifdef IPPROTO_DCCP
518 { IPPROTO_DCCP, "IPPROTO_DCCP" },
519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520#ifdef IPPROTO_IPV6
521 { IPPROTO_IPV6, "IPPROTO_IPV6" },
522#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000523#ifdef IPPROTO_ROUTING
524 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000526#ifdef IPPROTO_FRAGMENT
527 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
528#endif
529#ifdef IPPROTO_RSVP
530 { IPPROTO_RSVP, "IPPROTO_RSVP" },
531#endif
532#ifdef IPPROTO_GRE
533 { IPPROTO_GRE, "IPPROTO_GRE" },
534#endif
535#ifdef IPPROTO_ESP
536 { IPPROTO_ESP, "IPPROTO_ESP" },
537#endif
538#ifdef IPPROTO_AH
539 { IPPROTO_AH, "IPPROTO_AH" },
540#endif
541#ifdef IPPROTO_ICMPV6
542 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
543#endif
544#ifdef IPPROTO_NONE
545 { IPPROTO_NONE, "IPPROTO_NONE" },
546#endif
547#ifdef IPPROTO_DSTOPTS
548 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#endif
550#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000551 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552#endif
553#ifdef IPPROTO_ND
554 { IPPROTO_ND, "IPPROTO_ND" },
555#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000556#ifdef IPPROTO_MTP
557 { IPPROTO_MTP, "IPPROTO_MTP" },
558#endif
559#ifdef IPPROTO_ENCAP
560 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
561#endif
562#ifdef IPPROTO_PIM
563 { IPPROTO_PIM, "IPPROTO_PIM" },
564#endif
565#ifdef IPPROTO_COMP
566 { IPPROTO_COMP, "IPPROTO_COMP" },
567#endif
568#ifdef IPPROTO_SCTP
569 { IPPROTO_SCTP, "IPPROTO_SCTP" },
570#endif
571#ifdef IPPROTO_UDPLITE
572 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
573#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574#ifdef IPPROTO_RAW
575 { IPPROTO_RAW, "IPPROTO_RAW" },
576#endif
577#ifdef IPPROTO_MAX
578 { IPPROTO_MAX, "IPPROTO_MAX" },
579#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580 { 0, NULL },
581};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000582static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000583 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000585 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000587#ifdef MSG_DONTROUTE
588 { MSG_DONTROUTE, "MSG_DONTROUTE" },
589#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000591 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000593#ifdef MSG_PROBE
594 { MSG_PROBE, "MSG_PROBE" },
595#endif
596#ifdef MSG_TRUNC
597 { MSG_TRUNC, "MSG_TRUNC" },
598#endif
599#ifdef MSG_DONTWAIT
600 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601#endif
602#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000603 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604#endif
605#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000606 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000608#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000609 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000610#endif
611#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000612 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000613#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000614#ifdef MSG_CONFIRM
615 { MSG_CONFIRM, "MSG_CONFIRM" },
616#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000617#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000618 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000619#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000620#ifdef MSG_ERRQUEUE
621 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
622#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000623#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000624 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000625#endif
626#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000627 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000628#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000629#ifdef MSG_WAITFORONE
630 { MSG_WAITFORONE, "MSG_WAITFORONE" },
631#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000632#ifdef MSG_EOF
633 { MSG_EOF, "MSG_EOF" },
634#endif
635#ifdef MSG_FASTOPEN
636 { MSG_FASTOPEN, "MSG_FASTOPEN" },
637#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000638#ifdef MSG_CMSG_CLOEXEC
639 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
640#endif
641 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642};
643
Roland McGrathd9f816f2004-09-04 03:39:20 +0000644static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000646 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000647#endif
648#ifdef SO_ALLRAW
649 { SO_ALLRAW, "SO_ALLRAW" },
650#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000651#ifdef SO_ATTACH_FILTER
652 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
653#endif
654#ifdef SO_BINDTODEVICE
655 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
656#endif
657#ifdef SO_BROADCAST
658 { SO_BROADCAST, "SO_BROADCAST" },
659#endif
660#ifdef SO_BSDCOMPAT
661 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
662#endif
663#ifdef SO_DEBUG
664 { SO_DEBUG, "SO_DEBUG" },
665#endif
666#ifdef SO_DETACH_FILTER
667 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
668#endif
669#ifdef SO_DONTROUTE
670 { SO_DONTROUTE, "SO_DONTROUTE" },
671#endif
672#ifdef SO_ERROR
673 { SO_ERROR, "SO_ERROR" },
674#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000675#ifdef SO_ICS
676 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000678#ifdef SO_IMASOCKET
679 { SO_IMASOCKET, "SO_IMASOCKET" },
680#endif
681#ifdef SO_KEEPALIVE
682 { SO_KEEPALIVE, "SO_KEEPALIVE" },
683#endif
684#ifdef SO_LINGER
685 { SO_LINGER, "SO_LINGER" },
686#endif
687#ifdef SO_LISTENING
688 { SO_LISTENING, "SO_LISTENING" },
689#endif
690#ifdef SO_MGMT
691 { SO_MGMT, "SO_MGMT" },
692#endif
693#ifdef SO_NO_CHECK
694 { SO_NO_CHECK, "SO_NO_CHECK" },
695#endif
696#ifdef SO_OOBINLINE
697 { SO_OOBINLINE, "SO_OOBINLINE" },
698#endif
699#ifdef SO_ORDREL
700 { SO_ORDREL, "SO_ORDREL" },
701#endif
702#ifdef SO_PARALLELSVR
703 { SO_PARALLELSVR, "SO_PARALLELSVR" },
704#endif
705#ifdef SO_PASSCRED
706 { SO_PASSCRED, "SO_PASSCRED" },
707#endif
708#ifdef SO_PEERCRED
709 { SO_PEERCRED, "SO_PEERCRED" },
710#endif
711#ifdef SO_PEERNAME
712 { SO_PEERNAME, "SO_PEERNAME" },
713#endif
714#ifdef SO_PEERSEC
715 { SO_PEERSEC, "SO_PEERSEC" },
716#endif
717#ifdef SO_PRIORITY
718 { SO_PRIORITY, "SO_PRIORITY" },
719#endif
720#ifdef SO_PROTOTYPE
721 { SO_PROTOTYPE, "SO_PROTOTYPE" },
722#endif
723#ifdef SO_RCVBUF
724 { SO_RCVBUF, "SO_RCVBUF" },
725#endif
726#ifdef SO_RCVLOWAT
727 { SO_RCVLOWAT, "SO_RCVLOWAT" },
728#endif
729#ifdef SO_RCVTIMEO
730 { SO_RCVTIMEO, "SO_RCVTIMEO" },
731#endif
732#ifdef SO_RDWR
733 { SO_RDWR, "SO_RDWR" },
734#endif
735#ifdef SO_REUSEADDR
736 { SO_REUSEADDR, "SO_REUSEADDR" },
737#endif
738#ifdef SO_REUSEPORT
739 { SO_REUSEPORT, "SO_REUSEPORT" },
740#endif
741#ifdef SO_SECURITY_AUTHENTICATION
742 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
743#endif
744#ifdef SO_SECURITY_ENCRYPTION_NETWORK
745 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
746#endif
747#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
748 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
749#endif
750#ifdef SO_SEMA
751 { SO_SEMA, "SO_SEMA" },
752#endif
753#ifdef SO_SNDBUF
754 { SO_SNDBUF, "SO_SNDBUF" },
755#endif
756#ifdef SO_SNDLOWAT
757 { SO_SNDLOWAT, "SO_SNDLOWAT" },
758#endif
759#ifdef SO_SNDTIMEO
760 { SO_SNDTIMEO, "SO_SNDTIMEO" },
761#endif
762#ifdef SO_TIMESTAMP
763 { SO_TIMESTAMP, "SO_TIMESTAMP" },
764#endif
765#ifdef SO_TYPE
766 { SO_TYPE, "SO_TYPE" },
767#endif
768#ifdef SO_USELOOPBACK
769 { SO_USELOOPBACK, "SO_USELOOPBACK" },
770#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 { 0, NULL },
772};
773
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100774#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000775#define SOL_IP IPPROTO_IP
776#endif
777
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000779static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000780#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000781 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000782#endif
783#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000784 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000785#endif
786#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000787 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000789#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000790 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000791#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000792#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000793 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000794#endif
795#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000796 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
797#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000798#ifdef IP_RECVOPTS
799 { IP_RECVOPTS, "IP_RECVOPTS" },
800#endif
801#ifdef IP_RECVRETOPTS
802 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
803#endif
804#ifdef IP_RECVDSTADDR
805 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
806#endif
807#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000808 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000809#endif
810#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000811 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000812#endif
813#ifdef IP_PKTOPTIONS
814 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
815#endif
816#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000817 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000818#endif
819#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000820 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000821#endif
822#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000823 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000824#endif
825#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000826 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000827#endif
828#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000829 { IP_MTU, "IP_MTU" },
830#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000831#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000832 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000833#endif
834#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000835 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000836#endif
837#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000838 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000839#endif
840#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000841 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000842#endif
843#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000844 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000845#endif
846#ifdef IP_BROADCAST_IF
847 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
848#endif
849#ifdef IP_RECVIFINDEX
850 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
851#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000852#ifdef IP_MSFILTER
853 { IP_MSFILTER, "IP_MSFILTER" },
854#endif
855#ifdef MCAST_MSFILTER
856 { MCAST_MSFILTER, "MCAST_MSFILTER" },
857#endif
858#ifdef IP_FREEBIND
859 { IP_FREEBIND, "IP_FREEBIND" },
860#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000861 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000862};
863#endif /* SOL_IP */
864
Roland McGrath4f6ba692004-08-31 07:01:26 +0000865#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000866static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000867#ifdef IPV6_ADDRFORM
868 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
869#endif
870#ifdef MCAST_FILTER
871 { MCAST_FILTER, "MCAST_FILTER" },
872#endif
873#ifdef IPV6_PKTOPTIONS
874 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
875#endif
876#ifdef IPV6_MTU
877 { IPV6_MTU, "IPV6_MTU" },
878#endif
879#ifdef IPV6_V6ONLY
880 { IPV6_V6ONLY, "IPV6_V6ONLY" },
881#endif
882#ifdef IPV6_PKTINFO
883 { IPV6_PKTINFO, "IPV6_PKTINFO" },
884#endif
885#ifdef IPV6_HOPLIMIT
886 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
887#endif
888#ifdef IPV6_RTHDR
889 { IPV6_RTHDR, "IPV6_RTHDR" },
890#endif
891#ifdef IPV6_HOPOPTS
892 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
893#endif
894#ifdef IPV6_DSTOPTS
895 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
896#endif
897#ifdef IPV6_FLOWINFO
898 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
899#endif
900#ifdef IPV6_UNICAST_HOPS
901 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
902#endif
903#ifdef IPV6_MULTICAST_HOPS
904 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
905#endif
906#ifdef IPV6_MULTICAST_LOOP
907 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
908#endif
909#ifdef IPV6_MULTICAST_IF
910 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
911#endif
912#ifdef IPV6_MTU_DISCOVER
913 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
914#endif
915#ifdef IPV6_RECVERR
916 { IPV6_RECVERR, "IPV6_RECVERR" },
917#endif
918#ifdef IPV6_FLOWINFO_SEND
919 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
920#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000921#ifdef IPV6_ADD_MEMBERSHIP
922 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
923#endif
924#ifdef IPV6_DROP_MEMBERSHIP
925 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
926#endif
927#ifdef IPV6_ROUTER_ALERT
928 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
929#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000930 { 0, NULL },
931};
932#endif /* SOL_IPV6 */
933
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000935static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200936 { IPX_TYPE, "IPX_TYPE" },
937 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938};
939#endif /* SOL_IPX */
940
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000941#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000942static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000943#if defined(ICMP_FILTER)
944 { ICMP_FILTER, "ICMP_FILTER" },
945#endif
946 { 0, NULL },
947};
948#endif /* SOL_RAW */
949
950#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000951static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000952#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000953 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000954#endif
955#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000956 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000957#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000958#if defined(PACKET_RECV_OUTPUT)
959 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
960#endif
961#if defined(PACKET_RX_RING)
962 { PACKET_RX_RING, "PACKET_RX_RING" },
963#endif
964#if defined(PACKET_STATISTICS)
965 { PACKET_STATISTICS, "PACKET_STATISTICS" },
966#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000967#if defined(PACKET_COPY_THRESH)
968 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
969#endif
970#if defined(PACKET_AUXDATA)
971 { PACKET_AUXDATA, "PACKET_AUXDATA" },
972#endif
973#if defined(PACKET_ORIGDEV)
974 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
975#endif
976#if defined(PACKET_VERSION)
977 { PACKET_VERSION, "PACKET_VERSION" },
978#endif
979#if defined(PACKET_HDRLEN)
980 { PACKET_HDRLEN, "PACKET_HDRLEN" },
981#endif
982#if defined(PACKET_RESERVE)
983 { PACKET_RESERVE, "PACKET_RESERVE" },
984#endif
985#if defined(PACKET_TX_RING)
986 { PACKET_TX_RING, "PACKET_TX_RING" },
987#endif
988#if defined(PACKET_LOSS)
989 { PACKET_LOSS, "PACKET_LOSS" },
990#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000991 { 0, NULL },
992};
993#endif /* SOL_PACKET */
994
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100995#ifdef SOL_SCTP
996static const struct xlat socksctpoptions[] = {
997#if defined(SCTP_RTOINFO)
998 { SCTP_RTOINFO, "SCTP_RTOINFO" },
999#endif
1000#if defined(SCTP_ASSOCINFO)
1001 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
1002#endif
1003#if defined(SCTP_INITMSG)
1004 { SCTP_INITMSG, "SCTP_INITMSG" },
1005#endif
1006#if defined(SCTP_NODELAY)
1007 { SCTP_NODELAY, "SCTP_NODELAY" },
1008#endif
1009#if defined(SCTP_AUTOCLOSE)
1010 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
1011#endif
1012#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
1013 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
1014#endif
1015#if defined(SCTP_PRIMARY_ADDR)
1016 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
1017#endif
1018#if defined(SCTP_ADAPTATION_LAYER)
1019 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
1020#endif
1021#if defined(SCTP_DISABLE_FRAGMENTS)
1022 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
1023#endif
1024#if defined(SCTP_PEER_ADDR_PARAMS)
1025 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
1026#endif
1027#if defined(SCTP_DEFAULT_SEND_PARAM)
1028 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
1029#endif
1030#if defined(SCTP_EVENTS)
1031 { SCTP_EVENTS, "SCTP_EVENTS" },
1032#endif
1033#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
1034 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
1035#endif
1036#if defined(SCTP_MAXSEG)
1037 { SCTP_MAXSEG, "SCTP_MAXSEG" },
1038#endif
1039#if defined(SCTP_STATUS)
1040 { SCTP_STATUS, "SCTP_STATUS" },
1041#endif
1042#if defined(SCTP_GET_PEER_ADDR_INFO)
1043 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
1044#endif
1045#if defined(SCTP_DELAYED_ACK)
1046 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1047#endif
1048#if defined(SCTP_CONTEXT)
1049 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1050#endif
1051#if defined(SCTP_FRAGMENT_INTERLEAVE)
1052 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1053#endif
1054#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1055 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1056#endif
1057#if defined(SCTP_MAX_BURST)
1058 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1059#endif
1060#if defined(SCTP_AUTH_CHUNK)
1061 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1062#endif
1063#if defined(SCTP_HMAC_IDENT)
1064 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1065#endif
1066#if defined(SCTP_AUTH_KEY)
1067 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1068#endif
1069#if defined(SCTP_AUTH_ACTIVE_KEY)
1070 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1071#endif
1072#if defined(SCTP_AUTH_DELETE_KEY)
1073 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1074#endif
1075#if defined(SCTP_PEER_AUTH_CHUNKS)
1076 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1077#endif
1078#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1079 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1080#endif
1081#if defined(SCTP_GET_ASSOC_NUMBER)
1082 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1083#endif
1084
1085 /* linux specific things */
1086#if defined(SCTP_SOCKOPT_BINDX_ADD)
1087 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1088#endif
1089#if defined(SCTP_SOCKOPT_BINDX_REM)
1090 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1091#endif
1092#if defined(SCTP_SOCKOPT_PEELOFF)
1093 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1094#endif
1095#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1096 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1097#endif
1098#if defined(SCTP_GET_PEER_ADDRS_OLD)
1099 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1100#endif
1101#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1102 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1103#endif
1104#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1105 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1106#endif
1107#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1108 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1109#endif
1110#if defined(SCTP_GET_PEER_ADDRS)
1111 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1112#endif
1113#if defined(SCTP_GET_LOCAL_ADDRS)
1114 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1115#endif
1116
1117 { 0, NULL },
1118};
1119#endif
1120
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001121#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001122#define SOL_TCP IPPROTO_TCP
1123#endif
1124
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001126static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001127 { TCP_NODELAY, "TCP_NODELAY" },
1128 { TCP_MAXSEG, "TCP_MAXSEG" },
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001129#ifdef TCP_CORK
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001130 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001131#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001132#ifdef TCP_KEEPIDLE
1133 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001134#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001135#ifdef TCP_KEEPINTVL
1136 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001137#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001138#ifdef TCP_KEEPCNT
1139 { TCP_KEEPCNT, "TCP_KEEPCNT" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001140#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001141#ifdef TCP_SYNCNT
1142 { TCP_SYNCNT, "TCP_SYNCNT" },
John Hughes38ae88d2002-05-23 11:48:58 +00001143#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001144#ifdef TCP_LINGER2
1145 { TCP_LINGER2, "TCP_LINGER2" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001146#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001147#ifdef TCP_DEFER_ACCEPT
1148 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001149#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001150#ifdef TCP_WINDOW_CLAMP
1151 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001152#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001153#ifdef TCP_INFO
1154 { TCP_INFO, "TCP_INFO" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001155#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001156#ifdef TCP_QUICKACK
1157 { TCP_QUICKACK, "TCP_QUICKACK" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001158#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001159#ifdef TCP_CONGESTION
1160 { TCP_CONGESTION, "TCP_CONGESTION" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001161#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001162#ifdef TCP_MD5SIG
1163 { TCP_MD5SIG, "TCP_MD5SIG" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001164#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001165#ifdef TCP_COOKIE_TRANSACTIONS
1166 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001167#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001168#ifdef TCP_THIN_LINEAR_TIMEOUTS
1169 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001170#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001171#ifdef TCP_THIN_DUPACK
1172 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001173#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001174#ifdef TCP_USER_TIMEOUT
1175 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001176#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001177#ifdef TCP_REPAIR
1178 { TCP_REPAIR, "TCP_REPAIR" },
1179#endif
1180#ifdef TCP_REPAIR_QUEUE
1181 { TCP_REPAIR_QUEUE, "TCP_REPAIR_QUEUE" },
1182#endif
1183#ifdef TCP_QUEUE_SEQ
1184 { TCP_QUEUE_SEQ, "TCP_QUEUE_SEQ" },
1185#endif
1186#ifdef TCP_REPAIR_OPTIONS
1187 { TCP_REPAIR_OPTIONS, "TCP_REPAIR_OPTIONS" },
1188#endif
1189#ifdef TCP_FASTOPEN
1190 { TCP_FASTOPEN, "TCP_FASTOPEN" },
1191#endif
1192#ifdef TCP_TIMESTAMP
1193 { TCP_TIMESTAMP, "TCP_TIMESTAMP" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001194#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001195 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196};
1197#endif /* SOL_TCP */
1198
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001199#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001200static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001201#if defined(ICMP_ECHOREPLY)
1202 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1203#endif
1204#if defined(ICMP_DEST_UNREACH)
1205 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1206#endif
1207#if defined(ICMP_SOURCE_QUENCH)
1208 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1209#endif
1210#if defined(ICMP_REDIRECT)
1211 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1212#endif
1213#if defined(ICMP_ECHO)
1214 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1215#endif
1216#if defined(ICMP_TIME_EXCEEDED)
1217 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1218#endif
1219#if defined(ICMP_PARAMETERPROB)
1220 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1221#endif
1222#if defined(ICMP_TIMESTAMP)
1223 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1224#endif
1225#if defined(ICMP_TIMESTAMPREPLY)
1226 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1227#endif
1228#if defined(ICMP_INFO_REQUEST)
1229 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1230#endif
1231#if defined(ICMP_INFO_REPLY)
1232 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1233#endif
1234#if defined(ICMP_ADDRESS)
1235 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1236#endif
1237#if defined(ICMP_ADDRESSREPLY)
1238 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1239#endif
1240 { 0, NULL },
1241};
1242#endif /* SOL_RAW */
1243
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001244#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001245static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001246#if defined(PACKET_HOST)
1247 { PACKET_HOST, "PACKET_HOST" },
1248#endif
1249#if defined(PACKET_BROADCAST)
1250 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1251#endif
1252#if defined(PACKET_MULTICAST)
1253 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1254#endif
1255#if defined(PACKET_OTHERHOST)
1256 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1257#endif
1258#if defined(PACKET_OUTGOING)
1259 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1260#endif
1261#if defined(PACKET_LOOPBACK)
1262 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1263#endif
1264#if defined(PACKET_FASTROUTE)
1265 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1266#endif
1267 { 0, NULL },
1268};
1269#endif /* defined(AF_PACKET) */
1270
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001272printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001274 union {
1275 char pad[128];
1276 struct sockaddr sa;
1277 struct sockaddr_in sin;
1278 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001279#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001280 struct sockaddr_in6 sa6;
1281#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001282#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001283 struct sockaddr_ipx sipx;
1284#endif
1285#ifdef AF_PACKET
1286 struct sockaddr_ll ll;
1287#endif
1288#ifdef AF_NETLINK
1289 struct sockaddr_nl nl;
1290#endif
1291 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001292 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293
1294 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 return;
1297 }
1298 if (!verbose(tcp)) {
1299 tprintf("%#lx", addr);
1300 return;
1301 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001302
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001303 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1304 addrlen = sizeof(addrbuf);
1305
1306 memset(&addrbuf, 0, sizeof(addrbuf));
1307 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001308 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 return;
1310 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001311 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001312
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001313 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001314 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001315 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001316
1317 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001318 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001319 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001320 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001321 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001322 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001323 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001324 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001325 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001326 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001327 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328 break;
1329 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001330 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001331 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001333#ifdef HAVE_INET_NTOP
1334 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001335 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001336 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1337 ntohs(addrbuf.sa6.sin6_port), string_addr,
1338 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001339#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001340 {
1341#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001342 int numericscope = 0;
1343 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1344 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1345 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001346
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001347 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1348 numericscope++;
1349 else
1350 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1351 } else
1352 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001353
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001354 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001355#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001356 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001357 }
1358#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001359 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001360#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001361#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001363 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001365 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001366 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 /* Yes, I know, this does not look too
1368 * strace-ish, but otherwise the IPX
1369 * addresses just look monstrous...
1370 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001371 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001373 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001374 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001375 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1376 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377 }
1378 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001379#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001380#ifdef AF_PACKET
1381 case AF_PACKET:
1382 {
1383 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001384 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001385 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001386 addrbuf.ll.sll_ifindex);
1387 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1388 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001389 addrbuf.ll.sll_halen,
1390 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001391 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001392 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1393 }
1394 break;
1395
Denys Vlasenko84703742012-02-25 02:38:52 +01001396#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001397#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001398 case AF_NETLINK:
1399 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1400 break;
1401#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001403 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404
1405 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001406 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001408 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 break;
1410 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001411 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412}
1413
1414#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001415static const struct xlat scmvals[] = {
1416#ifdef SCM_RIGHTS
1417 { SCM_RIGHTS, "SCM_RIGHTS" },
1418#endif
1419#ifdef SCM_CREDENTIALS
1420 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1421#endif
1422 { 0, NULL }
1423};
1424
1425static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001426printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001427{
Roland McGrathaa524c82005-06-01 19:22:06 +00001428 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1429 NULL : malloc(len);
1430 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001431 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001432 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001433 return;
1434 }
1435
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001436 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001437 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001438 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001439
Roland McGrathaa524c82005-06-01 19:22:06 +00001440 if (cmsg->cmsg_level == SOL_SOCKET) {
1441 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001442
Roland McGrathaa524c82005-06-01 19:22:06 +00001443 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1444 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1445
1446 if (cmsg->cmsg_type == SCM_RIGHTS
1447 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001448 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001449 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001450
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001451 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001452 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001453 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001454 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001455 tprintf("%d", *fds++);
1456 first = 0;
1457 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001458 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001459 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001460 return;
1461 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001462 if (cmsg->cmsg_type == SCM_CREDENTIALS
1463 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001464 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001465
Roland McGrath50770822004-10-06 22:11:51 +00001466 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1467 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001468 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001469 return;
1470 }
1471 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001472 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001473 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001474}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001475
1476static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001477do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +01001478{
1479 tprintf("{msg_name(%d)=", msg->msg_namelen);
1480 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1481
1482 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001483 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
1484 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +01001485
1486#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1487 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1488 if (msg->msg_controllen)
1489 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1490 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001491 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001492 printflags(msg_flags, msg->msg_flags, "MSG_???");
1493#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1494 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1495 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1496#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001497 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001498}
1499
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001500struct msghdr32 {
1501 uint32_t /* void* */ msg_name;
1502 uint32_t /* socklen_t */msg_namelen;
1503 uint32_t /* iovec* */ msg_iov;
1504 uint32_t /* size_t */ msg_iovlen;
1505 uint32_t /* void* */ msg_control;
1506 uint32_t /* size_t */ msg_controllen;
1507 uint32_t /* int */ msg_flags;
1508};
1509struct mmsghdr32 {
1510 struct msghdr32 msg_hdr;
1511 uint32_t /* unsigned */ msg_len;
1512};
1513
Andreas Schwab0873f292010-02-12 21:39:12 +01001514static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001515printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001516{
1517 struct msghdr msg;
1518
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001519#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1520 if (current_wordsize == 4) {
1521 struct msghdr32 msg32;
1522
1523 if (umove(tcp, addr, &msg32) < 0) {
1524 tprintf("%#lx", addr);
1525 return;
1526 }
1527 msg.msg_name = (void*)(long)msg32.msg_name;
1528 msg.msg_namelen = msg32.msg_namelen;
1529 msg.msg_iov = (void*)(long)msg32.msg_iov;
1530 msg.msg_iovlen = msg32.msg_iovlen;
1531 msg.msg_control = (void*)(long)msg32.msg_control;
1532 msg.msg_controllen = msg32.msg_controllen;
1533 msg.msg_flags = msg32.msg_flags;
1534 } else
1535#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001536 if (umove(tcp, addr, &msg) < 0) {
1537 tprintf("%#lx", addr);
1538 return;
1539 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001540 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541}
1542
Andreas Schwab0873f292010-02-12 21:39:12 +01001543static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001544printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +01001545{
1546 struct mmsghdr {
1547 struct msghdr msg_hdr;
1548 unsigned msg_len;
1549 } mmsg;
1550
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001551#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1552 if (current_wordsize == 4) {
1553 struct mmsghdr32 mmsg32;
1554
1555 addr += sizeof(mmsg32) * idx;
1556 if (umove(tcp, addr, &mmsg32) < 0) {
1557 tprintf("%#lx", addr);
1558 return;
1559 }
1560 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
1561 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
1562 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
1563 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
1564 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
1565 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
1566 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
1567 mmsg.msg_len = mmsg32.msg_len;
1568 } else
1569#endif
1570 {
1571 addr += sizeof(mmsg) * idx;
1572 if (umove(tcp, addr, &mmsg) < 0) {
1573 tprintf("%#lx", addr);
1574 return;
1575 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001576 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001577 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001578 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +01001579 tprintf(", %u}", mmsg.msg_len);
1580}
Andreas Schwab0873f292010-02-12 21:39:12 +01001581
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001582static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001583decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001584{
1585 /* mmsgvec */
1586 if (syserror(tcp)) {
1587 tprintf("%#lx", tcp->u_arg[1]);
1588 } else {
1589 unsigned int len = tcp->u_rval;
1590 unsigned int i;
1591
1592 tprints("{");
1593 for (i = 0; i < len; ++i) {
1594 if (i)
1595 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001596 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001597 }
1598 tprints("}");
1599 }
1600 /* vlen */
1601 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1602 /* flags */
1603 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1604}
1605
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606#endif /* HAVE_SENDMSG */
1607
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001608/*
1609 * low bits of the socket type define real socket type,
1610 * other bits are socket type flags.
1611 */
1612static void
1613tprint_sock_type(struct tcb *tcp, int flags)
1614{
1615 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1616
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001617 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001618 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001619 flags &= ~SOCK_TYPE_MASK;
1620 if (!flags)
1621 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001622 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001623 }
1624 printflags(sock_type_flags, flags, "SOCK_???");
1625}
1626
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001628sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629{
1630 if (entering(tcp)) {
1631 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001632 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001633 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001634 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635 switch (tcp->u_arg[0]) {
1636 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001637#ifdef PF_INET6
1638 case PF_INET6:
1639#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1641 break;
1642#ifdef PF_IPX
1643 case PF_IPX:
1644 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001645 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001647 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001648 break;
1649#endif /* PF_IPX */
1650 default:
1651 tprintf("%lu", tcp->u_arg[2]);
1652 break;
1653 }
1654 }
1655 return 0;
1656}
1657
John Hughesbdf48f52001-03-06 15:08:09 +00001658int
Denys Vlasenko12014262011-05-30 14:00:14 +02001659sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660{
1661 if (entering(tcp)) {
1662 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001663 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664 tprintf(", %lu", tcp->u_arg[2]);
1665 }
1666 return 0;
1667}
1668
1669int
Denys Vlasenko12014262011-05-30 14:00:14 +02001670sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671{
1672 return sys_bind(tcp);
1673}
1674
1675int
Denys Vlasenko12014262011-05-30 14:00:14 +02001676sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001677{
1678 if (entering(tcp)) {
1679 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1680 }
1681 return 0;
1682}
1683
Paolo Bonzini705ff102009-08-14 12:34:05 +02001684static int
1685do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686{
1687 if (entering(tcp)) {
1688 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001689 return 0;
1690 }
1691 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001692 tprintf("%#lx, NULL", tcp->u_arg[1]);
1693 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001694 int len;
1695 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001696 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697 tprintf("%#lx", tcp->u_arg[1]);
1698 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001699 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001701 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001702 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001703 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001704 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001705 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001706 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1707 "SOCK_???");
1708 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709 return 0;
1710}
1711
1712int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001713sys_accept(struct tcb *tcp)
1714{
1715 return do_accept(tcp, -1);
1716}
1717
Paolo Bonzini705ff102009-08-14 12:34:05 +02001718int
1719sys_accept4(struct tcb *tcp)
1720{
1721 return do_accept(tcp, 3);
1722}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001723
1724int
Denys Vlasenko12014262011-05-30 14:00:14 +02001725sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726{
1727 if (entering(tcp)) {
1728 tprintf("%ld, ", tcp->u_arg[0]);
1729 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1730 tprintf(", %lu, ", tcp->u_arg[2]);
1731 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001732 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 }
1734 return 0;
1735}
1736
1737int
Denys Vlasenko12014262011-05-30 14:00:14 +02001738sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739{
1740 if (entering(tcp)) {
1741 tprintf("%ld, ", tcp->u_arg[0]);
1742 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1743 tprintf(", %lu, ", tcp->u_arg[2]);
1744 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001745 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001746 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001747 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001748 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749 /* to length */
1750 tprintf(", %lu", tcp->u_arg[5]);
1751 }
1752 return 0;
1753}
1754
1755#ifdef HAVE_SENDMSG
1756
1757int
Denys Vlasenko12014262011-05-30 14:00:14 +02001758sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759{
1760 if (entering(tcp)) {
1761 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levin043b5f82012-05-01 20:30:02 +00001762 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001764 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001765 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 }
1767 return 0;
1768}
1769
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001770int
1771sys_sendmmsg(struct tcb *tcp)
1772{
1773 if (entering(tcp)) {
1774 /* sockfd */
1775 tprintf("%d, ", (int) tcp->u_arg[0]);
1776 if (!verbose(tcp)) {
1777 tprintf("%#lx, %u, ",
1778 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1779 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1780 }
1781 } else {
1782 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001783 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001784 }
1785 return 0;
1786}
1787
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788#endif /* HAVE_SENDMSG */
1789
1790int
Denys Vlasenko12014262011-05-30 14:00:14 +02001791sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001792{
1793 if (entering(tcp)) {
1794 tprintf("%ld, ", tcp->u_arg[0]);
1795 } else {
1796 if (syserror(tcp))
1797 tprintf("%#lx", tcp->u_arg[1]);
1798 else
1799 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1800
1801 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001802 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803 }
1804 return 0;
1805}
1806
1807int
Denys Vlasenko12014262011-05-30 14:00:14 +02001808sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001809{
1810 int fromlen;
1811
1812 if (entering(tcp)) {
1813 tprintf("%ld, ", tcp->u_arg[0]);
1814 } else {
1815 if (syserror(tcp)) {
1816 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1817 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1818 tcp->u_arg[4], tcp->u_arg[5]);
1819 return 0;
1820 }
1821 /* buf */
1822 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1823 /* len */
1824 tprintf(", %lu, ", tcp->u_arg[2]);
1825 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001826 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 /* from address, len */
1828 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1829 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001830 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001831 else
1832 tprintf(", %#lx", tcp->u_arg[4]);
1833 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001834 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835 else
1836 tprintf(", %#lx", tcp->u_arg[5]);
1837 return 0;
1838 }
1839 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001840 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841 return 0;
1842 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001843 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001844 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845 /* from length */
1846 tprintf(", [%u]", fromlen);
1847 }
1848 return 0;
1849}
1850
1851#ifdef HAVE_SENDMSG
1852
1853int
Denys Vlasenko12014262011-05-30 14:00:14 +02001854sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855{
1856 if (entering(tcp)) {
1857 tprintf("%ld, ", tcp->u_arg[0]);
1858 } else {
1859 if (syserror(tcp) || !verbose(tcp))
1860 tprintf("%#lx", tcp->u_arg[1]);
1861 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001862 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001864 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001865 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 }
1867 return 0;
1868}
1869
Andreas Schwab0873f292010-02-12 21:39:12 +01001870int
1871sys_recvmmsg(struct tcb *tcp)
1872{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001873 /* +5 chars are for "left " prefix */
1874 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001875
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001876 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001877 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001878 if (verbose(tcp)) {
1879 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001880 /* Abusing tcp->auxstr as temp storage.
1881 * Will be used and freed on syscall exit.
1882 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001883 tcp->auxstr = strdup(str);
1884 } else {
1885 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1886 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001887 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001888 print_timespec(tcp, tcp->u_arg[4]);
1889 }
1890 return 0;
1891 } else {
1892 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001893 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001894 /* timeout on entrance */
1895 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1896 free((void *) tcp->auxstr);
1897 tcp->auxstr = NULL;
1898 }
1899 if (syserror(tcp))
1900 return 0;
1901 if (tcp->u_rval == 0) {
1902 tcp->auxstr = "Timeout";
1903 return RVAL_STR;
1904 }
1905 if (!verbose(tcp))
1906 return 0;
1907 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001908 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001909 tcp->auxstr = str;
1910 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001911 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001912}
Andreas Schwab0873f292010-02-12 21:39:12 +01001913
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914#endif /* HAVE_SENDMSG */
1915
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001916static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001917 { 0, "SHUT_RD" },
1918 { 1, "SHUT_WR" },
1919 { 2, "SHUT_RDWR" },
1920 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001921};
1922
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923int
Denys Vlasenko12014262011-05-30 14:00:14 +02001924sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925{
1926 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001927 tprintf("%ld, ", tcp->u_arg[0]);
1928 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 }
1930 return 0;
1931}
1932
1933int
Denys Vlasenko12014262011-05-30 14:00:14 +02001934sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935{
1936 return sys_accept(tcp);
1937}
1938
1939int
Denys Vlasenko12014262011-05-30 14:00:14 +02001940sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941{
1942 return sys_accept(tcp);
1943}
1944
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001945static int
1946do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 if (exiting(tcp)) {
1949 if (syserror(tcp)) {
1950 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001951 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001952#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001953 int fds[2];
1954
1955 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001956 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001957 else
1958 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001959#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001960 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1961#else
1962 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001964 }
1965 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001966 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001967 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1968 }
1969 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970 return 0;
1971}
1972
1973int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001974sys_pipe(struct tcb *tcp)
1975{
1976 return do_pipe(tcp, -1);
1977}
1978
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001979int
1980sys_pipe2(struct tcb *tcp)
1981{
1982 return do_pipe(tcp, 1);
1983}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001984
1985int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001986sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001987{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989
1990 if (entering(tcp)) {
1991 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001992 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001993 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001994 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995 switch (tcp->u_arg[0]) {
1996 case PF_INET:
1997 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1998 break;
1999#ifdef PF_IPX
2000 case PF_IPX:
2001 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002002 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002003 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002004 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005 break;
2006#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00002007 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002008 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009 break;
2010 }
2011 } else {
2012 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002013 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014 return 0;
2015 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002016 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002017 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018 else
2019 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002020 }
2021 return 0;
2022}
2023
2024int
Dmitry V. Levin31289192009-11-06 18:05:40 +00002025sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026{
2027 if (entering(tcp)) {
2028 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002029 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002030 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031 switch (tcp->u_arg[1]) {
2032 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034 break;
2035#ifdef SOL_IP
2036 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 break;
2039#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002040#ifdef SOL_IPV6
2041 case SOL_IPV6:
2042 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
2043 break;
2044#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045#ifdef SOL_IPX
2046 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048 break;
2049#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002050#ifdef SOL_PACKET
2051 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002052 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002053 break;
2054#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055#ifdef SOL_TCP
2056 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002058 break;
2059#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002060#ifdef SOL_SCTP
2061 case SOL_SCTP:
2062 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
2063 break;
2064#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065
2066 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2067 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00002068 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00002069 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002070 break;
2071 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002072 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00002074 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002075 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002076 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077 tcp->u_arg[3], tcp->u_arg[4]);
2078 return 0;
2079 }
John Hughes93f7fcc2002-05-22 15:46:49 +00002080
2081 switch (tcp->u_arg[1]) {
2082 case SOL_SOCKET:
2083 switch (tcp->u_arg[2]) {
2084#ifdef SO_LINGER
2085 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002086 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00002087 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002088 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00002089 tcp->u_arg[3],
2090 &linger) < 0)
2091 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00002092 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00002093 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00002094 linger.l_onoff,
2095 linger.l_linger,
2096 len);
2097 return 0;
2098 }
2099 break;
2100#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002101#ifdef SO_PEERCRED
2102 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002103 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002104 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002105 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002106 tcp->u_arg[3],
2107 &uc) < 0)
2108 break;
2109 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2110 "[%d]",
2111 (long)uc.pid,
2112 (long)uc.uid,
2113 (long)uc.gid,
2114 len);
2115 return 0;
2116 }
2117 break;
2118#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002119 }
2120 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002121 case SOL_PACKET:
2122 switch (tcp->u_arg[2]) {
2123#ifdef PACKET_STATISTICS
2124 case PACKET_STATISTICS:
2125 if (len == sizeof(struct tpacket_stats)) {
2126 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002127 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002128 tcp->u_arg[3],
2129 &stats) < 0)
2130 break;
2131 tprintf("{packets=%u, drops=%u}, "
2132 "[%d]",
2133 stats.tp_packets,
2134 stats.tp_drops,
2135 len);
2136 return 0;
2137 }
2138 break;
2139#endif
2140 }
2141 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002142 }
2143
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002144 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002145 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002146 }
2147 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002148 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002149 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002150 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151 }
2152 return 0;
2153}
2154
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002155#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002156static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002157{
2158 struct icmp_filter filter;
2159
2160 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002161 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002162 return;
2163 }
2164 if (syserror(tcp) || !verbose(tcp)) {
2165 tprintf("%#lx", addr);
2166 return;
2167 }
2168 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002169 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002170 return;
2171 }
2172
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002173 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002174 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002175 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002176}
2177#endif /* ICMP_FILTER */
2178
John Hughes38ae88d2002-05-23 11:48:58 +00002179static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002180printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002181{
2182 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002183 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002184 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002185 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002186 printxval(sockoptions, name, "SO_???");
2187 switch (name) {
2188#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002189 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002190 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002191 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002192 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002193 break;
2194 tprintf(", {onoff=%d, linger=%d}",
2195 linger.l_onoff,
2196 linger.l_linger);
2197 return 0;
2198 }
2199 break;
2200#endif
2201 }
2202 break;
2203#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002204 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00002205 printxval(sockipoptions, name, "IP_???");
2206 break;
2207#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002208#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002209 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00002210 printxval(sockipv6options, name, "IPV6_???");
2211 break;
2212#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002213#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002214 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00002215 printxval(sockipxoptions, name, "IPX_???");
2216 break;
2217#endif
2218#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002219 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002220 printxval(sockpacketoptions, name, "PACKET_???");
2221 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002222 switch (name) {
2223#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002224 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002225#endif
2226#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002227 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002228#endif
2229#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2230 if (len == sizeof(struct tpacket_req)) {
2231 struct tpacket_req req;
2232 if (umove(tcp, addr, &req) < 0)
2233 break;
2234 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2235 req.tp_block_size,
2236 req.tp_block_nr,
2237 req.tp_frame_size,
2238 req.tp_frame_nr);
2239 return 0;
2240 }
2241 break;
2242#endif /* PACKET_RX_RING || PACKET_TX_RING */
2243 }
John Hughes38ae88d2002-05-23 11:48:58 +00002244 break;
2245#endif
2246#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002247 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00002248 printxval(socktcpoptions, name, "TCP_???");
2249 break;
2250#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002251#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002252 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002253 printxval(socksctpoptions, name, "SCTP_???");
2254 break;
2255#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002256#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002257 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00002258 printxval(sockrawoptions, name, "RAW_???");
2259 switch (name) {
2260#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002261 case ICMP_FILTER:
2262 tprints(", ");
2263 printicmpfilter(tcp, addr);
2264 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002265#endif
2266 }
2267 break;
2268#endif
2269
Roland McGrath6d2b3492002-12-30 00:51:30 +00002270 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002271 * etc. still need work */
2272
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002273 default:
John Hughes38ae88d2002-05-23 11:48:58 +00002274 tprintf("%u", name);
2275 }
2276
2277 /* default arg printing */
2278
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002279 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002280
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002281 if (len == sizeof(int)) {
2282 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002283 }
2284 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002285 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002286 }
2287 return 0;
2288}
2289
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002290#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002291
2292void
Denys Vlasenko12014262011-05-30 14:00:14 +02002293print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002294{
2295 int c = 0;
2296 struct opthdr hdr;
2297
John Hughes2c4e3a82002-05-24 10:19:44 +00002298 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002299 if (umove(tcp, addr, &hdr) < 0) break;
2300 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002301 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002302 }
2303 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002305 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002306 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002307 addr += sizeof hdr;
2308 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002309 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002310 if (hdr.len > 0) {
2311 addr += hdr.len;
2312 len -= hdr.len;
2313 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002314 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002315 }
2316 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002317 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002318 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002319 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002320 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002321}
2322
2323#endif
2324
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325int
Denys Vlasenko12014262011-05-30 14:00:14 +02002326sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002327{
2328 if (entering(tcp)) {
2329 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002330 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002331 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002332 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002333 }
2334 return 0;
2335}