blob: 44d397b37d6b27462c3c74258dc1350eadb9c09c [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000053#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054#if defined(LINUX)
55#include <asm/types.h>
56#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
57# include <netipx/ipx.h>
58#else
59# include <linux/ipx.h>
60#endif
61#endif /* LINUX */
62
Wichert Akkermanf1850652001-02-16 20:29:03 +000063#if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000064#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000065#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
66#undef in6_addr
67#undef ipv6_mreq
68#undef sockaddr_in6
69#define in6_addr in6_addr_kernel
70#define ipv6_mreq ipv6_mreq_kernel
71#define sockaddr_in6 sockaddr_in6_kernel
72#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000073#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000074#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
75#undef in6_addr
76#undef ipv6_mreq
77#undef sockaddr_in6
78#define in6_addr in6_addr_libc
79#define ipv6_mreq ipv6_mreq_libc
80#define sockaddr_in6 sockaddr_in6_kernel
81#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000082#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000083#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000084
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#if defined(HAVE_SYS_UIO_H)
86#include <sys/uio.h>
87#endif
88
89#if defined(HAVE_LINUX_NETLINK_H)
90#include <linux/netlink.h>
91#endif
92
93#if defined(HAVE_LINUX_IF_PACKET_H)
94#include <linux/if_packet.h>
95#endif
96
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000097#if defined(HAVE_LINUX_ICMP_H)
98#include <linux/icmp.h>
99#endif
100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101#ifndef PF_UNSPEC
102#define PF_UNSPEC AF_UNSPEC
103#endif
104
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000105#if UNIXWARE >= 7
106#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
107#endif
108
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#ifdef LINUX
110/* Under Linux these are enums so we can't test for them with ifdef. */
111#define IPPROTO_EGP IPPROTO_EGP
112#define IPPROTO_PUP IPPROTO_PUP
113#define IPPROTO_IDP IPPROTO_IDP
114#define IPPROTO_IGMP IPPROTO_IGMP
115#define IPPROTO_RAW IPPROTO_RAW
116#define IPPROTO_MAX IPPROTO_MAX
117#endif
118
Roland McGrathd9f816f2004-09-04 03:39:20 +0000119static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000120#ifdef PF_AAL5
121 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#endif
123#ifdef PF_APPLETALK
124 { PF_APPLETALK, "PF_APPLETALK" },
125#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000126#ifdef PF_ASH
127 { PF_ASH, "PF_ASH" },
128#endif
129#ifdef PF_ATMPVC
130 { PF_ATMPVC, "PF_ATMPVC" },
131#endif
132#ifdef PF_ATMSVC
133 { PF_ATMSVC, "PF_ATMSVC" },
134#endif
135#ifdef PF_AX25
136 { PF_AX25, "PF_AX25" },
137#endif
138#ifdef PF_BLUETOOTH
139 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140#endif
141#ifdef PF_BRIDGE
142 { PF_BRIDGE, "PF_BRIDGE" },
143#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000144#ifdef PF_DECnet
145 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146#endif
147#ifdef PF_DECNET
148 { PF_DECNET, "PF_DECNET" },
149#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000150#ifdef PF_ECONET
151 { PF_ECONET, "PF_ECONET" },
152#endif
153#ifdef PF_FILE
154 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#endif
156#ifdef PF_IMPLINK
157 { PF_IMPLINK, "PF_IMPLINK" },
158#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000159#ifdef PF_INET
160 { PF_INET, "PF_INET" },
161#endif
162#ifdef PF_INET6
163 { PF_INET6, "PF_INET6" },
164#endif
165#ifdef PF_IPX
166 { PF_IPX, "PF_IPX" },
167#endif
168#ifdef PF_IRDA
169 { PF_IRDA, "PF_IRDA" },
170#endif
171#ifdef PF_ISO
172 { PF_ISO, "PF_ISO" },
173#endif
174#ifdef PF_KEY
175 { PF_KEY, "PF_KEY" },
176#endif
177#ifdef PF_UNIX
178 { PF_UNIX, "PF_UNIX" },
179#endif
180#ifdef PF_LOCAL
181 { PF_LOCAL, "PF_LOCAL" },
182#endif
183#ifdef PF_NETBEUI
184 { PF_NETBEUI, "PF_NETBEUI" },
185#endif
186#ifdef PF_NETLINK
187 { PF_NETLINK, "PF_NETLINK" },
188#endif
189#ifdef PF_NETROM
190 { PF_NETROM, "PF_NETROM" },
191#endif
192#ifdef PF_PACKET
193 { PF_PACKET, "PF_PACKET" },
194#endif
195#ifdef PF_PPPOX
196 { PF_PPPOX, "PF_PPPOX" },
197#endif
198#ifdef PF_ROSE
199 { PF_ROSE, "PF_ROSE" },
200#endif
201#ifdef PF_ROUTE
202 { PF_ROUTE, "PF_ROUTE" },
203#endif
204#ifdef PF_SECURITY
205 { PF_SECURITY, "PF_SECURITY" },
206#endif
207#ifdef PF_SNA
208 { PF_SNA, "PF_SNA" },
209#endif
210#ifdef PF_UNSPEC
211 { PF_UNSPEC, "PF_UNSPEC" },
212#endif
213#ifdef PF_WANPIPE
214 { PF_WANPIPE, "PF_WANPIPE" },
215#endif
216#ifdef PF_X25
217 { PF_X25, "PF_X25" },
218#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 { 0, NULL },
220};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000221const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000222#ifdef AF_APPLETALK
223 { AF_APPLETALK, "AF_APPLETALK" },
224#endif
225#ifdef AF_ASH
226 { AF_ASH, "AF_ASH" },
227#endif
228#ifdef AF_ATMPVC
229 { AF_ATMPVC, "AF_ATMPVC" },
230#endif
231#ifdef AF_ATMSVC
232 { AF_ATMSVC, "AF_ATMSVC" },
233#endif
234#ifdef AF_AX25
235 { AF_AX25, "AF_AX25" },
236#endif
237#ifdef AF_BLUETOOTH
238 { AF_BLUETOOTH, "AF_BLUETOOTH" },
239#endif
240#ifdef AF_BRIDGE
241 { AF_BRIDGE, "AF_BRIDGE" },
242#endif
243#ifdef AF_DECnet
244 { AF_DECnet, "AF_DECnet" },
245#endif
246#ifdef AF_ECONET
247 { AF_ECONET, "AF_ECONET" },
248#endif
249#ifdef AF_FILE
250 { AF_FILE, "AF_FILE" },
251#endif
252#ifdef AF_IMPLINK
253 { AF_IMPLINK, "AF_IMPLINK" },
254#endif
255#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000256 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000257#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000258#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000260#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000261#ifdef AF_IPX
262 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000263#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000264#ifdef AF_IRDA
265 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000266#endif
267#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000268 { AF_ISO, "AF_ISO" },
269#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000270#ifdef AF_KEY
271 { AF_KEY, "AF_KEY" },
272#endif
273#ifdef AF_UNIX
274 { AF_UNIX, "AF_UNIX" },
275#endif
276#ifdef AF_LOCAL
277 { AF_LOCAL, "AF_LOCAL" },
278#endif
279#ifdef AF_NETBEUI
280 { AF_NETBEUI, "AF_NETBEUI" },
281#endif
282#ifdef AF_NETLINK
283 { AF_NETLINK, "AF_NETLINK" },
284#endif
285#ifdef AF_NETROM
286 { AF_NETROM, "AF_NETROM" },
287#endif
288#ifdef AF_PACKET
289 { AF_PACKET, "AF_PACKET" },
290#endif
291#ifdef AF_PPPOX
292 { AF_PPPOX, "AF_PPPOX" },
293#endif
294#ifdef AF_ROSE
295 { AF_ROSE, "AF_ROSE" },
296#endif
297#ifdef AF_ROUTE
298 { AF_ROUTE, "AF_ROUTE" },
299#endif
300#ifdef AF_SECURITY
301 { AF_SECURITY, "AF_SECURITY" },
302#endif
303#ifdef AF_SNA
304 { AF_SNA, "AF_SNA" },
305#endif
306#ifdef AF_UNSPEC
307 { AF_UNSPEC, "AF_UNSPEC" },
308#endif
309#ifdef AF_WANPIPE
310 { AF_WANPIPE, "AF_WANPIPE" },
311#endif
312#ifdef AF_X25
313 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000314#endif
315 { 0, NULL },
316};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000317static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 { SOCK_STREAM, "SOCK_STREAM" },
319 { SOCK_DGRAM, "SOCK_DGRAM" },
320#ifdef SOCK_RAW
321 { SOCK_RAW, "SOCK_RAW" },
322#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000323#ifdef SOCK_RDM
324 { SOCK_RDM, "SOCK_RDM" },
325#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326#ifdef SOCK_SEQPACKET
327 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
328#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000329#ifdef SOCK_DCCP
330 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331#endif
332#ifdef SOCK_PACKET
333 { SOCK_PACKET, "SOCK_PACKET" },
334#endif
335 { 0, NULL },
336};
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000337const struct xlat sock_type_flags[] = {
338#ifdef SOCK_CLOEXEC
339 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
340#endif
341#ifdef SOCK_NONBLOCK
342 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
343#endif
344 { 0, NULL },
345};
346#ifndef SOCK_TYPE_MASK
347# define SOCK_TYPE_MASK 0xf
348#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000349static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000350#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000351 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000352#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000353#if defined(SOL_ICMP)
354 { SOL_ICMP, "SOL_ICMP" },
355#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000356#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000357 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000358#endif
359#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000361#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000362#if defined(SOL_IPV6)
363 { SOL_IPV6, "SOL_IPV6" },
364#endif
365#if defined(SOL_ICMPV6)
366 { SOL_ICMPV6, "SOL_ICMPV6" },
367#endif
368#if defined(SOL_RAW)
369 { SOL_RAW, "SOL_RAW" },
370#endif
371#if defined(SOL_IPX)
372 { SOL_IPX, "SOL_IPX" },
373#endif
374#if defined(SOL_IPX)
375 { SOL_IPX, "SOL_IPX" },
376#endif
377#if defined(SOL_AX25)
378 { SOL_AX25, "SOL_AX25" },
379#endif
380#if defined(SOL_ATALK)
381 { SOL_ATALK, "SOL_ATALK" },
382#endif
383#if defined(SOL_NETROM)
384 { SOL_NETROM, "SOL_NETROM" },
385#endif
386#if defined(SOL_ROSE)
387 { SOL_ROSE, "SOL_ROSE" },
388#endif
389#if defined(SOL_DECNET)
390 { SOL_DECNET, "SOL_DECNET" },
391#endif
392#if defined(SOL_X25)
393 { SOL_X25, "SOL_X25" },
394#endif
395#if defined(SOL_PACKET)
396 { SOL_PACKET, "SOL_PACKET" },
397#endif
398#if defined(SOL_ATM)
399 { SOL_ATM, "SOL_ATM" },
400#endif
401#if defined(SOL_AAL)
402 { SOL_AAL, "SOL_AAL" },
403#endif
404#if defined(SOL_IRDA)
405 { SOL_IRDA, "SOL_IRDA" },
406#endif
John Hughes61563572001-03-27 16:47:36 +0000407 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000408};
John Hughes93f7fcc2002-05-22 15:46:49 +0000409/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
410 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000411static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 { IPPROTO_IP, "IPPROTO_IP" },
413 { IPPROTO_ICMP, "IPPROTO_ICMP" },
414 { IPPROTO_TCP, "IPPROTO_TCP" },
415 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000416#ifdef IPPROTO_IGMP
417 { IPPROTO_IGMP, "IPPROTO_IGMP" },
418#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419#ifdef IPPROTO_GGP
420 { IPPROTO_GGP, "IPPROTO_GGP" },
421#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000422#ifdef IPPROTO_IPIP
423 { IPPROTO_IPIP, "IPPROTO_IPIP" },
424#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425#ifdef IPPROTO_EGP
426 { IPPROTO_EGP, "IPPROTO_EGP" },
427#endif
428#ifdef IPPROTO_PUP
429 { IPPROTO_PUP, "IPPROTO_PUP" },
430#endif
431#ifdef IPPROTO_IDP
432 { IPPROTO_IDP, "IPPROTO_IDP" },
433#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000434#ifdef IPPROTO_TP
435 { IPPROTO_TP, "IPPROTO_TP" },
436#endif
437#ifdef IPPROTO_DCCP
438 { IPPROTO_DCCP, "IPPROTO_DCCP" },
439#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440#ifdef IPPROTO_IPV6
441 { IPPROTO_IPV6, "IPPROTO_IPV6" },
442#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000443#ifdef IPPROTO_ROUTING
444 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000446#ifdef IPPROTO_FRAGMENT
447 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
448#endif
449#ifdef IPPROTO_RSVP
450 { IPPROTO_RSVP, "IPPROTO_RSVP" },
451#endif
452#ifdef IPPROTO_GRE
453 { IPPROTO_GRE, "IPPROTO_GRE" },
454#endif
455#ifdef IPPROTO_ESP
456 { IPPROTO_ESP, "IPPROTO_ESP" },
457#endif
458#ifdef IPPROTO_AH
459 { IPPROTO_AH, "IPPROTO_AH" },
460#endif
461#ifdef IPPROTO_ICMPV6
462 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
463#endif
464#ifdef IPPROTO_NONE
465 { IPPROTO_NONE, "IPPROTO_NONE" },
466#endif
467#ifdef IPPROTO_DSTOPTS
468 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469#endif
470#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000471 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472#endif
473#ifdef IPPROTO_ND
474 { IPPROTO_ND, "IPPROTO_ND" },
475#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000476#ifdef IPPROTO_MTP
477 { IPPROTO_MTP, "IPPROTO_MTP" },
478#endif
479#ifdef IPPROTO_ENCAP
480 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
481#endif
482#ifdef IPPROTO_PIM
483 { IPPROTO_PIM, "IPPROTO_PIM" },
484#endif
485#ifdef IPPROTO_COMP
486 { IPPROTO_COMP, "IPPROTO_COMP" },
487#endif
488#ifdef IPPROTO_SCTP
489 { IPPROTO_SCTP, "IPPROTO_SCTP" },
490#endif
491#ifdef IPPROTO_UDPLITE
492 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
493#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494#ifdef IPPROTO_RAW
495 { IPPROTO_RAW, "IPPROTO_RAW" },
496#endif
497#ifdef IPPROTO_MAX
498 { IPPROTO_MAX, "IPPROTO_MAX" },
499#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500 { 0, NULL },
501};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000502static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000503 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000505 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506#endif
507#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000508 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509#endif
510#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000511 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512#endif
513#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000514 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515#endif
516#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000517 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518#endif
519#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000520 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000522#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000523 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000524#endif
525#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000526 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000527#endif
528#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000529 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000530#endif
531#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000532 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000533#endif
534#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000535 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000536#endif
537#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000538 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000539#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000540#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000541 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000542#endif
543#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000544 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000545#endif
546#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000547 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000548#endif
549#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000550 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000551#endif
552#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000553 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000554#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000555#ifdef MSG_CMSG_CLOEXEC
556 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
557#endif
558 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559};
560
Roland McGrathd9f816f2004-09-04 03:39:20 +0000561static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000563 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000564#endif
565#ifdef SO_ALLRAW
566 { SO_ALLRAW, "SO_ALLRAW" },
567#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000568#ifdef SO_ATTACH_FILTER
569 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
570#endif
571#ifdef SO_BINDTODEVICE
572 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
573#endif
574#ifdef SO_BROADCAST
575 { SO_BROADCAST, "SO_BROADCAST" },
576#endif
577#ifdef SO_BSDCOMPAT
578 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
579#endif
580#ifdef SO_DEBUG
581 { SO_DEBUG, "SO_DEBUG" },
582#endif
583#ifdef SO_DETACH_FILTER
584 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
585#endif
586#ifdef SO_DONTROUTE
587 { SO_DONTROUTE, "SO_DONTROUTE" },
588#endif
589#ifdef SO_ERROR
590 { SO_ERROR, "SO_ERROR" },
591#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000592#ifdef SO_ICS
593 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000595#ifdef SO_IMASOCKET
596 { SO_IMASOCKET, "SO_IMASOCKET" },
597#endif
598#ifdef SO_KEEPALIVE
599 { SO_KEEPALIVE, "SO_KEEPALIVE" },
600#endif
601#ifdef SO_LINGER
602 { SO_LINGER, "SO_LINGER" },
603#endif
604#ifdef SO_LISTENING
605 { SO_LISTENING, "SO_LISTENING" },
606#endif
607#ifdef SO_MGMT
608 { SO_MGMT, "SO_MGMT" },
609#endif
610#ifdef SO_NO_CHECK
611 { SO_NO_CHECK, "SO_NO_CHECK" },
612#endif
613#ifdef SO_OOBINLINE
614 { SO_OOBINLINE, "SO_OOBINLINE" },
615#endif
616#ifdef SO_ORDREL
617 { SO_ORDREL, "SO_ORDREL" },
618#endif
619#ifdef SO_PARALLELSVR
620 { SO_PARALLELSVR, "SO_PARALLELSVR" },
621#endif
622#ifdef SO_PASSCRED
623 { SO_PASSCRED, "SO_PASSCRED" },
624#endif
625#ifdef SO_PEERCRED
626 { SO_PEERCRED, "SO_PEERCRED" },
627#endif
628#ifdef SO_PEERNAME
629 { SO_PEERNAME, "SO_PEERNAME" },
630#endif
631#ifdef SO_PEERSEC
632 { SO_PEERSEC, "SO_PEERSEC" },
633#endif
634#ifdef SO_PRIORITY
635 { SO_PRIORITY, "SO_PRIORITY" },
636#endif
637#ifdef SO_PROTOTYPE
638 { SO_PROTOTYPE, "SO_PROTOTYPE" },
639#endif
640#ifdef SO_RCVBUF
641 { SO_RCVBUF, "SO_RCVBUF" },
642#endif
643#ifdef SO_RCVLOWAT
644 { SO_RCVLOWAT, "SO_RCVLOWAT" },
645#endif
646#ifdef SO_RCVTIMEO
647 { SO_RCVTIMEO, "SO_RCVTIMEO" },
648#endif
649#ifdef SO_RDWR
650 { SO_RDWR, "SO_RDWR" },
651#endif
652#ifdef SO_REUSEADDR
653 { SO_REUSEADDR, "SO_REUSEADDR" },
654#endif
655#ifdef SO_REUSEPORT
656 { SO_REUSEPORT, "SO_REUSEPORT" },
657#endif
658#ifdef SO_SECURITY_AUTHENTICATION
659 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
660#endif
661#ifdef SO_SECURITY_ENCRYPTION_NETWORK
662 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
663#endif
664#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
665 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
666#endif
667#ifdef SO_SEMA
668 { SO_SEMA, "SO_SEMA" },
669#endif
670#ifdef SO_SNDBUF
671 { SO_SNDBUF, "SO_SNDBUF" },
672#endif
673#ifdef SO_SNDLOWAT
674 { SO_SNDLOWAT, "SO_SNDLOWAT" },
675#endif
676#ifdef SO_SNDTIMEO
677 { SO_SNDTIMEO, "SO_SNDTIMEO" },
678#endif
679#ifdef SO_TIMESTAMP
680 { SO_TIMESTAMP, "SO_TIMESTAMP" },
681#endif
682#ifdef SO_TYPE
683 { SO_TYPE, "SO_TYPE" },
684#endif
685#ifdef SO_USELOOPBACK
686 { SO_USELOOPBACK, "SO_USELOOPBACK" },
687#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688 { 0, NULL },
689};
690
John Hughes93f7fcc2002-05-22 15:46:49 +0000691#if !defined (SOL_IP) && defined (IPPROTO_IP)
692#define SOL_IP IPPROTO_IP
693#endif
694
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000696static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000697#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000698 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000699#endif
700#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000701 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000702#endif
703#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000704 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000706#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000707 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000709#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000710 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000711#endif
712#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000713 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
714#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000715#ifdef IP_RECVOPTS
716 { IP_RECVOPTS, "IP_RECVOPTS" },
717#endif
718#ifdef IP_RECVRETOPTS
719 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
720#endif
721#ifdef IP_RECVDSTADDR
722 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
723#endif
724#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000725 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000726#endif
727#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000728 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000729#endif
730#ifdef IP_PKTOPTIONS
731 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
732#endif
733#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000734 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000735#endif
736#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000737 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000738#endif
739#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000740 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000741#endif
742#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000743 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000744#endif
745#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000746 { IP_MTU, "IP_MTU" },
747#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000748#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000749 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000750#endif
751#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000752 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000753#endif
754#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000755 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000756#endif
757#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000758 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000759#endif
760#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000761 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000762#endif
763#ifdef IP_BROADCAST_IF
764 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
765#endif
766#ifdef IP_RECVIFINDEX
767 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
768#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000769#ifdef IP_MSFILTER
770 { IP_MSFILTER, "IP_MSFILTER" },
771#endif
772#ifdef MCAST_MSFILTER
773 { MCAST_MSFILTER, "MCAST_MSFILTER" },
774#endif
775#ifdef IP_FREEBIND
776 { IP_FREEBIND, "IP_FREEBIND" },
777#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000778 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779};
780#endif /* SOL_IP */
781
Roland McGrath4f6ba692004-08-31 07:01:26 +0000782#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000783static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000784#ifdef IPV6_ADDRFORM
785 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
786#endif
787#ifdef MCAST_FILTER
788 { MCAST_FILTER, "MCAST_FILTER" },
789#endif
790#ifdef IPV6_PKTOPTIONS
791 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
792#endif
793#ifdef IPV6_MTU
794 { IPV6_MTU, "IPV6_MTU" },
795#endif
796#ifdef IPV6_V6ONLY
797 { IPV6_V6ONLY, "IPV6_V6ONLY" },
798#endif
799#ifdef IPV6_PKTINFO
800 { IPV6_PKTINFO, "IPV6_PKTINFO" },
801#endif
802#ifdef IPV6_HOPLIMIT
803 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
804#endif
805#ifdef IPV6_RTHDR
806 { IPV6_RTHDR, "IPV6_RTHDR" },
807#endif
808#ifdef IPV6_HOPOPTS
809 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
810#endif
811#ifdef IPV6_DSTOPTS
812 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
813#endif
814#ifdef IPV6_FLOWINFO
815 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
816#endif
817#ifdef IPV6_UNICAST_HOPS
818 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
819#endif
820#ifdef IPV6_MULTICAST_HOPS
821 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
822#endif
823#ifdef IPV6_MULTICAST_LOOP
824 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
825#endif
826#ifdef IPV6_MULTICAST_IF
827 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
828#endif
829#ifdef IPV6_MTU_DISCOVER
830 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
831#endif
832#ifdef IPV6_RECVERR
833 { IPV6_RECVERR, "IPV6_RECVERR" },
834#endif
835#ifdef IPV6_FLOWINFO_SEND
836 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
837#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000838#ifdef IPV6_ADD_MEMBERSHIP
839 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
840#endif
841#ifdef IPV6_DROP_MEMBERSHIP
842 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
843#endif
844#ifdef IPV6_ROUTER_ALERT
845 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
846#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000847 { 0, NULL },
848};
849#endif /* SOL_IPV6 */
850
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000852static const struct xlat sockipxoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 { IPX_TYPE, "IPX_TYPE" },
854 { 0, NULL },
855};
856#endif /* SOL_IPX */
857
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000858#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000859static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000860#if defined(ICMP_FILTER)
861 { ICMP_FILTER, "ICMP_FILTER" },
862#endif
863 { 0, NULL },
864};
865#endif /* SOL_RAW */
866
867#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000868static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000869#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000870 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000871#endif
872#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000873 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000874#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000875#if defined(PACKET_RECV_OUTPUT)
876 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
877#endif
878#if defined(PACKET_RX_RING)
879 { PACKET_RX_RING, "PACKET_RX_RING" },
880#endif
881#if defined(PACKET_STATISTICS)
882 { PACKET_STATISTICS, "PACKET_STATISTICS" },
883#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000884#if defined(PACKET_COPY_THRESH)
885 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
886#endif
887#if defined(PACKET_AUXDATA)
888 { PACKET_AUXDATA, "PACKET_AUXDATA" },
889#endif
890#if defined(PACKET_ORIGDEV)
891 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
892#endif
893#if defined(PACKET_VERSION)
894 { PACKET_VERSION, "PACKET_VERSION" },
895#endif
896#if defined(PACKET_HDRLEN)
897 { PACKET_HDRLEN, "PACKET_HDRLEN" },
898#endif
899#if defined(PACKET_RESERVE)
900 { PACKET_RESERVE, "PACKET_RESERVE" },
901#endif
902#if defined(PACKET_TX_RING)
903 { PACKET_TX_RING, "PACKET_TX_RING" },
904#endif
905#if defined(PACKET_LOSS)
906 { PACKET_LOSS, "PACKET_LOSS" },
907#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000908 { 0, NULL },
909};
910#endif /* SOL_PACKET */
911
John Hughes93f7fcc2002-05-22 15:46:49 +0000912#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
913#define SOL_TCP IPPROTO_TCP
914#endif
915
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000917static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000918 { TCP_NODELAY, "TCP_NODELAY" },
919 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000920#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000921 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000922#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000923#if defined(TCP_KEEPIDLE)
924 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
925#endif
926#if defined(TCP_KEEPINTVL)
927 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
928#endif
929#if defined(TCP_KEEPCNT)
930 { TCP_KEEPCNT, "TCP_KEEPCNT" },
931#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000932#if defined(TCP_NKEEP)
933 { TCP_NKEEP, "TCP_NKEEP" },
934#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000935#if defined(TCP_SYNCNT)
936 { TCP_SYNCNT, "TCP_SYNCNT" },
937#endif
938#if defined(TCP_LINGER2)
939 { TCP_LINGER2, "TCP_LINGER2" },
940#endif
941#if defined(TCP_DEFER_ACCEPT)
942 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
943#endif
944#if defined(TCP_WINDOW_CLAMP)
945 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
946#endif
947#if defined(TCP_INFO)
948 { TCP_INFO, "TCP_INFO" },
949#endif
950#if defined(TCP_QUICKACK)
951 { TCP_QUICKACK, "TCP_QUICKACK" },
952#endif
953 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954};
955#endif /* SOL_TCP */
956
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000957#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000958static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000959#if defined(ICMP_ECHOREPLY)
960 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
961#endif
962#if defined(ICMP_DEST_UNREACH)
963 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
964#endif
965#if defined(ICMP_SOURCE_QUENCH)
966 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
967#endif
968#if defined(ICMP_REDIRECT)
969 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
970#endif
971#if defined(ICMP_ECHO)
972 { (1<<ICMP_ECHO), "ICMP_ECHO" },
973#endif
974#if defined(ICMP_TIME_EXCEEDED)
975 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
976#endif
977#if defined(ICMP_PARAMETERPROB)
978 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
979#endif
980#if defined(ICMP_TIMESTAMP)
981 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
982#endif
983#if defined(ICMP_TIMESTAMPREPLY)
984 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
985#endif
986#if defined(ICMP_INFO_REQUEST)
987 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
988#endif
989#if defined(ICMP_INFO_REPLY)
990 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
991#endif
992#if defined(ICMP_ADDRESS)
993 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
994#endif
995#if defined(ICMP_ADDRESSREPLY)
996 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
997#endif
998 { 0, NULL },
999};
1000#endif /* SOL_RAW */
1001
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001002#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001003static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001004#if defined(PACKET_HOST)
1005 { PACKET_HOST, "PACKET_HOST" },
1006#endif
1007#if defined(PACKET_BROADCAST)
1008 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1009#endif
1010#if defined(PACKET_MULTICAST)
1011 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1012#endif
1013#if defined(PACKET_OTHERHOST)
1014 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1015#endif
1016#if defined(PACKET_OUTGOING)
1017 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1018#endif
1019#if defined(PACKET_LOOPBACK)
1020 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1021#endif
1022#if defined(PACKET_FASTROUTE)
1023 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1024#endif
1025 { 0, NULL },
1026};
1027#endif /* defined(AF_PACKET) */
1028
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001029
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001031printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001033 union {
1034 char pad[128];
1035 struct sockaddr sa;
1036 struct sockaddr_in sin;
1037 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001038#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001039 struct sockaddr_in6 sa6;
1040#endif
1041#if defined(LINUX) && defined(AF_IPX)
1042 struct sockaddr_ipx sipx;
1043#endif
1044#ifdef AF_PACKET
1045 struct sockaddr_ll ll;
1046#endif
1047#ifdef AF_NETLINK
1048 struct sockaddr_nl nl;
1049#endif
1050 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001051 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052
1053 if (addr == 0) {
1054 tprintf("NULL");
1055 return;
1056 }
1057 if (!verbose(tcp)) {
1058 tprintf("%#lx", addr);
1059 return;
1060 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001061
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001062 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1063 addrlen = sizeof(addrbuf);
1064
1065 memset(&addrbuf, 0, sizeof(addrbuf));
1066 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 tprintf("{...}");
1068 return;
1069 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001070 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001071
John Hughes1fcb1d62001-09-18 15:56:53 +00001072 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001073 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1074 tprintf(", ");
1075
1076 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001078 if (addrlen == 2) {
1079 tprintf("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001080 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001081 tprintf("path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001082 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001083 } else {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001084 tprintf("path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001085 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001086 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087 break;
1088 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001089 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001090 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001092#ifdef HAVE_INET_NTOP
1093 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001094 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001095 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1096 ntohs(addrbuf.sa6.sin6_port), string_addr,
1097 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001098#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001099 {
1100#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1101 int numericscope = 0;
1102 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1103 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1104 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001105
Wichert Akkermanf1850652001-02-16 20:29:03 +00001106 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1107 numericscope++;
1108 else
1109 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1110 } else
1111 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001112
Wichert Akkermanf1850652001-02-16 20:29:03 +00001113 if (numericscope)
1114#endif
1115 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1116 }
1117#endif
1118 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001119#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001120#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001121 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001122 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001124 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001125 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 /* Yes, I know, this does not look too
1127 * strace-ish, but otherwise the IPX
1128 * addresses just look monstrous...
1129 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001130 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001132 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001134 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1135 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136 }
1137 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001138#endif /* AF_IPX && linux */
1139#ifdef AF_PACKET
1140 case AF_PACKET:
1141 {
1142 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001143 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001144 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001145 addrbuf.ll.sll_ifindex);
1146 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1147 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001148 addrbuf.ll.sll_halen,
1149 addrbuf.ll.sll_hatype);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001151 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1152 }
1153 break;
1154
1155#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001156#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001157 case AF_NETLINK:
1158 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1159 break;
1160#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001161 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001162 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001163
1164 default:
John Hughes1fcb1d62001-09-18 15:56:53 +00001165 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001167 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001168 break;
1169 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001170 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171}
1172
1173#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001174static const struct xlat scmvals[] = {
1175#ifdef SCM_RIGHTS
1176 { SCM_RIGHTS, "SCM_RIGHTS" },
1177#endif
1178#ifdef SCM_CREDENTIALS
1179 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1180#endif
1181 { 0, NULL }
1182};
1183
1184static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001185printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001186{
Roland McGrathaa524c82005-06-01 19:22:06 +00001187 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1188 NULL : malloc(len);
1189 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001190 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001191 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001192 return;
1193 }
1194
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001195 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001196 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Roland McGrath50770822004-10-06 22:11:51 +00001197 tprintf(", cmsg_type=");
1198
Roland McGrathaa524c82005-06-01 19:22:06 +00001199 if (cmsg->cmsg_level == SOL_SOCKET) {
1200 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001201
Roland McGrathaa524c82005-06-01 19:22:06 +00001202 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1203 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1204
1205 if (cmsg->cmsg_type == SCM_RIGHTS
1206 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1207 int *fds = (int *) CMSG_DATA (cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001208 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001209
Roland McGrath50770822004-10-06 22:11:51 +00001210 tprintf(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001211 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001212 if (!first)
1213 tprintf(", ");
1214 tprintf("%d", *fds++);
1215 first = 0;
1216 }
1217 tprintf("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001218 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001219 return;
1220 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001221 if (cmsg->cmsg_type == SCM_CREDENTIALS
1222 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1223 struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1224
Roland McGrath50770822004-10-06 22:11:51 +00001225 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1226 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001227 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001228 return;
1229 }
1230 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001231 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001232 tprintf(", ...}");
1233}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234
1235static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001236do_msghdr(struct tcb *tcp, struct msghdr *msg)
1237{
1238 tprintf("{msg_name(%d)=", msg->msg_namelen);
1239 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1240
1241 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1242 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
1243 (unsigned long)msg->msg_iov);
1244
1245#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1246 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1247 if (msg->msg_controllen)
1248 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1249 msg->msg_controllen);
1250 tprintf(", msg_flags=");
1251 printflags(msg_flags, msg->msg_flags, "MSG_???");
1252#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1253 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1254 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1255#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1256 tprintf("}");
1257}
1258
1259static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260printmsghdr(tcp, addr)
1261struct tcb *tcp;
1262long addr;
1263{
1264 struct msghdr msg;
1265
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001266 if (umove(tcp, addr, &msg) < 0) {
1267 tprintf("%#lx", addr);
1268 return;
1269 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001270 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271}
1272
Andreas Schwab0873f292010-02-12 21:39:12 +01001273#ifdef LINUX
1274static void
1275printmmsghdr(struct tcb *tcp, long addr)
1276{
1277 struct mmsghdr {
1278 struct msghdr msg_hdr;
1279 unsigned msg_len;
1280 } mmsg;
1281
1282 if (umove(tcp, addr, &mmsg) < 0) {
1283 tprintf("%#lx", addr);
1284 return;
1285 }
1286 tprintf("{");
1287 do_msghdr(tcp, &mmsg.msg_hdr);
1288 tprintf(", %u}", mmsg.msg_len);
1289}
1290#endif
1291
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292#endif /* HAVE_SENDMSG */
1293
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001294/*
1295 * low bits of the socket type define real socket type,
1296 * other bits are socket type flags.
1297 */
1298static void
1299tprint_sock_type(struct tcb *tcp, int flags)
1300{
1301 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1302
1303 if (str)
1304 {
1305 tprintf("%s", str);
1306 flags &= ~SOCK_TYPE_MASK;
1307 if (!flags)
1308 return;
1309 tprintf("|");
1310 }
1311 printflags(sock_type_flags, flags, "SOCK_???");
1312}
1313
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001315sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316{
1317 if (entering(tcp)) {
1318 printxval(domains, tcp->u_arg[0], "PF_???");
1319 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001320 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321 tprintf(", ");
1322 switch (tcp->u_arg[0]) {
1323 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001324#ifdef PF_INET6
1325 case PF_INET6:
1326#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001327 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1328 break;
1329#ifdef PF_IPX
1330 case PF_IPX:
1331 /* BTW: I don't believe this.. */
1332 tprintf("[");
1333 printxval(domains, tcp->u_arg[2], "PF_???");
1334 tprintf("]");
1335 break;
1336#endif /* PF_IPX */
1337 default:
1338 tprintf("%lu", tcp->u_arg[2]);
1339 break;
1340 }
1341 }
1342 return 0;
1343}
1344
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001345#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346int
John Hughesbdf48f52001-03-06 15:08:09 +00001347sys_so_socket(tcp)
1348struct tcb *tcp;
1349{
1350 if (entering(tcp)) {
1351 /* not sure really what these args are... but this
1352 * is how truss prints it
1353 */
1354 tprintf("%ld, %ld, %ld, ",
1355 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1356 printpath(tcp, tcp->u_arg[3]);
1357 tprintf(", %ld", tcp->u_arg[4]);
1358 }
1359 return 0;
1360}
1361
1362int
1363sys_so_socketpair(tcp)
1364struct tcb *tcp;
1365{
1366 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001367 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001368 tprintf("0x%lx", tcp->u_arg[0]);
1369 }
1370 return 0;
1371}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001372#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001373
1374int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375sys_bind(tcp)
1376struct tcb *tcp;
1377{
1378 if (entering(tcp)) {
1379 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001380 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381 tprintf(", %lu", tcp->u_arg[2]);
1382 }
1383 return 0;
1384}
1385
1386int
1387sys_connect(tcp)
1388struct tcb *tcp;
1389{
1390 return sys_bind(tcp);
1391}
1392
1393int
1394sys_listen(tcp)
1395struct tcb *tcp;
1396{
1397 if (entering(tcp)) {
1398 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1399 }
1400 return 0;
1401}
1402
Paolo Bonzini705ff102009-08-14 12:34:05 +02001403static int
1404do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001405{
1406 if (entering(tcp)) {
1407 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001408 return 0;
1409 }
1410 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 tprintf("%#lx, NULL", tcp->u_arg[1]);
1412 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001413 int len;
1414 if (tcp->u_arg[1] == 0 || syserror(tcp)
1415 || umove (tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416 tprintf("%#lx", tcp->u_arg[1]);
1417 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001418 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 }
1420 tprintf(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001421 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001423 if (flags_arg >= 0) {
1424 tprintf(", ");
1425 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1426 "SOCK_???");
1427 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428 return 0;
1429}
1430
1431int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001432sys_accept(struct tcb *tcp)
1433{
1434 return do_accept(tcp, -1);
1435}
1436
1437#ifdef LINUX
1438int
1439sys_accept4(struct tcb *tcp)
1440{
1441 return do_accept(tcp, 3);
1442}
1443#endif
1444
1445int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446sys_send(tcp)
1447struct tcb *tcp;
1448{
1449 if (entering(tcp)) {
1450 tprintf("%ld, ", tcp->u_arg[0]);
1451 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1452 tprintf(", %lu, ", tcp->u_arg[2]);
1453 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001454 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455 }
1456 return 0;
1457}
1458
1459int
1460sys_sendto(tcp)
1461struct tcb *tcp;
1462{
1463 if (entering(tcp)) {
1464 tprintf("%ld, ", tcp->u_arg[0]);
1465 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1466 tprintf(", %lu, ", tcp->u_arg[2]);
1467 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001468 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001469 /* to address */
1470 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001471 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001472 /* to length */
1473 tprintf(", %lu", tcp->u_arg[5]);
1474 }
1475 return 0;
1476}
1477
1478#ifdef HAVE_SENDMSG
1479
1480int
1481sys_sendmsg(tcp)
1482struct tcb *tcp;
1483{
1484 if (entering(tcp)) {
1485 tprintf("%ld, ", tcp->u_arg[0]);
1486 printmsghdr(tcp, tcp->u_arg[1]);
1487 /* flags */
1488 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001489 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490 }
1491 return 0;
1492}
1493
1494#endif /* HAVE_SENDMSG */
1495
1496int
1497sys_recv(tcp)
1498struct tcb *tcp;
1499{
1500 if (entering(tcp)) {
1501 tprintf("%ld, ", tcp->u_arg[0]);
1502 } else {
1503 if (syserror(tcp))
1504 tprintf("%#lx", tcp->u_arg[1]);
1505 else
1506 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1507
1508 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001509 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001510 }
1511 return 0;
1512}
1513
1514int
1515sys_recvfrom(tcp)
1516struct tcb *tcp;
1517{
1518 int fromlen;
1519
1520 if (entering(tcp)) {
1521 tprintf("%ld, ", tcp->u_arg[0]);
1522 } else {
1523 if (syserror(tcp)) {
1524 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1525 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1526 tcp->u_arg[4], tcp->u_arg[5]);
1527 return 0;
1528 }
1529 /* buf */
1530 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1531 /* len */
1532 tprintf(", %lu, ", tcp->u_arg[2]);
1533 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001534 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535 /* from address, len */
1536 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1537 if (tcp->u_arg[4] == 0)
1538 tprintf(", NULL");
1539 else
1540 tprintf(", %#lx", tcp->u_arg[4]);
1541 if (tcp->u_arg[5] == 0)
1542 tprintf(", NULL");
1543 else
1544 tprintf(", %#lx", tcp->u_arg[5]);
1545 return 0;
1546 }
1547 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1548 tprintf(", {...}, [?]");
1549 return 0;
1550 }
1551 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001552 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001553 /* from length */
1554 tprintf(", [%u]", fromlen);
1555 }
1556 return 0;
1557}
1558
1559#ifdef HAVE_SENDMSG
1560
1561int
1562sys_recvmsg(tcp)
1563struct tcb *tcp;
1564{
1565 if (entering(tcp)) {
1566 tprintf("%ld, ", tcp->u_arg[0]);
1567 } else {
1568 if (syserror(tcp) || !verbose(tcp))
1569 tprintf("%#lx", tcp->u_arg[1]);
1570 else
1571 printmsghdr(tcp, tcp->u_arg[1]);
1572 /* flags */
1573 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001574 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575 }
1576 return 0;
1577}
1578
Andreas Schwab0873f292010-02-12 21:39:12 +01001579#ifdef LINUX
1580int
1581sys_recvmmsg(struct tcb *tcp)
1582{
Dmitry V. Levine6591032010-03-29 20:45:48 +04001583 static char str[128];
Andreas Schwab0873f292010-02-12 21:39:12 +01001584 if (entering(tcp)) {
Dmitry V. Levine6591032010-03-29 20:45:48 +04001585
Andreas Schwab0873f292010-02-12 21:39:12 +01001586 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001587 if (verbose(tcp)) {
1588 sprint_timespec(str, tcp, tcp->u_arg[4]);
1589 tcp->auxstr = strdup(str);
1590 } else {
1591 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1592 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1593 tprintf(", ");
1594 print_timespec(tcp, tcp->u_arg[4]);
1595 }
1596 return 0;
1597 } else {
1598 if (verbose(tcp)) {
1599 if (syserror(tcp))
1600 tprintf("%#lx", tcp->u_arg[1]);
1601 else
1602 printmmsghdr(tcp, tcp->u_arg[1]);
1603 tprintf(", %ld, ", tcp->u_arg[2]);
1604 /* flags */
1605 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1606 /* timeout on entrance */
1607 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1608 free((void *) tcp->auxstr);
1609 tcp->auxstr = NULL;
1610 }
1611 if (syserror(tcp))
1612 return 0;
1613 if (tcp->u_rval == 0) {
1614 tcp->auxstr = "Timeout";
1615 return RVAL_STR;
1616 }
1617 if (!verbose(tcp))
1618 return 0;
1619 /* timeout on exit */
1620 strcpy(str, "left ");
1621 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1622 tcp->auxstr = str;
1623 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001624 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001625}
1626#endif
1627
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628#endif /* HAVE_SENDMSG */
1629
1630int
1631sys_shutdown(tcp)
1632struct tcb *tcp;
1633{
1634 if (entering(tcp)) {
1635 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1636 switch (tcp->u_arg[1]) {
1637 case 0:
1638 tprintf("%s", " /* receive */");
1639 break;
1640 case 1:
1641 tprintf("%s", " /* send */");
1642 break;
1643 case 2:
1644 tprintf("%s", " /* send and receive */");
1645 break;
1646 }
1647 }
1648 return 0;
1649}
1650
1651int
1652sys_getsockname(tcp)
1653struct tcb *tcp;
1654{
1655 return sys_accept(tcp);
1656}
1657
1658int
1659sys_getpeername(tcp)
1660struct tcb *tcp;
1661{
1662 return sys_accept(tcp);
1663}
1664
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001665static int
1666do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 if (exiting(tcp)) {
1669 if (syserror(tcp)) {
1670 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001671 } else {
1672#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1673 int fds[2];
1674
1675 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1676 tprintf("[...]");
1677 else
1678 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001679#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001680 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1681#else
1682 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001684 }
1685 if (flags_arg >= 0) {
1686 tprintf(", ");
1687 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1688 }
1689 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 return 0;
1691}
1692
1693int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001694sys_pipe(struct tcb *tcp)
1695{
1696 return do_pipe(tcp, -1);
1697}
1698
1699#ifdef LINUX
1700int
1701sys_pipe2(struct tcb *tcp)
1702{
1703 return do_pipe(tcp, 1);
1704}
1705#endif
1706
1707int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001708sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709{
1710#ifdef LINUX
1711 int fds[2];
1712#endif
1713
1714 if (entering(tcp)) {
1715 printxval(domains, tcp->u_arg[0], "PF_???");
1716 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001717 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718 tprintf(", ");
1719 switch (tcp->u_arg[0]) {
1720 case PF_INET:
1721 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1722 break;
1723#ifdef PF_IPX
1724 case PF_IPX:
1725 /* BTW: I don't believe this.. */
1726 tprintf("[");
1727 printxval(domains, tcp->u_arg[2], "PF_???");
1728 tprintf("]");
1729 break;
1730#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001731 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001732 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733 break;
1734 }
1735 } else {
1736 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001737 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738 return 0;
1739 }
1740#ifdef LINUX
1741 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001742 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001743 else
1744 tprintf(", [%u, %u]", fds[0], fds[1]);
1745#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001746#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001747 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001748#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749 }
1750 return 0;
1751}
1752
1753int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001754sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755{
1756 if (entering(tcp)) {
1757 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001758 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1759 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 switch (tcp->u_arg[1]) {
1761 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763 break;
1764#ifdef SOL_IP
1765 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001767 break;
1768#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001769#ifdef SOL_IPV6
1770 case SOL_IPV6:
1771 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1772 break;
1773#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001774#ifdef SOL_IPX
1775 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 break;
1778#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001779#ifdef SOL_PACKET
1780 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001781 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001782 break;
1783#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784#ifdef SOL_TCP
1785 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787 break;
1788#endif
1789
1790 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1791 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001792 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001793 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794 break;
1795 }
Dmitry V. Levin31289192009-11-06 18:05:40 +00001796 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001797 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001798 int len;
John Hughes93f7fcc2002-05-22 15:46:49 +00001799 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001800 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801 tcp->u_arg[3], tcp->u_arg[4]);
1802 return 0;
1803 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001804
1805 switch (tcp->u_arg[1]) {
1806 case SOL_SOCKET:
1807 switch (tcp->u_arg[2]) {
1808#ifdef SO_LINGER
1809 case SO_LINGER:
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001810 if (len == sizeof (struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001811 struct linger linger;
1812 if (umove (tcp,
1813 tcp->u_arg[3],
1814 &linger) < 0)
1815 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001816 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001817 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001818 linger.l_onoff,
1819 linger.l_linger,
1820 len);
1821 return 0;
1822 }
1823 break;
1824#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001825#ifdef SO_PEERCRED
1826 case SO_PEERCRED:
1827 if (len == sizeof (struct ucred)) {
1828 struct ucred uc;
1829 if (umove (tcp,
1830 tcp->u_arg[3],
1831 &uc) < 0)
1832 break;
1833 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1834 "[%d]",
1835 (long)uc.pid,
1836 (long)uc.uid,
1837 (long)uc.gid,
1838 len);
1839 return 0;
1840 }
1841 break;
1842#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001843 }
1844 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001845 case SOL_PACKET:
1846 switch (tcp->u_arg[2]) {
1847#ifdef PACKET_STATISTICS
1848 case PACKET_STATISTICS:
1849 if (len == sizeof(struct tpacket_stats)) {
1850 struct tpacket_stats stats;
1851 if (umove (tcp,
1852 tcp->u_arg[3],
1853 &stats) < 0)
1854 break;
1855 tprintf("{packets=%u, drops=%u}, "
1856 "[%d]",
1857 stats.tp_packets,
1858 stats.tp_drops,
1859 len);
1860 return 0;
1861 }
1862 break;
1863#endif
1864 }
1865 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001866 }
1867
John Hughes93f7fcc2002-05-22 15:46:49 +00001868 if (len == sizeof (int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001869 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001870 }
1871 else {
1872 printstr (tcp, tcp->u_arg[3], len);
1873 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001874 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875 }
1876 return 0;
1877}
1878
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001879#if defined(ICMP_FILTER)
1880static void printicmpfilter(tcp, addr)
1881struct tcb *tcp;
1882long addr;
1883{
1884 struct icmp_filter filter;
1885
1886 if (!addr) {
1887 tprintf("NULL");
1888 return;
1889 }
1890 if (syserror(tcp) || !verbose(tcp)) {
1891 tprintf("%#lx", addr);
1892 return;
1893 }
1894 if (umove(tcp, addr, &filter) < 0) {
1895 tprintf("{...}");
1896 return;
1897 }
1898
1899 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001900 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001901 tprintf(")");
1902}
1903#endif /* ICMP_FILTER */
1904
John Hughes38ae88d2002-05-23 11:48:58 +00001905static int
1906printsockopt (tcp, level, name, addr, len)
1907struct tcb *tcp;
1908int level;
1909int name;
1910long addr;
1911int len;
1912{
1913 printxval(socketlayers, level, "SOL_??");
1914 tprintf (", ");
1915 switch (level) {
1916 case SOL_SOCKET:
1917 printxval(sockoptions, name, "SO_???");
1918 switch (name) {
1919#if defined(SO_LINGER)
1920 case SO_LINGER:
1921 if (len == sizeof (struct linger)) {
1922 struct linger linger;
1923 if (umove (tcp, addr, &linger) < 0)
1924 break;
1925 tprintf(", {onoff=%d, linger=%d}",
1926 linger.l_onoff,
1927 linger.l_linger);
1928 return 0;
1929 }
1930 break;
1931#endif
1932 }
1933 break;
1934#ifdef SOL_IP
1935 case SOL_IP:
1936 printxval(sockipoptions, name, "IP_???");
1937 break;
1938#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001939#ifdef SOL_IPV6
1940 case SOL_IPV6:
1941 printxval(sockipv6options, name, "IPV6_???");
1942 break;
1943#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001944#ifdef SOL_IPX
1945 case SOL_IPX:
1946 printxval(sockipxoptions, name, "IPX_???");
1947 break;
1948#endif
1949#ifdef SOL_PACKET
1950 case SOL_PACKET:
1951 printxval(sockpacketoptions, name, "PACKET_???");
1952 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001953 switch (name) {
1954#ifdef PACKET_RX_RING
1955 case PACKET_RX_RING:
1956#endif
1957#ifdef PACKET_TX_RING
1958 case PACKET_TX_RING:
1959#endif
1960#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1961 if (len == sizeof(struct tpacket_req)) {
1962 struct tpacket_req req;
1963 if (umove(tcp, addr, &req) < 0)
1964 break;
1965 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1966 req.tp_block_size,
1967 req.tp_block_nr,
1968 req.tp_frame_size,
1969 req.tp_frame_nr);
1970 return 0;
1971 }
1972 break;
1973#endif /* PACKET_RX_RING || PACKET_TX_RING */
1974 }
John Hughes38ae88d2002-05-23 11:48:58 +00001975 break;
1976#endif
1977#ifdef SOL_TCP
1978 case SOL_TCP:
1979 printxval(socktcpoptions, name, "TCP_???");
1980 break;
1981#endif
1982#ifdef SOL_RAW
1983 case SOL_RAW:
1984 printxval(sockrawoptions, name, "RAW_???");
1985 switch (name) {
1986#if defined(ICMP_FILTER)
1987 case ICMP_FILTER:
1988 tprintf(", ");
1989 printicmpfilter(tcp, addr);
1990 return 0;
1991#endif
1992 }
1993 break;
1994#endif
1995
Roland McGrath6d2b3492002-12-30 00:51:30 +00001996 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001997 * etc. still need work */
1998
1999 default:
2000 tprintf("%u", name);
2001 }
2002
2003 /* default arg printing */
2004
2005 tprintf (", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002006
John Hughes38ae88d2002-05-23 11:48:58 +00002007 if (len == sizeof (int)) {
Roland McGrath9814a942005-07-04 23:28:10 +00002008 printnum_int (tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002009 }
2010 else {
2011 printstr (tcp, addr, len);
2012 }
2013 return 0;
2014}
2015
2016
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002017#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002018
2019void
2020print_sock_optmgmt (tcp, addr, len)
2021struct tcb *tcp;
2022long addr;
2023int len;
2024{
2025 int c = 0;
2026 struct opthdr hdr;
2027
John Hughes2c4e3a82002-05-24 10:19:44 +00002028 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002029 if (umove(tcp, addr, &hdr) < 0) break;
2030 if (c++) {
2031 tprintf (", ");
2032 }
2033 else if (len > hdr.len + sizeof hdr) {
2034 tprintf ("[");
2035 }
2036 tprintf ("{");
2037 addr += sizeof hdr;
2038 len -= sizeof hdr;
2039 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002040 if (hdr.len > 0) {
2041 addr += hdr.len;
2042 len -= hdr.len;
2043 }
John Hughes38ae88d2002-05-23 11:48:58 +00002044 tprintf ("}");
2045 }
2046 if (len > 0) {
2047 if (c++) tprintf (", ");
2048 printstr (tcp, addr, len);
2049 }
2050 if (c > 1) tprintf ("]");
2051}
2052
2053#endif
2054
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055int
2056sys_setsockopt(tcp)
2057struct tcb *tcp;
2058{
2059 if (entering(tcp)) {
2060 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes38ae88d2002-05-23 11:48:58 +00002061 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
2062 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002063 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064 }
2065 return 0;
2066}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002067
2068#if UNIXWARE >= 7
2069
Roland McGrathd9f816f2004-09-04 03:39:20 +00002070static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002071 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2072 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2073 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2074 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2075 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2076 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
2077 { 0, NULL },
2078};
2079
2080
2081int
2082netlib_call(tcp, func)
2083struct tcb *tcp;
2084int (*func) ();
2085{
2086 if (entering(tcp)) {
2087 int i;
2088 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2089 tprintf(", ");
2090 --tcp->u_nargs;
2091 for (i = 0; i < tcp->u_nargs; i++)
2092 tcp->u_arg[i] = tcp->u_arg[i + 1];
2093 return func (tcp);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002094
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002095 }
2096
2097 return func (tcp);
2098}
2099
2100int
2101sys_xsocket(tcp)
2102struct tcb *tcp;
2103{
2104 return netlib_call (tcp, sys_socket);
2105}
2106
2107int
2108sys_xsocketpair(tcp)
2109struct tcb *tcp;
2110{
2111 return netlib_call (tcp, sys_socketpair);
2112}
2113
2114int
2115sys_xbind(tcp)
2116struct tcb *tcp;
2117{
2118 return netlib_call (tcp, sys_bind);
2119}
2120
2121int
2122sys_xconnect(tcp)
2123struct tcb *tcp;
2124{
2125 return netlib_call (tcp, sys_connect);
2126}
2127
2128int
2129sys_xlisten(tcp)
2130struct tcb *tcp;
2131{
2132 return netlib_call (tcp, sys_listen);
2133}
2134
2135int
2136sys_xaccept(tcp)
2137struct tcb *tcp;
2138{
2139 return netlib_call (tcp, sys_accept);
2140}
2141
2142int
2143sys_xsendmsg(tcp)
2144struct tcb *tcp;
2145{
2146 return netlib_call (tcp, sys_sendmsg);
2147}
2148
2149int
2150sys_xrecvmsg(tcp)
2151struct tcb *tcp;
2152{
2153 return netlib_call (tcp, sys_recvmsg);
2154}
2155
2156int
2157sys_xgetsockaddr(tcp)
2158struct tcb *tcp;
2159{
2160 if (entering(tcp)) {
2161 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2162 tprintf(", ");
2163 if (tcp->u_arg[1] == 0) {
2164 tprintf ("LOCALNAME, ");
2165 }
2166 else if (tcp->u_arg[1] == 1) {
2167 tprintf ("REMOTENAME, ");
2168 }
2169 else {
2170 tprintf ("%ld, ", tcp->u_arg [1]);
2171 }
2172 tprintf ("%ld, ", tcp->u_arg [2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002173 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002174 else {
2175 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2176 tprintf("%#lx", tcp->u_arg[3]);
2177 } else {
2178 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2179 }
2180 tprintf(", ");
2181 printnum(tcp, tcp->u_arg[4], "%lu");
2182 }
2183
2184 return 0;
2185
2186}
2187
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002188int
2189sys_xgetsockopt(tcp)
2190struct tcb *tcp;
2191{
2192 return netlib_call (tcp, sys_getsockopt);
2193}
2194
2195int
2196sys_xsetsockopt(tcp)
2197struct tcb *tcp;
2198{
2199 return netlib_call (tcp, sys_setsockopt);
2200}
2201
2202int
2203sys_xshutdown(tcp)
2204struct tcb *tcp;
2205{
2206 return netlib_call (tcp, sys_shutdown);
2207}
2208
Dmitry V. Levine5e60852009-12-31 22:50:49 +00002209#endif /* UNIXWARE */