blob: 4e8df10a9a7bbca1e7d88f9f422f248861634c69 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/stat.h>
36#include <sys/socket.h>
37#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000038
39#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40#define in6_addr in6_addr_libc
41#define ipv6_mreq ipv6_mreq_libc
42#define sockaddr_in6 sockaddr_in6_libc
43#endif
44
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000047#include <netinet/tcp.h>
48#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000049#ifdef HAVE_NETINET_UDP_H
50#include <netinet/udp.h>
51#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010052#ifdef HAVE_NETINET_SCTP_H
53#include <netinet/sctp.h>
54#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000056#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#if defined(LINUX)
58#include <asm/types.h>
59#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
60# include <netipx/ipx.h>
61#else
62# include <linux/ipx.h>
63#endif
64#endif /* LINUX */
65
Wichert Akkermanf1850652001-02-16 20:29:03 +000066#if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000067#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000068#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
69#undef in6_addr
70#undef ipv6_mreq
71#undef sockaddr_in6
72#define in6_addr in6_addr_kernel
73#define ipv6_mreq ipv6_mreq_kernel
74#define sockaddr_in6 sockaddr_in6_kernel
75#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000076#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000077#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
78#undef in6_addr
79#undef ipv6_mreq
80#undef sockaddr_in6
81#define in6_addr in6_addr_libc
82#define ipv6_mreq ipv6_mreq_libc
83#define sockaddr_in6 sockaddr_in6_kernel
84#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000085#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000086#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000087
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000088#if defined(HAVE_SYS_UIO_H)
89#include <sys/uio.h>
90#endif
91
92#if defined(HAVE_LINUX_NETLINK_H)
93#include <linux/netlink.h>
94#endif
95
96#if defined(HAVE_LINUX_IF_PACKET_H)
97#include <linux/if_packet.h>
98#endif
99
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000100#if defined(HAVE_LINUX_ICMP_H)
101#include <linux/icmp.h>
102#endif
103
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104#ifndef PF_UNSPEC
105#define PF_UNSPEC AF_UNSPEC
106#endif
107
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000108#if UNIXWARE >= 7
109#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
110#endif
111
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#ifdef LINUX
113/* Under Linux these are enums so we can't test for them with ifdef. */
114#define IPPROTO_EGP IPPROTO_EGP
115#define IPPROTO_PUP IPPROTO_PUP
116#define IPPROTO_IDP IPPROTO_IDP
117#define IPPROTO_IGMP IPPROTO_IGMP
118#define IPPROTO_RAW IPPROTO_RAW
119#define IPPROTO_MAX IPPROTO_MAX
120#endif
121
Roland McGrathd9f816f2004-09-04 03:39:20 +0000122static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000123#ifdef PF_AAL5
124 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125#endif
126#ifdef PF_APPLETALK
127 { PF_APPLETALK, "PF_APPLETALK" },
128#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000129#ifdef PF_ASH
130 { PF_ASH, "PF_ASH" },
131#endif
132#ifdef PF_ATMPVC
133 { PF_ATMPVC, "PF_ATMPVC" },
134#endif
135#ifdef PF_ATMSVC
136 { PF_ATMSVC, "PF_ATMSVC" },
137#endif
138#ifdef PF_AX25
139 { PF_AX25, "PF_AX25" },
140#endif
141#ifdef PF_BLUETOOTH
142 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143#endif
144#ifdef PF_BRIDGE
145 { PF_BRIDGE, "PF_BRIDGE" },
146#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000147#ifdef PF_DECnet
148 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149#endif
150#ifdef PF_DECNET
151 { PF_DECNET, "PF_DECNET" },
152#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000153#ifdef PF_ECONET
154 { PF_ECONET, "PF_ECONET" },
155#endif
156#ifdef PF_FILE
157 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158#endif
159#ifdef PF_IMPLINK
160 { PF_IMPLINK, "PF_IMPLINK" },
161#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000162#ifdef PF_INET
163 { PF_INET, "PF_INET" },
164#endif
165#ifdef PF_INET6
166 { PF_INET6, "PF_INET6" },
167#endif
168#ifdef PF_IPX
169 { PF_IPX, "PF_IPX" },
170#endif
171#ifdef PF_IRDA
172 { PF_IRDA, "PF_IRDA" },
173#endif
174#ifdef PF_ISO
175 { PF_ISO, "PF_ISO" },
176#endif
177#ifdef PF_KEY
178 { PF_KEY, "PF_KEY" },
179#endif
180#ifdef PF_UNIX
181 { PF_UNIX, "PF_UNIX" },
182#endif
183#ifdef PF_LOCAL
184 { PF_LOCAL, "PF_LOCAL" },
185#endif
186#ifdef PF_NETBEUI
187 { PF_NETBEUI, "PF_NETBEUI" },
188#endif
189#ifdef PF_NETLINK
190 { PF_NETLINK, "PF_NETLINK" },
191#endif
192#ifdef PF_NETROM
193 { PF_NETROM, "PF_NETROM" },
194#endif
195#ifdef PF_PACKET
196 { PF_PACKET, "PF_PACKET" },
197#endif
198#ifdef PF_PPPOX
199 { PF_PPPOX, "PF_PPPOX" },
200#endif
201#ifdef PF_ROSE
202 { PF_ROSE, "PF_ROSE" },
203#endif
204#ifdef PF_ROUTE
205 { PF_ROUTE, "PF_ROUTE" },
206#endif
207#ifdef PF_SECURITY
208 { PF_SECURITY, "PF_SECURITY" },
209#endif
210#ifdef PF_SNA
211 { PF_SNA, "PF_SNA" },
212#endif
213#ifdef PF_UNSPEC
214 { PF_UNSPEC, "PF_UNSPEC" },
215#endif
216#ifdef PF_WANPIPE
217 { PF_WANPIPE, "PF_WANPIPE" },
218#endif
219#ifdef PF_X25
220 { PF_X25, "PF_X25" },
221#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { 0, NULL },
223};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000224const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000225#ifdef AF_APPLETALK
226 { AF_APPLETALK, "AF_APPLETALK" },
227#endif
228#ifdef AF_ASH
229 { AF_ASH, "AF_ASH" },
230#endif
231#ifdef AF_ATMPVC
232 { AF_ATMPVC, "AF_ATMPVC" },
233#endif
234#ifdef AF_ATMSVC
235 { AF_ATMSVC, "AF_ATMSVC" },
236#endif
237#ifdef AF_AX25
238 { AF_AX25, "AF_AX25" },
239#endif
240#ifdef AF_BLUETOOTH
241 { AF_BLUETOOTH, "AF_BLUETOOTH" },
242#endif
243#ifdef AF_BRIDGE
244 { AF_BRIDGE, "AF_BRIDGE" },
245#endif
246#ifdef AF_DECnet
247 { AF_DECnet, "AF_DECnet" },
248#endif
249#ifdef AF_ECONET
250 { AF_ECONET, "AF_ECONET" },
251#endif
252#ifdef AF_FILE
253 { AF_FILE, "AF_FILE" },
254#endif
255#ifdef AF_IMPLINK
256 { AF_IMPLINK, "AF_IMPLINK" },
257#endif
258#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000260#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000261#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000262 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000263#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000264#ifdef AF_IPX
265 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000266#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000267#ifdef AF_IRDA
268 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000269#endif
270#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000271 { AF_ISO, "AF_ISO" },
272#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000273#ifdef AF_KEY
274 { AF_KEY, "AF_KEY" },
275#endif
276#ifdef AF_UNIX
277 { AF_UNIX, "AF_UNIX" },
278#endif
279#ifdef AF_LOCAL
280 { AF_LOCAL, "AF_LOCAL" },
281#endif
282#ifdef AF_NETBEUI
283 { AF_NETBEUI, "AF_NETBEUI" },
284#endif
285#ifdef AF_NETLINK
286 { AF_NETLINK, "AF_NETLINK" },
287#endif
288#ifdef AF_NETROM
289 { AF_NETROM, "AF_NETROM" },
290#endif
291#ifdef AF_PACKET
292 { AF_PACKET, "AF_PACKET" },
293#endif
294#ifdef AF_PPPOX
295 { AF_PPPOX, "AF_PPPOX" },
296#endif
297#ifdef AF_ROSE
298 { AF_ROSE, "AF_ROSE" },
299#endif
300#ifdef AF_ROUTE
301 { AF_ROUTE, "AF_ROUTE" },
302#endif
303#ifdef AF_SECURITY
304 { AF_SECURITY, "AF_SECURITY" },
305#endif
306#ifdef AF_SNA
307 { AF_SNA, "AF_SNA" },
308#endif
309#ifdef AF_UNSPEC
310 { AF_UNSPEC, "AF_UNSPEC" },
311#endif
312#ifdef AF_WANPIPE
313 { AF_WANPIPE, "AF_WANPIPE" },
314#endif
315#ifdef AF_X25
316 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000317#endif
318 { 0, NULL },
319};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000320static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 { SOCK_STREAM, "SOCK_STREAM" },
322 { SOCK_DGRAM, "SOCK_DGRAM" },
323#ifdef SOCK_RAW
324 { SOCK_RAW, "SOCK_RAW" },
325#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000326#ifdef SOCK_RDM
327 { SOCK_RDM, "SOCK_RDM" },
328#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329#ifdef SOCK_SEQPACKET
330 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
331#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000332#ifdef SOCK_DCCP
333 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334#endif
335#ifdef SOCK_PACKET
336 { SOCK_PACKET, "SOCK_PACKET" },
337#endif
338 { 0, NULL },
339};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000340static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000341#ifdef SOCK_CLOEXEC
342 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
343#endif
344#ifdef SOCK_NONBLOCK
345 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
346#endif
347 { 0, NULL },
348};
349#ifndef SOCK_TYPE_MASK
350# define SOCK_TYPE_MASK 0xf
351#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000352static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000353#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000354 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000355#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000356#if defined(SOL_ICMP)
357 { SOL_ICMP, "SOL_ICMP" },
358#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000359#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000361#endif
362#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000363 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000364#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000365#if defined(SOL_IPV6)
366 { SOL_IPV6, "SOL_IPV6" },
367#endif
368#if defined(SOL_ICMPV6)
369 { SOL_ICMPV6, "SOL_ICMPV6" },
370#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100371#if defined(SOL_SCTP)
372 { SOL_SCTP, "SOL_SCTP" },
373#endif
374#if defined(SOL_UDPLITE)
375 { SOL_UDPLITE, "SOL_UDPLITE" },
376#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000377#if defined(SOL_RAW)
378 { SOL_RAW, "SOL_RAW" },
379#endif
380#if defined(SOL_IPX)
381 { SOL_IPX, "SOL_IPX" },
382#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000383#if defined(SOL_AX25)
384 { SOL_AX25, "SOL_AX25" },
385#endif
386#if defined(SOL_ATALK)
387 { SOL_ATALK, "SOL_ATALK" },
388#endif
389#if defined(SOL_NETROM)
390 { SOL_NETROM, "SOL_NETROM" },
391#endif
392#if defined(SOL_ROSE)
393 { SOL_ROSE, "SOL_ROSE" },
394#endif
395#if defined(SOL_DECNET)
396 { SOL_DECNET, "SOL_DECNET" },
397#endif
398#if defined(SOL_X25)
399 { SOL_X25, "SOL_X25" },
400#endif
401#if defined(SOL_PACKET)
402 { SOL_PACKET, "SOL_PACKET" },
403#endif
404#if defined(SOL_ATM)
405 { SOL_ATM, "SOL_ATM" },
406#endif
407#if defined(SOL_AAL)
408 { SOL_AAL, "SOL_AAL" },
409#endif
410#if defined(SOL_IRDA)
411 { SOL_IRDA, "SOL_IRDA" },
412#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100413#if defined(SOL_NETBEUI)
414 { SOL_NETBEUI, "SOL_NETBEUI" },
415#endif
416#if defined(SOL_LLC)
417 { SOL_LLC, "SOL_LLC" },
418#endif
419#if defined(SOL_DCCP)
420 { SOL_DCCP, "SOL_DCCP" },
421#endif
422#if defined(SOL_NETLINK)
423 { SOL_NETLINK, "SOL_NETLINK" },
424#endif
425#if defined(SOL_TIPC)
426 { SOL_TIPC, "SOL_TIPC" },
427#endif
428#if defined(SOL_RXRPC)
429 { SOL_RXRPC, "SOL_RXRPC" },
430#endif
431#if defined(SOL_PPPOL2TP)
432 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
433#endif
434#if defined(SOL_BLUETOOTH)
435 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
436#endif
437#if defined(SOL_PNPIPE)
438 { SOL_PNPIPE, "SOL_PNPIPE" },
439#endif
440#if defined(SOL_RDS)
441 { SOL_RDS, "SOL_RDS" },
442#endif
443#if defined(SOL_IUVC)
444 { SOL_IUCV, "SOL_IUCV" },
445#endif
446#if defined(SOL_CAIF)
447 { SOL_CAIF, "SOL_CAIF" },
448#endif
John Hughes61563572001-03-27 16:47:36 +0000449 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000450 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000451};
John Hughes93f7fcc2002-05-22 15:46:49 +0000452/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
453 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000454static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 { IPPROTO_IP, "IPPROTO_IP" },
456 { IPPROTO_ICMP, "IPPROTO_ICMP" },
457 { IPPROTO_TCP, "IPPROTO_TCP" },
458 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000459#ifdef IPPROTO_IGMP
460 { IPPROTO_IGMP, "IPPROTO_IGMP" },
461#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462#ifdef IPPROTO_GGP
463 { IPPROTO_GGP, "IPPROTO_GGP" },
464#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000465#ifdef IPPROTO_IPIP
466 { IPPROTO_IPIP, "IPPROTO_IPIP" },
467#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468#ifdef IPPROTO_EGP
469 { IPPROTO_EGP, "IPPROTO_EGP" },
470#endif
471#ifdef IPPROTO_PUP
472 { IPPROTO_PUP, "IPPROTO_PUP" },
473#endif
474#ifdef IPPROTO_IDP
475 { IPPROTO_IDP, "IPPROTO_IDP" },
476#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000477#ifdef IPPROTO_TP
478 { IPPROTO_TP, "IPPROTO_TP" },
479#endif
480#ifdef IPPROTO_DCCP
481 { IPPROTO_DCCP, "IPPROTO_DCCP" },
482#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483#ifdef IPPROTO_IPV6
484 { IPPROTO_IPV6, "IPPROTO_IPV6" },
485#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000486#ifdef IPPROTO_ROUTING
487 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000489#ifdef IPPROTO_FRAGMENT
490 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
491#endif
492#ifdef IPPROTO_RSVP
493 { IPPROTO_RSVP, "IPPROTO_RSVP" },
494#endif
495#ifdef IPPROTO_GRE
496 { IPPROTO_GRE, "IPPROTO_GRE" },
497#endif
498#ifdef IPPROTO_ESP
499 { IPPROTO_ESP, "IPPROTO_ESP" },
500#endif
501#ifdef IPPROTO_AH
502 { IPPROTO_AH, "IPPROTO_AH" },
503#endif
504#ifdef IPPROTO_ICMPV6
505 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
506#endif
507#ifdef IPPROTO_NONE
508 { IPPROTO_NONE, "IPPROTO_NONE" },
509#endif
510#ifdef IPPROTO_DSTOPTS
511 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512#endif
513#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000514 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515#endif
516#ifdef IPPROTO_ND
517 { IPPROTO_ND, "IPPROTO_ND" },
518#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000519#ifdef IPPROTO_MTP
520 { IPPROTO_MTP, "IPPROTO_MTP" },
521#endif
522#ifdef IPPROTO_ENCAP
523 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
524#endif
525#ifdef IPPROTO_PIM
526 { IPPROTO_PIM, "IPPROTO_PIM" },
527#endif
528#ifdef IPPROTO_COMP
529 { IPPROTO_COMP, "IPPROTO_COMP" },
530#endif
531#ifdef IPPROTO_SCTP
532 { IPPROTO_SCTP, "IPPROTO_SCTP" },
533#endif
534#ifdef IPPROTO_UDPLITE
535 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
536#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537#ifdef IPPROTO_RAW
538 { IPPROTO_RAW, "IPPROTO_RAW" },
539#endif
540#ifdef IPPROTO_MAX
541 { IPPROTO_MAX, "IPPROTO_MAX" },
542#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 { 0, NULL },
544};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000545static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000546 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000548 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#endif
550#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000551 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552#endif
553#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000554 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555#endif
556#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000557 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558#endif
559#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000560 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561#endif
562#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000563 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000566 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000567#endif
568#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000569 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000570#endif
571#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000572 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000573#endif
574#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000575 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000576#endif
577#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000578 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000579#endif
580#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000581 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000582#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000583#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000584 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000585#endif
586#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000587 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000588#endif
589#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000590 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000591#endif
592#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000593 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000594#endif
595#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000596 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000597#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000598#ifdef MSG_CMSG_CLOEXEC
599 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
600#endif
601 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602};
603
Roland McGrathd9f816f2004-09-04 03:39:20 +0000604static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000605#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000606 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000607#endif
608#ifdef SO_ALLRAW
609 { SO_ALLRAW, "SO_ALLRAW" },
610#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000611#ifdef SO_ATTACH_FILTER
612 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
613#endif
614#ifdef SO_BINDTODEVICE
615 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
616#endif
617#ifdef SO_BROADCAST
618 { SO_BROADCAST, "SO_BROADCAST" },
619#endif
620#ifdef SO_BSDCOMPAT
621 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
622#endif
623#ifdef SO_DEBUG
624 { SO_DEBUG, "SO_DEBUG" },
625#endif
626#ifdef SO_DETACH_FILTER
627 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
628#endif
629#ifdef SO_DONTROUTE
630 { SO_DONTROUTE, "SO_DONTROUTE" },
631#endif
632#ifdef SO_ERROR
633 { SO_ERROR, "SO_ERROR" },
634#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000635#ifdef SO_ICS
636 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000638#ifdef SO_IMASOCKET
639 { SO_IMASOCKET, "SO_IMASOCKET" },
640#endif
641#ifdef SO_KEEPALIVE
642 { SO_KEEPALIVE, "SO_KEEPALIVE" },
643#endif
644#ifdef SO_LINGER
645 { SO_LINGER, "SO_LINGER" },
646#endif
647#ifdef SO_LISTENING
648 { SO_LISTENING, "SO_LISTENING" },
649#endif
650#ifdef SO_MGMT
651 { SO_MGMT, "SO_MGMT" },
652#endif
653#ifdef SO_NO_CHECK
654 { SO_NO_CHECK, "SO_NO_CHECK" },
655#endif
656#ifdef SO_OOBINLINE
657 { SO_OOBINLINE, "SO_OOBINLINE" },
658#endif
659#ifdef SO_ORDREL
660 { SO_ORDREL, "SO_ORDREL" },
661#endif
662#ifdef SO_PARALLELSVR
663 { SO_PARALLELSVR, "SO_PARALLELSVR" },
664#endif
665#ifdef SO_PASSCRED
666 { SO_PASSCRED, "SO_PASSCRED" },
667#endif
668#ifdef SO_PEERCRED
669 { SO_PEERCRED, "SO_PEERCRED" },
670#endif
671#ifdef SO_PEERNAME
672 { SO_PEERNAME, "SO_PEERNAME" },
673#endif
674#ifdef SO_PEERSEC
675 { SO_PEERSEC, "SO_PEERSEC" },
676#endif
677#ifdef SO_PRIORITY
678 { SO_PRIORITY, "SO_PRIORITY" },
679#endif
680#ifdef SO_PROTOTYPE
681 { SO_PROTOTYPE, "SO_PROTOTYPE" },
682#endif
683#ifdef SO_RCVBUF
684 { SO_RCVBUF, "SO_RCVBUF" },
685#endif
686#ifdef SO_RCVLOWAT
687 { SO_RCVLOWAT, "SO_RCVLOWAT" },
688#endif
689#ifdef SO_RCVTIMEO
690 { SO_RCVTIMEO, "SO_RCVTIMEO" },
691#endif
692#ifdef SO_RDWR
693 { SO_RDWR, "SO_RDWR" },
694#endif
695#ifdef SO_REUSEADDR
696 { SO_REUSEADDR, "SO_REUSEADDR" },
697#endif
698#ifdef SO_REUSEPORT
699 { SO_REUSEPORT, "SO_REUSEPORT" },
700#endif
701#ifdef SO_SECURITY_AUTHENTICATION
702 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
703#endif
704#ifdef SO_SECURITY_ENCRYPTION_NETWORK
705 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
706#endif
707#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
708 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
709#endif
710#ifdef SO_SEMA
711 { SO_SEMA, "SO_SEMA" },
712#endif
713#ifdef SO_SNDBUF
714 { SO_SNDBUF, "SO_SNDBUF" },
715#endif
716#ifdef SO_SNDLOWAT
717 { SO_SNDLOWAT, "SO_SNDLOWAT" },
718#endif
719#ifdef SO_SNDTIMEO
720 { SO_SNDTIMEO, "SO_SNDTIMEO" },
721#endif
722#ifdef SO_TIMESTAMP
723 { SO_TIMESTAMP, "SO_TIMESTAMP" },
724#endif
725#ifdef SO_TYPE
726 { SO_TYPE, "SO_TYPE" },
727#endif
728#ifdef SO_USELOOPBACK
729 { SO_USELOOPBACK, "SO_USELOOPBACK" },
730#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 { 0, NULL },
732};
733
John Hughes93f7fcc2002-05-22 15:46:49 +0000734#if !defined (SOL_IP) && defined (IPPROTO_IP)
735#define SOL_IP IPPROTO_IP
736#endif
737
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000739static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000740#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000741 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000742#endif
743#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000744 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000745#endif
746#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000747 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000749#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000750 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000752#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000753 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000754#endif
755#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000756 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
757#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000758#ifdef IP_RECVOPTS
759 { IP_RECVOPTS, "IP_RECVOPTS" },
760#endif
761#ifdef IP_RECVRETOPTS
762 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
763#endif
764#ifdef IP_RECVDSTADDR
765 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
766#endif
767#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000768 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000769#endif
770#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000771 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000772#endif
773#ifdef IP_PKTOPTIONS
774 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
775#endif
776#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000777 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000778#endif
779#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000780 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000781#endif
782#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000783 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000784#endif
785#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000786 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000787#endif
788#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000789 { IP_MTU, "IP_MTU" },
790#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000792 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000793#endif
794#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000795 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000796#endif
797#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000798 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000799#endif
800#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000801 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000802#endif
803#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000804 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000805#endif
806#ifdef IP_BROADCAST_IF
807 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
808#endif
809#ifdef IP_RECVIFINDEX
810 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
811#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000812#ifdef IP_MSFILTER
813 { IP_MSFILTER, "IP_MSFILTER" },
814#endif
815#ifdef MCAST_MSFILTER
816 { MCAST_MSFILTER, "MCAST_MSFILTER" },
817#endif
818#ifdef IP_FREEBIND
819 { IP_FREEBIND, "IP_FREEBIND" },
820#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000821 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822};
823#endif /* SOL_IP */
824
Roland McGrath4f6ba692004-08-31 07:01:26 +0000825#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000826static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000827#ifdef IPV6_ADDRFORM
828 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
829#endif
830#ifdef MCAST_FILTER
831 { MCAST_FILTER, "MCAST_FILTER" },
832#endif
833#ifdef IPV6_PKTOPTIONS
834 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
835#endif
836#ifdef IPV6_MTU
837 { IPV6_MTU, "IPV6_MTU" },
838#endif
839#ifdef IPV6_V6ONLY
840 { IPV6_V6ONLY, "IPV6_V6ONLY" },
841#endif
842#ifdef IPV6_PKTINFO
843 { IPV6_PKTINFO, "IPV6_PKTINFO" },
844#endif
845#ifdef IPV6_HOPLIMIT
846 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
847#endif
848#ifdef IPV6_RTHDR
849 { IPV6_RTHDR, "IPV6_RTHDR" },
850#endif
851#ifdef IPV6_HOPOPTS
852 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
853#endif
854#ifdef IPV6_DSTOPTS
855 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
856#endif
857#ifdef IPV6_FLOWINFO
858 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
859#endif
860#ifdef IPV6_UNICAST_HOPS
861 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
862#endif
863#ifdef IPV6_MULTICAST_HOPS
864 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
865#endif
866#ifdef IPV6_MULTICAST_LOOP
867 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
868#endif
869#ifdef IPV6_MULTICAST_IF
870 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
871#endif
872#ifdef IPV6_MTU_DISCOVER
873 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
874#endif
875#ifdef IPV6_RECVERR
876 { IPV6_RECVERR, "IPV6_RECVERR" },
877#endif
878#ifdef IPV6_FLOWINFO_SEND
879 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
880#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000881#ifdef IPV6_ADD_MEMBERSHIP
882 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
883#endif
884#ifdef IPV6_DROP_MEMBERSHIP
885 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
886#endif
887#ifdef IPV6_ROUTER_ALERT
888 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
889#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000890 { 0, NULL },
891};
892#endif /* SOL_IPV6 */
893
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000895static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200896 { IPX_TYPE, "IPX_TYPE" },
897 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898};
899#endif /* SOL_IPX */
900
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000901#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000902static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000903#if defined(ICMP_FILTER)
904 { ICMP_FILTER, "ICMP_FILTER" },
905#endif
906 { 0, NULL },
907};
908#endif /* SOL_RAW */
909
910#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000911static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000912#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000913 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000914#endif
915#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000916 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000917#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000918#if defined(PACKET_RECV_OUTPUT)
919 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
920#endif
921#if defined(PACKET_RX_RING)
922 { PACKET_RX_RING, "PACKET_RX_RING" },
923#endif
924#if defined(PACKET_STATISTICS)
925 { PACKET_STATISTICS, "PACKET_STATISTICS" },
926#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000927#if defined(PACKET_COPY_THRESH)
928 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
929#endif
930#if defined(PACKET_AUXDATA)
931 { PACKET_AUXDATA, "PACKET_AUXDATA" },
932#endif
933#if defined(PACKET_ORIGDEV)
934 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
935#endif
936#if defined(PACKET_VERSION)
937 { PACKET_VERSION, "PACKET_VERSION" },
938#endif
939#if defined(PACKET_HDRLEN)
940 { PACKET_HDRLEN, "PACKET_HDRLEN" },
941#endif
942#if defined(PACKET_RESERVE)
943 { PACKET_RESERVE, "PACKET_RESERVE" },
944#endif
945#if defined(PACKET_TX_RING)
946 { PACKET_TX_RING, "PACKET_TX_RING" },
947#endif
948#if defined(PACKET_LOSS)
949 { PACKET_LOSS, "PACKET_LOSS" },
950#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000951 { 0, NULL },
952};
953#endif /* SOL_PACKET */
954
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100955#ifdef SOL_SCTP
956static const struct xlat socksctpoptions[] = {
957#if defined(SCTP_RTOINFO)
958 { SCTP_RTOINFO, "SCTP_RTOINFO" },
959#endif
960#if defined(SCTP_ASSOCINFO)
961 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
962#endif
963#if defined(SCTP_INITMSG)
964 { SCTP_INITMSG, "SCTP_INITMSG" },
965#endif
966#if defined(SCTP_NODELAY)
967 { SCTP_NODELAY, "SCTP_NODELAY" },
968#endif
969#if defined(SCTP_AUTOCLOSE)
970 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
971#endif
972#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
973 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
974#endif
975#if defined(SCTP_PRIMARY_ADDR)
976 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
977#endif
978#if defined(SCTP_ADAPTATION_LAYER)
979 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
980#endif
981#if defined(SCTP_DISABLE_FRAGMENTS)
982 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
983#endif
984#if defined(SCTP_PEER_ADDR_PARAMS)
985 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
986#endif
987#if defined(SCTP_DEFAULT_SEND_PARAM)
988 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
989#endif
990#if defined(SCTP_EVENTS)
991 { SCTP_EVENTS, "SCTP_EVENTS" },
992#endif
993#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
994 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
995#endif
996#if defined(SCTP_MAXSEG)
997 { SCTP_MAXSEG, "SCTP_MAXSEG" },
998#endif
999#if defined(SCTP_STATUS)
1000 { SCTP_STATUS, "SCTP_STATUS" },
1001#endif
1002#if defined(SCTP_GET_PEER_ADDR_INFO)
1003 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
1004#endif
1005#if defined(SCTP_DELAYED_ACK)
1006 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1007#endif
1008#if defined(SCTP_CONTEXT)
1009 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1010#endif
1011#if defined(SCTP_FRAGMENT_INTERLEAVE)
1012 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1013#endif
1014#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1015 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1016#endif
1017#if defined(SCTP_MAX_BURST)
1018 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1019#endif
1020#if defined(SCTP_AUTH_CHUNK)
1021 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1022#endif
1023#if defined(SCTP_HMAC_IDENT)
1024 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1025#endif
1026#if defined(SCTP_AUTH_KEY)
1027 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1028#endif
1029#if defined(SCTP_AUTH_ACTIVE_KEY)
1030 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1031#endif
1032#if defined(SCTP_AUTH_DELETE_KEY)
1033 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1034#endif
1035#if defined(SCTP_PEER_AUTH_CHUNKS)
1036 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1037#endif
1038#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1039 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1040#endif
1041#if defined(SCTP_GET_ASSOC_NUMBER)
1042 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1043#endif
1044
1045 /* linux specific things */
1046#if defined(SCTP_SOCKOPT_BINDX_ADD)
1047 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1048#endif
1049#if defined(SCTP_SOCKOPT_BINDX_REM)
1050 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1051#endif
1052#if defined(SCTP_SOCKOPT_PEELOFF)
1053 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1054#endif
1055#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1056 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1057#endif
1058#if defined(SCTP_GET_PEER_ADDRS_OLD)
1059 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1060#endif
1061#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1062 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1063#endif
1064#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1065 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1066#endif
1067#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1068 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1069#endif
1070#if defined(SCTP_GET_PEER_ADDRS)
1071 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1072#endif
1073#if defined(SCTP_GET_LOCAL_ADDRS)
1074 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1075#endif
1076
1077 { 0, NULL },
1078};
1079#endif
1080
John Hughes93f7fcc2002-05-22 15:46:49 +00001081#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
1082#define SOL_TCP IPPROTO_TCP
1083#endif
1084
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001086static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001087 { TCP_NODELAY, "TCP_NODELAY" },
1088 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001089#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001090 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001091#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001092#if defined(TCP_KEEPIDLE)
1093 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1094#endif
1095#if defined(TCP_KEEPINTVL)
1096 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1097#endif
1098#if defined(TCP_KEEPCNT)
1099 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1100#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001101#if defined(TCP_NKEEP)
1102 { TCP_NKEEP, "TCP_NKEEP" },
1103#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001104#if defined(TCP_SYNCNT)
1105 { TCP_SYNCNT, "TCP_SYNCNT" },
1106#endif
1107#if defined(TCP_LINGER2)
1108 { TCP_LINGER2, "TCP_LINGER2" },
1109#endif
1110#if defined(TCP_DEFER_ACCEPT)
1111 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1112#endif
1113#if defined(TCP_WINDOW_CLAMP)
1114 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1115#endif
1116#if defined(TCP_INFO)
1117 { TCP_INFO, "TCP_INFO" },
1118#endif
1119#if defined(TCP_QUICKACK)
1120 { TCP_QUICKACK, "TCP_QUICKACK" },
1121#endif
Dmitry V. Levinb05fc542011-12-01 21:06:00 +00001122#if defined(TCP_CONGESTION)
1123 { TCP_CONGESTION, "TCP_CONGESTION" },
1124#endif
1125#if defined(TCP_MD5SIG)
1126 { TCP_MD5SIG, "TCP_MD5SIG" },
1127#endif
1128#if defined(TCP_COOKIE_TRANSACTIONS)
1129 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1130#endif
1131#if defined(TCP_THIN_LINEAR_TIMEOUTS)
1132 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1133#endif
1134#if defined(TCP_THIN_DUPACK)
1135 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1136#endif
1137#if defined(TCP_USER_TIMEOUT)
1138 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1139#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001140 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141};
1142#endif /* SOL_TCP */
1143
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001144#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001145static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001146#if defined(ICMP_ECHOREPLY)
1147 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1148#endif
1149#if defined(ICMP_DEST_UNREACH)
1150 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1151#endif
1152#if defined(ICMP_SOURCE_QUENCH)
1153 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1154#endif
1155#if defined(ICMP_REDIRECT)
1156 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1157#endif
1158#if defined(ICMP_ECHO)
1159 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1160#endif
1161#if defined(ICMP_TIME_EXCEEDED)
1162 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1163#endif
1164#if defined(ICMP_PARAMETERPROB)
1165 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1166#endif
1167#if defined(ICMP_TIMESTAMP)
1168 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1169#endif
1170#if defined(ICMP_TIMESTAMPREPLY)
1171 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1172#endif
1173#if defined(ICMP_INFO_REQUEST)
1174 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1175#endif
1176#if defined(ICMP_INFO_REPLY)
1177 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1178#endif
1179#if defined(ICMP_ADDRESS)
1180 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1181#endif
1182#if defined(ICMP_ADDRESSREPLY)
1183 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1184#endif
1185 { 0, NULL },
1186};
1187#endif /* SOL_RAW */
1188
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001189#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001190static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001191#if defined(PACKET_HOST)
1192 { PACKET_HOST, "PACKET_HOST" },
1193#endif
1194#if defined(PACKET_BROADCAST)
1195 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1196#endif
1197#if defined(PACKET_MULTICAST)
1198 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1199#endif
1200#if defined(PACKET_OTHERHOST)
1201 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1202#endif
1203#if defined(PACKET_OUTGOING)
1204 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1205#endif
1206#if defined(PACKET_LOOPBACK)
1207 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1208#endif
1209#if defined(PACKET_FASTROUTE)
1210 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1211#endif
1212 { 0, NULL },
1213};
1214#endif /* defined(AF_PACKET) */
1215
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001216
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001218printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001220 union {
1221 char pad[128];
1222 struct sockaddr sa;
1223 struct sockaddr_in sin;
1224 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001225#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001226 struct sockaddr_in6 sa6;
1227#endif
1228#if defined(LINUX) && defined(AF_IPX)
1229 struct sockaddr_ipx sipx;
1230#endif
1231#ifdef AF_PACKET
1232 struct sockaddr_ll ll;
1233#endif
1234#ifdef AF_NETLINK
1235 struct sockaddr_nl nl;
1236#endif
1237 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001238 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239
1240 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001241 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242 return;
1243 }
1244 if (!verbose(tcp)) {
1245 tprintf("%#lx", addr);
1246 return;
1247 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001248
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001249 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1250 addrlen = sizeof(addrbuf);
1251
1252 memset(&addrbuf, 0, sizeof(addrbuf));
1253 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001254 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255 return;
1256 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001257 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001258
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001259 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001260 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001261 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001262
1263 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001265 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001266 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001267 } else if (addrbuf.sau.sun_path[0]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001268 tprints("path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001269 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001270 } else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001271 tprints("path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001272 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001273 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274 break;
1275 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001276 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001277 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001279#ifdef HAVE_INET_NTOP
1280 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001281 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001282 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1283 ntohs(addrbuf.sa6.sin6_port), string_addr,
1284 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001285#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001286 {
1287#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001288 int numericscope = 0;
1289 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1290 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1291 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001292
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001293 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1294 numericscope++;
1295 else
1296 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1297 } else
1298 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001299
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001300 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001301#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001302 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001303 }
1304#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001305 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001306#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001307#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001309 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001311 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001312 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313 /* Yes, I know, this does not look too
1314 * strace-ish, but otherwise the IPX
1315 * addresses just look monstrous...
1316 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001317 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001318 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001319 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001320 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001321 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1322 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323 }
1324 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001325#endif /* AF_IPX && linux */
1326#ifdef AF_PACKET
1327 case AF_PACKET:
1328 {
1329 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001330 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001331 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001332 addrbuf.ll.sll_ifindex);
1333 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1334 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001335 addrbuf.ll.sll_halen,
1336 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001337 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001338 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1339 }
1340 break;
1341
1342#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001343#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001344 case AF_NETLINK:
1345 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1346 break;
1347#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001348 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001349 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001350
1351 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001352 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001354 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 break;
1356 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001357 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358}
1359
1360#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001361static const struct xlat scmvals[] = {
1362#ifdef SCM_RIGHTS
1363 { SCM_RIGHTS, "SCM_RIGHTS" },
1364#endif
1365#ifdef SCM_CREDENTIALS
1366 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1367#endif
1368 { 0, NULL }
1369};
1370
1371static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001372printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001373{
Roland McGrathaa524c82005-06-01 19:22:06 +00001374 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1375 NULL : malloc(len);
1376 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001377 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001378 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001379 return;
1380 }
1381
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001382 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001383 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001384 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +00001385
Roland McGrathaa524c82005-06-01 19:22:06 +00001386 if (cmsg->cmsg_level == SOL_SOCKET) {
1387 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001388
Roland McGrathaa524c82005-06-01 19:22:06 +00001389 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1390 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1391
1392 if (cmsg->cmsg_type == SCM_RIGHTS
1393 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001394 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001395 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001396
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001397 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001398 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001399 if (!first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001400 tprints(", ");
Roland McGrath50770822004-10-06 22:11:51 +00001401 tprintf("%d", *fds++);
1402 first = 0;
1403 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001404 tprints("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001405 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001406 return;
1407 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001408 if (cmsg->cmsg_type == SCM_CREDENTIALS
1409 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001410 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001411
Roland McGrath50770822004-10-06 22:11:51 +00001412 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1413 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001414 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001415 return;
1416 }
1417 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001418 free(cmsg);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001419 tprints(", ...}");
Roland McGrath50770822004-10-06 22:11:51 +00001420}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421
1422static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001423do_msghdr(struct tcb *tcp, struct msghdr *msg)
1424{
1425 tprintf("{msg_name(%d)=", msg->msg_namelen);
1426 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1427
1428 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1429 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
Dmitry V. Levin88849682011-06-13 22:58:44 +00001430 (unsigned long)msg->msg_iov, 1);
Andreas Schwab0873f292010-02-12 21:39:12 +01001431
1432#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1433 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1434 if (msg->msg_controllen)
1435 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1436 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001437 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +01001438 printflags(msg_flags, msg->msg_flags, "MSG_???");
1439#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1440 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1441 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1442#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001443 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +01001444}
1445
1446static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001447printmsghdr(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001448{
1449 struct msghdr msg;
1450
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001451 if (umove(tcp, addr, &msg) < 0) {
1452 tprintf("%#lx", addr);
1453 return;
1454 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001455 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456}
1457
Andreas Schwab0873f292010-02-12 21:39:12 +01001458#ifdef LINUX
1459static void
1460printmmsghdr(struct tcb *tcp, long addr)
1461{
1462 struct mmsghdr {
1463 struct msghdr msg_hdr;
1464 unsigned msg_len;
1465 } mmsg;
1466
1467 if (umove(tcp, addr, &mmsg) < 0) {
1468 tprintf("%#lx", addr);
1469 return;
1470 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001471 tprints("{");
Andreas Schwab0873f292010-02-12 21:39:12 +01001472 do_msghdr(tcp, &mmsg.msg_hdr);
1473 tprintf(", %u}", mmsg.msg_len);
1474}
1475#endif
1476
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477#endif /* HAVE_SENDMSG */
1478
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001479/*
1480 * low bits of the socket type define real socket type,
1481 * other bits are socket type flags.
1482 */
1483static void
1484tprint_sock_type(struct tcb *tcp, int flags)
1485{
1486 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1487
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001488 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001489 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001490 flags &= ~SOCK_TYPE_MASK;
1491 if (!flags)
1492 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001493 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001494 }
1495 printflags(sock_type_flags, flags, "SOCK_???");
1496}
1497
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001498int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001499sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500{
1501 if (entering(tcp)) {
1502 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001503 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001504 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001505 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001506 switch (tcp->u_arg[0]) {
1507 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001508#ifdef PF_INET6
1509 case PF_INET6:
1510#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1512 break;
1513#ifdef PF_IPX
1514 case PF_IPX:
1515 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001516 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001517 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001518 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 break;
1520#endif /* PF_IPX */
1521 default:
1522 tprintf("%lu", tcp->u_arg[2]);
1523 break;
1524 }
1525 }
1526 return 0;
1527}
1528
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001529#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001530int
Denys Vlasenko12014262011-05-30 14:00:14 +02001531sys_so_socket(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001532{
1533 if (entering(tcp)) {
1534 /* not sure really what these args are... but this
1535 * is how truss prints it
1536 */
1537 tprintf("%ld, %ld, %ld, ",
1538 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1539 printpath(tcp, tcp->u_arg[3]);
1540 tprintf(", %ld", tcp->u_arg[4]);
1541 }
1542 return 0;
1543}
1544
1545int
Denys Vlasenko12014262011-05-30 14:00:14 +02001546sys_so_socketpair(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001547{
1548 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001549 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001550 tprintf("0x%lx", tcp->u_arg[0]);
1551 }
1552 return 0;
1553}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001554#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001555
1556int
Denys Vlasenko12014262011-05-30 14:00:14 +02001557sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558{
1559 if (entering(tcp)) {
1560 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001561 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562 tprintf(", %lu", tcp->u_arg[2]);
1563 }
1564 return 0;
1565}
1566
1567int
Denys Vlasenko12014262011-05-30 14:00:14 +02001568sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569{
1570 return sys_bind(tcp);
1571}
1572
1573int
Denys Vlasenko12014262011-05-30 14:00:14 +02001574sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575{
1576 if (entering(tcp)) {
1577 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1578 }
1579 return 0;
1580}
1581
Paolo Bonzini705ff102009-08-14 12:34:05 +02001582static int
1583do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584{
1585 if (entering(tcp)) {
1586 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001587 return 0;
1588 }
1589 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590 tprintf("%#lx, NULL", tcp->u_arg[1]);
1591 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001592 int len;
1593 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001594 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001595 tprintf("%#lx", tcp->u_arg[1]);
1596 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001597 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001599 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001600 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001601 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001602 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001603 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +02001604 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1605 "SOCK_???");
1606 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607 return 0;
1608}
1609
1610int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001611sys_accept(struct tcb *tcp)
1612{
1613 return do_accept(tcp, -1);
1614}
1615
1616#ifdef LINUX
1617int
1618sys_accept4(struct tcb *tcp)
1619{
1620 return do_accept(tcp, 3);
1621}
1622#endif
1623
1624int
Denys Vlasenko12014262011-05-30 14:00:14 +02001625sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626{
1627 if (entering(tcp)) {
1628 tprintf("%ld, ", tcp->u_arg[0]);
1629 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1630 tprintf(", %lu, ", tcp->u_arg[2]);
1631 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001632 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633 }
1634 return 0;
1635}
1636
1637int
Denys Vlasenko12014262011-05-30 14:00:14 +02001638sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639{
1640 if (entering(tcp)) {
1641 tprintf("%ld, ", tcp->u_arg[0]);
1642 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1643 tprintf(", %lu, ", tcp->u_arg[2]);
1644 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001645 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001647 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001648 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001649 /* to length */
1650 tprintf(", %lu", tcp->u_arg[5]);
1651 }
1652 return 0;
1653}
1654
1655#ifdef HAVE_SENDMSG
1656
1657int
Denys Vlasenko12014262011-05-30 14:00:14 +02001658sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659{
1660 if (entering(tcp)) {
1661 tprintf("%ld, ", tcp->u_arg[0]);
1662 printmsghdr(tcp, tcp->u_arg[1]);
1663 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001664 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001665 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666 }
1667 return 0;
1668}
1669
1670#endif /* HAVE_SENDMSG */
1671
1672int
Denys Vlasenko12014262011-05-30 14:00:14 +02001673sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674{
1675 if (entering(tcp)) {
1676 tprintf("%ld, ", tcp->u_arg[0]);
1677 } else {
1678 if (syserror(tcp))
1679 tprintf("%#lx", tcp->u_arg[1]);
1680 else
1681 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1682
1683 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001684 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685 }
1686 return 0;
1687}
1688
1689int
Denys Vlasenko12014262011-05-30 14:00:14 +02001690sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691{
1692 int fromlen;
1693
1694 if (entering(tcp)) {
1695 tprintf("%ld, ", tcp->u_arg[0]);
1696 } else {
1697 if (syserror(tcp)) {
1698 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1699 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1700 tcp->u_arg[4], tcp->u_arg[5]);
1701 return 0;
1702 }
1703 /* buf */
1704 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1705 /* len */
1706 tprintf(", %lu, ", tcp->u_arg[2]);
1707 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001708 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709 /* from address, len */
1710 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1711 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001712 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001713 else
1714 tprintf(", %#lx", tcp->u_arg[4]);
1715 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001716 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001717 else
1718 tprintf(", %#lx", tcp->u_arg[5]);
1719 return 0;
1720 }
1721 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001722 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723 return 0;
1724 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001725 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001726 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001727 /* from length */
1728 tprintf(", [%u]", fromlen);
1729 }
1730 return 0;
1731}
1732
1733#ifdef HAVE_SENDMSG
1734
1735int
Denys Vlasenko12014262011-05-30 14:00:14 +02001736sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001737{
1738 if (entering(tcp)) {
1739 tprintf("%ld, ", tcp->u_arg[0]);
1740 } else {
1741 if (syserror(tcp) || !verbose(tcp))
1742 tprintf("%#lx", tcp->u_arg[1]);
1743 else
1744 printmsghdr(tcp, tcp->u_arg[1]);
1745 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001746 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001747 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748 }
1749 return 0;
1750}
1751
Andreas Schwab0873f292010-02-12 21:39:12 +01001752#ifdef LINUX
1753int
1754sys_recvmmsg(struct tcb *tcp)
1755{
Dmitry V. Levine6591032010-03-29 20:45:48 +04001756 static char str[128];
Andreas Schwab0873f292010-02-12 21:39:12 +01001757 if (entering(tcp)) {
Dmitry V. Levine6591032010-03-29 20:45:48 +04001758
Andreas Schwab0873f292010-02-12 21:39:12 +01001759 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001760 if (verbose(tcp)) {
1761 sprint_timespec(str, tcp, tcp->u_arg[4]);
1762 tcp->auxstr = strdup(str);
1763 } else {
1764 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1765 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001766 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001767 print_timespec(tcp, tcp->u_arg[4]);
1768 }
1769 return 0;
1770 } else {
1771 if (verbose(tcp)) {
1772 if (syserror(tcp))
1773 tprintf("%#lx", tcp->u_arg[1]);
1774 else
1775 printmmsghdr(tcp, tcp->u_arg[1]);
1776 tprintf(", %ld, ", tcp->u_arg[2]);
1777 /* flags */
1778 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1779 /* timeout on entrance */
1780 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1781 free((void *) tcp->auxstr);
1782 tcp->auxstr = NULL;
1783 }
1784 if (syserror(tcp))
1785 return 0;
1786 if (tcp->u_rval == 0) {
1787 tcp->auxstr = "Timeout";
1788 return RVAL_STR;
1789 }
1790 if (!verbose(tcp))
1791 return 0;
1792 /* timeout on exit */
1793 strcpy(str, "left ");
1794 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1795 tcp->auxstr = str;
1796 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001797 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001798}
1799#endif
1800
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801#endif /* HAVE_SENDMSG */
1802
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001803static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001804 { 0, "SHUT_RD" },
1805 { 1, "SHUT_WR" },
1806 { 2, "SHUT_RDWR" },
1807 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001808};
1809
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810int
Denys Vlasenko12014262011-05-30 14:00:14 +02001811sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001812{
1813 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001814 tprintf("%ld, ", tcp->u_arg[0]);
1815 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816 }
1817 return 0;
1818}
1819
1820int
Denys Vlasenko12014262011-05-30 14:00:14 +02001821sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001822{
1823 return sys_accept(tcp);
1824}
1825
1826int
Denys Vlasenko12014262011-05-30 14:00:14 +02001827sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828{
1829 return sys_accept(tcp);
1830}
1831
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001832static int
1833do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835 if (exiting(tcp)) {
1836 if (syserror(tcp)) {
1837 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001838 } else {
1839#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1840 int fds[2];
1841
1842 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001843 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001844 else
1845 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001846#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001847 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1848#else
1849 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001850#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001851 }
1852 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001853 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001854 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1855 }
1856 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001857 return 0;
1858}
1859
1860int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001861sys_pipe(struct tcb *tcp)
1862{
1863 return do_pipe(tcp, -1);
1864}
1865
1866#ifdef LINUX
1867int
1868sys_pipe2(struct tcb *tcp)
1869{
1870 return do_pipe(tcp, 1);
1871}
1872#endif
1873
1874int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001875sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001876{
1877#ifdef LINUX
1878 int fds[2];
1879#endif
1880
1881 if (entering(tcp)) {
1882 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001883 tprints(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001884 tprint_sock_type(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001885 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886 switch (tcp->u_arg[0]) {
1887 case PF_INET:
1888 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1889 break;
1890#ifdef PF_IPX
1891 case PF_IPX:
1892 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001893 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001895 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 break;
1897#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001898 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001899 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900 break;
1901 }
1902 } else {
1903 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001904 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905 return 0;
1906 }
1907#ifdef LINUX
1908 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001909 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 else
1911 tprintf(", [%u, %u]", fds[0], fds[1]);
1912#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001913#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001915#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 }
1917 return 0;
1918}
1919
1920int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001921sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922{
1923 if (entering(tcp)) {
1924 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001925 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001926 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 switch (tcp->u_arg[1]) {
1928 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001930 break;
1931#ifdef SOL_IP
1932 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934 break;
1935#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001936#ifdef SOL_IPV6
1937 case SOL_IPV6:
1938 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1939 break;
1940#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941#ifdef SOL_IPX
1942 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944 break;
1945#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001946#ifdef SOL_PACKET
1947 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001948 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001949 break;
1950#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951#ifdef SOL_TCP
1952 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001953 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954 break;
1955#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001956#ifdef SOL_SCTP
1957 case SOL_SCTP:
1958 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1959 break;
1960#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001961
1962 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1963 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001964 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001965 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966 break;
1967 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001968 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001969 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001970 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001971 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001972 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973 tcp->u_arg[3], tcp->u_arg[4]);
1974 return 0;
1975 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001976
1977 switch (tcp->u_arg[1]) {
1978 case SOL_SOCKET:
1979 switch (tcp->u_arg[2]) {
1980#ifdef SO_LINGER
1981 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001982 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001983 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001984 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001985 tcp->u_arg[3],
1986 &linger) < 0)
1987 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001988 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001989 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001990 linger.l_onoff,
1991 linger.l_linger,
1992 len);
1993 return 0;
1994 }
1995 break;
1996#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001997#ifdef SO_PEERCRED
1998 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001999 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002000 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002001 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00002002 tcp->u_arg[3],
2003 &uc) < 0)
2004 break;
2005 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2006 "[%d]",
2007 (long)uc.pid,
2008 (long)uc.uid,
2009 (long)uc.gid,
2010 len);
2011 return 0;
2012 }
2013 break;
2014#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00002015 }
2016 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002017 case SOL_PACKET:
2018 switch (tcp->u_arg[2]) {
2019#ifdef PACKET_STATISTICS
2020 case PACKET_STATISTICS:
2021 if (len == sizeof(struct tpacket_stats)) {
2022 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002023 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002024 tcp->u_arg[3],
2025 &stats) < 0)
2026 break;
2027 tprintf("{packets=%u, drops=%u}, "
2028 "[%d]",
2029 stats.tp_packets,
2030 stats.tp_drops,
2031 len);
2032 return 0;
2033 }
2034 break;
2035#endif
2036 }
2037 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002038 }
2039
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002040 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002041 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002042 }
2043 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002044 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002045 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002046 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 }
2048 return 0;
2049}
2050
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002051#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002052static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002053{
2054 struct icmp_filter filter;
2055
2056 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002057 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002058 return;
2059 }
2060 if (syserror(tcp) || !verbose(tcp)) {
2061 tprintf("%#lx", addr);
2062 return;
2063 }
2064 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002065 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002066 return;
2067 }
2068
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002069 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002070 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002071 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002072}
2073#endif /* ICMP_FILTER */
2074
John Hughes38ae88d2002-05-23 11:48:58 +00002075static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002076printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002077{
2078 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002079 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002080 switch (level) {
2081 case SOL_SOCKET:
2082 printxval(sockoptions, name, "SO_???");
2083 switch (name) {
2084#if defined(SO_LINGER)
2085 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002086 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002087 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002088 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002089 break;
2090 tprintf(", {onoff=%d, linger=%d}",
2091 linger.l_onoff,
2092 linger.l_linger);
2093 return 0;
2094 }
2095 break;
2096#endif
2097 }
2098 break;
2099#ifdef SOL_IP
2100 case SOL_IP:
2101 printxval(sockipoptions, name, "IP_???");
2102 break;
2103#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002104#ifdef SOL_IPV6
2105 case SOL_IPV6:
2106 printxval(sockipv6options, name, "IPV6_???");
2107 break;
2108#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002109#ifdef SOL_IPX
2110 case SOL_IPX:
2111 printxval(sockipxoptions, name, "IPX_???");
2112 break;
2113#endif
2114#ifdef SOL_PACKET
2115 case SOL_PACKET:
2116 printxval(sockpacketoptions, name, "PACKET_???");
2117 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002118 switch (name) {
2119#ifdef PACKET_RX_RING
2120 case PACKET_RX_RING:
2121#endif
2122#ifdef PACKET_TX_RING
2123 case PACKET_TX_RING:
2124#endif
2125#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2126 if (len == sizeof(struct tpacket_req)) {
2127 struct tpacket_req req;
2128 if (umove(tcp, addr, &req) < 0)
2129 break;
2130 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2131 req.tp_block_size,
2132 req.tp_block_nr,
2133 req.tp_frame_size,
2134 req.tp_frame_nr);
2135 return 0;
2136 }
2137 break;
2138#endif /* PACKET_RX_RING || PACKET_TX_RING */
2139 }
John Hughes38ae88d2002-05-23 11:48:58 +00002140 break;
2141#endif
2142#ifdef SOL_TCP
2143 case SOL_TCP:
2144 printxval(socktcpoptions, name, "TCP_???");
2145 break;
2146#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002147#ifdef SOL_SCTP
2148 case SOL_SCTP:
2149 printxval(socksctpoptions, name, "SCTP_???");
2150 break;
2151#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002152#ifdef SOL_RAW
2153 case SOL_RAW:
2154 printxval(sockrawoptions, name, "RAW_???");
2155 switch (name) {
2156#if defined(ICMP_FILTER)
2157 case ICMP_FILTER:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002158 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002159 printicmpfilter(tcp, addr);
2160 return 0;
2161#endif
2162 }
2163 break;
2164#endif
2165
Roland McGrath6d2b3492002-12-30 00:51:30 +00002166 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002167 * etc. still need work */
2168
2169 default:
2170 tprintf("%u", name);
2171 }
2172
2173 /* default arg printing */
2174
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002175 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002176
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002177 if (len == sizeof(int)) {
2178 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002179 }
2180 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002181 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002182 }
2183 return 0;
2184}
2185
2186
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002187#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002188
2189void
Denys Vlasenko12014262011-05-30 14:00:14 +02002190print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002191{
2192 int c = 0;
2193 struct opthdr hdr;
2194
John Hughes2c4e3a82002-05-24 10:19:44 +00002195 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002196 if (umove(tcp, addr, &hdr) < 0) break;
2197 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002198 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002199 }
2200 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002201 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002202 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002203 tprints("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002204 addr += sizeof hdr;
2205 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002206 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002207 if (hdr.len > 0) {
2208 addr += hdr.len;
2209 len -= hdr.len;
2210 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002211 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002212 }
2213 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002214 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002215 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002216 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002217 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002218}
2219
2220#endif
2221
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222int
Denys Vlasenko12014262011-05-30 14:00:14 +02002223sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224{
2225 if (entering(tcp)) {
2226 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002227 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002228 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002229 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 }
2231 return 0;
2232}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002233
2234#if UNIXWARE >= 7
2235
Roland McGrathd9f816f2004-09-04 03:39:20 +00002236static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002237 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2238 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2239 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2240 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2241 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2242 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002243 { 0, NULL },
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002244};
2245
2246
2247int
Denys Vlasenko12014262011-05-30 14:00:14 +02002248netlib_call(struct tcb *tcp, int (*func)())
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002249{
2250 if (entering(tcp)) {
2251 int i;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002252 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002253 tprints(", ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002254 --tcp->u_nargs;
2255 for (i = 0; i < tcp->u_nargs; i++)
2256 tcp->u_arg[i] = tcp->u_arg[i + 1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002257 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002258 }
2259
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002260 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002261}
2262
2263int
Denys Vlasenko12014262011-05-30 14:00:14 +02002264sys_xsocket(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002265{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002266 return netlib_call(tcp, sys_socket);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002267}
2268
2269int
Denys Vlasenko12014262011-05-30 14:00:14 +02002270sys_xsocketpair(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002271{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002272 return netlib_call(tcp, sys_socketpair);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002273}
2274
2275int
Denys Vlasenko12014262011-05-30 14:00:14 +02002276sys_xbind(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002277{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002278 return netlib_call(tcp, sys_bind);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002279}
2280
2281int
Denys Vlasenko12014262011-05-30 14:00:14 +02002282sys_xconnect(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002283{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002284 return netlib_call(tcp, sys_connect);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002285}
2286
2287int
Denys Vlasenko12014262011-05-30 14:00:14 +02002288sys_xlisten(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002289{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002290 return netlib_call(tcp, sys_listen);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002291}
2292
2293int
Denys Vlasenko12014262011-05-30 14:00:14 +02002294sys_xaccept(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002295{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002296 return netlib_call(tcp, sys_accept);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002297}
2298
2299int
Denys Vlasenko12014262011-05-30 14:00:14 +02002300sys_xsendmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002301{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002302 return netlib_call(tcp, sys_sendmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002303}
2304
2305int
Denys Vlasenko12014262011-05-30 14:00:14 +02002306sys_xrecvmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002307{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002308 return netlib_call(tcp, sys_recvmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002309}
2310
2311int
Denys Vlasenko12014262011-05-30 14:00:14 +02002312sys_xgetsockaddr(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002313{
2314 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002315 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002316 tprints(", ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002317 if (tcp->u_arg[1] == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002318 tprints("LOCALNAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002319 }
2320 else if (tcp->u_arg[1] == 1) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002321 tprints("REMOTENAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002322 }
2323 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002324 tprintf("%ld, ", tcp->u_arg[1]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002325 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002326 tprintf("%ld, ", tcp->u_arg[2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002327 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002328 else {
2329 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2330 tprintf("%#lx", tcp->u_arg[3]);
2331 } else {
2332 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2333 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002334 tprints(", ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002335 printnum(tcp, tcp->u_arg[4], "%lu");
2336 }
2337
2338 return 0;
2339
2340}
2341
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002342int
Denys Vlasenko12014262011-05-30 14:00:14 +02002343sys_xgetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002344{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002345 return netlib_call(tcp, sys_getsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002346}
2347
2348int
Denys Vlasenko12014262011-05-30 14:00:14 +02002349sys_xsetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002350{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002351 return netlib_call(tcp, sys_setsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002352}
2353
2354int
Denys Vlasenko12014262011-05-30 14:00:14 +02002355sys_xshutdown(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002356{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002357 return netlib_call(tcp, sys_shutdown);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002358}
2359
Dmitry V. Levine5e60852009-12-31 22:50:49 +00002360#endif /* UNIXWARE */