blob: 31e63dd95f70293902b92d6d7aadb75883b1f94a [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
34#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000035#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# define in6_addr in6_addr_libc
37# define ipv6_mreq ipv6_mreq_libc
38# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000039#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000041#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010042# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000043#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000044#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010047#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000051#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010053#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010054# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Denys Vlasenko99aa1812013-02-08 18:49:06 +010059#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010060# if defined(HAVE_LINUX_IN6_H)
61# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
62# undef in6_addr
63# undef ipv6_mreq
64# undef sockaddr_in6
65# define in6_addr in6_addr_kernel
66# define ipv6_mreq ipv6_mreq_kernel
67# define sockaddr_in6 sockaddr_in6_kernel
68# endif
69# include <linux/in6.h>
70# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
71# undef in6_addr
72# undef ipv6_mreq
73# undef sockaddr_in6
74# define in6_addr in6_addr_libc
75# define ipv6_mreq ipv6_mreq_libc
76# define sockaddr_in6 sockaddr_in6_kernel
77# endif
78# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000079#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000080
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000081#if defined(HAVE_SYS_UIO_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010082# include <sys/uio.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010085# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010088# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010091# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010094# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095#endif
96
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097/* Under Linux these are enums so we can't test for them with ifdef. */
98#define IPPROTO_EGP IPPROTO_EGP
99#define IPPROTO_PUP IPPROTO_PUP
100#define IPPROTO_IDP IPPROTO_IDP
101#define IPPROTO_IGMP IPPROTO_IGMP
102#define IPPROTO_RAW IPPROTO_RAW
103#define IPPROTO_MAX IPPROTO_MAX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104
Roland McGrathd9f816f2004-09-04 03:39:20 +0000105static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000106#ifdef PF_AAL5
107 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#endif
109#ifdef PF_APPLETALK
110 { PF_APPLETALK, "PF_APPLETALK" },
111#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000112#ifdef PF_ASH
113 { PF_ASH, "PF_ASH" },
114#endif
115#ifdef PF_ATMPVC
116 { PF_ATMPVC, "PF_ATMPVC" },
117#endif
118#ifdef PF_ATMSVC
119 { PF_ATMSVC, "PF_ATMSVC" },
120#endif
121#ifdef PF_AX25
122 { PF_AX25, "PF_AX25" },
123#endif
124#ifdef PF_BLUETOOTH
125 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#endif
127#ifdef PF_BRIDGE
128 { PF_BRIDGE, "PF_BRIDGE" },
129#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000130#ifdef PF_DECnet
131 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000132#endif
133#ifdef PF_DECNET
134 { PF_DECNET, "PF_DECNET" },
135#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000136#ifdef PF_ECONET
137 { PF_ECONET, "PF_ECONET" },
138#endif
139#ifdef PF_FILE
140 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#endif
142#ifdef PF_IMPLINK
143 { PF_IMPLINK, "PF_IMPLINK" },
144#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000145#ifdef PF_INET
146 { PF_INET, "PF_INET" },
147#endif
148#ifdef PF_INET6
149 { PF_INET6, "PF_INET6" },
150#endif
151#ifdef PF_IPX
152 { PF_IPX, "PF_IPX" },
153#endif
154#ifdef PF_IRDA
155 { PF_IRDA, "PF_IRDA" },
156#endif
157#ifdef PF_ISO
158 { PF_ISO, "PF_ISO" },
159#endif
160#ifdef PF_KEY
161 { PF_KEY, "PF_KEY" },
162#endif
163#ifdef PF_UNIX
164 { PF_UNIX, "PF_UNIX" },
165#endif
166#ifdef PF_LOCAL
167 { PF_LOCAL, "PF_LOCAL" },
168#endif
169#ifdef PF_NETBEUI
170 { PF_NETBEUI, "PF_NETBEUI" },
171#endif
172#ifdef PF_NETLINK
173 { PF_NETLINK, "PF_NETLINK" },
174#endif
175#ifdef PF_NETROM
176 { PF_NETROM, "PF_NETROM" },
177#endif
178#ifdef PF_PACKET
179 { PF_PACKET, "PF_PACKET" },
180#endif
181#ifdef PF_PPPOX
182 { PF_PPPOX, "PF_PPPOX" },
183#endif
184#ifdef PF_ROSE
185 { PF_ROSE, "PF_ROSE" },
186#endif
187#ifdef PF_ROUTE
188 { PF_ROUTE, "PF_ROUTE" },
189#endif
190#ifdef PF_SECURITY
191 { PF_SECURITY, "PF_SECURITY" },
192#endif
193#ifdef PF_SNA
194 { PF_SNA, "PF_SNA" },
195#endif
196#ifdef PF_UNSPEC
197 { PF_UNSPEC, "PF_UNSPEC" },
198#endif
199#ifdef PF_WANPIPE
200 { PF_WANPIPE, "PF_WANPIPE" },
201#endif
202#ifdef PF_X25
203 { PF_X25, "PF_X25" },
204#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 { 0, NULL },
206};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000207const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000208#ifdef AF_APPLETALK
209 { AF_APPLETALK, "AF_APPLETALK" },
210#endif
211#ifdef AF_ASH
212 { AF_ASH, "AF_ASH" },
213#endif
214#ifdef AF_ATMPVC
215 { AF_ATMPVC, "AF_ATMPVC" },
216#endif
217#ifdef AF_ATMSVC
218 { AF_ATMSVC, "AF_ATMSVC" },
219#endif
220#ifdef AF_AX25
221 { AF_AX25, "AF_AX25" },
222#endif
223#ifdef AF_BLUETOOTH
224 { AF_BLUETOOTH, "AF_BLUETOOTH" },
225#endif
226#ifdef AF_BRIDGE
227 { AF_BRIDGE, "AF_BRIDGE" },
228#endif
229#ifdef AF_DECnet
230 { AF_DECnet, "AF_DECnet" },
231#endif
232#ifdef AF_ECONET
233 { AF_ECONET, "AF_ECONET" },
234#endif
235#ifdef AF_FILE
236 { AF_FILE, "AF_FILE" },
237#endif
238#ifdef AF_IMPLINK
239 { AF_IMPLINK, "AF_IMPLINK" },
240#endif
241#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000243#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000244#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000245 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000246#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000247#ifdef AF_IPX
248 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000249#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000250#ifdef AF_IRDA
251 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000252#endif
253#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000254 { AF_ISO, "AF_ISO" },
255#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000256#ifdef AF_KEY
257 { AF_KEY, "AF_KEY" },
258#endif
259#ifdef AF_UNIX
260 { AF_UNIX, "AF_UNIX" },
261#endif
262#ifdef AF_LOCAL
263 { AF_LOCAL, "AF_LOCAL" },
264#endif
265#ifdef AF_NETBEUI
266 { AF_NETBEUI, "AF_NETBEUI" },
267#endif
268#ifdef AF_NETLINK
269 { AF_NETLINK, "AF_NETLINK" },
270#endif
271#ifdef AF_NETROM
272 { AF_NETROM, "AF_NETROM" },
273#endif
274#ifdef AF_PACKET
275 { AF_PACKET, "AF_PACKET" },
276#endif
277#ifdef AF_PPPOX
278 { AF_PPPOX, "AF_PPPOX" },
279#endif
280#ifdef AF_ROSE
281 { AF_ROSE, "AF_ROSE" },
282#endif
283#ifdef AF_ROUTE
284 { AF_ROUTE, "AF_ROUTE" },
285#endif
286#ifdef AF_SECURITY
287 { AF_SECURITY, "AF_SECURITY" },
288#endif
289#ifdef AF_SNA
290 { AF_SNA, "AF_SNA" },
291#endif
292#ifdef AF_UNSPEC
293 { AF_UNSPEC, "AF_UNSPEC" },
294#endif
295#ifdef AF_WANPIPE
296 { AF_WANPIPE, "AF_WANPIPE" },
297#endif
298#ifdef AF_X25
299 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300#endif
301 { 0, NULL },
302};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000303static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304 { SOCK_STREAM, "SOCK_STREAM" },
305 { SOCK_DGRAM, "SOCK_DGRAM" },
306#ifdef SOCK_RAW
307 { SOCK_RAW, "SOCK_RAW" },
308#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000309#ifdef SOCK_RDM
310 { SOCK_RDM, "SOCK_RDM" },
311#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312#ifdef SOCK_SEQPACKET
313 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
314#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000315#ifdef SOCK_DCCP
316 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317#endif
318#ifdef SOCK_PACKET
319 { SOCK_PACKET, "SOCK_PACKET" },
320#endif
321 { 0, NULL },
322};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000323static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000324#ifdef SOCK_CLOEXEC
325 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
326#endif
327#ifdef SOCK_NONBLOCK
328 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
329#endif
330 { 0, NULL },
331};
332#ifndef SOCK_TYPE_MASK
333# define SOCK_TYPE_MASK 0xf
334#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000335static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000336#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000337 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000338#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000339#if defined(SOL_ICMP)
340 { SOL_ICMP, "SOL_ICMP" },
341#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000342#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000343 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000344#endif
345#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000346 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000347#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000348#if defined(SOL_IPV6)
349 { SOL_IPV6, "SOL_IPV6" },
350#endif
351#if defined(SOL_ICMPV6)
352 { SOL_ICMPV6, "SOL_ICMPV6" },
353#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100354#if defined(SOL_SCTP)
355 { SOL_SCTP, "SOL_SCTP" },
356#endif
357#if defined(SOL_UDPLITE)
358 { SOL_UDPLITE, "SOL_UDPLITE" },
359#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360#if defined(SOL_RAW)
361 { SOL_RAW, "SOL_RAW" },
362#endif
363#if defined(SOL_IPX)
364 { SOL_IPX, "SOL_IPX" },
365#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000366#if defined(SOL_AX25)
367 { SOL_AX25, "SOL_AX25" },
368#endif
369#if defined(SOL_ATALK)
370 { SOL_ATALK, "SOL_ATALK" },
371#endif
372#if defined(SOL_NETROM)
373 { SOL_NETROM, "SOL_NETROM" },
374#endif
375#if defined(SOL_ROSE)
376 { SOL_ROSE, "SOL_ROSE" },
377#endif
378#if defined(SOL_DECNET)
379 { SOL_DECNET, "SOL_DECNET" },
380#endif
381#if defined(SOL_X25)
382 { SOL_X25, "SOL_X25" },
383#endif
384#if defined(SOL_PACKET)
385 { SOL_PACKET, "SOL_PACKET" },
386#endif
387#if defined(SOL_ATM)
388 { SOL_ATM, "SOL_ATM" },
389#endif
390#if defined(SOL_AAL)
391 { SOL_AAL, "SOL_AAL" },
392#endif
393#if defined(SOL_IRDA)
394 { SOL_IRDA, "SOL_IRDA" },
395#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100396#if defined(SOL_NETBEUI)
397 { SOL_NETBEUI, "SOL_NETBEUI" },
398#endif
399#if defined(SOL_LLC)
400 { SOL_LLC, "SOL_LLC" },
401#endif
402#if defined(SOL_DCCP)
403 { SOL_DCCP, "SOL_DCCP" },
404#endif
405#if defined(SOL_NETLINK)
406 { SOL_NETLINK, "SOL_NETLINK" },
407#endif
408#if defined(SOL_TIPC)
409 { SOL_TIPC, "SOL_TIPC" },
410#endif
411#if defined(SOL_RXRPC)
412 { SOL_RXRPC, "SOL_RXRPC" },
413#endif
414#if defined(SOL_PPPOL2TP)
415 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
416#endif
417#if defined(SOL_BLUETOOTH)
418 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
419#endif
420#if defined(SOL_PNPIPE)
421 { SOL_PNPIPE, "SOL_PNPIPE" },
422#endif
423#if defined(SOL_RDS)
424 { SOL_RDS, "SOL_RDS" },
425#endif
426#if defined(SOL_IUVC)
427 { SOL_IUCV, "SOL_IUCV" },
428#endif
429#if defined(SOL_CAIF)
430 { SOL_CAIF, "SOL_CAIF" },
431#endif
John Hughes61563572001-03-27 16:47:36 +0000432 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000433 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000434};
John Hughes93f7fcc2002-05-22 15:46:49 +0000435/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
436 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000437static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 { IPPROTO_IP, "IPPROTO_IP" },
439 { IPPROTO_ICMP, "IPPROTO_ICMP" },
440 { IPPROTO_TCP, "IPPROTO_TCP" },
441 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000442#ifdef IPPROTO_IGMP
443 { IPPROTO_IGMP, "IPPROTO_IGMP" },
444#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445#ifdef IPPROTO_GGP
446 { IPPROTO_GGP, "IPPROTO_GGP" },
447#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000448#ifdef IPPROTO_IPIP
449 { IPPROTO_IPIP, "IPPROTO_IPIP" },
450#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451#ifdef IPPROTO_EGP
452 { IPPROTO_EGP, "IPPROTO_EGP" },
453#endif
454#ifdef IPPROTO_PUP
455 { IPPROTO_PUP, "IPPROTO_PUP" },
456#endif
457#ifdef IPPROTO_IDP
458 { IPPROTO_IDP, "IPPROTO_IDP" },
459#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000460#ifdef IPPROTO_TP
461 { IPPROTO_TP, "IPPROTO_TP" },
462#endif
463#ifdef IPPROTO_DCCP
464 { IPPROTO_DCCP, "IPPROTO_DCCP" },
465#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466#ifdef IPPROTO_IPV6
467 { IPPROTO_IPV6, "IPPROTO_IPV6" },
468#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000469#ifdef IPPROTO_ROUTING
470 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000472#ifdef IPPROTO_FRAGMENT
473 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
474#endif
475#ifdef IPPROTO_RSVP
476 { IPPROTO_RSVP, "IPPROTO_RSVP" },
477#endif
478#ifdef IPPROTO_GRE
479 { IPPROTO_GRE, "IPPROTO_GRE" },
480#endif
481#ifdef IPPROTO_ESP
482 { IPPROTO_ESP, "IPPROTO_ESP" },
483#endif
484#ifdef IPPROTO_AH
485 { IPPROTO_AH, "IPPROTO_AH" },
486#endif
487#ifdef IPPROTO_ICMPV6
488 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
489#endif
490#ifdef IPPROTO_NONE
491 { IPPROTO_NONE, "IPPROTO_NONE" },
492#endif
493#ifdef IPPROTO_DSTOPTS
494 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495#endif
496#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000497 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498#endif
499#ifdef IPPROTO_ND
500 { IPPROTO_ND, "IPPROTO_ND" },
501#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000502#ifdef IPPROTO_MTP
503 { IPPROTO_MTP, "IPPROTO_MTP" },
504#endif
505#ifdef IPPROTO_ENCAP
506 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
507#endif
508#ifdef IPPROTO_PIM
509 { IPPROTO_PIM, "IPPROTO_PIM" },
510#endif
511#ifdef IPPROTO_COMP
512 { IPPROTO_COMP, "IPPROTO_COMP" },
513#endif
514#ifdef IPPROTO_SCTP
515 { IPPROTO_SCTP, "IPPROTO_SCTP" },
516#endif
517#ifdef IPPROTO_UDPLITE
518 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520#ifdef IPPROTO_RAW
521 { IPPROTO_RAW, "IPPROTO_RAW" },
522#endif
523#ifdef IPPROTO_MAX
524 { IPPROTO_MAX, "IPPROTO_MAX" },
525#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 { 0, NULL },
527};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000528static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000529 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000531 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532#endif
533#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000534 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535#endif
536#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000537 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538#endif
539#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000540 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541#endif
542#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000543 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544#endif
545#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000546 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000548#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000549 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000550#endif
551#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000552 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000553#endif
554#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000555 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000556#endif
557#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000558 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000559#endif
560#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000561 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000562#endif
563#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000564 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000566#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000567 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000568#endif
569#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000570 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000571#endif
572#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000573 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000574#endif
575#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000576 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000577#endif
578#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000579 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000580#endif
Dmitry V. Levin3df080a2012-03-13 01:26:26 +0000581#ifdef MSG_WAITFORONE
582 { MSG_WAITFORONE, "MSG_WAITFORONE" },
583#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000584#ifdef MSG_CMSG_CLOEXEC
585 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
586#endif
587 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588};
589
Roland McGrathd9f816f2004-09-04 03:39:20 +0000590static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000592 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000593#endif
594#ifdef SO_ALLRAW
595 { SO_ALLRAW, "SO_ALLRAW" },
596#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000597#ifdef SO_ATTACH_FILTER
598 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
599#endif
600#ifdef SO_BINDTODEVICE
601 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
602#endif
603#ifdef SO_BROADCAST
604 { SO_BROADCAST, "SO_BROADCAST" },
605#endif
606#ifdef SO_BSDCOMPAT
607 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
608#endif
609#ifdef SO_DEBUG
610 { SO_DEBUG, "SO_DEBUG" },
611#endif
612#ifdef SO_DETACH_FILTER
613 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
614#endif
615#ifdef SO_DONTROUTE
616 { SO_DONTROUTE, "SO_DONTROUTE" },
617#endif
618#ifdef SO_ERROR
619 { SO_ERROR, "SO_ERROR" },
620#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000621#ifdef SO_ICS
622 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000624#ifdef SO_IMASOCKET
625 { SO_IMASOCKET, "SO_IMASOCKET" },
626#endif
627#ifdef SO_KEEPALIVE
628 { SO_KEEPALIVE, "SO_KEEPALIVE" },
629#endif
630#ifdef SO_LINGER
631 { SO_LINGER, "SO_LINGER" },
632#endif
633#ifdef SO_LISTENING
634 { SO_LISTENING, "SO_LISTENING" },
635#endif
636#ifdef SO_MGMT
637 { SO_MGMT, "SO_MGMT" },
638#endif
639#ifdef SO_NO_CHECK
640 { SO_NO_CHECK, "SO_NO_CHECK" },
641#endif
642#ifdef SO_OOBINLINE
643 { SO_OOBINLINE, "SO_OOBINLINE" },
644#endif
645#ifdef SO_ORDREL
646 { SO_ORDREL, "SO_ORDREL" },
647#endif
648#ifdef SO_PARALLELSVR
649 { SO_PARALLELSVR, "SO_PARALLELSVR" },
650#endif
651#ifdef SO_PASSCRED
652 { SO_PASSCRED, "SO_PASSCRED" },
653#endif
654#ifdef SO_PEERCRED
655 { SO_PEERCRED, "SO_PEERCRED" },
656#endif
657#ifdef SO_PEERNAME
658 { SO_PEERNAME, "SO_PEERNAME" },
659#endif
660#ifdef SO_PEERSEC
661 { SO_PEERSEC, "SO_PEERSEC" },
662#endif
663#ifdef SO_PRIORITY
664 { SO_PRIORITY, "SO_PRIORITY" },
665#endif
666#ifdef SO_PROTOTYPE
667 { SO_PROTOTYPE, "SO_PROTOTYPE" },
668#endif
669#ifdef SO_RCVBUF
670 { SO_RCVBUF, "SO_RCVBUF" },
671#endif
672#ifdef SO_RCVLOWAT
673 { SO_RCVLOWAT, "SO_RCVLOWAT" },
674#endif
675#ifdef SO_RCVTIMEO
676 { SO_RCVTIMEO, "SO_RCVTIMEO" },
677#endif
678#ifdef SO_RDWR
679 { SO_RDWR, "SO_RDWR" },
680#endif
681#ifdef SO_REUSEADDR
682 { SO_REUSEADDR, "SO_REUSEADDR" },
683#endif
684#ifdef SO_REUSEPORT
685 { SO_REUSEPORT, "SO_REUSEPORT" },
686#endif
687#ifdef SO_SECURITY_AUTHENTICATION
688 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
689#endif
690#ifdef SO_SECURITY_ENCRYPTION_NETWORK
691 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
692#endif
693#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
694 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
695#endif
696#ifdef SO_SEMA
697 { SO_SEMA, "SO_SEMA" },
698#endif
699#ifdef SO_SNDBUF
700 { SO_SNDBUF, "SO_SNDBUF" },
701#endif
702#ifdef SO_SNDLOWAT
703 { SO_SNDLOWAT, "SO_SNDLOWAT" },
704#endif
705#ifdef SO_SNDTIMEO
706 { SO_SNDTIMEO, "SO_SNDTIMEO" },
707#endif
708#ifdef SO_TIMESTAMP
709 { SO_TIMESTAMP, "SO_TIMESTAMP" },
710#endif
711#ifdef SO_TYPE
712 { SO_TYPE, "SO_TYPE" },
713#endif
714#ifdef SO_USELOOPBACK
715 { SO_USELOOPBACK, "SO_USELOOPBACK" },
716#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717 { 0, NULL },
718};
719
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100720#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000721#define SOL_IP IPPROTO_IP
722#endif
723
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000725static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000726#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000727 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000728#endif
729#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000730 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000731#endif
732#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000733 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000735#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000736 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000738#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000739 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000740#endif
741#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000742 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
743#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000744#ifdef IP_RECVOPTS
745 { IP_RECVOPTS, "IP_RECVOPTS" },
746#endif
747#ifdef IP_RECVRETOPTS
748 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
749#endif
750#ifdef IP_RECVDSTADDR
751 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
752#endif
753#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000754 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000755#endif
756#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000757 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000758#endif
759#ifdef IP_PKTOPTIONS
760 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
761#endif
762#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000763 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000764#endif
765#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000766 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000767#endif
768#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000769 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000770#endif
771#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000772 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000773#endif
774#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000775 { IP_MTU, "IP_MTU" },
776#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000777#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000778 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000779#endif
780#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000781 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000782#endif
783#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000784 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000785#endif
786#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000787 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000788#endif
789#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000790 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#endif
792#ifdef IP_BROADCAST_IF
793 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
794#endif
795#ifdef IP_RECVIFINDEX
796 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
797#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000798#ifdef IP_MSFILTER
799 { IP_MSFILTER, "IP_MSFILTER" },
800#endif
801#ifdef MCAST_MSFILTER
802 { MCAST_MSFILTER, "MCAST_MSFILTER" },
803#endif
804#ifdef IP_FREEBIND
805 { IP_FREEBIND, "IP_FREEBIND" },
806#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000807 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808};
809#endif /* SOL_IP */
810
Roland McGrath4f6ba692004-08-31 07:01:26 +0000811#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000812static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000813#ifdef IPV6_ADDRFORM
814 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
815#endif
816#ifdef MCAST_FILTER
817 { MCAST_FILTER, "MCAST_FILTER" },
818#endif
819#ifdef IPV6_PKTOPTIONS
820 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
821#endif
822#ifdef IPV6_MTU
823 { IPV6_MTU, "IPV6_MTU" },
824#endif
825#ifdef IPV6_V6ONLY
826 { IPV6_V6ONLY, "IPV6_V6ONLY" },
827#endif
828#ifdef IPV6_PKTINFO
829 { IPV6_PKTINFO, "IPV6_PKTINFO" },
830#endif
831#ifdef IPV6_HOPLIMIT
832 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
833#endif
834#ifdef IPV6_RTHDR
835 { IPV6_RTHDR, "IPV6_RTHDR" },
836#endif
837#ifdef IPV6_HOPOPTS
838 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
839#endif
840#ifdef IPV6_DSTOPTS
841 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
842#endif
843#ifdef IPV6_FLOWINFO
844 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
845#endif
846#ifdef IPV6_UNICAST_HOPS
847 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
848#endif
849#ifdef IPV6_MULTICAST_HOPS
850 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
851#endif
852#ifdef IPV6_MULTICAST_LOOP
853 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
854#endif
855#ifdef IPV6_MULTICAST_IF
856 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
857#endif
858#ifdef IPV6_MTU_DISCOVER
859 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
860#endif
861#ifdef IPV6_RECVERR
862 { IPV6_RECVERR, "IPV6_RECVERR" },
863#endif
864#ifdef IPV6_FLOWINFO_SEND
865 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
866#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000867#ifdef IPV6_ADD_MEMBERSHIP
868 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
869#endif
870#ifdef IPV6_DROP_MEMBERSHIP
871 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
872#endif
873#ifdef IPV6_ROUTER_ALERT
874 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
875#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000876 { 0, NULL },
877};
878#endif /* SOL_IPV6 */
879
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000880#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000881static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200882 { IPX_TYPE, "IPX_TYPE" },
883 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884};
885#endif /* SOL_IPX */
886
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000887#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000888static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000889#if defined(ICMP_FILTER)
890 { ICMP_FILTER, "ICMP_FILTER" },
891#endif
892 { 0, NULL },
893};
894#endif /* SOL_RAW */
895
896#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000897static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000898#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000899 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000900#endif
901#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000902 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000903#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000904#if defined(PACKET_RECV_OUTPUT)
905 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
906#endif
907#if defined(PACKET_RX_RING)
908 { PACKET_RX_RING, "PACKET_RX_RING" },
909#endif
910#if defined(PACKET_STATISTICS)
911 { PACKET_STATISTICS, "PACKET_STATISTICS" },
912#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000913#if defined(PACKET_COPY_THRESH)
914 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
915#endif
916#if defined(PACKET_AUXDATA)
917 { PACKET_AUXDATA, "PACKET_AUXDATA" },
918#endif
919#if defined(PACKET_ORIGDEV)
920 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
921#endif
922#if defined(PACKET_VERSION)
923 { PACKET_VERSION, "PACKET_VERSION" },
924#endif
925#if defined(PACKET_HDRLEN)
926 { PACKET_HDRLEN, "PACKET_HDRLEN" },
927#endif
928#if defined(PACKET_RESERVE)
929 { PACKET_RESERVE, "PACKET_RESERVE" },
930#endif
931#if defined(PACKET_TX_RING)
932 { PACKET_TX_RING, "PACKET_TX_RING" },
933#endif
934#if defined(PACKET_LOSS)
935 { PACKET_LOSS, "PACKET_LOSS" },
936#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000937 { 0, NULL },
938};
939#endif /* SOL_PACKET */
940
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100941#ifdef SOL_SCTP
942static const struct xlat socksctpoptions[] = {
943#if defined(SCTP_RTOINFO)
944 { SCTP_RTOINFO, "SCTP_RTOINFO" },
945#endif
946#if defined(SCTP_ASSOCINFO)
947 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
948#endif
949#if defined(SCTP_INITMSG)
950 { SCTP_INITMSG, "SCTP_INITMSG" },
951#endif
952#if defined(SCTP_NODELAY)
953 { SCTP_NODELAY, "SCTP_NODELAY" },
954#endif
955#if defined(SCTP_AUTOCLOSE)
956 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
957#endif
958#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
959 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
960#endif
961#if defined(SCTP_PRIMARY_ADDR)
962 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
963#endif
964#if defined(SCTP_ADAPTATION_LAYER)
965 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
966#endif
967#if defined(SCTP_DISABLE_FRAGMENTS)
968 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
969#endif
970#if defined(SCTP_PEER_ADDR_PARAMS)
971 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
972#endif
973#if defined(SCTP_DEFAULT_SEND_PARAM)
974 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
975#endif
976#if defined(SCTP_EVENTS)
977 { SCTP_EVENTS, "SCTP_EVENTS" },
978#endif
979#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
980 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
981#endif
982#if defined(SCTP_MAXSEG)
983 { SCTP_MAXSEG, "SCTP_MAXSEG" },
984#endif
985#if defined(SCTP_STATUS)
986 { SCTP_STATUS, "SCTP_STATUS" },
987#endif
988#if defined(SCTP_GET_PEER_ADDR_INFO)
989 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
990#endif
991#if defined(SCTP_DELAYED_ACK)
992 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
993#endif
994#if defined(SCTP_CONTEXT)
995 { SCTP_CONTEXT, "SCTP_CONTEXT" },
996#endif
997#if defined(SCTP_FRAGMENT_INTERLEAVE)
998 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
999#endif
1000#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1001 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1002#endif
1003#if defined(SCTP_MAX_BURST)
1004 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1005#endif
1006#if defined(SCTP_AUTH_CHUNK)
1007 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1008#endif
1009#if defined(SCTP_HMAC_IDENT)
1010 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1011#endif
1012#if defined(SCTP_AUTH_KEY)
1013 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1014#endif
1015#if defined(SCTP_AUTH_ACTIVE_KEY)
1016 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1017#endif
1018#if defined(SCTP_AUTH_DELETE_KEY)
1019 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1020#endif
1021#if defined(SCTP_PEER_AUTH_CHUNKS)
1022 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1023#endif
1024#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1025 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1026#endif
1027#if defined(SCTP_GET_ASSOC_NUMBER)
1028 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1029#endif
1030
1031 /* linux specific things */
1032#if defined(SCTP_SOCKOPT_BINDX_ADD)
1033 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1034#endif
1035#if defined(SCTP_SOCKOPT_BINDX_REM)
1036 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1037#endif
1038#if defined(SCTP_SOCKOPT_PEELOFF)
1039 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1040#endif
1041#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1042 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1043#endif
1044#if defined(SCTP_GET_PEER_ADDRS_OLD)
1045 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1046#endif
1047#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1048 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1049#endif
1050#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1051 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1052#endif
1053#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1054 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1055#endif
1056#if defined(SCTP_GET_PEER_ADDRS)
1057 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1058#endif
1059#if defined(SCTP_GET_LOCAL_ADDRS)
1060 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1061#endif
1062
1063 { 0, NULL },
1064};
1065#endif
1066
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001067#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +00001068#define SOL_TCP IPPROTO_TCP
1069#endif
1070
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001072static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001073 { TCP_NODELAY, "TCP_NODELAY" },
1074 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001075#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001076 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001077#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001078#if defined(TCP_KEEPIDLE)
1079 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1080#endif
1081#if defined(TCP_KEEPINTVL)
1082 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1083#endif
1084#if defined(TCP_KEEPCNT)
1085 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1086#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001087#if defined(TCP_NKEEP)
1088 { TCP_NKEEP, "TCP_NKEEP" },
1089#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001090#if defined(TCP_SYNCNT)
1091 { TCP_SYNCNT, "TCP_SYNCNT" },
1092#endif
1093#if defined(TCP_LINGER2)
1094 { TCP_LINGER2, "TCP_LINGER2" },
1095#endif
1096#if defined(TCP_DEFER_ACCEPT)
1097 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1098#endif
1099#if defined(TCP_WINDOW_CLAMP)
1100 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1101#endif
1102#if defined(TCP_INFO)
1103 { TCP_INFO, "TCP_INFO" },
1104#endif
1105#if defined(TCP_QUICKACK)
1106 { TCP_QUICKACK, "TCP_QUICKACK" },
1107#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001108#if defined(TCP_CONGESTION)
1109 { TCP_CONGESTION, "TCP_CONGESTION" },
1110#endif
1111#if defined(TCP_MD5SIG)
1112 { TCP_MD5SIG, "TCP_MD5SIG" },
1113#endif
1114#if defined(TCP_COOKIE_TRANSACTIONS)
1115 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1116#endif
1117#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1118 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1119#endif
1120#if defined(TCP_THIN_DUPACK)
1121 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1122#endif
1123#if defined(TCP_USER_TIMEOUT)
1124 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1125#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001126 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127};
1128#endif /* SOL_TCP */
1129
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001130#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001131static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001132#if defined(ICMP_ECHOREPLY)
1133 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1134#endif
1135#if defined(ICMP_DEST_UNREACH)
1136 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1137#endif
1138#if defined(ICMP_SOURCE_QUENCH)
1139 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1140#endif
1141#if defined(ICMP_REDIRECT)
1142 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1143#endif
1144#if defined(ICMP_ECHO)
1145 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1146#endif
1147#if defined(ICMP_TIME_EXCEEDED)
1148 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1149#endif
1150#if defined(ICMP_PARAMETERPROB)
1151 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1152#endif
1153#if defined(ICMP_TIMESTAMP)
1154 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1155#endif
1156#if defined(ICMP_TIMESTAMPREPLY)
1157 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1158#endif
1159#if defined(ICMP_INFO_REQUEST)
1160 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1161#endif
1162#if defined(ICMP_INFO_REPLY)
1163 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1164#endif
1165#if defined(ICMP_ADDRESS)
1166 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1167#endif
1168#if defined(ICMP_ADDRESSREPLY)
1169 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1170#endif
1171 { 0, NULL },
1172};
1173#endif /* SOL_RAW */
1174
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001175#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001176static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001177#if defined(PACKET_HOST)
1178 { PACKET_HOST, "PACKET_HOST" },
1179#endif
1180#if defined(PACKET_BROADCAST)
1181 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1182#endif
1183#if defined(PACKET_MULTICAST)
1184 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1185#endif
1186#if defined(PACKET_OTHERHOST)
1187 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1188#endif
1189#if defined(PACKET_OUTGOING)
1190 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1191#endif
1192#if defined(PACKET_LOOPBACK)
1193 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1194#endif
1195#if defined(PACKET_FASTROUTE)
1196 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1197#endif
1198 { 0, NULL },
1199};
1200#endif /* defined(AF_PACKET) */
1201
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001203printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001204{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001205 union {
1206 char pad[128];
1207 struct sockaddr sa;
1208 struct sockaddr_in sin;
1209 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001210#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001211 struct sockaddr_in6 sa6;
1212#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001213#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001214 struct sockaddr_ipx sipx;
1215#endif
1216#ifdef AF_PACKET
1217 struct sockaddr_ll ll;
1218#endif
1219#ifdef AF_NETLINK
1220 struct sockaddr_nl nl;
1221#endif
1222 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001223 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224
1225 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001226 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227 return;
1228 }
1229 if (!verbose(tcp)) {
1230 tprintf("%#lx", addr);
1231 return;
1232 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001233
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001234 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1235 addrlen = sizeof(addrbuf);
1236
1237 memset(&addrbuf, 0, sizeof(addrbuf));
1238 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001239 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240 return;
1241 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001242 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001243
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001244 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001245 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001246 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001247
1248 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001250 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001251 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001252 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001253 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001254 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001255 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +00001256 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001257 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001258 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259 break;
1260 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001261 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001262 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001264#ifdef HAVE_INET_NTOP
1265 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001266 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001267 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1268 ntohs(addrbuf.sa6.sin6_port), string_addr,
1269 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001270#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001271 {
1272#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001273 int numericscope = 0;
1274 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1275 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1276 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001277
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001278 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1279 numericscope++;
1280 else
1281 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1282 } else
1283 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001284
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001285 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001286#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001288 }
1289#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001290 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001291#endif
Denys Vlasenko84703742012-02-25 02:38:52 +01001292#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001294 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001296 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001297 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 /* Yes, I know, this does not look too
1299 * strace-ish, but otherwise the IPX
1300 * addresses just look monstrous...
1301 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001302 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001304 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001305 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001306 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1307 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 }
1309 break;
Denys Vlasenko84703742012-02-25 02:38:52 +01001310#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001311#ifdef AF_PACKET
1312 case AF_PACKET:
1313 {
1314 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001315 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001316 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001317 addrbuf.ll.sll_ifindex);
1318 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1319 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001320 addrbuf.ll.sll_halen,
1321 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001322 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001323 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1324 }
1325 break;
1326
Denys Vlasenko84703742012-02-25 02:38:52 +01001327#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001328#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001329 case AF_NETLINK:
1330 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1331 break;
1332#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001333 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001334 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335
1336 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001337 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001339 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 break;
1341 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001342 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343}
1344
1345#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001346static const struct xlat scmvals[] = {
1347#ifdef SCM_RIGHTS
1348 { SCM_RIGHTS, "SCM_RIGHTS" },
1349#endif
1350#ifdef SCM_CREDENTIALS
1351 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1352#endif
1353 { 0, NULL }
1354};
1355
1356static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001357printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001358{
Roland McGrathaa524c82005-06-01 19:22:06 +00001359 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1360 NULL : malloc(len);
1361 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001362 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001363 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001364 return;
1365 }
1366
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001367 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001368 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001370
Roland McGrathaa524c82005-06-01 19:22:06 +00001371 if (cmsg->cmsg_level == SOL_SOCKET) {
1372 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001373
Roland McGrathaa524c82005-06-01 19:22:06 +00001374 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1375 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1376
1377 if (cmsg->cmsg_type == SCM_RIGHTS
1378 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001379 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001380 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001381
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001382 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001383 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001384 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001386 tprintf("%d", *fds++);
1387 first = 0;
1388 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001389 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001390 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001391 return;
1392 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001393 if (cmsg->cmsg_type == SCM_CREDENTIALS
1394 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001395 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001396
Roland McGrath50770822004-10-06 22:11:51 +00001397 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1398 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001399 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001400 return;
1401 }
1402 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001403 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001404 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001405}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406
1407static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001408do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +01001409{
1410 tprintf("{msg_name(%d)=", msg->msg_namelen);
1411 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1412
1413 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001414 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
1415 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +01001416
1417#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1418 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1419 if (msg->msg_controllen)
1420 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1421 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001422 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001423 printflags(msg_flags, msg->msg_flags, "MSG_???");
1424#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1425 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1426 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1427#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001428 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001429}
1430
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001431struct msghdr32 {
1432 uint32_t /* void* */ msg_name;
1433 uint32_t /* socklen_t */msg_namelen;
1434 uint32_t /* iovec* */ msg_iov;
1435 uint32_t /* size_t */ msg_iovlen;
1436 uint32_t /* void* */ msg_control;
1437 uint32_t /* size_t */ msg_controllen;
1438 uint32_t /* int */ msg_flags;
1439};
1440struct mmsghdr32 {
1441 struct msghdr32 msg_hdr;
1442 uint32_t /* unsigned */ msg_len;
1443};
1444
Andreas Schwab0873f292010-02-12 21:39:12 +01001445static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001446printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447{
1448 struct msghdr msg;
1449
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001450#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1451 if (current_wordsize == 4) {
1452 struct msghdr32 msg32;
1453
1454 if (umove(tcp, addr, &msg32) < 0) {
1455 tprintf("%#lx", addr);
1456 return;
1457 }
1458 msg.msg_name = (void*)(long)msg32.msg_name;
1459 msg.msg_namelen = msg32.msg_namelen;
1460 msg.msg_iov = (void*)(long)msg32.msg_iov;
1461 msg.msg_iovlen = msg32.msg_iovlen;
1462 msg.msg_control = (void*)(long)msg32.msg_control;
1463 msg.msg_controllen = msg32.msg_controllen;
1464 msg.msg_flags = msg32.msg_flags;
1465 } else
1466#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001467 if (umove(tcp, addr, &msg) < 0) {
1468 tprintf("%#lx", addr);
1469 return;
1470 }
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001471 do_msghdr(tcp, &msg, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001472}
1473
Andreas Schwab0873f292010-02-12 21:39:12 +01001474static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001475printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +01001476{
1477 struct mmsghdr {
1478 struct msghdr msg_hdr;
1479 unsigned msg_len;
1480 } mmsg;
1481
Denys Vlasenko3e759d42013-02-12 11:57:48 +01001482#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1483 if (current_wordsize == 4) {
1484 struct mmsghdr32 mmsg32;
1485
1486 addr += sizeof(mmsg32) * idx;
1487 if (umove(tcp, addr, &mmsg32) < 0) {
1488 tprintf("%#lx", addr);
1489 return;
1490 }
1491 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
1492 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
1493 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
1494 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
1495 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
1496 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
1497 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
1498 mmsg.msg_len = mmsg32.msg_len;
1499 } else
1500#endif
1501 {
1502 addr += sizeof(mmsg) * idx;
1503 if (umove(tcp, addr, &mmsg) < 0) {
1504 tprintf("%#lx", addr);
1505 return;
1506 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001507 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001508 tprints("{");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001509 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +01001510 tprintf(", %u}", mmsg.msg_len);
1511}
Andreas Schwab0873f292010-02-12 21:39:12 +01001512
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001513static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001514decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001515{
1516 /* mmsgvec */
1517 if (syserror(tcp)) {
1518 tprintf("%#lx", tcp->u_arg[1]);
1519 } else {
1520 unsigned int len = tcp->u_rval;
1521 unsigned int i;
1522
1523 tprints("{");
1524 for (i = 0; i < len; ++i) {
1525 if (i)
1526 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001527 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001528 }
1529 tprints("}");
1530 }
1531 /* vlen */
1532 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1533 /* flags */
1534 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1535}
1536
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537#endif /* HAVE_SENDMSG */
1538
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001539/*
1540 * low bits of the socket type define real socket type,
1541 * other bits are socket type flags.
1542 */
1543static void
1544tprint_sock_type(struct tcb *tcp, int flags)
1545{
1546 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1547
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001548 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001549 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001550 flags &= ~SOCK_TYPE_MASK;
1551 if (!flags)
1552 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001553 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001554 }
1555 printflags(sock_type_flags, flags, "SOCK_???");
1556}
1557
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001559sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560{
1561 if (entering(tcp)) {
1562 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001563 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001564 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001565 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566 switch (tcp->u_arg[0]) {
1567 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001568#ifdef PF_INET6
1569 case PF_INET6:
1570#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001571 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1572 break;
1573#ifdef PF_IPX
1574 case PF_IPX:
1575 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001576 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001578 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001579 break;
1580#endif /* PF_IPX */
1581 default:
1582 tprintf("%lu", tcp->u_arg[2]);
1583 break;
1584 }
1585 }
1586 return 0;
1587}
1588
John Hughesbdf48f52001-03-06 15:08:09 +00001589int
Denys Vlasenko12014262011-05-30 14:00:14 +02001590sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591{
1592 if (entering(tcp)) {
1593 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001594 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001595 tprintf(", %lu", tcp->u_arg[2]);
1596 }
1597 return 0;
1598}
1599
1600int
Denys Vlasenko12014262011-05-30 14:00:14 +02001601sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602{
1603 return sys_bind(tcp);
1604}
1605
1606int
Denys Vlasenko12014262011-05-30 14:00:14 +02001607sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608{
1609 if (entering(tcp)) {
1610 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1611 }
1612 return 0;
1613}
1614
Paolo Bonzini705ff102009-08-14 12:34:05 +02001615static int
1616do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001617{
1618 if (entering(tcp)) {
1619 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001620 return 0;
1621 }
1622 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623 tprintf("%#lx, NULL", tcp->u_arg[1]);
1624 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001625 int len;
1626 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001627 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628 tprintf("%#lx", tcp->u_arg[1]);
1629 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001630 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001632 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001633 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001635 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001636 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001637 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1638 "SOCK_???");
1639 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 return 0;
1641}
1642
1643int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001644sys_accept(struct tcb *tcp)
1645{
1646 return do_accept(tcp, -1);
1647}
1648
Paolo Bonzini705ff102009-08-14 12:34:05 +02001649int
1650sys_accept4(struct tcb *tcp)
1651{
1652 return do_accept(tcp, 3);
1653}
Paolo Bonzini705ff102009-08-14 12:34:05 +02001654
1655int
Denys Vlasenko12014262011-05-30 14:00:14 +02001656sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657{
1658 if (entering(tcp)) {
1659 tprintf("%ld, ", tcp->u_arg[0]);
1660 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1661 tprintf(", %lu, ", tcp->u_arg[2]);
1662 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001663 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664 }
1665 return 0;
1666}
1667
1668int
Denys Vlasenko12014262011-05-30 14:00:14 +02001669sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670{
1671 if (entering(tcp)) {
1672 tprintf("%ld, ", tcp->u_arg[0]);
1673 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1674 tprintf(", %lu, ", tcp->u_arg[2]);
1675 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001676 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001677 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001678 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001679 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680 /* to length */
1681 tprintf(", %lu", tcp->u_arg[5]);
1682 }
1683 return 0;
1684}
1685
1686#ifdef HAVE_SENDMSG
1687
1688int
Denys Vlasenko12014262011-05-30 14:00:14 +02001689sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690{
1691 if (entering(tcp)) {
1692 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levin043b5f82012-05-01 20:30:02 +00001693 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001695 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001696 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697 }
1698 return 0;
1699}
1700
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001701int
1702sys_sendmmsg(struct tcb *tcp)
1703{
1704 if (entering(tcp)) {
1705 /* sockfd */
1706 tprintf("%d, ", (int) tcp->u_arg[0]);
1707 if (!verbose(tcp)) {
1708 tprintf("%#lx, %u, ",
1709 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1710 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1711 }
1712 } else {
1713 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001714 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +00001715 }
1716 return 0;
1717}
1718
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719#endif /* HAVE_SENDMSG */
1720
1721int
Denys Vlasenko12014262011-05-30 14:00:14 +02001722sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723{
1724 if (entering(tcp)) {
1725 tprintf("%ld, ", tcp->u_arg[0]);
1726 } else {
1727 if (syserror(tcp))
1728 tprintf("%#lx", tcp->u_arg[1]);
1729 else
1730 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1731
1732 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001733 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734 }
1735 return 0;
1736}
1737
1738int
Denys Vlasenko12014262011-05-30 14:00:14 +02001739sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740{
1741 int fromlen;
1742
1743 if (entering(tcp)) {
1744 tprintf("%ld, ", tcp->u_arg[0]);
1745 } else {
1746 if (syserror(tcp)) {
1747 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1748 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1749 tcp->u_arg[4], tcp->u_arg[5]);
1750 return 0;
1751 }
1752 /* buf */
1753 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1754 /* len */
1755 tprintf(", %lu, ", tcp->u_arg[2]);
1756 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001757 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 /* from address, len */
1759 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1760 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001761 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762 else
1763 tprintf(", %#lx", tcp->u_arg[4]);
1764 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001765 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 else
1767 tprintf(", %#lx", tcp->u_arg[5]);
1768 return 0;
1769 }
1770 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001771 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772 return 0;
1773 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001774 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001775 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776 /* from length */
1777 tprintf(", [%u]", fromlen);
1778 }
1779 return 0;
1780}
1781
1782#ifdef HAVE_SENDMSG
1783
1784int
Denys Vlasenko12014262011-05-30 14:00:14 +02001785sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786{
1787 if (entering(tcp)) {
1788 tprintf("%ld, ", tcp->u_arg[0]);
1789 } else {
1790 if (syserror(tcp) || !verbose(tcp))
1791 tprintf("%#lx", tcp->u_arg[1]);
1792 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001793 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001795 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001796 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 }
1798 return 0;
1799}
1800
Andreas Schwab0873f292010-02-12 21:39:12 +01001801int
1802sys_recvmmsg(struct tcb *tcp)
1803{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001804 /* +5 chars are for "left " prefix */
1805 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001806
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001807 if (entering(tcp)) {
Andreas Schwab0873f292010-02-12 21:39:12 +01001808 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001809 if (verbose(tcp)) {
1810 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001811 /* Abusing tcp->auxstr as temp storage.
1812 * Will be used and freed on syscall exit.
1813 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001814 tcp->auxstr = strdup(str);
1815 } else {
1816 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1817 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001818 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001819 print_timespec(tcp, tcp->u_arg[4]);
1820 }
1821 return 0;
1822 } else {
1823 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001824 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001825 /* timeout on entrance */
1826 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1827 free((void *) tcp->auxstr);
1828 tcp->auxstr = NULL;
1829 }
1830 if (syserror(tcp))
1831 return 0;
1832 if (tcp->u_rval == 0) {
1833 tcp->auxstr = "Timeout";
1834 return RVAL_STR;
1835 }
1836 if (!verbose(tcp))
1837 return 0;
1838 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001839 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001840 tcp->auxstr = str;
1841 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001842 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001843}
Andreas Schwab0873f292010-02-12 21:39:12 +01001844
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845#endif /* HAVE_SENDMSG */
1846
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001847static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001848 { 0, "SHUT_RD" },
1849 { 1, "SHUT_WR" },
1850 { 2, "SHUT_RDWR" },
1851 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001852};
1853
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854int
Denys Vlasenko12014262011-05-30 14:00:14 +02001855sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856{
1857 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001858 tprintf("%ld, ", tcp->u_arg[0]);
1859 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860 }
1861 return 0;
1862}
1863
1864int
Denys Vlasenko12014262011-05-30 14:00:14 +02001865sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866{
1867 return sys_accept(tcp);
1868}
1869
1870int
Denys Vlasenko12014262011-05-30 14:00:14 +02001871sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001872{
1873 return sys_accept(tcp);
1874}
1875
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001876static int
1877do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 if (exiting(tcp)) {
1880 if (syserror(tcp)) {
1881 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001882 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001883#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001884 int fds[2];
1885
1886 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001887 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001888 else
1889 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001890#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001891 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1892#else
1893 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001895 }
1896 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001897 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001898 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1899 }
1900 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901 return 0;
1902}
1903
1904int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001905sys_pipe(struct tcb *tcp)
1906{
1907 return do_pipe(tcp, -1);
1908}
1909
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001910int
1911sys_pipe2(struct tcb *tcp)
1912{
1913 return do_pipe(tcp, 1);
1914}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001915
1916int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001917sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920
1921 if (entering(tcp)) {
1922 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001923 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001924 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001925 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 switch (tcp->u_arg[0]) {
1927 case PF_INET:
1928 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1929 break;
1930#ifdef PF_IPX
1931 case PF_IPX:
1932 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001933 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001935 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 break;
1937#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001938 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001939 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940 break;
1941 }
1942 } else {
1943 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001944 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945 return 0;
1946 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001948 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001949 else
1950 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951 }
1952 return 0;
1953}
1954
1955int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001956sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957{
1958 if (entering(tcp)) {
1959 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001960 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001961 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962 switch (tcp->u_arg[1]) {
1963 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001964 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965 break;
1966#ifdef SOL_IP
1967 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001969 break;
1970#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001971#ifdef SOL_IPV6
1972 case SOL_IPV6:
1973 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1974 break;
1975#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001976#ifdef SOL_IPX
1977 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001978 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979 break;
1980#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001981#ifdef SOL_PACKET
1982 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001983 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001984 break;
1985#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986#ifdef SOL_TCP
1987 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989 break;
1990#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001991#ifdef SOL_SCTP
1992 case SOL_SCTP:
1993 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1994 break;
1995#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001996
1997 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1998 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001999 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00002000 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002001 break;
2002 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002003 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002004 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00002005 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002006 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002007 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008 tcp->u_arg[3], tcp->u_arg[4]);
2009 return 0;
2010 }
John Hughes93f7fcc2002-05-22 15:46:49 +00002011
2012 switch (tcp->u_arg[1]) {
2013 case SOL_SOCKET:
2014 switch (tcp->u_arg[2]) {
2015#ifdef SO_LINGER
2016 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002017 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00002018 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002019 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00002020 tcp->u_arg[3],
2021 &linger) < 0)
2022 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00002023 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00002024 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00002025 linger.l_onoff,
2026 linger.l_linger,
2027 len);
2028 return 0;
2029 }
2030 break;
2031#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002032#ifdef SO_PEERCRED
2033 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002034 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002035 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002036 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002037 tcp->u_arg[3],
2038 &uc) < 0)
2039 break;
2040 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2041 "[%d]",
2042 (long)uc.pid,
2043 (long)uc.uid,
2044 (long)uc.gid,
2045 len);
2046 return 0;
2047 }
2048 break;
2049#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002050 }
2051 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002052 case SOL_PACKET:
2053 switch (tcp->u_arg[2]) {
2054#ifdef PACKET_STATISTICS
2055 case PACKET_STATISTICS:
2056 if (len == sizeof(struct tpacket_stats)) {
2057 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002058 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002059 tcp->u_arg[3],
2060 &stats) < 0)
2061 break;
2062 tprintf("{packets=%u, drops=%u}, "
2063 "[%d]",
2064 stats.tp_packets,
2065 stats.tp_drops,
2066 len);
2067 return 0;
2068 }
2069 break;
2070#endif
2071 }
2072 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002073 }
2074
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002075 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002076 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002077 }
2078 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002079 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002080 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002081 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082 }
2083 return 0;
2084}
2085
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002086#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002087static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002088{
2089 struct icmp_filter filter;
2090
2091 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002092 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002093 return;
2094 }
2095 if (syserror(tcp) || !verbose(tcp)) {
2096 tprintf("%#lx", addr);
2097 return;
2098 }
2099 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002100 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002101 return;
2102 }
2103
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002104 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002105 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002106 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002107}
2108#endif /* ICMP_FILTER */
2109
John Hughes38ae88d2002-05-23 11:48:58 +00002110static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002111printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002112{
2113 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002114 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002115 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002116 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002117 printxval(sockoptions, name, "SO_???");
2118 switch (name) {
2119#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002120 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002121 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002122 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002123 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002124 break;
2125 tprintf(", {onoff=%d, linger=%d}",
2126 linger.l_onoff,
2127 linger.l_linger);
2128 return 0;
2129 }
2130 break;
2131#endif
2132 }
2133 break;
2134#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002135 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00002136 printxval(sockipoptions, name, "IP_???");
2137 break;
2138#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002139#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002140 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00002141 printxval(sockipv6options, name, "IPV6_???");
2142 break;
2143#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002144#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002145 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00002146 printxval(sockipxoptions, name, "IPX_???");
2147 break;
2148#endif
2149#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002150 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00002151 printxval(sockpacketoptions, name, "PACKET_???");
2152 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002153 switch (name) {
2154#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002155 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002156#endif
2157#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002158 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002159#endif
2160#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2161 if (len == sizeof(struct tpacket_req)) {
2162 struct tpacket_req req;
2163 if (umove(tcp, addr, &req) < 0)
2164 break;
2165 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2166 req.tp_block_size,
2167 req.tp_block_nr,
2168 req.tp_frame_size,
2169 req.tp_frame_nr);
2170 return 0;
2171 }
2172 break;
2173#endif /* PACKET_RX_RING || PACKET_TX_RING */
2174 }
John Hughes38ae88d2002-05-23 11:48:58 +00002175 break;
2176#endif
2177#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002178 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00002179 printxval(socktcpoptions, name, "TCP_???");
2180 break;
2181#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002182#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002183 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002184 printxval(socksctpoptions, name, "SCTP_???");
2185 break;
2186#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002187#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002188 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00002189 printxval(sockrawoptions, name, "RAW_???");
2190 switch (name) {
2191#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002192 case ICMP_FILTER:
2193 tprints(", ");
2194 printicmpfilter(tcp, addr);
2195 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00002196#endif
2197 }
2198 break;
2199#endif
2200
Roland McGrath6d2b3492002-12-30 00:51:30 +00002201 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002202 * etc. still need work */
2203
Denys Vlasenko989ebc92012-03-17 04:42:07 +01002204 default:
John Hughes38ae88d2002-05-23 11:48:58 +00002205 tprintf("%u", name);
2206 }
2207
2208 /* default arg printing */
2209
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002210 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002211
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002212 if (len == sizeof(int)) {
2213 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002214 }
2215 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002216 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002217 }
2218 return 0;
2219}
2220
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002221#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002222
2223void
Denys Vlasenko12014262011-05-30 14:00:14 +02002224print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002225{
2226 int c = 0;
2227 struct opthdr hdr;
2228
John Hughes2c4e3a82002-05-24 10:19:44 +00002229 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002230 if (umove(tcp, addr, &hdr) < 0) break;
2231 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002232 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002233 }
2234 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002235 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002236 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002237 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002238 addr += sizeof hdr;
2239 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002240 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002241 if (hdr.len > 0) {
2242 addr += hdr.len;
2243 len -= hdr.len;
2244 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002245 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002246 }
2247 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002248 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002249 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002250 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002251 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002252}
2253
2254#endif
2255
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002256int
Denys Vlasenko12014262011-05-30 14:00:14 +02002257sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002258{
2259 if (entering(tcp)) {
2260 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002261 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002262 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002263 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002264 }
2265 return 0;
2266}