blob: fba521be564ee65e4e0ffbdedde0bfa94f782688 [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"
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +020032#include <limits.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033#include <sys/stat.h>
34#include <sys/socket.h>
35#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000036#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010037# define in6_addr in6_addr_libc
38# define ipv6_mreq ipv6_mreq_libc
39# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000040#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010043# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000044#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000045#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010046# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000047#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010048#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010049# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010050#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000052#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#include <asm/types.h>
54#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010055# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010057# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Denys Vlasenkoc36c3522012-02-25 02:47:15 +010060#if defined(__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010061# if defined(HAVE_LINUX_IN6_H)
62# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
63# undef in6_addr
64# undef ipv6_mreq
65# undef sockaddr_in6
66# define in6_addr in6_addr_kernel
67# define ipv6_mreq ipv6_mreq_kernel
68# define sockaddr_in6 sockaddr_in6_kernel
69# endif
70# include <linux/in6.h>
71# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
72# undef in6_addr
73# undef ipv6_mreq
74# undef sockaddr_in6
75# define in6_addr in6_addr_libc
76# define ipv6_mreq ipv6_mreq_libc
77# define sockaddr_in6 sockaddr_in6_kernel
78# endif
79# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000080#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000081
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000082#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010083# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010086# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000088#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010089# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000090#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000091#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010092# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000093#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010095# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096#endif
97
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098/* Under Linux these are enums so we can't test for them with ifdef. */
99#define IPPROTO_EGP IPPROTO_EGP
100#define IPPROTO_PUP IPPROTO_PUP
101#define IPPROTO_IDP IPPROTO_IDP
102#define IPPROTO_IGMP IPPROTO_IGMP
103#define IPPROTO_RAW IPPROTO_RAW
104#define IPPROTO_MAX IPPROTO_MAX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105
Roland McGrathd9f816f2004-09-04 03:39:20 +0000106static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000107#ifdef PF_AAL5
108 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#endif
110#ifdef PF_APPLETALK
111 { PF_APPLETALK, "PF_APPLETALK" },
112#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000113#ifdef PF_ASH
114 { PF_ASH, "PF_ASH" },
115#endif
116#ifdef PF_ATMPVC
117 { PF_ATMPVC, "PF_ATMPVC" },
118#endif
119#ifdef PF_ATMSVC
120 { PF_ATMSVC, "PF_ATMSVC" },
121#endif
122#ifdef PF_AX25
123 { PF_AX25, "PF_AX25" },
124#endif
125#ifdef PF_BLUETOOTH
126 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127#endif
128#ifdef PF_BRIDGE
129 { PF_BRIDGE, "PF_BRIDGE" },
130#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000131#ifdef PF_DECnet
132 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133#endif
134#ifdef PF_DECNET
135 { PF_DECNET, "PF_DECNET" },
136#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000137#ifdef PF_ECONET
138 { PF_ECONET, "PF_ECONET" },
139#endif
140#ifdef PF_FILE
141 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#endif
143#ifdef PF_IMPLINK
144 { PF_IMPLINK, "PF_IMPLINK" },
145#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000146#ifdef PF_INET
147 { PF_INET, "PF_INET" },
148#endif
149#ifdef PF_INET6
150 { PF_INET6, "PF_INET6" },
151#endif
152#ifdef PF_IPX
153 { PF_IPX, "PF_IPX" },
154#endif
155#ifdef PF_IRDA
156 { PF_IRDA, "PF_IRDA" },
157#endif
158#ifdef PF_ISO
159 { PF_ISO, "PF_ISO" },
160#endif
161#ifdef PF_KEY
162 { PF_KEY, "PF_KEY" },
163#endif
164#ifdef PF_UNIX
165 { PF_UNIX, "PF_UNIX" },
166#endif
167#ifdef PF_LOCAL
168 { PF_LOCAL, "PF_LOCAL" },
169#endif
170#ifdef PF_NETBEUI
171 { PF_NETBEUI, "PF_NETBEUI" },
172#endif
173#ifdef PF_NETLINK
174 { PF_NETLINK, "PF_NETLINK" },
175#endif
176#ifdef PF_NETROM
177 { PF_NETROM, "PF_NETROM" },
178#endif
179#ifdef PF_PACKET
180 { PF_PACKET, "PF_PACKET" },
181#endif
182#ifdef PF_PPPOX
183 { PF_PPPOX, "PF_PPPOX" },
184#endif
185#ifdef PF_ROSE
186 { PF_ROSE, "PF_ROSE" },
187#endif
188#ifdef PF_ROUTE
189 { PF_ROUTE, "PF_ROUTE" },
190#endif
191#ifdef PF_SECURITY
192 { PF_SECURITY, "PF_SECURITY" },
193#endif
194#ifdef PF_SNA
195 { PF_SNA, "PF_SNA" },
196#endif
197#ifdef PF_UNSPEC
198 { PF_UNSPEC, "PF_UNSPEC" },
199#endif
200#ifdef PF_WANPIPE
201 { PF_WANPIPE, "PF_WANPIPE" },
202#endif
203#ifdef PF_X25
204 { PF_X25, "PF_X25" },
205#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206 { 0, NULL },
207};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000208const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000209#ifdef AF_APPLETALK
210 { AF_APPLETALK, "AF_APPLETALK" },
211#endif
212#ifdef AF_ASH
213 { AF_ASH, "AF_ASH" },
214#endif
215#ifdef AF_ATMPVC
216 { AF_ATMPVC, "AF_ATMPVC" },
217#endif
218#ifdef AF_ATMSVC
219 { AF_ATMSVC, "AF_ATMSVC" },
220#endif
221#ifdef AF_AX25
222 { AF_AX25, "AF_AX25" },
223#endif
224#ifdef AF_BLUETOOTH
225 { AF_BLUETOOTH, "AF_BLUETOOTH" },
226#endif
227#ifdef AF_BRIDGE
228 { AF_BRIDGE, "AF_BRIDGE" },
229#endif
230#ifdef AF_DECnet
231 { AF_DECnet, "AF_DECnet" },
232#endif
233#ifdef AF_ECONET
234 { AF_ECONET, "AF_ECONET" },
235#endif
236#ifdef AF_FILE
237 { AF_FILE, "AF_FILE" },
238#endif
239#ifdef AF_IMPLINK
240 { AF_IMPLINK, "AF_IMPLINK" },
241#endif
242#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000243 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000244#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000245#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000246 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000247#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000248#ifdef AF_IPX
249 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000250#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000251#ifdef AF_IRDA
252 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000253#endif
254#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000255 { AF_ISO, "AF_ISO" },
256#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000257#ifdef AF_KEY
258 { AF_KEY, "AF_KEY" },
259#endif
260#ifdef AF_UNIX
261 { AF_UNIX, "AF_UNIX" },
262#endif
263#ifdef AF_LOCAL
264 { AF_LOCAL, "AF_LOCAL" },
265#endif
266#ifdef AF_NETBEUI
267 { AF_NETBEUI, "AF_NETBEUI" },
268#endif
269#ifdef AF_NETLINK
270 { AF_NETLINK, "AF_NETLINK" },
271#endif
272#ifdef AF_NETROM
273 { AF_NETROM, "AF_NETROM" },
274#endif
275#ifdef AF_PACKET
276 { AF_PACKET, "AF_PACKET" },
277#endif
278#ifdef AF_PPPOX
279 { AF_PPPOX, "AF_PPPOX" },
280#endif
281#ifdef AF_ROSE
282 { AF_ROSE, "AF_ROSE" },
283#endif
284#ifdef AF_ROUTE
285 { AF_ROUTE, "AF_ROUTE" },
286#endif
287#ifdef AF_SECURITY
288 { AF_SECURITY, "AF_SECURITY" },
289#endif
290#ifdef AF_SNA
291 { AF_SNA, "AF_SNA" },
292#endif
293#ifdef AF_UNSPEC
294 { AF_UNSPEC, "AF_UNSPEC" },
295#endif
296#ifdef AF_WANPIPE
297 { AF_WANPIPE, "AF_WANPIPE" },
298#endif
299#ifdef AF_X25
300 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000301#endif
302 { 0, NULL },
303};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000304static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305 { SOCK_STREAM, "SOCK_STREAM" },
306 { SOCK_DGRAM, "SOCK_DGRAM" },
307#ifdef SOCK_RAW
308 { SOCK_RAW, "SOCK_RAW" },
309#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000310#ifdef SOCK_RDM
311 { SOCK_RDM, "SOCK_RDM" },
312#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313#ifdef SOCK_SEQPACKET
314 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
315#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000316#ifdef SOCK_DCCP
317 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318#endif
319#ifdef SOCK_PACKET
320 { SOCK_PACKET, "SOCK_PACKET" },
321#endif
322 { 0, NULL },
323};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000324static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000325#ifdef SOCK_CLOEXEC
326 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
327#endif
328#ifdef SOCK_NONBLOCK
329 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
330#endif
331 { 0, NULL },
332};
333#ifndef SOCK_TYPE_MASK
334# define SOCK_TYPE_MASK 0xf
335#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000336static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000337#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000338 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000339#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000340#if defined(SOL_ICMP)
341 { SOL_ICMP, "SOL_ICMP" },
342#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000343#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000344 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000345#endif
346#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000347 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000348#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000349#if defined(SOL_IPV6)
350 { SOL_IPV6, "SOL_IPV6" },
351#endif
352#if defined(SOL_ICMPV6)
353 { SOL_ICMPV6, "SOL_ICMPV6" },
354#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100355#if defined(SOL_SCTP)
356 { SOL_SCTP, "SOL_SCTP" },
357#endif
358#if defined(SOL_UDPLITE)
359 { SOL_UDPLITE, "SOL_UDPLITE" },
360#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000361#if defined(SOL_RAW)
362 { SOL_RAW, "SOL_RAW" },
363#endif
364#if defined(SOL_IPX)
365 { SOL_IPX, "SOL_IPX" },
366#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000367#if defined(SOL_AX25)
368 { SOL_AX25, "SOL_AX25" },
369#endif
370#if defined(SOL_ATALK)
371 { SOL_ATALK, "SOL_ATALK" },
372#endif
373#if defined(SOL_NETROM)
374 { SOL_NETROM, "SOL_NETROM" },
375#endif
376#if defined(SOL_ROSE)
377 { SOL_ROSE, "SOL_ROSE" },
378#endif
379#if defined(SOL_DECNET)
380 { SOL_DECNET, "SOL_DECNET" },
381#endif
382#if defined(SOL_X25)
383 { SOL_X25, "SOL_X25" },
384#endif
385#if defined(SOL_PACKET)
386 { SOL_PACKET, "SOL_PACKET" },
387#endif
388#if defined(SOL_ATM)
389 { SOL_ATM, "SOL_ATM" },
390#endif
391#if defined(SOL_AAL)
392 { SOL_AAL, "SOL_AAL" },
393#endif
394#if defined(SOL_IRDA)
395 { SOL_IRDA, "SOL_IRDA" },
396#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100397#if defined(SOL_NETBEUI)
398 { SOL_NETBEUI, "SOL_NETBEUI" },
399#endif
400#if defined(SOL_LLC)
401 { SOL_LLC, "SOL_LLC" },
402#endif
403#if defined(SOL_DCCP)
404 { SOL_DCCP, "SOL_DCCP" },
405#endif
406#if defined(SOL_NETLINK)
407 { SOL_NETLINK, "SOL_NETLINK" },
408#endif
409#if defined(SOL_TIPC)
410 { SOL_TIPC, "SOL_TIPC" },
411#endif
412#if defined(SOL_RXRPC)
413 { SOL_RXRPC, "SOL_RXRPC" },
414#endif
415#if defined(SOL_PPPOL2TP)
416 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
417#endif
418#if defined(SOL_BLUETOOTH)
419 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
420#endif
421#if defined(SOL_PNPIPE)
422 { SOL_PNPIPE, "SOL_PNPIPE" },
423#endif
424#if defined(SOL_RDS)
425 { SOL_RDS, "SOL_RDS" },
426#endif
427#if defined(SOL_IUVC)
428 { SOL_IUCV, "SOL_IUCV" },
429#endif
430#if defined(SOL_CAIF)
431 { SOL_CAIF, "SOL_CAIF" },
432#endif
John Hughes61563572001-03-27 16:47:36 +0000433 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000434 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000435};
John Hughes93f7fcc2002-05-22 15:46:49 +0000436/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
437 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000438static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439 { IPPROTO_IP, "IPPROTO_IP" },
440 { IPPROTO_ICMP, "IPPROTO_ICMP" },
441 { IPPROTO_TCP, "IPPROTO_TCP" },
442 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000443#ifdef IPPROTO_IGMP
444 { IPPROTO_IGMP, "IPPROTO_IGMP" },
445#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446#ifdef IPPROTO_GGP
447 { IPPROTO_GGP, "IPPROTO_GGP" },
448#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000449#ifdef IPPROTO_IPIP
450 { IPPROTO_IPIP, "IPPROTO_IPIP" },
451#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452#ifdef IPPROTO_EGP
453 { IPPROTO_EGP, "IPPROTO_EGP" },
454#endif
455#ifdef IPPROTO_PUP
456 { IPPROTO_PUP, "IPPROTO_PUP" },
457#endif
458#ifdef IPPROTO_IDP
459 { IPPROTO_IDP, "IPPROTO_IDP" },
460#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000461#ifdef IPPROTO_TP
462 { IPPROTO_TP, "IPPROTO_TP" },
463#endif
464#ifdef IPPROTO_DCCP
465 { IPPROTO_DCCP, "IPPROTO_DCCP" },
466#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467#ifdef IPPROTO_IPV6
468 { IPPROTO_IPV6, "IPPROTO_IPV6" },
469#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000470#ifdef IPPROTO_ROUTING
471 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000473#ifdef IPPROTO_FRAGMENT
474 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
475#endif
476#ifdef IPPROTO_RSVP
477 { IPPROTO_RSVP, "IPPROTO_RSVP" },
478#endif
479#ifdef IPPROTO_GRE
480 { IPPROTO_GRE, "IPPROTO_GRE" },
481#endif
482#ifdef IPPROTO_ESP
483 { IPPROTO_ESP, "IPPROTO_ESP" },
484#endif
485#ifdef IPPROTO_AH
486 { IPPROTO_AH, "IPPROTO_AH" },
487#endif
488#ifdef IPPROTO_ICMPV6
489 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
490#endif
491#ifdef IPPROTO_NONE
492 { IPPROTO_NONE, "IPPROTO_NONE" },
493#endif
494#ifdef IPPROTO_DSTOPTS
495 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496#endif
497#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000498 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499#endif
500#ifdef IPPROTO_ND
501 { IPPROTO_ND, "IPPROTO_ND" },
502#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000503#ifdef IPPROTO_MTP
504 { IPPROTO_MTP, "IPPROTO_MTP" },
505#endif
506#ifdef IPPROTO_ENCAP
507 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
508#endif
509#ifdef IPPROTO_PIM
510 { IPPROTO_PIM, "IPPROTO_PIM" },
511#endif
512#ifdef IPPROTO_COMP
513 { IPPROTO_COMP, "IPPROTO_COMP" },
514#endif
515#ifdef IPPROTO_SCTP
516 { IPPROTO_SCTP, "IPPROTO_SCTP" },
517#endif
518#ifdef IPPROTO_UDPLITE
519 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
520#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521#ifdef IPPROTO_RAW
522 { IPPROTO_RAW, "IPPROTO_RAW" },
523#endif
524#ifdef IPPROTO_MAX
525 { IPPROTO_MAX, "IPPROTO_MAX" },
526#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 { 0, NULL },
528};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000529static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000530 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000532 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533#endif
534#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000535 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536#endif
537#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000538 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539#endif
540#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000541 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542#endif
543#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000544 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545#endif
546#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000547 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000549#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000550 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000551#endif
552#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000553 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000554#endif
555#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000556 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000557#endif
558#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000559 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000560#endif
561#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000562 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000563#endif
564#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000565 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000566#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000567#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000568 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000569#endif
570#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000571 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000572#endif
573#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000574 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000575#endif
576#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000577 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000578#endif
579#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000580 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000581#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000582#ifdef MSG_WAITFORONE
583 { MSG_WAITFORONE, "MSG_WAITFORONE" },
584#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000585#ifdef MSG_CMSG_CLOEXEC
586 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
587#endif
588 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589};
590
Roland McGrathd9f816f2004-09-04 03:39:20 +0000591static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000593 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000594#endif
595#ifdef SO_ALLRAW
596 { SO_ALLRAW, "SO_ALLRAW" },
597#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000598#ifdef SO_ATTACH_FILTER
599 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
600#endif
601#ifdef SO_BINDTODEVICE
602 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
603#endif
604#ifdef SO_BROADCAST
605 { SO_BROADCAST, "SO_BROADCAST" },
606#endif
607#ifdef SO_BSDCOMPAT
608 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
609#endif
610#ifdef SO_DEBUG
611 { SO_DEBUG, "SO_DEBUG" },
612#endif
613#ifdef SO_DETACH_FILTER
614 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
615#endif
616#ifdef SO_DONTROUTE
617 { SO_DONTROUTE, "SO_DONTROUTE" },
618#endif
619#ifdef SO_ERROR
620 { SO_ERROR, "SO_ERROR" },
621#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000622#ifdef SO_ICS
623 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000625#ifdef SO_IMASOCKET
626 { SO_IMASOCKET, "SO_IMASOCKET" },
627#endif
628#ifdef SO_KEEPALIVE
629 { SO_KEEPALIVE, "SO_KEEPALIVE" },
630#endif
631#ifdef SO_LINGER
632 { SO_LINGER, "SO_LINGER" },
633#endif
634#ifdef SO_LISTENING
635 { SO_LISTENING, "SO_LISTENING" },
636#endif
637#ifdef SO_MGMT
638 { SO_MGMT, "SO_MGMT" },
639#endif
640#ifdef SO_NO_CHECK
641 { SO_NO_CHECK, "SO_NO_CHECK" },
642#endif
643#ifdef SO_OOBINLINE
644 { SO_OOBINLINE, "SO_OOBINLINE" },
645#endif
646#ifdef SO_ORDREL
647 { SO_ORDREL, "SO_ORDREL" },
648#endif
649#ifdef SO_PARALLELSVR
650 { SO_PARALLELSVR, "SO_PARALLELSVR" },
651#endif
652#ifdef SO_PASSCRED
653 { SO_PASSCRED, "SO_PASSCRED" },
654#endif
655#ifdef SO_PEERCRED
656 { SO_PEERCRED, "SO_PEERCRED" },
657#endif
658#ifdef SO_PEERNAME
659 { SO_PEERNAME, "SO_PEERNAME" },
660#endif
661#ifdef SO_PEERSEC
662 { SO_PEERSEC, "SO_PEERSEC" },
663#endif
664#ifdef SO_PRIORITY
665 { SO_PRIORITY, "SO_PRIORITY" },
666#endif
667#ifdef SO_PROTOTYPE
668 { SO_PROTOTYPE, "SO_PROTOTYPE" },
669#endif
670#ifdef SO_RCVBUF
671 { SO_RCVBUF, "SO_RCVBUF" },
672#endif
673#ifdef SO_RCVLOWAT
674 { SO_RCVLOWAT, "SO_RCVLOWAT" },
675#endif
676#ifdef SO_RCVTIMEO
677 { SO_RCVTIMEO, "SO_RCVTIMEO" },
678#endif
679#ifdef SO_RDWR
680 { SO_RDWR, "SO_RDWR" },
681#endif
682#ifdef SO_REUSEADDR
683 { SO_REUSEADDR, "SO_REUSEADDR" },
684#endif
685#ifdef SO_REUSEPORT
686 { SO_REUSEPORT, "SO_REUSEPORT" },
687#endif
688#ifdef SO_SECURITY_AUTHENTICATION
689 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
690#endif
691#ifdef SO_SECURITY_ENCRYPTION_NETWORK
692 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
693#endif
694#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
695 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
696#endif
697#ifdef SO_SEMA
698 { SO_SEMA, "SO_SEMA" },
699#endif
700#ifdef SO_SNDBUF
701 { SO_SNDBUF, "SO_SNDBUF" },
702#endif
703#ifdef SO_SNDLOWAT
704 { SO_SNDLOWAT, "SO_SNDLOWAT" },
705#endif
706#ifdef SO_SNDTIMEO
707 { SO_SNDTIMEO, "SO_SNDTIMEO" },
708#endif
709#ifdef SO_TIMESTAMP
710 { SO_TIMESTAMP, "SO_TIMESTAMP" },
711#endif
712#ifdef SO_TYPE
713 { SO_TYPE, "SO_TYPE" },
714#endif
715#ifdef SO_USELOOPBACK
716 { SO_USELOOPBACK, "SO_USELOOPBACK" },
717#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718 { 0, NULL },
719};
720
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100721#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000722#define SOL_IP IPPROTO_IP
723#endif
724
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000726static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000727#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000728 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000729#endif
730#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000731 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000732#endif
733#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000734 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000736#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000737 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000739#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000740 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000741#endif
742#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000743 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
744#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000745#ifdef IP_RECVOPTS
746 { IP_RECVOPTS, "IP_RECVOPTS" },
747#endif
748#ifdef IP_RECVRETOPTS
749 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
750#endif
751#ifdef IP_RECVDSTADDR
752 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
753#endif
754#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000755 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000756#endif
757#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000758 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000759#endif
760#ifdef IP_PKTOPTIONS
761 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
762#endif
763#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000764 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000765#endif
766#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000767 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000768#endif
769#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000770 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000771#endif
772#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000773 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000774#endif
775#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000776 { IP_MTU, "IP_MTU" },
777#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000778#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000779 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000780#endif
781#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000782 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000783#endif
784#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000785 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000786#endif
787#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000788 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000789#endif
790#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000791 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000792#endif
793#ifdef IP_BROADCAST_IF
794 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
795#endif
796#ifdef IP_RECVIFINDEX
797 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
798#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000799#ifdef IP_MSFILTER
800 { IP_MSFILTER, "IP_MSFILTER" },
801#endif
802#ifdef MCAST_MSFILTER
803 { MCAST_MSFILTER, "MCAST_MSFILTER" },
804#endif
805#ifdef IP_FREEBIND
806 { IP_FREEBIND, "IP_FREEBIND" },
807#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000808 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809};
810#endif /* SOL_IP */
811
Roland McGrath4f6ba692004-08-31 07:01:26 +0000812#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000813static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000814#ifdef IPV6_ADDRFORM
815 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
816#endif
817#ifdef MCAST_FILTER
818 { MCAST_FILTER, "MCAST_FILTER" },
819#endif
820#ifdef IPV6_PKTOPTIONS
821 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
822#endif
823#ifdef IPV6_MTU
824 { IPV6_MTU, "IPV6_MTU" },
825#endif
826#ifdef IPV6_V6ONLY
827 { IPV6_V6ONLY, "IPV6_V6ONLY" },
828#endif
829#ifdef IPV6_PKTINFO
830 { IPV6_PKTINFO, "IPV6_PKTINFO" },
831#endif
832#ifdef IPV6_HOPLIMIT
833 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
834#endif
835#ifdef IPV6_RTHDR
836 { IPV6_RTHDR, "IPV6_RTHDR" },
837#endif
838#ifdef IPV6_HOPOPTS
839 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
840#endif
841#ifdef IPV6_DSTOPTS
842 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
843#endif
844#ifdef IPV6_FLOWINFO
845 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
846#endif
847#ifdef IPV6_UNICAST_HOPS
848 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
849#endif
850#ifdef IPV6_MULTICAST_HOPS
851 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
852#endif
853#ifdef IPV6_MULTICAST_LOOP
854 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
855#endif
856#ifdef IPV6_MULTICAST_IF
857 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
858#endif
859#ifdef IPV6_MTU_DISCOVER
860 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
861#endif
862#ifdef IPV6_RECVERR
863 { IPV6_RECVERR, "IPV6_RECVERR" },
864#endif
865#ifdef IPV6_FLOWINFO_SEND
866 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
867#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000868#ifdef IPV6_ADD_MEMBERSHIP
869 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
870#endif
871#ifdef IPV6_DROP_MEMBERSHIP
872 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
873#endif
874#ifdef IPV6_ROUTER_ALERT
875 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
876#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000877 { 0, NULL },
878};
879#endif /* SOL_IPV6 */
880
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000882static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200883 { IPX_TYPE, "IPX_TYPE" },
884 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000885};
886#endif /* SOL_IPX */
887
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000888#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000889static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000890#if defined(ICMP_FILTER)
891 { ICMP_FILTER, "ICMP_FILTER" },
892#endif
893 { 0, NULL },
894};
895#endif /* SOL_RAW */
896
897#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000898static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000899#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000900 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000901#endif
902#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000903 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000904#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000905#if defined(PACKET_RECV_OUTPUT)
906 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
907#endif
908#if defined(PACKET_RX_RING)
909 { PACKET_RX_RING, "PACKET_RX_RING" },
910#endif
911#if defined(PACKET_STATISTICS)
912 { PACKET_STATISTICS, "PACKET_STATISTICS" },
913#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000914#if defined(PACKET_COPY_THRESH)
915 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
916#endif
917#if defined(PACKET_AUXDATA)
918 { PACKET_AUXDATA, "PACKET_AUXDATA" },
919#endif
920#if defined(PACKET_ORIGDEV)
921 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
922#endif
923#if defined(PACKET_VERSION)
924 { PACKET_VERSION, "PACKET_VERSION" },
925#endif
926#if defined(PACKET_HDRLEN)
927 { PACKET_HDRLEN, "PACKET_HDRLEN" },
928#endif
929#if defined(PACKET_RESERVE)
930 { PACKET_RESERVE, "PACKET_RESERVE" },
931#endif
932#if defined(PACKET_TX_RING)
933 { PACKET_TX_RING, "PACKET_TX_RING" },
934#endif
935#if defined(PACKET_LOSS)
936 { PACKET_LOSS, "PACKET_LOSS" },
937#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000938 { 0, NULL },
939};
940#endif /* SOL_PACKET */
941
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100942#ifdef SOL_SCTP
943static const struct xlat socksctpoptions[] = {
944#if defined(SCTP_RTOINFO)
945 { SCTP_RTOINFO, "SCTP_RTOINFO" },
946#endif
947#if defined(SCTP_ASSOCINFO)
948 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
949#endif
950#if defined(SCTP_INITMSG)
951 { SCTP_INITMSG, "SCTP_INITMSG" },
952#endif
953#if defined(SCTP_NODELAY)
954 { SCTP_NODELAY, "SCTP_NODELAY" },
955#endif
956#if defined(SCTP_AUTOCLOSE)
957 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
958#endif
959#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
960 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
961#endif
962#if defined(SCTP_PRIMARY_ADDR)
963 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
964#endif
965#if defined(SCTP_ADAPTATION_LAYER)
966 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
967#endif
968#if defined(SCTP_DISABLE_FRAGMENTS)
969 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
970#endif
971#if defined(SCTP_PEER_ADDR_PARAMS)
972 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
973#endif
974#if defined(SCTP_DEFAULT_SEND_PARAM)
975 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
976#endif
977#if defined(SCTP_EVENTS)
978 { SCTP_EVENTS, "SCTP_EVENTS" },
979#endif
980#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
981 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
982#endif
983#if defined(SCTP_MAXSEG)
984 { SCTP_MAXSEG, "SCTP_MAXSEG" },
985#endif
986#if defined(SCTP_STATUS)
987 { SCTP_STATUS, "SCTP_STATUS" },
988#endif
989#if defined(SCTP_GET_PEER_ADDR_INFO)
990 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
991#endif
992#if defined(SCTP_DELAYED_ACK)
993 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
994#endif
995#if defined(SCTP_CONTEXT)
996 { SCTP_CONTEXT, "SCTP_CONTEXT" },
997#endif
998#if defined(SCTP_FRAGMENT_INTERLEAVE)
999 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1000#endif
1001#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1002 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1003#endif
1004#if defined(SCTP_MAX_BURST)
1005 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1006#endif
1007#if defined(SCTP_AUTH_CHUNK)
1008 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1009#endif
1010#if defined(SCTP_HMAC_IDENT)
1011 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1012#endif
1013#if defined(SCTP_AUTH_KEY)
1014 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1015#endif
1016#if defined(SCTP_AUTH_ACTIVE_KEY)
1017 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1018#endif
1019#if defined(SCTP_AUTH_DELETE_KEY)
1020 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1021#endif
1022#if defined(SCTP_PEER_AUTH_CHUNKS)
1023 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1024#endif
1025#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1026 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1027#endif
1028#if defined(SCTP_GET_ASSOC_NUMBER)
1029 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1030#endif
1031
1032 /* linux specific things */
1033#if defined(SCTP_SOCKOPT_BINDX_ADD)
1034 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1035#endif
1036#if defined(SCTP_SOCKOPT_BINDX_REM)
1037 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1038#endif
1039#if defined(SCTP_SOCKOPT_PEELOFF)
1040 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1041#endif
1042#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1043 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1044#endif
1045#if defined(SCTP_GET_PEER_ADDRS_OLD)
1046 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1047#endif
1048#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1049 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1050#endif
1051#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1052 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1053#endif
1054#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1055 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1056#endif
1057#if defined(SCTP_GET_PEER_ADDRS)
1058 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1059#endif
1060#if defined(SCTP_GET_LOCAL_ADDRS)
1061 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1062#endif
1063
1064 { 0, NULL },
1065};
1066#endif
1067
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001068#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001069#define SOL_TCP IPPROTO_TCP
1070#endif
1071
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001073static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001074 { TCP_NODELAY, "TCP_NODELAY" },
1075 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001076#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001077 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001078#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001079#if defined(TCP_KEEPIDLE)
1080 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1081#endif
1082#if defined(TCP_KEEPINTVL)
1083 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1084#endif
1085#if defined(TCP_KEEPCNT)
1086 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1087#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001088#if defined(TCP_NKEEP)
1089 { TCP_NKEEP, "TCP_NKEEP" },
1090#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001091#if defined(TCP_SYNCNT)
1092 { TCP_SYNCNT, "TCP_SYNCNT" },
1093#endif
1094#if defined(TCP_LINGER2)
1095 { TCP_LINGER2, "TCP_LINGER2" },
1096#endif
1097#if defined(TCP_DEFER_ACCEPT)
1098 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1099#endif
1100#if defined(TCP_WINDOW_CLAMP)
1101 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1102#endif
1103#if defined(TCP_INFO)
1104 { TCP_INFO, "TCP_INFO" },
1105#endif
1106#if defined(TCP_QUICKACK)
1107 { TCP_QUICKACK, "TCP_QUICKACK" },
1108#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001109#if defined(TCP_CONGESTION)
1110 { TCP_CONGESTION, "TCP_CONGESTION" },
1111#endif
1112#if defined(TCP_MD5SIG)
1113 { TCP_MD5SIG, "TCP_MD5SIG" },
1114#endif
1115#if defined(TCP_COOKIE_TRANSACTIONS)
1116 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1117#endif
1118#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1119 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1120#endif
1121#if defined(TCP_THIN_DUPACK)
1122 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1123#endif
1124#if defined(TCP_USER_TIMEOUT)
1125 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1126#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001127 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128};
1129#endif /* SOL_TCP */
1130
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001131#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001132static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001133#if defined(ICMP_ECHOREPLY)
1134 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1135#endif
1136#if defined(ICMP_DEST_UNREACH)
1137 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1138#endif
1139#if defined(ICMP_SOURCE_QUENCH)
1140 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1141#endif
1142#if defined(ICMP_REDIRECT)
1143 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1144#endif
1145#if defined(ICMP_ECHO)
1146 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1147#endif
1148#if defined(ICMP_TIME_EXCEEDED)
1149 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1150#endif
1151#if defined(ICMP_PARAMETERPROB)
1152 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1153#endif
1154#if defined(ICMP_TIMESTAMP)
1155 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1156#endif
1157#if defined(ICMP_TIMESTAMPREPLY)
1158 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1159#endif
1160#if defined(ICMP_INFO_REQUEST)
1161 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1162#endif
1163#if defined(ICMP_INFO_REPLY)
1164 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1165#endif
1166#if defined(ICMP_ADDRESS)
1167 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1168#endif
1169#if defined(ICMP_ADDRESSREPLY)
1170 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1171#endif
1172 { 0, NULL },
1173};
1174#endif /* SOL_RAW */
1175
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001176#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001177static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001178#if defined(PACKET_HOST)
1179 { PACKET_HOST, "PACKET_HOST" },
1180#endif
1181#if defined(PACKET_BROADCAST)
1182 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1183#endif
1184#if defined(PACKET_MULTICAST)
1185 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1186#endif
1187#if defined(PACKET_OTHERHOST)
1188 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1189#endif
1190#if defined(PACKET_OUTGOING)
1191 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1192#endif
1193#if defined(PACKET_LOOPBACK)
1194 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1195#endif
1196#if defined(PACKET_FASTROUTE)
1197 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1198#endif
1199 { 0, NULL },
1200};
1201#endif /* defined(AF_PACKET) */
1202
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001203void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001204printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001206 union {
1207 char pad[128];
1208 struct sockaddr sa;
1209 struct sockaddr_in sin;
1210 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001211#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001212 struct sockaddr_in6 sa6;
1213#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001214#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001215 struct sockaddr_ipx sipx;
1216#endif
1217#ifdef AF_PACKET
1218 struct sockaddr_ll ll;
1219#endif
1220#ifdef AF_NETLINK
1221 struct sockaddr_nl nl;
1222#endif
1223 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001224 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225
1226 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001227 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 return;
1229 }
1230 if (!verbose(tcp)) {
1231 tprintf("%#lx", addr);
1232 return;
1233 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001234
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001235 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1236 addrlen = sizeof(addrbuf);
1237
1238 memset(&addrbuf, 0, sizeof(addrbuf));
1239 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001240 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241 return;
1242 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001243 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001244
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001245 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001246 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001247 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001248
1249 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001250 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001251 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001252 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001253 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001254 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001255 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001256 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001257 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001258 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001259 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 break;
1261 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001262 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001263 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001265#ifdef HAVE_INET_NTOP
1266 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001267 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001268 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1269 ntohs(addrbuf.sa6.sin6_port), string_addr,
1270 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001271#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001272 {
1273#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001274 int numericscope = 0;
1275 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1276 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1277 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001278
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001279 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1280 numericscope++;
1281 else
1282 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1283 } else
1284 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001285
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001286 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001287#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001288 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001289 }
1290#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001291 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001292#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001293#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001295 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001297 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001298 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 /* Yes, I know, this does not look too
1300 * strace-ish, but otherwise the IPX
1301 * addresses just look monstrous...
1302 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001303 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001305 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001306 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001307 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1308 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 }
1310 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001311#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001312#ifdef AF_PACKET
1313 case AF_PACKET:
1314 {
1315 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001316 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001317 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001318 addrbuf.ll.sll_ifindex);
1319 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1320 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001321 addrbuf.ll.sll_halen,
1322 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001323 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001324 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1325 }
1326 break;
1327
Denys Vlasenko84703742012-02-25 02:38:52 +01001328#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001329#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001330 case AF_NETLINK:
1331 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1332 break;
1333#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001335 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336
1337 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001338 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001339 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001340 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001341 break;
1342 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001343 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344}
1345
1346#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001347static const struct xlat scmvals[] = {
1348#ifdef SCM_RIGHTS
1349 { SCM_RIGHTS, "SCM_RIGHTS" },
1350#endif
1351#ifdef SCM_CREDENTIALS
1352 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1353#endif
1354 { 0, NULL }
1355};
1356
1357static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001358printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001359{
Roland McGrathaa524c82005-06-01 19:22:06 +00001360 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1361 NULL : malloc(len);
1362 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001363 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001364 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001365 return;
1366 }
1367
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001368 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001369 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001370 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001371
Roland McGrathaa524c82005-06-01 19:22:06 +00001372 if (cmsg->cmsg_level == SOL_SOCKET) {
1373 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001374
Roland McGrathaa524c82005-06-01 19:22:06 +00001375 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1376 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1377
1378 if (cmsg->cmsg_type == SCM_RIGHTS
1379 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001380 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001381 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001382
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001383 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001384 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001385 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001386 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001387 tprintf("%d", *fds++);
1388 first = 0;
1389 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001390 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001391 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001392 return;
1393 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001394 if (cmsg->cmsg_type == SCM_CREDENTIALS
1395 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001396 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001397
Roland McGrath50770822004-10-06 22:11:51 +00001398 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1399 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001400 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001401 return;
1402 }
1403 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001404 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001405 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001406}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407
1408static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001409do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +01001410{
1411 tprintf("{msg_name(%d)=", msg->msg_namelen);
1412 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1413
1414 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001415 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
1416 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +01001417
1418#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1419 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1420 if (msg->msg_controllen)
1421 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1422 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001423 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001424 printflags(msg_flags, msg->msg_flags, "MSG_???");
1425#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1426 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1427 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1428#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001429 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001430}
1431
1432static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001433printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434{
1435 struct msghdr msg;
1436
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001437 if (umove(tcp, addr, &msg) < 0) {
1438 tprintf("%#lx", addr);
1439 return;
1440 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001441 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442}
1443
Andreas Schwab0873f292010-02-12 21:39:12 +01001444static void
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001445printmmsghdr(struct tcb *tcp, long addr, unsigned int idx)
Andreas Schwab0873f292010-02-12 21:39:12 +01001446{
1447 struct mmsghdr {
1448 struct msghdr msg_hdr;
1449 unsigned msg_len;
1450 } mmsg;
1451
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001452 addr += sizeof(mmsg) * idx;
Andreas Schwab0873f292010-02-12 21:39:12 +01001453 if (umove(tcp, addr, &mmsg) < 0) {
1454 tprintf("%#lx", addr);
1455 return;
1456 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001457 tprints("{");
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001458 do_msghdr(tcp, &mmsg.msg_hdr, ULONG_MAX);
Andreas Schwab0873f292010-02-12 21:39:12 +01001459 tprintf(", %u}", mmsg.msg_len);
1460}
Andreas Schwab0873f292010-02-12 21:39:12 +01001461
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001462static void
1463decode_mmsg(struct tcb *tcp)
1464{
1465 /* mmsgvec */
1466 if (syserror(tcp)) {
1467 tprintf("%#lx", tcp->u_arg[1]);
1468 } else {
1469 unsigned int len = tcp->u_rval;
1470 unsigned int i;
1471
1472 tprints("{");
1473 for (i = 0; i < len; ++i) {
1474 if (i)
1475 tprints(", ");
1476 printmmsghdr(tcp, tcp->u_arg[1], i);
1477 }
1478 tprints("}");
1479 }
1480 /* vlen */
1481 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1482 /* flags */
1483 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1484}
1485
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486#endif /* HAVE_SENDMSG */
1487
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001488/*
1489 * low bits of the socket type define real socket type,
1490 * other bits are socket type flags.
1491 */
1492static void
1493tprint_sock_type(struct tcb *tcp, int flags)
1494{
1495 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1496
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001497 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001498 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001499 flags &= ~SOCK_TYPE_MASK;
1500 if (!flags)
1501 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001502 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001503 }
1504 printflags(sock_type_flags, flags, "SOCK_???");
1505}
1506
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001507int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001508sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509{
1510 if (entering(tcp)) {
1511 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001512 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001513 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001514 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001515 switch (tcp->u_arg[0]) {
1516 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001517#ifdef PF_INET6
1518 case PF_INET6:
1519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1521 break;
1522#ifdef PF_IPX
1523 case PF_IPX:
1524 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001525 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001526 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001527 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001528 break;
1529#endif /* PF_IPX */
1530 default:
1531 tprintf("%lu", tcp->u_arg[2]);
1532 break;
1533 }
1534 }
1535 return 0;
1536}
1537
John Hughesbdf48f52001-03-06 15:08:09 +00001538int
Denys Vlasenko12014262011-05-30 14:00:14 +02001539sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001540{
1541 if (entering(tcp)) {
1542 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001543 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 tprintf(", %lu", tcp->u_arg[2]);
1545 }
1546 return 0;
1547}
1548
1549int
Denys Vlasenko12014262011-05-30 14:00:14 +02001550sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551{
1552 return sys_bind(tcp);
1553}
1554
1555int
Denys Vlasenko12014262011-05-30 14:00:14 +02001556sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001557{
1558 if (entering(tcp)) {
1559 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1560 }
1561 return 0;
1562}
1563
Paolo Bonzini705ff102009-08-14 12:34:05 +02001564static int
1565do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566{
1567 if (entering(tcp)) {
1568 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001569 return 0;
1570 }
1571 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 tprintf("%#lx, NULL", tcp->u_arg[1]);
1573 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001574 int len;
1575 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001576 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577 tprintf("%#lx", tcp->u_arg[1]);
1578 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001579 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001581 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001582 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001584 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001585 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001586 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1587 "SOCK_???");
1588 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001589 return 0;
1590}
1591
1592int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001593sys_accept(struct tcb *tcp)
1594{
1595 return do_accept(tcp, -1);
1596}
1597
Paolo Bonzini705ff102009-08-14 12:34:05 +02001598int
1599sys_accept4(struct tcb *tcp)
1600{
1601 return do_accept(tcp, 3);
1602}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001603
1604int
Denys Vlasenko12014262011-05-30 14:00:14 +02001605sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606{
1607 if (entering(tcp)) {
1608 tprintf("%ld, ", tcp->u_arg[0]);
1609 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1610 tprintf(", %lu, ", tcp->u_arg[2]);
1611 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001612 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 }
1614 return 0;
1615}
1616
1617int
Denys Vlasenko12014262011-05-30 14:00:14 +02001618sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619{
1620 if (entering(tcp)) {
1621 tprintf("%ld, ", tcp->u_arg[0]);
1622 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1623 tprintf(", %lu, ", tcp->u_arg[2]);
1624 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001625 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001627 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001628 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629 /* to length */
1630 tprintf(", %lu", tcp->u_arg[5]);
1631 }
1632 return 0;
1633}
1634
1635#ifdef HAVE_SENDMSG
1636
1637int
Denys Vlasenko12014262011-05-30 14:00:14 +02001638sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639{
1640 if (entering(tcp)) {
1641 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001642 printmsghdr(tcp, tcp->u_arg[1], ULONG_MAX);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001643 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001644 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001645 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 }
1647 return 0;
1648}
1649
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001650int
1651sys_sendmmsg(struct tcb *tcp)
1652{
1653 if (entering(tcp)) {
1654 /* sockfd */
1655 tprintf("%d, ", (int) tcp->u_arg[0]);
1656 if (!verbose(tcp)) {
1657 tprintf("%#lx, %u, ",
1658 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1659 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1660 }
1661 } else {
1662 if (verbose(tcp))
1663 decode_mmsg(tcp);
1664 }
1665 return 0;
1666}
1667
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668#endif /* HAVE_SENDMSG */
1669
1670int
Denys Vlasenko12014262011-05-30 14:00:14 +02001671sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001672{
1673 if (entering(tcp)) {
1674 tprintf("%ld, ", tcp->u_arg[0]);
1675 } else {
1676 if (syserror(tcp))
1677 tprintf("%#lx", tcp->u_arg[1]);
1678 else
1679 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1680
1681 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001682 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683 }
1684 return 0;
1685}
1686
1687int
Denys Vlasenko12014262011-05-30 14:00:14 +02001688sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689{
1690 int fromlen;
1691
1692 if (entering(tcp)) {
1693 tprintf("%ld, ", tcp->u_arg[0]);
1694 } else {
1695 if (syserror(tcp)) {
1696 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1697 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1698 tcp->u_arg[4], tcp->u_arg[5]);
1699 return 0;
1700 }
1701 /* buf */
1702 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1703 /* len */
1704 tprintf(", %lu, ", tcp->u_arg[2]);
1705 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001706 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001707 /* from address, len */
1708 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1709 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001710 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001711 else
1712 tprintf(", %#lx", tcp->u_arg[4]);
1713 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001714 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001715 else
1716 tprintf(", %#lx", tcp->u_arg[5]);
1717 return 0;
1718 }
1719 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001720 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 return 0;
1722 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001723 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001724 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001725 /* from length */
1726 tprintf(", [%u]", fromlen);
1727 }
1728 return 0;
1729}
1730
1731#ifdef HAVE_SENDMSG
1732
1733int
Denys Vlasenko12014262011-05-30 14:00:14 +02001734sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735{
1736 if (entering(tcp)) {
1737 tprintf("%ld, ", tcp->u_arg[0]);
1738 } else {
1739 if (syserror(tcp) || !verbose(tcp))
1740 tprintf("%#lx", tcp->u_arg[1]);
1741 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001742 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001743 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001744 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001745 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001746 }
1747 return 0;
1748}
1749
Andreas Schwab0873f292010-02-12 21:39:12 +01001750int
1751sys_recvmmsg(struct tcb *tcp)
1752{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001753 /* +5 chars are for "left " prefix */
1754 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001755
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001756 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001757 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001758 if (verbose(tcp)) {
1759 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001760 /* Abusing tcp->auxstr as temp storage.
1761 * Will be used and freed on syscall exit.
1762 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001763 tcp->auxstr = strdup(str);
1764 } else {
1765 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1766 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001767 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001768 print_timespec(tcp, tcp->u_arg[4]);
1769 }
1770 return 0;
1771 } else {
1772 if (verbose(tcp)) {
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001773 decode_mmsg(tcp);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001774 /* timeout on entrance */
1775 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1776 free((void *) tcp->auxstr);
1777 tcp->auxstr = NULL;
1778 }
1779 if (syserror(tcp))
1780 return 0;
1781 if (tcp->u_rval == 0) {
1782 tcp->auxstr = "Timeout";
1783 return RVAL_STR;
1784 }
1785 if (!verbose(tcp))
1786 return 0;
1787 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001788 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001789 tcp->auxstr = str;
1790 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001791 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001792}
Andreas Schwab0873f292010-02-12 21:39:12 +01001793
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794#endif /* HAVE_SENDMSG */
1795
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001796static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001797 { 0, "SHUT_RD" },
1798 { 1, "SHUT_WR" },
1799 { 2, "SHUT_RDWR" },
1800 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001801};
1802
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803int
Denys Vlasenko12014262011-05-30 14:00:14 +02001804sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805{
1806 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001807 tprintf("%ld, ", tcp->u_arg[0]);
1808 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001809 }
1810 return 0;
1811}
1812
1813int
Denys Vlasenko12014262011-05-30 14:00:14 +02001814sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815{
1816 return sys_accept(tcp);
1817}
1818
1819int
Denys Vlasenko12014262011-05-30 14:00:14 +02001820sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821{
1822 return sys_accept(tcp);
1823}
1824
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001825static int
1826do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828 if (exiting(tcp)) {
1829 if (syserror(tcp)) {
1830 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001831 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001832#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001833 int fds[2];
1834
1835 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001836 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001837 else
1838 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001839#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001840 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1841#else
1842 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001844 }
1845 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001846 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001847 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1848 }
1849 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001850 return 0;
1851}
1852
1853int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001854sys_pipe(struct tcb *tcp)
1855{
1856 return do_pipe(tcp, -1);
1857}
1858
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001859int
1860sys_pipe2(struct tcb *tcp)
1861{
1862 return do_pipe(tcp, 1);
1863}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001864
1865int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001866sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001869
1870 if (entering(tcp)) {
1871 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001872 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001873 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001874 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875 switch (tcp->u_arg[0]) {
1876 case PF_INET:
1877 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1878 break;
1879#ifdef PF_IPX
1880 case PF_IPX:
1881 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001882 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001884 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001885 break;
1886#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001887 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001888 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889 break;
1890 }
1891 } else {
1892 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001893 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894 return 0;
1895 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001897 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001898 else
1899 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900 }
1901 return 0;
1902}
1903
1904int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001905sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906{
1907 if (entering(tcp)) {
1908 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001909 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001910 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911 switch (tcp->u_arg[1]) {
1912 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001913 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 break;
1915#ifdef SOL_IP
1916 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918 break;
1919#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001920#ifdef SOL_IPV6
1921 case SOL_IPV6:
1922 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1923 break;
1924#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925#ifdef SOL_IPX
1926 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001928 break;
1929#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001930#ifdef SOL_PACKET
1931 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001932 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001933 break;
1934#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935#ifdef SOL_TCP
1936 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001938 break;
1939#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001940#ifdef SOL_SCTP
1941 case SOL_SCTP:
1942 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1943 break;
1944#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945
1946 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1947 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001948 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001949 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950 break;
1951 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001952 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001953 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001954 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001955 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001956 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957 tcp->u_arg[3], tcp->u_arg[4]);
1958 return 0;
1959 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001960
1961 switch (tcp->u_arg[1]) {
1962 case SOL_SOCKET:
1963 switch (tcp->u_arg[2]) {
1964#ifdef SO_LINGER
1965 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001966 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001967 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001968 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001969 tcp->u_arg[3],
1970 &linger) < 0)
1971 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001972 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001973 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001974 linger.l_onoff,
1975 linger.l_linger,
1976 len);
1977 return 0;
1978 }
1979 break;
1980#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001981#ifdef SO_PEERCRED
1982 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001983 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001984 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001985 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001986 tcp->u_arg[3],
1987 &uc) < 0)
1988 break;
1989 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1990 "[%d]",
1991 (long)uc.pid,
1992 (long)uc.uid,
1993 (long)uc.gid,
1994 len);
1995 return 0;
1996 }
1997 break;
1998#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001999 }
2000 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002001 case SOL_PACKET:
2002 switch (tcp->u_arg[2]) {
2003#ifdef PACKET_STATISTICS
2004 case PACKET_STATISTICS:
2005 if (len == sizeof(struct tpacket_stats)) {
2006 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002007 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002008 tcp->u_arg[3],
2009 &stats) < 0)
2010 break;
2011 tprintf("{packets=%u, drops=%u}, "
2012 "[%d]",
2013 stats.tp_packets,
2014 stats.tp_drops,
2015 len);
2016 return 0;
2017 }
2018 break;
2019#endif
2020 }
2021 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002022 }
2023
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002024 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002025 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002026 }
2027 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002028 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002029 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002030 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031 }
2032 return 0;
2033}
2034
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002035#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002036static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002037{
2038 struct icmp_filter filter;
2039
2040 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002041 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002042 return;
2043 }
2044 if (syserror(tcp) || !verbose(tcp)) {
2045 tprintf("%#lx", addr);
2046 return;
2047 }
2048 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002050 return;
2051 }
2052
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002053 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002054 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002055 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002056}
2057#endif /* ICMP_FILTER */
2058
John Hughes38ae88d2002-05-23 11:48:58 +00002059static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002060printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002061{
2062 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002063 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002064 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002065 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002066 printxval(sockoptions, name, "SO_???");
2067 switch (name) {
2068#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002069 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002070 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002071 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002072 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002073 break;
2074 tprintf(", {onoff=%d, linger=%d}",
2075 linger.l_onoff,
2076 linger.l_linger);
2077 return 0;
2078 }
2079 break;
2080#endif
2081 }
2082 break;
2083#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002084 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00002085 printxval(sockipoptions, name, "IP_???");
2086 break;
2087#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002088#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002089 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00002090 printxval(sockipv6options, name, "IPV6_???");
2091 break;
2092#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002093#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002094 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00002095 printxval(sockipxoptions, name, "IPX_???");
2096 break;
2097#endif
2098#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002099 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002100 printxval(sockpacketoptions, name, "PACKET_???");
2101 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002102 switch (name) {
2103#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002104 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002105#endif
2106#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002107 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002108#endif
2109#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2110 if (len == sizeof(struct tpacket_req)) {
2111 struct tpacket_req req;
2112 if (umove(tcp, addr, &req) < 0)
2113 break;
2114 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2115 req.tp_block_size,
2116 req.tp_block_nr,
2117 req.tp_frame_size,
2118 req.tp_frame_nr);
2119 return 0;
2120 }
2121 break;
2122#endif /* PACKET_RX_RING || PACKET_TX_RING */
2123 }
John Hughes38ae88d2002-05-23 11:48:58 +00002124 break;
2125#endif
2126#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002127 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00002128 printxval(socktcpoptions, name, "TCP_???");
2129 break;
2130#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002131#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002132 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002133 printxval(socksctpoptions, name, "SCTP_???");
2134 break;
2135#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002136#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002137 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00002138 printxval(sockrawoptions, name, "RAW_???");
2139 switch (name) {
2140#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002141 case ICMP_FILTER:
2142 tprints(", ");
2143 printicmpfilter(tcp, addr);
2144 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002145#endif
2146 }
2147 break;
2148#endif
2149
Roland McGrath6d2b3492002-12-30 00:51:30 +00002150 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002151 * etc. still need work */
2152
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002153 default:
John Hughes38ae88d2002-05-23 11:48:58 +00002154 tprintf("%u", name);
2155 }
2156
2157 /* default arg printing */
2158
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002159 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002160
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002161 if (len == sizeof(int)) {
2162 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002163 }
2164 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002165 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002166 }
2167 return 0;
2168}
2169
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002170#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002171
2172void
Denys Vlasenko12014262011-05-30 14:00:14 +02002173print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002174{
2175 int c = 0;
2176 struct opthdr hdr;
2177
John Hughes2c4e3a82002-05-24 10:19:44 +00002178 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002179 if (umove(tcp, addr, &hdr) < 0) break;
2180 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002181 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002182 }
2183 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002184 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002185 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002186 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002187 addr += sizeof hdr;
2188 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002189 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002190 if (hdr.len > 0) {
2191 addr += hdr.len;
2192 len -= hdr.len;
2193 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002194 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002195 }
2196 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002197 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002198 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002199 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002200 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002201}
2202
2203#endif
2204
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205int
Denys Vlasenko12014262011-05-30 14:00:14 +02002206sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207{
2208 if (entering(tcp)) {
2209 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002210 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002211 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002212 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 }
2214 return 0;
2215}