blob: ea785b3e060454ad6b5483e228f0612a9abe64c5 [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
Roland McGrathd9f816f2004-09-04 03:39:20 +000097static const struct xlat domains[] = {
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +000098#ifdef PF_UNSPEC
99 { PF_UNSPEC, "PF_UNSPEC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000100#endif
101#ifdef PF_LOCAL
102 { PF_LOCAL, "PF_LOCAL" },
103#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000104#ifdef PF_UNIX
105 { PF_UNIX, "PF_UNIX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000106#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000107#ifdef PF_INET
108 { PF_INET, "PF_INET" },
109#endif
110#ifdef PF_AX25
111 { PF_AX25, "PF_AX25" },
112#endif
113#ifdef PF_IPX
114 { PF_IPX, "PF_IPX" },
115#endif
116#ifdef PF_APPLETALK
117 { PF_APPLETALK, "PF_APPLETALK" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000118#endif
119#ifdef PF_NETROM
120 { PF_NETROM, "PF_NETROM" },
121#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000122#ifdef PF_BRIDGE
123 { PF_BRIDGE, "PF_BRIDGE" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000124#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000125#ifdef PF_ATMPVC
126 { PF_ATMPVC, "PF_ATMPVC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000127#endif
128#ifdef PF_X25
129 { PF_X25, "PF_X25" },
130#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000131#ifdef PF_INET6
132 { PF_INET6, "PF_INET6" },
133#endif
134#ifdef PF_ROSE
135 { PF_ROSE, "PF_ROSE" },
136#endif
137#ifdef PF_DECnet
138 { PF_DECnet, "PF_DECnet" },
139#endif
140#ifdef PF_NETBEUI
141 { PF_NETBEUI, "PF_NETBEUI" },
142#endif
143#ifdef PF_SECURITY
144 { PF_SECURITY, "PF_SECURITY" },
145#endif
146#ifdef PF_KEY
147 { PF_KEY, "PF_KEY" },
148#endif
149#ifdef PF_NETLINK
150 { PF_NETLINK, "PF_NETLINK" },
151#endif
152#ifdef PF_ROUTE
153 { PF_ROUTE, "PF_ROUTE" },
154#endif
155#ifdef PF_PACKET
156 { PF_PACKET, "PF_PACKET" },
157#endif
158#ifdef PF_ASH
159 { PF_ASH, "PF_ASH" },
160#endif
161#ifdef PF_ECONET
162 { PF_ECONET, "PF_ECONET" },
163#endif
164#ifdef PF_ATMSVC
165 { PF_ATMSVC, "PF_ATMSVC" },
166#endif
167#ifdef PF_RDS
168 { PF_RDS, "PF_RDS" },
169#endif
170#ifdef PF_SNA
171 { PF_SNA, "PF_SNA" },
172#endif
173#ifdef PF_IRDA
174 { PF_IRDA, "PF_IRDA" },
175#endif
176#ifdef PF_PPPOX
177 { PF_PPPOX, "PF_PPPOX" },
178#endif
179#ifdef PF_WANPIPE
180 { PF_WANPIPE, "PF_WANPIPE" },
181#endif
182#ifdef PF_LLC
183 { PF_LLC, "PF_LLC" },
184#endif
185#ifdef PF_CAN
186 { PF_CAN, "PF_CAN" },
187#endif
188#ifdef PF_TIPC
189 { PF_TIPC, "PF_TIPC" },
190#endif
191#ifdef PF_BLUETOOTH
192 { PF_BLUETOOTH, "PF_BLUETOOTH" },
193#endif
194#ifdef PF_IUCV
195 { PF_IUCV, "PF_IUCV" },
196#endif
197#ifdef PF_RXRPC
198 { PF_RXRPC, "PF_RXRPC" },
199#endif
200#ifdef PF_ISDN
201 { PF_ISDN, "PF_ISDN" },
202#endif
203#ifdef PF_PHONET
204 { PF_PHONET, "PF_PHONET" },
205#endif
206#ifdef PF_IEEE802154
207 { PF_IEEE802154,"PF_IEEE802154" },
208#endif
209#ifdef PF_CAIF
210 { PF_CAIF, "PF_CAIF" },
211#endif
212#ifdef PF_ALG
213 { PF_ALG, "PF_ALG" },
214#endif
215#ifdef PF_NFC
216 { PF_NFC, "PF_NFC" },
217#endif
218#ifdef PF_VSOCK
219 { PF_VSOCK, "PF_VSOCK" },
220#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221 { 0, NULL },
222};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000223const struct xlat addrfams[] = {
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000224#ifdef AF_UNSPEC
225 { AF_UNSPEC, "AF_UNSPEC" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000226#endif
227#ifdef AF_LOCAL
228 { AF_LOCAL, "AF_LOCAL" },
229#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000230#ifdef AF_UNIX
231 { AF_UNIX, "AF_UNIX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000232#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000233#ifdef AF_INET
234 { AF_INET, "AF_INET" },
235#endif
236#ifdef AF_AX25
237 { AF_AX25, "AF_AX25" },
238#endif
239#ifdef AF_IPX
240 { AF_IPX, "AF_IPX" },
241#endif
242#ifdef AF_APPLETALK
243 { AF_APPLETALK, "AF_APPLETALK" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000244#endif
245#ifdef AF_NETROM
246 { AF_NETROM, "AF_NETROM" },
247#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000248#ifdef AF_BRIDGE
249 { AF_BRIDGE, "AF_BRIDGE" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000250#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000251#ifdef AF_ATMPVC
252 { AF_ATMPVC, "AF_ATMPVC" },
253#endif
254#ifdef AF_X25
255 { AF_X25, "AF_X25" },
256#endif
257#ifdef AF_INET6
258 { AF_INET6, "AF_INET6" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000259#endif
260#ifdef AF_ROSE
261 { AF_ROSE, "AF_ROSE" },
262#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000263#ifdef AF_DECnet
264 { AF_DECnet, "AF_DECnet" },
265#endif
266#ifdef AF_NETBEUI
267 { AF_NETBEUI, "AF_NETBEUI" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000268#endif
269#ifdef AF_SECURITY
270 { AF_SECURITY, "AF_SECURITY" },
271#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000272#ifdef AF_KEY
273 { AF_KEY, "AF_KEY" },
274#endif
275#ifdef AF_NETLINK
276 { AF_NETLINK, "AF_NETLINK" },
277#endif
278#ifdef AF_ROUTE
279 { AF_ROUTE, "AF_ROUTE" },
280#endif
281#ifdef AF_PACKET
282 { AF_PACKET, "AF_PACKET" },
283#endif
284#ifdef AF_ASH
285 { AF_ASH, "AF_ASH" },
286#endif
287#ifdef AF_ECONET
288 { AF_ECONET, "AF_ECONET" },
289#endif
290#ifdef AF_ATMSVC
291 { AF_ATMSVC, "AF_ATMSVC" },
292#endif
293#ifdef AF_RDS
294 { AF_RDS, "AF_RDS" },
295#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000296#ifdef AF_SNA
297 { AF_SNA, "AF_SNA" },
298#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000299#ifdef AF_IRDA
300 { AF_IRDA, "AF_IRDA" },
301#endif
302#ifdef AF_PPPOX
303 { AF_PPPOX, "AF_PPPOX" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000304#endif
305#ifdef AF_WANPIPE
306 { AF_WANPIPE, "AF_WANPIPE" },
307#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000308#ifdef AF_LLC
309 { AF_LLC, "AF_LLC" },
310#endif
311#ifdef AF_CAN
312 { AF_CAN, "AF_CAN" },
313#endif
314#ifdef AF_TIPC
315 { AF_TIPC, "AF_TIPC" },
316#endif
317#ifdef AF_BLUETOOTH
318 { AF_BLUETOOTH, "AF_BLUETOOTH" },
319#endif
320#ifdef AF_IUCV
321 { AF_IUCV, "AF_IUCV" },
322#endif
323#ifdef AF_RXRPC
324 { AF_RXRPC, "AF_RXRPC" },
325#endif
326#ifdef AF_ISDN
327 { AF_ISDN, "AF_ISDN" },
328#endif
329#ifdef AF_PHONET
330 { AF_PHONET, "AF_PHONET" },
331#endif
332#ifdef AF_IEEE802154
333 { AF_IEEE802154,"AF_IEEE802154" },
334#endif
335#ifdef AF_CAIF
336 { AF_CAIF, "AF_CAIF" },
337#endif
338#ifdef AF_ALG
339 { AF_ALG, "AF_ALG" },
340#endif
341#ifdef AF_NFC
342 { AF_NFC, "AF_NFC" },
343#endif
344#ifdef AF_VSOCK
345 { AF_VSOCK, "AF_VSOCK" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000346#endif
347 { 0, NULL },
348};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000349static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000350 { SOCK_STREAM, "SOCK_STREAM" },
351 { SOCK_DGRAM, "SOCK_DGRAM" },
352#ifdef SOCK_RAW
353 { SOCK_RAW, "SOCK_RAW" },
354#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000355#ifdef SOCK_RDM
356 { SOCK_RDM, "SOCK_RDM" },
357#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358#ifdef SOCK_SEQPACKET
359 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
360#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000361#ifdef SOCK_DCCP
362 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363#endif
364#ifdef SOCK_PACKET
365 { SOCK_PACKET, "SOCK_PACKET" },
366#endif
367 { 0, NULL },
368};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000369static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000370#ifdef SOCK_CLOEXEC
371 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
372#endif
373#ifdef SOCK_NONBLOCK
374 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
375#endif
376 { 0, NULL },
377};
378#ifndef SOCK_TYPE_MASK
379# define SOCK_TYPE_MASK 0xf
380#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000381static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000382#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000383 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000384#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000385#if defined(SOL_ICMP)
386 { SOL_ICMP, "SOL_ICMP" },
387#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000388#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000389 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000390#endif
391#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000392 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000393#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000394#if defined(SOL_IPV6)
395 { SOL_IPV6, "SOL_IPV6" },
396#endif
397#if defined(SOL_ICMPV6)
398 { SOL_ICMPV6, "SOL_ICMPV6" },
399#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100400#if defined(SOL_SCTP)
401 { SOL_SCTP, "SOL_SCTP" },
402#endif
403#if defined(SOL_UDPLITE)
404 { SOL_UDPLITE, "SOL_UDPLITE" },
405#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000406#if defined(SOL_RAW)
407 { SOL_RAW, "SOL_RAW" },
408#endif
409#if defined(SOL_IPX)
410 { SOL_IPX, "SOL_IPX" },
411#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000412#if defined(SOL_AX25)
413 { SOL_AX25, "SOL_AX25" },
414#endif
415#if defined(SOL_ATALK)
416 { SOL_ATALK, "SOL_ATALK" },
417#endif
418#if defined(SOL_NETROM)
419 { SOL_NETROM, "SOL_NETROM" },
420#endif
421#if defined(SOL_ROSE)
422 { SOL_ROSE, "SOL_ROSE" },
423#endif
424#if defined(SOL_DECNET)
425 { SOL_DECNET, "SOL_DECNET" },
426#endif
427#if defined(SOL_X25)
428 { SOL_X25, "SOL_X25" },
429#endif
430#if defined(SOL_PACKET)
431 { SOL_PACKET, "SOL_PACKET" },
432#endif
433#if defined(SOL_ATM)
434 { SOL_ATM, "SOL_ATM" },
435#endif
436#if defined(SOL_AAL)
437 { SOL_AAL, "SOL_AAL" },
438#endif
439#if defined(SOL_IRDA)
440 { SOL_IRDA, "SOL_IRDA" },
441#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100442#if defined(SOL_NETBEUI)
443 { SOL_NETBEUI, "SOL_NETBEUI" },
444#endif
445#if defined(SOL_LLC)
446 { SOL_LLC, "SOL_LLC" },
447#endif
448#if defined(SOL_DCCP)
449 { SOL_DCCP, "SOL_DCCP" },
450#endif
451#if defined(SOL_NETLINK)
452 { SOL_NETLINK, "SOL_NETLINK" },
453#endif
454#if defined(SOL_TIPC)
455 { SOL_TIPC, "SOL_TIPC" },
456#endif
457#if defined(SOL_RXRPC)
458 { SOL_RXRPC, "SOL_RXRPC" },
459#endif
460#if defined(SOL_PPPOL2TP)
461 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
462#endif
463#if defined(SOL_BLUETOOTH)
464 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
465#endif
466#if defined(SOL_PNPIPE)
467 { SOL_PNPIPE, "SOL_PNPIPE" },
468#endif
469#if defined(SOL_RDS)
470 { SOL_RDS, "SOL_RDS" },
471#endif
472#if defined(SOL_IUVC)
473 { SOL_IUCV, "SOL_IUCV" },
474#endif
475#if defined(SOL_CAIF)
476 { SOL_CAIF, "SOL_CAIF" },
477#endif
John Hughes61563572001-03-27 16:47:36 +0000478 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000479 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000480};
John Hughes93f7fcc2002-05-22 15:46:49 +0000481/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
482 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000483static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484 { IPPROTO_IP, "IPPROTO_IP" },
485 { IPPROTO_ICMP, "IPPROTO_ICMP" },
486 { IPPROTO_TCP, "IPPROTO_TCP" },
487 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000488#ifdef IPPROTO_IGMP
489 { IPPROTO_IGMP, "IPPROTO_IGMP" },
490#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491#ifdef IPPROTO_GGP
492 { IPPROTO_GGP, "IPPROTO_GGP" },
493#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000494#ifdef IPPROTO_IPIP
495 { IPPROTO_IPIP, "IPPROTO_IPIP" },
496#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497#ifdef IPPROTO_EGP
498 { IPPROTO_EGP, "IPPROTO_EGP" },
499#endif
500#ifdef IPPROTO_PUP
501 { IPPROTO_PUP, "IPPROTO_PUP" },
502#endif
503#ifdef IPPROTO_IDP
504 { IPPROTO_IDP, "IPPROTO_IDP" },
505#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000506#ifdef IPPROTO_TP
507 { IPPROTO_TP, "IPPROTO_TP" },
508#endif
509#ifdef IPPROTO_DCCP
510 { IPPROTO_DCCP, "IPPROTO_DCCP" },
511#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512#ifdef IPPROTO_IPV6
513 { IPPROTO_IPV6, "IPPROTO_IPV6" },
514#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000515#ifdef IPPROTO_ROUTING
516 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000518#ifdef IPPROTO_FRAGMENT
519 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
520#endif
521#ifdef IPPROTO_RSVP
522 { IPPROTO_RSVP, "IPPROTO_RSVP" },
523#endif
524#ifdef IPPROTO_GRE
525 { IPPROTO_GRE, "IPPROTO_GRE" },
526#endif
527#ifdef IPPROTO_ESP
528 { IPPROTO_ESP, "IPPROTO_ESP" },
529#endif
530#ifdef IPPROTO_AH
531 { IPPROTO_AH, "IPPROTO_AH" },
532#endif
533#ifdef IPPROTO_ICMPV6
534 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
535#endif
536#ifdef IPPROTO_NONE
537 { IPPROTO_NONE, "IPPROTO_NONE" },
538#endif
539#ifdef IPPROTO_DSTOPTS
540 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541#endif
542#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000543 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544#endif
545#ifdef IPPROTO_ND
546 { IPPROTO_ND, "IPPROTO_ND" },
547#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000548#ifdef IPPROTO_MTP
549 { IPPROTO_MTP, "IPPROTO_MTP" },
550#endif
551#ifdef IPPROTO_ENCAP
552 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
553#endif
554#ifdef IPPROTO_PIM
555 { IPPROTO_PIM, "IPPROTO_PIM" },
556#endif
557#ifdef IPPROTO_COMP
558 { IPPROTO_COMP, "IPPROTO_COMP" },
559#endif
560#ifdef IPPROTO_SCTP
561 { IPPROTO_SCTP, "IPPROTO_SCTP" },
562#endif
563#ifdef IPPROTO_UDPLITE
564 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
565#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566#ifdef IPPROTO_RAW
567 { IPPROTO_RAW, "IPPROTO_RAW" },
568#endif
569#ifdef IPPROTO_MAX
570 { IPPROTO_MAX, "IPPROTO_MAX" },
571#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572 { 0, NULL },
573};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000574static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000575 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000577 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000579#ifdef MSG_DONTROUTE
580 { MSG_DONTROUTE, "MSG_DONTROUTE" },
581#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000583 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000585#ifdef MSG_PROBE
586 { MSG_PROBE, "MSG_PROBE" },
587#endif
588#ifdef MSG_TRUNC
589 { MSG_TRUNC, "MSG_TRUNC" },
590#endif
591#ifdef MSG_DONTWAIT
592 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593#endif
594#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000595 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596#endif
597#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000598 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000600#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000601 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000602#endif
603#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000604 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000605#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000606#ifdef MSG_CONFIRM
607 { MSG_CONFIRM, "MSG_CONFIRM" },
608#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000609#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000610 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000611#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000612#ifdef MSG_ERRQUEUE
613 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
614#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000615#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000616 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000617#endif
618#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000619 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000620#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000621#ifdef MSG_WAITFORONE
622 { MSG_WAITFORONE, "MSG_WAITFORONE" },
623#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +0000624#ifdef MSG_EOF
625 { MSG_EOF, "MSG_EOF" },
626#endif
627#ifdef MSG_FASTOPEN
628 { MSG_FASTOPEN, "MSG_FASTOPEN" },
629#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000630#ifdef MSG_CMSG_CLOEXEC
631 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
632#endif
633 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634};
635
Roland McGrathd9f816f2004-09-04 03:39:20 +0000636static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000638 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000639#endif
640#ifdef SO_ALLRAW
641 { SO_ALLRAW, "SO_ALLRAW" },
642#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000643#ifdef SO_ATTACH_FILTER
644 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
645#endif
646#ifdef SO_BINDTODEVICE
647 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
648#endif
649#ifdef SO_BROADCAST
650 { SO_BROADCAST, "SO_BROADCAST" },
651#endif
652#ifdef SO_BSDCOMPAT
653 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
654#endif
655#ifdef SO_DEBUG
656 { SO_DEBUG, "SO_DEBUG" },
657#endif
658#ifdef SO_DETACH_FILTER
659 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
660#endif
661#ifdef SO_DONTROUTE
662 { SO_DONTROUTE, "SO_DONTROUTE" },
663#endif
664#ifdef SO_ERROR
665 { SO_ERROR, "SO_ERROR" },
666#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000667#ifdef SO_ICS
668 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000670#ifdef SO_IMASOCKET
671 { SO_IMASOCKET, "SO_IMASOCKET" },
672#endif
673#ifdef SO_KEEPALIVE
674 { SO_KEEPALIVE, "SO_KEEPALIVE" },
675#endif
676#ifdef SO_LINGER
677 { SO_LINGER, "SO_LINGER" },
678#endif
679#ifdef SO_LISTENING
680 { SO_LISTENING, "SO_LISTENING" },
681#endif
682#ifdef SO_MGMT
683 { SO_MGMT, "SO_MGMT" },
684#endif
685#ifdef SO_NO_CHECK
686 { SO_NO_CHECK, "SO_NO_CHECK" },
687#endif
688#ifdef SO_OOBINLINE
689 { SO_OOBINLINE, "SO_OOBINLINE" },
690#endif
691#ifdef SO_ORDREL
692 { SO_ORDREL, "SO_ORDREL" },
693#endif
694#ifdef SO_PARALLELSVR
695 { SO_PARALLELSVR, "SO_PARALLELSVR" },
696#endif
697#ifdef SO_PASSCRED
698 { SO_PASSCRED, "SO_PASSCRED" },
699#endif
700#ifdef SO_PEERCRED
701 { SO_PEERCRED, "SO_PEERCRED" },
702#endif
703#ifdef SO_PEERNAME
704 { SO_PEERNAME, "SO_PEERNAME" },
705#endif
706#ifdef SO_PEERSEC
707 { SO_PEERSEC, "SO_PEERSEC" },
708#endif
709#ifdef SO_PRIORITY
710 { SO_PRIORITY, "SO_PRIORITY" },
711#endif
712#ifdef SO_PROTOTYPE
713 { SO_PROTOTYPE, "SO_PROTOTYPE" },
714#endif
715#ifdef SO_RCVBUF
716 { SO_RCVBUF, "SO_RCVBUF" },
717#endif
718#ifdef SO_RCVLOWAT
719 { SO_RCVLOWAT, "SO_RCVLOWAT" },
720#endif
721#ifdef SO_RCVTIMEO
722 { SO_RCVTIMEO, "SO_RCVTIMEO" },
723#endif
724#ifdef SO_RDWR
725 { SO_RDWR, "SO_RDWR" },
726#endif
727#ifdef SO_REUSEADDR
728 { SO_REUSEADDR, "SO_REUSEADDR" },
729#endif
730#ifdef SO_REUSEPORT
731 { SO_REUSEPORT, "SO_REUSEPORT" },
732#endif
733#ifdef SO_SECURITY_AUTHENTICATION
734 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
735#endif
736#ifdef SO_SECURITY_ENCRYPTION_NETWORK
737 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
738#endif
739#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
740 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
741#endif
742#ifdef SO_SEMA
743 { SO_SEMA, "SO_SEMA" },
744#endif
745#ifdef SO_SNDBUF
746 { SO_SNDBUF, "SO_SNDBUF" },
747#endif
748#ifdef SO_SNDLOWAT
749 { SO_SNDLOWAT, "SO_SNDLOWAT" },
750#endif
751#ifdef SO_SNDTIMEO
752 { SO_SNDTIMEO, "SO_SNDTIMEO" },
753#endif
754#ifdef SO_TIMESTAMP
755 { SO_TIMESTAMP, "SO_TIMESTAMP" },
756#endif
757#ifdef SO_TYPE
758 { SO_TYPE, "SO_TYPE" },
759#endif
760#ifdef SO_USELOOPBACK
761 { SO_USELOOPBACK, "SO_USELOOPBACK" },
762#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 { 0, NULL },
764};
765
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100766#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000767#define SOL_IP IPPROTO_IP
768#endif
769
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000771static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000772#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000773 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000774#endif
775#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000776 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000777#endif
778#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000779 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000781#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000782 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000784#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000785 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000786#endif
787#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000788 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
789#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000790#ifdef IP_RECVOPTS
791 { IP_RECVOPTS, "IP_RECVOPTS" },
792#endif
793#ifdef IP_RECVRETOPTS
794 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
795#endif
796#ifdef IP_RECVDSTADDR
797 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
798#endif
799#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000800 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000801#endif
802#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000803 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000804#endif
805#ifdef IP_PKTOPTIONS
806 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
807#endif
808#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000809 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000810#endif
811#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000812 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000813#endif
814#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000815 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000816#endif
817#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000818 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000819#endif
820#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000821 { IP_MTU, "IP_MTU" },
822#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000823#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000824 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000825#endif
826#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000827 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000828#endif
829#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000830 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000831#endif
832#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000833 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000834#endif
835#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000836 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000837#endif
838#ifdef IP_BROADCAST_IF
839 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
840#endif
841#ifdef IP_RECVIFINDEX
842 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
843#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000844#ifdef IP_MSFILTER
845 { IP_MSFILTER, "IP_MSFILTER" },
846#endif
847#ifdef MCAST_MSFILTER
848 { MCAST_MSFILTER, "MCAST_MSFILTER" },
849#endif
850#ifdef IP_FREEBIND
851 { IP_FREEBIND, "IP_FREEBIND" },
852#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000853 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854};
855#endif /* SOL_IP */
856
Roland McGrath4f6ba692004-08-31 07:01:26 +0000857#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000858static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000859#ifdef IPV6_ADDRFORM
860 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
861#endif
862#ifdef MCAST_FILTER
863 { MCAST_FILTER, "MCAST_FILTER" },
864#endif
865#ifdef IPV6_PKTOPTIONS
866 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
867#endif
868#ifdef IPV6_MTU
869 { IPV6_MTU, "IPV6_MTU" },
870#endif
871#ifdef IPV6_V6ONLY
872 { IPV6_V6ONLY, "IPV6_V6ONLY" },
873#endif
874#ifdef IPV6_PKTINFO
875 { IPV6_PKTINFO, "IPV6_PKTINFO" },
876#endif
877#ifdef IPV6_HOPLIMIT
878 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
879#endif
880#ifdef IPV6_RTHDR
881 { IPV6_RTHDR, "IPV6_RTHDR" },
882#endif
883#ifdef IPV6_HOPOPTS
884 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
885#endif
886#ifdef IPV6_DSTOPTS
887 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
888#endif
889#ifdef IPV6_FLOWINFO
890 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
891#endif
892#ifdef IPV6_UNICAST_HOPS
893 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
894#endif
895#ifdef IPV6_MULTICAST_HOPS
896 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
897#endif
898#ifdef IPV6_MULTICAST_LOOP
899 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
900#endif
901#ifdef IPV6_MULTICAST_IF
902 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
903#endif
904#ifdef IPV6_MTU_DISCOVER
905 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
906#endif
907#ifdef IPV6_RECVERR
908 { IPV6_RECVERR, "IPV6_RECVERR" },
909#endif
910#ifdef IPV6_FLOWINFO_SEND
911 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
912#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000913#ifdef IPV6_ADD_MEMBERSHIP
914 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
915#endif
916#ifdef IPV6_DROP_MEMBERSHIP
917 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
918#endif
919#ifdef IPV6_ROUTER_ALERT
920 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
921#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000922 { 0, NULL },
923};
924#endif /* SOL_IPV6 */
925
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000926#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000927static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200928 { IPX_TYPE, "IPX_TYPE" },
929 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930};
931#endif /* SOL_IPX */
932
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000933#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000934static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000935#if defined(ICMP_FILTER)
936 { ICMP_FILTER, "ICMP_FILTER" },
937#endif
938 { 0, NULL },
939};
940#endif /* SOL_RAW */
941
942#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000943static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000944#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000945 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000946#endif
947#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000948 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000949#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000950#if defined(PACKET_RECV_OUTPUT)
951 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
952#endif
953#if defined(PACKET_RX_RING)
954 { PACKET_RX_RING, "PACKET_RX_RING" },
955#endif
956#if defined(PACKET_STATISTICS)
957 { PACKET_STATISTICS, "PACKET_STATISTICS" },
958#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000959#if defined(PACKET_COPY_THRESH)
960 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
961#endif
962#if defined(PACKET_AUXDATA)
963 { PACKET_AUXDATA, "PACKET_AUXDATA" },
964#endif
965#if defined(PACKET_ORIGDEV)
966 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
967#endif
968#if defined(PACKET_VERSION)
969 { PACKET_VERSION, "PACKET_VERSION" },
970#endif
971#if defined(PACKET_HDRLEN)
972 { PACKET_HDRLEN, "PACKET_HDRLEN" },
973#endif
974#if defined(PACKET_RESERVE)
975 { PACKET_RESERVE, "PACKET_RESERVE" },
976#endif
977#if defined(PACKET_TX_RING)
978 { PACKET_TX_RING, "PACKET_TX_RING" },
979#endif
980#if defined(PACKET_LOSS)
981 { PACKET_LOSS, "PACKET_LOSS" },
982#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000983 { 0, NULL },
984};
985#endif /* SOL_PACKET */
986
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100987#ifdef SOL_SCTP
988static const struct xlat socksctpoptions[] = {
989#if defined(SCTP_RTOINFO)
990 { SCTP_RTOINFO, "SCTP_RTOINFO" },
991#endif
992#if defined(SCTP_ASSOCINFO)
993 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
994#endif
995#if defined(SCTP_INITMSG)
996 { SCTP_INITMSG, "SCTP_INITMSG" },
997#endif
998#if defined(SCTP_NODELAY)
999 { SCTP_NODELAY, "SCTP_NODELAY" },
1000#endif
1001#if defined(SCTP_AUTOCLOSE)
1002 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
1003#endif
1004#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
1005 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
1006#endif
1007#if defined(SCTP_PRIMARY_ADDR)
1008 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
1009#endif
1010#if defined(SCTP_ADAPTATION_LAYER)
1011 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
1012#endif
1013#if defined(SCTP_DISABLE_FRAGMENTS)
1014 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
1015#endif
1016#if defined(SCTP_PEER_ADDR_PARAMS)
1017 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
1018#endif
1019#if defined(SCTP_DEFAULT_SEND_PARAM)
1020 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
1021#endif
1022#if defined(SCTP_EVENTS)
1023 { SCTP_EVENTS, "SCTP_EVENTS" },
1024#endif
1025#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
1026 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
1027#endif
1028#if defined(SCTP_MAXSEG)
1029 { SCTP_MAXSEG, "SCTP_MAXSEG" },
1030#endif
1031#if defined(SCTP_STATUS)
1032 { SCTP_STATUS, "SCTP_STATUS" },
1033#endif
1034#if defined(SCTP_GET_PEER_ADDR_INFO)
1035 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
1036#endif
1037#if defined(SCTP_DELAYED_ACK)
1038 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1039#endif
1040#if defined(SCTP_CONTEXT)
1041 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1042#endif
1043#if defined(SCTP_FRAGMENT_INTERLEAVE)
1044 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1045#endif
1046#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1047 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1048#endif
1049#if defined(SCTP_MAX_BURST)
1050 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1051#endif
1052#if defined(SCTP_AUTH_CHUNK)
1053 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1054#endif
1055#if defined(SCTP_HMAC_IDENT)
1056 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1057#endif
1058#if defined(SCTP_AUTH_KEY)
1059 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1060#endif
1061#if defined(SCTP_AUTH_ACTIVE_KEY)
1062 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1063#endif
1064#if defined(SCTP_AUTH_DELETE_KEY)
1065 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1066#endif
1067#if defined(SCTP_PEER_AUTH_CHUNKS)
1068 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1069#endif
1070#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1071 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1072#endif
1073#if defined(SCTP_GET_ASSOC_NUMBER)
1074 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1075#endif
1076
1077 /* linux specific things */
1078#if defined(SCTP_SOCKOPT_BINDX_ADD)
1079 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1080#endif
1081#if defined(SCTP_SOCKOPT_BINDX_REM)
1082 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1083#endif
1084#if defined(SCTP_SOCKOPT_PEELOFF)
1085 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1086#endif
1087#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1088 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1089#endif
1090#if defined(SCTP_GET_PEER_ADDRS_OLD)
1091 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1092#endif
1093#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1094 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1095#endif
1096#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1097 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1098#endif
1099#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1100 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1101#endif
1102#if defined(SCTP_GET_PEER_ADDRS)
1103 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1104#endif
1105#if defined(SCTP_GET_LOCAL_ADDRS)
1106 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1107#endif
1108
1109 { 0, NULL },
1110};
1111#endif
1112
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001113#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001114#define SOL_TCP IPPROTO_TCP
1115#endif
1116
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001118static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001119 { TCP_NODELAY, "TCP_NODELAY" },
1120 { TCP_MAXSEG, "TCP_MAXSEG" },
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001121#ifdef TCP_CORK
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001122 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001123#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001124#ifdef TCP_KEEPIDLE
1125 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001126#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001127#ifdef TCP_KEEPINTVL
1128 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001129#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001130#ifdef TCP_KEEPCNT
1131 { TCP_KEEPCNT, "TCP_KEEPCNT" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001132#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001133#ifdef TCP_SYNCNT
1134 { TCP_SYNCNT, "TCP_SYNCNT" },
John Hughes38ae88d2002-05-23 11:48:58 +00001135#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001136#ifdef TCP_LINGER2
1137 { TCP_LINGER2, "TCP_LINGER2" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001138#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001139#ifdef TCP_DEFER_ACCEPT
1140 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001141#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001142#ifdef TCP_WINDOW_CLAMP
1143 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001144#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001145#ifdef TCP_INFO
1146 { TCP_INFO, "TCP_INFO" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001147#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001148#ifdef TCP_QUICKACK
1149 { TCP_QUICKACK, "TCP_QUICKACK" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001150#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001151#ifdef TCP_CONGESTION
1152 { TCP_CONGESTION, "TCP_CONGESTION" },
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001153#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001154#ifdef TCP_MD5SIG
1155 { TCP_MD5SIG, "TCP_MD5SIG" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001156#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001157#ifdef TCP_COOKIE_TRANSACTIONS
1158 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001159#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001160#ifdef TCP_THIN_LINEAR_TIMEOUTS
1161 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001162#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001163#ifdef TCP_THIN_DUPACK
1164 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001165#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001166#ifdef TCP_USER_TIMEOUT
1167 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001168#endif
Dmitry V. Levinea0d2a62013-05-16 22:19:30 +00001169#ifdef TCP_REPAIR
1170 { TCP_REPAIR, "TCP_REPAIR" },
1171#endif
1172#ifdef TCP_REPAIR_QUEUE
1173 { TCP_REPAIR_QUEUE, "TCP_REPAIR_QUEUE" },
1174#endif
1175#ifdef TCP_QUEUE_SEQ
1176 { TCP_QUEUE_SEQ, "TCP_QUEUE_SEQ" },
1177#endif
1178#ifdef TCP_REPAIR_OPTIONS
1179 { TCP_REPAIR_OPTIONS, "TCP_REPAIR_OPTIONS" },
1180#endif
1181#ifdef TCP_FASTOPEN
1182 { TCP_FASTOPEN, "TCP_FASTOPEN" },
1183#endif
1184#ifdef TCP_TIMESTAMP
1185 { TCP_TIMESTAMP, "TCP_TIMESTAMP" },
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001186#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001187 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001188};
1189#endif /* SOL_TCP */
1190
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001191#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001192static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001193#if defined(ICMP_ECHOREPLY)
1194 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1195#endif
1196#if defined(ICMP_DEST_UNREACH)
1197 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1198#endif
1199#if defined(ICMP_SOURCE_QUENCH)
1200 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1201#endif
1202#if defined(ICMP_REDIRECT)
1203 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1204#endif
1205#if defined(ICMP_ECHO)
1206 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1207#endif
1208#if defined(ICMP_TIME_EXCEEDED)
1209 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1210#endif
1211#if defined(ICMP_PARAMETERPROB)
1212 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1213#endif
1214#if defined(ICMP_TIMESTAMP)
1215 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1216#endif
1217#if defined(ICMP_TIMESTAMPREPLY)
1218 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1219#endif
1220#if defined(ICMP_INFO_REQUEST)
1221 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1222#endif
1223#if defined(ICMP_INFO_REPLY)
1224 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1225#endif
1226#if defined(ICMP_ADDRESS)
1227 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1228#endif
1229#if defined(ICMP_ADDRESSREPLY)
1230 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1231#endif
1232 { 0, NULL },
1233};
1234#endif /* SOL_RAW */
1235
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001236#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001237static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001238#if defined(PACKET_HOST)
1239 { PACKET_HOST, "PACKET_HOST" },
1240#endif
1241#if defined(PACKET_BROADCAST)
1242 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1243#endif
1244#if defined(PACKET_MULTICAST)
1245 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1246#endif
1247#if defined(PACKET_OTHERHOST)
1248 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1249#endif
1250#if defined(PACKET_OUTGOING)
1251 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1252#endif
1253#if defined(PACKET_LOOPBACK)
1254 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1255#endif
1256#if defined(PACKET_FASTROUTE)
1257 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1258#endif
1259 { 0, NULL },
1260};
1261#endif /* defined(AF_PACKET) */
1262
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001264printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001266 union {
1267 char pad[128];
1268 struct sockaddr sa;
1269 struct sockaddr_in sin;
1270 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001271#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001272 struct sockaddr_in6 sa6;
1273#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001274#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001275 struct sockaddr_ipx sipx;
1276#endif
1277#ifdef AF_PACKET
1278 struct sockaddr_ll ll;
1279#endif
1280#ifdef AF_NETLINK
1281 struct sockaddr_nl nl;
1282#endif
1283 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001284 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001285
1286 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001287 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 return;
1289 }
1290 if (!verbose(tcp)) {
1291 tprintf("%#lx", addr);
1292 return;
1293 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001294
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001295 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1296 addrlen = sizeof(addrbuf);
1297
1298 memset(&addrbuf, 0, sizeof(addrbuf));
1299 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001300 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 return;
1302 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001303 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001304
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001305 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001306 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001307 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001308
1309 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001311 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001312 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001313 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001314 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001315 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001316 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001317 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001318 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001319 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001320 break;
1321 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001322 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001323 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001325#ifdef HAVE_INET_NTOP
1326 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001327 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001328 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1329 ntohs(addrbuf.sa6.sin6_port), string_addr,
1330 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001331#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001332 {
1333#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001334 int numericscope = 0;
1335 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1336 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1337 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001338
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001339 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1340 numericscope++;
1341 else
1342 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1343 } else
1344 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001345
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001346 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001347#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001348 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001349 }
1350#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001351 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001352#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001353#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001354 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001355 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001357 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001358 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001359 /* Yes, I know, this does not look too
1360 * strace-ish, but otherwise the IPX
1361 * addresses just look monstrous...
1362 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001363 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001364 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001365 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001366 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001367 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1368 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369 }
1370 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001371#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001372#ifdef AF_PACKET
1373 case AF_PACKET:
1374 {
1375 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001376 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001377 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001378 addrbuf.ll.sll_ifindex);
1379 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1380 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001381 addrbuf.ll.sll_halen,
1382 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001383 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001384 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1385 }
1386 break;
1387
Denys Vlasenko84703742012-02-25 02:38:52 +01001388#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001389#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001390 case AF_NETLINK:
1391 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1392 break;
1393#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001395 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001396
1397 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001398 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001400 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001401 break;
1402 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001403 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001404}
1405
1406#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001407static const struct xlat scmvals[] = {
1408#ifdef SCM_RIGHTS
1409 { SCM_RIGHTS, "SCM_RIGHTS" },
1410#endif
1411#ifdef SCM_CREDENTIALS
1412 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1413#endif
1414 { 0, NULL }
1415};
1416
1417static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001418printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001419{
Roland McGrathaa524c82005-06-01 19:22:06 +00001420 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1421 NULL : malloc(len);
1422 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001423 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001424 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001425 return;
1426 }
1427
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001428 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001429 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001430 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001431
Roland McGrathaa524c82005-06-01 19:22:06 +00001432 if (cmsg->cmsg_level == SOL_SOCKET) {
1433 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001434
Roland McGrathaa524c82005-06-01 19:22:06 +00001435 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1436 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1437
1438 if (cmsg->cmsg_type == SCM_RIGHTS
1439 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001440 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001441 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001442
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001443 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001444 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001445 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001446 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001447 tprintf("%d", *fds++);
1448 first = 0;
1449 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001450 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001451 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001452 return;
1453 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001454 if (cmsg->cmsg_type == SCM_CREDENTIALS
1455 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001456 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001457
Roland McGrath50770822004-10-06 22:11:51 +00001458 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1459 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001460 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001461 return;
1462 }
1463 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001464 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001465 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001466}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467
1468static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001469do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +01001470{
1471 tprintf("{msg_name(%d)=", msg->msg_namelen);
1472 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1473
1474 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001475 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
1476 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +01001477
1478#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1479 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1480 if (msg->msg_controllen)
1481 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1482 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001483 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001484 printflags(msg_flags, msg->msg_flags, "MSG_???");
1485#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1486 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1487 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1488#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001489 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001490}
1491
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001492struct msghdr32 {
1493 uint32_t /* void* */ msg_name;
1494 uint32_t /* socklen_t */msg_namelen;
1495 uint32_t /* iovec* */ msg_iov;
1496 uint32_t /* size_t */ msg_iovlen;
1497 uint32_t /* void* */ msg_control;
1498 uint32_t /* size_t */ msg_controllen;
1499 uint32_t /* int */ msg_flags;
1500};
1501struct mmsghdr32 {
1502 struct msghdr32 msg_hdr;
1503 uint32_t /* unsigned */ msg_len;
1504};
1505
Andreas Schwab0873f292010-02-12 21:39:12 +01001506static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001507printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508{
1509 struct msghdr msg;
1510
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001511#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1512 if (current_wordsize == 4) {
1513 struct msghdr32 msg32;
1514
1515 if (umove(tcp, addr, &msg32) < 0) {
1516 tprintf("%#lx", addr);
1517 return;
1518 }
1519 msg.msg_name = (void*)(long)msg32.msg_name;
1520 msg.msg_namelen = msg32.msg_namelen;
1521 msg.msg_iov = (void*)(long)msg32.msg_iov;
1522 msg.msg_iovlen = msg32.msg_iovlen;
1523 msg.msg_control = (void*)(long)msg32.msg_control;
1524 msg.msg_controllen = msg32.msg_controllen;
1525 msg.msg_flags = msg32.msg_flags;
1526 } else
1527#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001528 if (umove(tcp, addr, &msg) < 0) {
1529 tprintf("%#lx", addr);
1530 return;
1531 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001532 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533}
1534
Andreas Schwab0873f292010-02-12 21:39:12 +01001535static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001536printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +01001537{
1538 struct mmsghdr {
1539 struct msghdr msg_hdr;
1540 unsigned msg_len;
1541 } mmsg;
1542
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001543#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1544 if (current_wordsize == 4) {
1545 struct mmsghdr32 mmsg32;
1546
1547 addr += sizeof(mmsg32) * idx;
1548 if (umove(tcp, addr, &mmsg32) < 0) {
1549 tprintf("%#lx", addr);
1550 return;
1551 }
1552 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
1553 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
1554 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
1555 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
1556 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
1557 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
1558 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
1559 mmsg.msg_len = mmsg32.msg_len;
1560 } else
1561#endif
1562 {
1563 addr += sizeof(mmsg) * idx;
1564 if (umove(tcp, addr, &mmsg) < 0) {
1565 tprintf("%#lx", addr);
1566 return;
1567 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001568 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001569 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001570 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +01001571 tprintf(", %u}", mmsg.msg_len);
1572}
Andreas Schwab0873f292010-02-12 21:39:12 +01001573
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001574static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001575decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001576{
1577 /* mmsgvec */
1578 if (syserror(tcp)) {
1579 tprintf("%#lx", tcp->u_arg[1]);
1580 } else {
1581 unsigned int len = tcp->u_rval;
1582 unsigned int i;
1583
1584 tprints("{");
1585 for (i = 0; i < len; ++i) {
1586 if (i)
1587 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001588 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001589 }
1590 tprints("}");
1591 }
1592 /* vlen */
1593 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1594 /* flags */
1595 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1596}
1597
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598#endif /* HAVE_SENDMSG */
1599
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001600/*
1601 * low bits of the socket type define real socket type,
1602 * other bits are socket type flags.
1603 */
1604static void
1605tprint_sock_type(struct tcb *tcp, int flags)
1606{
1607 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1608
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001609 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001610 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001611 flags &= ~SOCK_TYPE_MASK;
1612 if (!flags)
1613 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001614 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001615 }
1616 printflags(sock_type_flags, flags, "SOCK_???");
1617}
1618
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001620sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621{
1622 if (entering(tcp)) {
1623 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001624 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001625 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001626 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 switch (tcp->u_arg[0]) {
1628 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001629#ifdef PF_INET6
1630 case PF_INET6:
1631#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1633 break;
1634#ifdef PF_IPX
1635 case PF_IPX:
1636 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001637 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001639 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 break;
1641#endif /* PF_IPX */
1642 default:
1643 tprintf("%lu", tcp->u_arg[2]);
1644 break;
1645 }
1646 }
1647 return 0;
1648}
1649
John Hughesbdf48f52001-03-06 15:08:09 +00001650int
Denys Vlasenko12014262011-05-30 14:00:14 +02001651sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652{
1653 if (entering(tcp)) {
1654 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001655 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656 tprintf(", %lu", tcp->u_arg[2]);
1657 }
1658 return 0;
1659}
1660
1661int
Denys Vlasenko12014262011-05-30 14:00:14 +02001662sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001663{
1664 return sys_bind(tcp);
1665}
1666
1667int
Denys Vlasenko12014262011-05-30 14:00:14 +02001668sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669{
1670 if (entering(tcp)) {
1671 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1672 }
1673 return 0;
1674}
1675
Paolo Bonzini705ff102009-08-14 12:34:05 +02001676static int
1677do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678{
1679 if (entering(tcp)) {
1680 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001681 return 0;
1682 }
1683 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 tprintf("%#lx, NULL", tcp->u_arg[1]);
1685 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001686 int len;
1687 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001688 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 tprintf("%#lx", tcp->u_arg[1]);
1690 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001691 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001692 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001693 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001694 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001696 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001697 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001698 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1699 "SOCK_???");
1700 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701 return 0;
1702}
1703
1704int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001705sys_accept(struct tcb *tcp)
1706{
1707 return do_accept(tcp, -1);
1708}
1709
Paolo Bonzini705ff102009-08-14 12:34:05 +02001710int
1711sys_accept4(struct tcb *tcp)
1712{
1713 return do_accept(tcp, 3);
1714}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001715
1716int
Denys Vlasenko12014262011-05-30 14:00:14 +02001717sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718{
1719 if (entering(tcp)) {
1720 tprintf("%ld, ", tcp->u_arg[0]);
1721 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1722 tprintf(", %lu, ", tcp->u_arg[2]);
1723 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001724 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001725 }
1726 return 0;
1727}
1728
1729int
Denys Vlasenko12014262011-05-30 14:00:14 +02001730sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731{
1732 if (entering(tcp)) {
1733 tprintf("%ld, ", tcp->u_arg[0]);
1734 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1735 tprintf(", %lu, ", tcp->u_arg[2]);
1736 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001737 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001739 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001740 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001741 /* to length */
1742 tprintf(", %lu", tcp->u_arg[5]);
1743 }
1744 return 0;
1745}
1746
1747#ifdef HAVE_SENDMSG
1748
1749int
Denys Vlasenko12014262011-05-30 14:00:14 +02001750sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751{
1752 if (entering(tcp)) {
1753 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levin043b5f82012-05-01 20:30:02 +00001754 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001756 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001757 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 }
1759 return 0;
1760}
1761
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001762int
1763sys_sendmmsg(struct tcb *tcp)
1764{
1765 if (entering(tcp)) {
1766 /* sockfd */
1767 tprintf("%d, ", (int) tcp->u_arg[0]);
1768 if (!verbose(tcp)) {
1769 tprintf("%#lx, %u, ",
1770 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1771 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1772 }
1773 } else {
1774 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001775 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001776 }
1777 return 0;
1778}
1779
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780#endif /* HAVE_SENDMSG */
1781
1782int
Denys Vlasenko12014262011-05-30 14:00:14 +02001783sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784{
1785 if (entering(tcp)) {
1786 tprintf("%ld, ", tcp->u_arg[0]);
1787 } else {
1788 if (syserror(tcp))
1789 tprintf("%#lx", tcp->u_arg[1]);
1790 else
1791 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1792
1793 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001794 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795 }
1796 return 0;
1797}
1798
1799int
Denys Vlasenko12014262011-05-30 14:00:14 +02001800sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801{
1802 int fromlen;
1803
1804 if (entering(tcp)) {
1805 tprintf("%ld, ", tcp->u_arg[0]);
1806 } else {
1807 if (syserror(tcp)) {
1808 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1809 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1810 tcp->u_arg[4], tcp->u_arg[5]);
1811 return 0;
1812 }
1813 /* buf */
1814 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1815 /* len */
1816 tprintf(", %lu, ", tcp->u_arg[2]);
1817 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001818 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001819 /* from address, len */
1820 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1821 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001822 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823 else
1824 tprintf(", %#lx", tcp->u_arg[4]);
1825 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001826 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 else
1828 tprintf(", %#lx", tcp->u_arg[5]);
1829 return 0;
1830 }
1831 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001832 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 return 0;
1834 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001835 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001836 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001837 /* from length */
1838 tprintf(", [%u]", fromlen);
1839 }
1840 return 0;
1841}
1842
1843#ifdef HAVE_SENDMSG
1844
1845int
Denys Vlasenko12014262011-05-30 14:00:14 +02001846sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847{
1848 if (entering(tcp)) {
1849 tprintf("%ld, ", tcp->u_arg[0]);
1850 } else {
1851 if (syserror(tcp) || !verbose(tcp))
1852 tprintf("%#lx", tcp->u_arg[1]);
1853 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001854 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001856 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001857 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858 }
1859 return 0;
1860}
1861
Andreas Schwab0873f292010-02-12 21:39:12 +01001862int
1863sys_recvmmsg(struct tcb *tcp)
1864{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001865 /* +5 chars are for "left " prefix */
1866 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001867
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001868 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001869 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001870 if (verbose(tcp)) {
1871 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001872 /* Abusing tcp->auxstr as temp storage.
1873 * Will be used and freed on syscall exit.
1874 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001875 tcp->auxstr = strdup(str);
1876 } else {
1877 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1878 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001879 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001880 print_timespec(tcp, tcp->u_arg[4]);
1881 }
1882 return 0;
1883 } else {
1884 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001885 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001886 /* timeout on entrance */
1887 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1888 free((void *) tcp->auxstr);
1889 tcp->auxstr = NULL;
1890 }
1891 if (syserror(tcp))
1892 return 0;
1893 if (tcp->u_rval == 0) {
1894 tcp->auxstr = "Timeout";
1895 return RVAL_STR;
1896 }
1897 if (!verbose(tcp))
1898 return 0;
1899 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001900 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001901 tcp->auxstr = str;
1902 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001903 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001904}
Andreas Schwab0873f292010-02-12 21:39:12 +01001905
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906#endif /* HAVE_SENDMSG */
1907
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001908static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001909 { 0, "SHUT_RD" },
1910 { 1, "SHUT_WR" },
1911 { 2, "SHUT_RDWR" },
1912 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001913};
1914
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915int
Denys Vlasenko12014262011-05-30 14:00:14 +02001916sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917{
1918 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001919 tprintf("%ld, ", tcp->u_arg[0]);
1920 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921 }
1922 return 0;
1923}
1924
1925int
Denys Vlasenko12014262011-05-30 14:00:14 +02001926sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927{
1928 return sys_accept(tcp);
1929}
1930
1931int
Denys Vlasenko12014262011-05-30 14:00:14 +02001932sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933{
1934 return sys_accept(tcp);
1935}
1936
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001937static int
1938do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001939{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 if (exiting(tcp)) {
1941 if (syserror(tcp)) {
1942 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001943 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001944#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001945 int fds[2];
1946
1947 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001948 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001949 else
1950 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001951#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001952 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1953#else
1954 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001955#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001956 }
1957 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001958 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001959 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1960 }
1961 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962 return 0;
1963}
1964
1965int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001966sys_pipe(struct tcb *tcp)
1967{
1968 return do_pipe(tcp, -1);
1969}
1970
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001971int
1972sys_pipe2(struct tcb *tcp)
1973{
1974 return do_pipe(tcp, 1);
1975}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001976
1977int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001978sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001980 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981
1982 if (entering(tcp)) {
1983 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001984 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001985 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001986 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001987 switch (tcp->u_arg[0]) {
1988 case PF_INET:
1989 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1990 break;
1991#ifdef PF_IPX
1992 case PF_IPX:
1993 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001994 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001996 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997 break;
1998#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001999 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002000 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002001 break;
2002 }
2003 } else {
2004 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002005 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006 return 0;
2007 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002009 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010 else
2011 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012 }
2013 return 0;
2014}
2015
2016int
Dmitry V. Levin31289192009-11-06 18:05:40 +00002017sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018{
2019 if (entering(tcp)) {
2020 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002021 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002022 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023 switch (tcp->u_arg[1]) {
2024 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026 break;
2027#ifdef SOL_IP
2028 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030 break;
2031#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002032#ifdef SOL_IPV6
2033 case SOL_IPV6:
2034 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
2035 break;
2036#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037#ifdef SOL_IPX
2038 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002039 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002040 break;
2041#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002042#ifdef SOL_PACKET
2043 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002044 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002045 break;
2046#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047#ifdef SOL_TCP
2048 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 break;
2051#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002052#ifdef SOL_SCTP
2053 case SOL_SCTP:
2054 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
2055 break;
2056#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057
2058 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2059 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00002060 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00002061 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062 break;
2063 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002064 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00002066 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002067 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002068 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069 tcp->u_arg[3], tcp->u_arg[4]);
2070 return 0;
2071 }
John Hughes93f7fcc2002-05-22 15:46:49 +00002072
2073 switch (tcp->u_arg[1]) {
2074 case SOL_SOCKET:
2075 switch (tcp->u_arg[2]) {
2076#ifdef SO_LINGER
2077 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002078 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00002079 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002080 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00002081 tcp->u_arg[3],
2082 &linger) < 0)
2083 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00002084 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00002085 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00002086 linger.l_onoff,
2087 linger.l_linger,
2088 len);
2089 return 0;
2090 }
2091 break;
2092#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002093#ifdef SO_PEERCRED
2094 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002095 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002096 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002097 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002098 tcp->u_arg[3],
2099 &uc) < 0)
2100 break;
2101 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2102 "[%d]",
2103 (long)uc.pid,
2104 (long)uc.uid,
2105 (long)uc.gid,
2106 len);
2107 return 0;
2108 }
2109 break;
2110#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002111 }
2112 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002113 case SOL_PACKET:
2114 switch (tcp->u_arg[2]) {
2115#ifdef PACKET_STATISTICS
2116 case PACKET_STATISTICS:
2117 if (len == sizeof(struct tpacket_stats)) {
2118 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002119 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002120 tcp->u_arg[3],
2121 &stats) < 0)
2122 break;
2123 tprintf("{packets=%u, drops=%u}, "
2124 "[%d]",
2125 stats.tp_packets,
2126 stats.tp_drops,
2127 len);
2128 return 0;
2129 }
2130 break;
2131#endif
2132 }
2133 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002134 }
2135
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002136 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002137 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002138 }
2139 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002140 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002141 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002142 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143 }
2144 return 0;
2145}
2146
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002147#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002148static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002149{
2150 struct icmp_filter filter;
2151
2152 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002153 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002154 return;
2155 }
2156 if (syserror(tcp) || !verbose(tcp)) {
2157 tprintf("%#lx", addr);
2158 return;
2159 }
2160 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002161 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002162 return;
2163 }
2164
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002165 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002166 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002167 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002168}
2169#endif /* ICMP_FILTER */
2170
John Hughes38ae88d2002-05-23 11:48:58 +00002171static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002172printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002173{
2174 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002175 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002176 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002177 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002178 printxval(sockoptions, name, "SO_???");
2179 switch (name) {
2180#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002181 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002182 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002183 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002184 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002185 break;
2186 tprintf(", {onoff=%d, linger=%d}",
2187 linger.l_onoff,
2188 linger.l_linger);
2189 return 0;
2190 }
2191 break;
2192#endif
2193 }
2194 break;
2195#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002196 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00002197 printxval(sockipoptions, name, "IP_???");
2198 break;
2199#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002200#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002201 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00002202 printxval(sockipv6options, name, "IPV6_???");
2203 break;
2204#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002205#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002206 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00002207 printxval(sockipxoptions, name, "IPX_???");
2208 break;
2209#endif
2210#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002211 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002212 printxval(sockpacketoptions, name, "PACKET_???");
2213 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002214 switch (name) {
2215#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002216 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002217#endif
2218#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002219 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002220#endif
2221#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2222 if (len == sizeof(struct tpacket_req)) {
2223 struct tpacket_req req;
2224 if (umove(tcp, addr, &req) < 0)
2225 break;
2226 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2227 req.tp_block_size,
2228 req.tp_block_nr,
2229 req.tp_frame_size,
2230 req.tp_frame_nr);
2231 return 0;
2232 }
2233 break;
2234#endif /* PACKET_RX_RING || PACKET_TX_RING */
2235 }
John Hughes38ae88d2002-05-23 11:48:58 +00002236 break;
2237#endif
2238#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002239 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00002240 printxval(socktcpoptions, name, "TCP_???");
2241 break;
2242#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002243#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002244 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002245 printxval(socksctpoptions, name, "SCTP_???");
2246 break;
2247#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002248#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002249 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00002250 printxval(sockrawoptions, name, "RAW_???");
2251 switch (name) {
2252#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002253 case ICMP_FILTER:
2254 tprints(", ");
2255 printicmpfilter(tcp, addr);
2256 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002257#endif
2258 }
2259 break;
2260#endif
2261
Roland McGrath6d2b3492002-12-30 00:51:30 +00002262 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002263 * etc. still need work */
2264
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002265 default:
John Hughes38ae88d2002-05-23 11:48:58 +00002266 tprintf("%u", name);
2267 }
2268
2269 /* default arg printing */
2270
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002271 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002272
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002273 if (len == sizeof(int)) {
2274 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002275 }
2276 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002277 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002278 }
2279 return 0;
2280}
2281
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282int
Denys Vlasenko12014262011-05-30 14:00:14 +02002283sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284{
2285 if (entering(tcp)) {
2286 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002287 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002288 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002289 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002290 }
2291 return 0;
2292}