blob: eb8168a5fd92bf7252bf1a7bd02af22b5a49cc60 [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
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100368#if defined(SOL_SCTP)
369 { SOL_SCTP, "SOL_SCTP" },
370#endif
371#if defined(SOL_UDPLITE)
372 { SOL_UDPLITE, "SOL_UDPLITE" },
373#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000374#if defined(SOL_RAW)
375 { SOL_RAW, "SOL_RAW" },
376#endif
377#if defined(SOL_IPX)
378 { SOL_IPX, "SOL_IPX" },
379#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000380#if defined(SOL_AX25)
381 { SOL_AX25, "SOL_AX25" },
382#endif
383#if defined(SOL_ATALK)
384 { SOL_ATALK, "SOL_ATALK" },
385#endif
386#if defined(SOL_NETROM)
387 { SOL_NETROM, "SOL_NETROM" },
388#endif
389#if defined(SOL_ROSE)
390 { SOL_ROSE, "SOL_ROSE" },
391#endif
392#if defined(SOL_DECNET)
393 { SOL_DECNET, "SOL_DECNET" },
394#endif
395#if defined(SOL_X25)
396 { SOL_X25, "SOL_X25" },
397#endif
398#if defined(SOL_PACKET)
399 { SOL_PACKET, "SOL_PACKET" },
400#endif
401#if defined(SOL_ATM)
402 { SOL_ATM, "SOL_ATM" },
403#endif
404#if defined(SOL_AAL)
405 { SOL_AAL, "SOL_AAL" },
406#endif
407#if defined(SOL_IRDA)
408 { SOL_IRDA, "SOL_IRDA" },
409#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100410#if defined(SOL_NETBEUI)
411 { SOL_NETBEUI, "SOL_NETBEUI" },
412#endif
413#if defined(SOL_LLC)
414 { SOL_LLC, "SOL_LLC" },
415#endif
416#if defined(SOL_DCCP)
417 { SOL_DCCP, "SOL_DCCP" },
418#endif
419#if defined(SOL_NETLINK)
420 { SOL_NETLINK, "SOL_NETLINK" },
421#endif
422#if defined(SOL_TIPC)
423 { SOL_TIPC, "SOL_TIPC" },
424#endif
425#if defined(SOL_RXRPC)
426 { SOL_RXRPC, "SOL_RXRPC" },
427#endif
428#if defined(SOL_PPPOL2TP)
429 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
430#endif
431#if defined(SOL_BLUETOOTH)
432 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
433#endif
434#if defined(SOL_PNPIPE)
435 { SOL_PNPIPE, "SOL_PNPIPE" },
436#endif
437#if defined(SOL_RDS)
438 { SOL_RDS, "SOL_RDS" },
439#endif
440#if defined(SOL_IUVC)
441 { SOL_IUCV, "SOL_IUCV" },
442#endif
443#if defined(SOL_CAIF)
444 { SOL_CAIF, "SOL_CAIF" },
445#endif
John Hughes61563572001-03-27 16:47:36 +0000446 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000447};
John Hughes93f7fcc2002-05-22 15:46:49 +0000448/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
449 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000450static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451 { IPPROTO_IP, "IPPROTO_IP" },
452 { IPPROTO_ICMP, "IPPROTO_ICMP" },
453 { IPPROTO_TCP, "IPPROTO_TCP" },
454 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000455#ifdef IPPROTO_IGMP
456 { IPPROTO_IGMP, "IPPROTO_IGMP" },
457#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458#ifdef IPPROTO_GGP
459 { IPPROTO_GGP, "IPPROTO_GGP" },
460#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000461#ifdef IPPROTO_IPIP
462 { IPPROTO_IPIP, "IPPROTO_IPIP" },
463#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464#ifdef IPPROTO_EGP
465 { IPPROTO_EGP, "IPPROTO_EGP" },
466#endif
467#ifdef IPPROTO_PUP
468 { IPPROTO_PUP, "IPPROTO_PUP" },
469#endif
470#ifdef IPPROTO_IDP
471 { IPPROTO_IDP, "IPPROTO_IDP" },
472#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000473#ifdef IPPROTO_TP
474 { IPPROTO_TP, "IPPROTO_TP" },
475#endif
476#ifdef IPPROTO_DCCP
477 { IPPROTO_DCCP, "IPPROTO_DCCP" },
478#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479#ifdef IPPROTO_IPV6
480 { IPPROTO_IPV6, "IPPROTO_IPV6" },
481#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000482#ifdef IPPROTO_ROUTING
483 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000485#ifdef IPPROTO_FRAGMENT
486 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
487#endif
488#ifdef IPPROTO_RSVP
489 { IPPROTO_RSVP, "IPPROTO_RSVP" },
490#endif
491#ifdef IPPROTO_GRE
492 { IPPROTO_GRE, "IPPROTO_GRE" },
493#endif
494#ifdef IPPROTO_ESP
495 { IPPROTO_ESP, "IPPROTO_ESP" },
496#endif
497#ifdef IPPROTO_AH
498 { IPPROTO_AH, "IPPROTO_AH" },
499#endif
500#ifdef IPPROTO_ICMPV6
501 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
502#endif
503#ifdef IPPROTO_NONE
504 { IPPROTO_NONE, "IPPROTO_NONE" },
505#endif
506#ifdef IPPROTO_DSTOPTS
507 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508#endif
509#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000510 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511#endif
512#ifdef IPPROTO_ND
513 { IPPROTO_ND, "IPPROTO_ND" },
514#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000515#ifdef IPPROTO_MTP
516 { IPPROTO_MTP, "IPPROTO_MTP" },
517#endif
518#ifdef IPPROTO_ENCAP
519 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
520#endif
521#ifdef IPPROTO_PIM
522 { IPPROTO_PIM, "IPPROTO_PIM" },
523#endif
524#ifdef IPPROTO_COMP
525 { IPPROTO_COMP, "IPPROTO_COMP" },
526#endif
527#ifdef IPPROTO_SCTP
528 { IPPROTO_SCTP, "IPPROTO_SCTP" },
529#endif
530#ifdef IPPROTO_UDPLITE
531 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
532#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533#ifdef IPPROTO_RAW
534 { IPPROTO_RAW, "IPPROTO_RAW" },
535#endif
536#ifdef IPPROTO_MAX
537 { IPPROTO_MAX, "IPPROTO_MAX" },
538#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 { 0, NULL },
540};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000541static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000542 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000544 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545#endif
546#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000547 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548#endif
549#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000550 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551#endif
552#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000553 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554#endif
555#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000556 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557#endif
558#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000559 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000561#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000562 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000563#endif
564#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000565 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000566#endif
567#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000568 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000569#endif
570#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000571 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000572#endif
573#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000574 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000575#endif
576#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000577 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000578#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000579#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000580 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000581#endif
582#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000583 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000584#endif
585#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000586 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000587#endif
588#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000589 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000590#endif
591#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000592 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000593#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000594#ifdef MSG_CMSG_CLOEXEC
595 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
596#endif
597 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598};
599
Roland McGrathd9f816f2004-09-04 03:39:20 +0000600static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000602 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000603#endif
604#ifdef SO_ALLRAW
605 { SO_ALLRAW, "SO_ALLRAW" },
606#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000607#ifdef SO_ATTACH_FILTER
608 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
609#endif
610#ifdef SO_BINDTODEVICE
611 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
612#endif
613#ifdef SO_BROADCAST
614 { SO_BROADCAST, "SO_BROADCAST" },
615#endif
616#ifdef SO_BSDCOMPAT
617 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
618#endif
619#ifdef SO_DEBUG
620 { SO_DEBUG, "SO_DEBUG" },
621#endif
622#ifdef SO_DETACH_FILTER
623 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
624#endif
625#ifdef SO_DONTROUTE
626 { SO_DONTROUTE, "SO_DONTROUTE" },
627#endif
628#ifdef SO_ERROR
629 { SO_ERROR, "SO_ERROR" },
630#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000631#ifdef SO_ICS
632 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000634#ifdef SO_IMASOCKET
635 { SO_IMASOCKET, "SO_IMASOCKET" },
636#endif
637#ifdef SO_KEEPALIVE
638 { SO_KEEPALIVE, "SO_KEEPALIVE" },
639#endif
640#ifdef SO_LINGER
641 { SO_LINGER, "SO_LINGER" },
642#endif
643#ifdef SO_LISTENING
644 { SO_LISTENING, "SO_LISTENING" },
645#endif
646#ifdef SO_MGMT
647 { SO_MGMT, "SO_MGMT" },
648#endif
649#ifdef SO_NO_CHECK
650 { SO_NO_CHECK, "SO_NO_CHECK" },
651#endif
652#ifdef SO_OOBINLINE
653 { SO_OOBINLINE, "SO_OOBINLINE" },
654#endif
655#ifdef SO_ORDREL
656 { SO_ORDREL, "SO_ORDREL" },
657#endif
658#ifdef SO_PARALLELSVR
659 { SO_PARALLELSVR, "SO_PARALLELSVR" },
660#endif
661#ifdef SO_PASSCRED
662 { SO_PASSCRED, "SO_PASSCRED" },
663#endif
664#ifdef SO_PEERCRED
665 { SO_PEERCRED, "SO_PEERCRED" },
666#endif
667#ifdef SO_PEERNAME
668 { SO_PEERNAME, "SO_PEERNAME" },
669#endif
670#ifdef SO_PEERSEC
671 { SO_PEERSEC, "SO_PEERSEC" },
672#endif
673#ifdef SO_PRIORITY
674 { SO_PRIORITY, "SO_PRIORITY" },
675#endif
676#ifdef SO_PROTOTYPE
677 { SO_PROTOTYPE, "SO_PROTOTYPE" },
678#endif
679#ifdef SO_RCVBUF
680 { SO_RCVBUF, "SO_RCVBUF" },
681#endif
682#ifdef SO_RCVLOWAT
683 { SO_RCVLOWAT, "SO_RCVLOWAT" },
684#endif
685#ifdef SO_RCVTIMEO
686 { SO_RCVTIMEO, "SO_RCVTIMEO" },
687#endif
688#ifdef SO_RDWR
689 { SO_RDWR, "SO_RDWR" },
690#endif
691#ifdef SO_REUSEADDR
692 { SO_REUSEADDR, "SO_REUSEADDR" },
693#endif
694#ifdef SO_REUSEPORT
695 { SO_REUSEPORT, "SO_REUSEPORT" },
696#endif
697#ifdef SO_SECURITY_AUTHENTICATION
698 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
699#endif
700#ifdef SO_SECURITY_ENCRYPTION_NETWORK
701 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
702#endif
703#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
704 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
705#endif
706#ifdef SO_SEMA
707 { SO_SEMA, "SO_SEMA" },
708#endif
709#ifdef SO_SNDBUF
710 { SO_SNDBUF, "SO_SNDBUF" },
711#endif
712#ifdef SO_SNDLOWAT
713 { SO_SNDLOWAT, "SO_SNDLOWAT" },
714#endif
715#ifdef SO_SNDTIMEO
716 { SO_SNDTIMEO, "SO_SNDTIMEO" },
717#endif
718#ifdef SO_TIMESTAMP
719 { SO_TIMESTAMP, "SO_TIMESTAMP" },
720#endif
721#ifdef SO_TYPE
722 { SO_TYPE, "SO_TYPE" },
723#endif
724#ifdef SO_USELOOPBACK
725 { SO_USELOOPBACK, "SO_USELOOPBACK" },
726#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727 { 0, NULL },
728};
729
John Hughes93f7fcc2002-05-22 15:46:49 +0000730#if !defined (SOL_IP) && defined (IPPROTO_IP)
731#define SOL_IP IPPROTO_IP
732#endif
733
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000735static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000736#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000737 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000738#endif
739#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000740 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000741#endif
742#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000743 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000745#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000746 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000748#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000749 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000750#endif
751#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000752 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
753#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000754#ifdef IP_RECVOPTS
755 { IP_RECVOPTS, "IP_RECVOPTS" },
756#endif
757#ifdef IP_RECVRETOPTS
758 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
759#endif
760#ifdef IP_RECVDSTADDR
761 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
762#endif
763#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000764 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000765#endif
766#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000767 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000768#endif
769#ifdef IP_PKTOPTIONS
770 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
771#endif
772#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000773 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000774#endif
775#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000776 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000777#endif
778#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000779 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000780#endif
781#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000782 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000783#endif
784#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000785 { IP_MTU, "IP_MTU" },
786#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000787#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000788 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000789#endif
790#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000791 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000792#endif
793#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000794 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000795#endif
796#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000797 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000798#endif
799#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000800 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000801#endif
802#ifdef IP_BROADCAST_IF
803 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
804#endif
805#ifdef IP_RECVIFINDEX
806 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
807#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000808#ifdef IP_MSFILTER
809 { IP_MSFILTER, "IP_MSFILTER" },
810#endif
811#ifdef MCAST_MSFILTER
812 { MCAST_MSFILTER, "MCAST_MSFILTER" },
813#endif
814#ifdef IP_FREEBIND
815 { IP_FREEBIND, "IP_FREEBIND" },
816#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000817 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818};
819#endif /* SOL_IP */
820
Roland McGrath4f6ba692004-08-31 07:01:26 +0000821#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000822static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000823#ifdef IPV6_ADDRFORM
824 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
825#endif
826#ifdef MCAST_FILTER
827 { MCAST_FILTER, "MCAST_FILTER" },
828#endif
829#ifdef IPV6_PKTOPTIONS
830 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
831#endif
832#ifdef IPV6_MTU
833 { IPV6_MTU, "IPV6_MTU" },
834#endif
835#ifdef IPV6_V6ONLY
836 { IPV6_V6ONLY, "IPV6_V6ONLY" },
837#endif
838#ifdef IPV6_PKTINFO
839 { IPV6_PKTINFO, "IPV6_PKTINFO" },
840#endif
841#ifdef IPV6_HOPLIMIT
842 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
843#endif
844#ifdef IPV6_RTHDR
845 { IPV6_RTHDR, "IPV6_RTHDR" },
846#endif
847#ifdef IPV6_HOPOPTS
848 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
849#endif
850#ifdef IPV6_DSTOPTS
851 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
852#endif
853#ifdef IPV6_FLOWINFO
854 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
855#endif
856#ifdef IPV6_UNICAST_HOPS
857 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
858#endif
859#ifdef IPV6_MULTICAST_HOPS
860 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
861#endif
862#ifdef IPV6_MULTICAST_LOOP
863 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
864#endif
865#ifdef IPV6_MULTICAST_IF
866 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
867#endif
868#ifdef IPV6_MTU_DISCOVER
869 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
870#endif
871#ifdef IPV6_RECVERR
872 { IPV6_RECVERR, "IPV6_RECVERR" },
873#endif
874#ifdef IPV6_FLOWINFO_SEND
875 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
876#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000877#ifdef IPV6_ADD_MEMBERSHIP
878 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
879#endif
880#ifdef IPV6_DROP_MEMBERSHIP
881 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
882#endif
883#ifdef IPV6_ROUTER_ALERT
884 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
885#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000886 { 0, NULL },
887};
888#endif /* SOL_IPV6 */
889
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000891static const struct xlat sockipxoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000892 { IPX_TYPE, "IPX_TYPE" },
893 { 0, NULL },
894};
895#endif /* SOL_IPX */
896
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000897#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000898static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000899#if defined(ICMP_FILTER)
900 { ICMP_FILTER, "ICMP_FILTER" },
901#endif
902 { 0, NULL },
903};
904#endif /* SOL_RAW */
905
906#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000907static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000908#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000909 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000910#endif
911#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000912 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000913#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000914#if defined(PACKET_RECV_OUTPUT)
915 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
916#endif
917#if defined(PACKET_RX_RING)
918 { PACKET_RX_RING, "PACKET_RX_RING" },
919#endif
920#if defined(PACKET_STATISTICS)
921 { PACKET_STATISTICS, "PACKET_STATISTICS" },
922#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000923#if defined(PACKET_COPY_THRESH)
924 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
925#endif
926#if defined(PACKET_AUXDATA)
927 { PACKET_AUXDATA, "PACKET_AUXDATA" },
928#endif
929#if defined(PACKET_ORIGDEV)
930 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
931#endif
932#if defined(PACKET_VERSION)
933 { PACKET_VERSION, "PACKET_VERSION" },
934#endif
935#if defined(PACKET_HDRLEN)
936 { PACKET_HDRLEN, "PACKET_HDRLEN" },
937#endif
938#if defined(PACKET_RESERVE)
939 { PACKET_RESERVE, "PACKET_RESERVE" },
940#endif
941#if defined(PACKET_TX_RING)
942 { PACKET_TX_RING, "PACKET_TX_RING" },
943#endif
944#if defined(PACKET_LOSS)
945 { PACKET_LOSS, "PACKET_LOSS" },
946#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000947 { 0, NULL },
948};
949#endif /* SOL_PACKET */
950
John Hughes93f7fcc2002-05-22 15:46:49 +0000951#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
952#define SOL_TCP IPPROTO_TCP
953#endif
954
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000956static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000957 { TCP_NODELAY, "TCP_NODELAY" },
958 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000959#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000960 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000961#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000962#if defined(TCP_KEEPIDLE)
963 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
964#endif
965#if defined(TCP_KEEPINTVL)
966 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
967#endif
968#if defined(TCP_KEEPCNT)
969 { TCP_KEEPCNT, "TCP_KEEPCNT" },
970#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000971#if defined(TCP_NKEEP)
972 { TCP_NKEEP, "TCP_NKEEP" },
973#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000974#if defined(TCP_SYNCNT)
975 { TCP_SYNCNT, "TCP_SYNCNT" },
976#endif
977#if defined(TCP_LINGER2)
978 { TCP_LINGER2, "TCP_LINGER2" },
979#endif
980#if defined(TCP_DEFER_ACCEPT)
981 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
982#endif
983#if defined(TCP_WINDOW_CLAMP)
984 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
985#endif
986#if defined(TCP_INFO)
987 { TCP_INFO, "TCP_INFO" },
988#endif
989#if defined(TCP_QUICKACK)
990 { TCP_QUICKACK, "TCP_QUICKACK" },
991#endif
992 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993};
994#endif /* SOL_TCP */
995
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000996#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000997static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000998#if defined(ICMP_ECHOREPLY)
999 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1000#endif
1001#if defined(ICMP_DEST_UNREACH)
1002 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1003#endif
1004#if defined(ICMP_SOURCE_QUENCH)
1005 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1006#endif
1007#if defined(ICMP_REDIRECT)
1008 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1009#endif
1010#if defined(ICMP_ECHO)
1011 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1012#endif
1013#if defined(ICMP_TIME_EXCEEDED)
1014 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1015#endif
1016#if defined(ICMP_PARAMETERPROB)
1017 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1018#endif
1019#if defined(ICMP_TIMESTAMP)
1020 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1021#endif
1022#if defined(ICMP_TIMESTAMPREPLY)
1023 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1024#endif
1025#if defined(ICMP_INFO_REQUEST)
1026 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1027#endif
1028#if defined(ICMP_INFO_REPLY)
1029 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1030#endif
1031#if defined(ICMP_ADDRESS)
1032 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1033#endif
1034#if defined(ICMP_ADDRESSREPLY)
1035 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1036#endif
1037 { 0, NULL },
1038};
1039#endif /* SOL_RAW */
1040
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001041#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001042static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001043#if defined(PACKET_HOST)
1044 { PACKET_HOST, "PACKET_HOST" },
1045#endif
1046#if defined(PACKET_BROADCAST)
1047 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1048#endif
1049#if defined(PACKET_MULTICAST)
1050 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1051#endif
1052#if defined(PACKET_OTHERHOST)
1053 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1054#endif
1055#if defined(PACKET_OUTGOING)
1056 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1057#endif
1058#if defined(PACKET_LOOPBACK)
1059 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1060#endif
1061#if defined(PACKET_FASTROUTE)
1062 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1063#endif
1064 { 0, NULL },
1065};
1066#endif /* defined(AF_PACKET) */
1067
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001068
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001070printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001072 union {
1073 char pad[128];
1074 struct sockaddr sa;
1075 struct sockaddr_in sin;
1076 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001077#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001078 struct sockaddr_in6 sa6;
1079#endif
1080#if defined(LINUX) && defined(AF_IPX)
1081 struct sockaddr_ipx sipx;
1082#endif
1083#ifdef AF_PACKET
1084 struct sockaddr_ll ll;
1085#endif
1086#ifdef AF_NETLINK
1087 struct sockaddr_nl nl;
1088#endif
1089 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001090 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091
1092 if (addr == 0) {
1093 tprintf("NULL");
1094 return;
1095 }
1096 if (!verbose(tcp)) {
1097 tprintf("%#lx", addr);
1098 return;
1099 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001100
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001101 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1102 addrlen = sizeof(addrbuf);
1103
1104 memset(&addrbuf, 0, sizeof(addrbuf));
1105 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001106 tprintf("{...}");
1107 return;
1108 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001109 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001110
John Hughes1fcb1d62001-09-18 15:56:53 +00001111 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001112 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1113 tprintf(", ");
1114
1115 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001117 if (addrlen == 2) {
1118 tprintf("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001119 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001120 tprintf("path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001121 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001122 } else {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001123 tprintf("path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001124 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001125 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 break;
1127 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001128 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001129 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001131#ifdef HAVE_INET_NTOP
1132 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001133 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001134 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1135 ntohs(addrbuf.sa6.sin6_port), string_addr,
1136 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001137#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001138 {
1139#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1140 int numericscope = 0;
1141 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1142 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1143 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001144
Wichert Akkermanf1850652001-02-16 20:29:03 +00001145 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1146 numericscope++;
1147 else
1148 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1149 } else
1150 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001151
Wichert Akkermanf1850652001-02-16 20:29:03 +00001152 if (numericscope)
1153#endif
1154 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1155 }
1156#endif
1157 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001158#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001159#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001160 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001161 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001163 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001164 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 /* Yes, I know, this does not look too
1166 * strace-ish, but otherwise the IPX
1167 * addresses just look monstrous...
1168 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001169 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001170 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001171 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001172 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001173 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1174 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001175 }
1176 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001177#endif /* AF_IPX && linux */
1178#ifdef AF_PACKET
1179 case AF_PACKET:
1180 {
1181 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001182 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001183 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001184 addrbuf.ll.sll_ifindex);
1185 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1186 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001187 addrbuf.ll.sll_halen,
1188 addrbuf.ll.sll_hatype);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001189 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001190 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1191 }
1192 break;
1193
1194#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001195#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001196 case AF_NETLINK:
1197 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1198 break;
1199#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001200 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001201 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202
1203 default:
John Hughes1fcb1d62001-09-18 15:56:53 +00001204 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001206 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001207 break;
1208 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001209 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001210}
1211
1212#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001213static const struct xlat scmvals[] = {
1214#ifdef SCM_RIGHTS
1215 { SCM_RIGHTS, "SCM_RIGHTS" },
1216#endif
1217#ifdef SCM_CREDENTIALS
1218 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1219#endif
1220 { 0, NULL }
1221};
1222
1223static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001224printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001225{
Roland McGrathaa524c82005-06-01 19:22:06 +00001226 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1227 NULL : malloc(len);
1228 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001229 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001230 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001231 return;
1232 }
1233
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001234 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001235 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Roland McGrath50770822004-10-06 22:11:51 +00001236 tprintf(", cmsg_type=");
1237
Roland McGrathaa524c82005-06-01 19:22:06 +00001238 if (cmsg->cmsg_level == SOL_SOCKET) {
1239 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001240
Roland McGrathaa524c82005-06-01 19:22:06 +00001241 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1242 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1243
1244 if (cmsg->cmsg_type == SCM_RIGHTS
1245 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1246 int *fds = (int *) CMSG_DATA (cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001247 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001248
Roland McGrath50770822004-10-06 22:11:51 +00001249 tprintf(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001250 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001251 if (!first)
1252 tprintf(", ");
1253 tprintf("%d", *fds++);
1254 first = 0;
1255 }
1256 tprintf("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001257 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001258 return;
1259 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001260 if (cmsg->cmsg_type == SCM_CREDENTIALS
1261 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1262 struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1263
Roland McGrath50770822004-10-06 22:11:51 +00001264 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1265 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001266 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001267 return;
1268 }
1269 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001270 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001271 tprintf(", ...}");
1272}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273
1274static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001275do_msghdr(struct tcb *tcp, struct msghdr *msg)
1276{
1277 tprintf("{msg_name(%d)=", msg->msg_namelen);
1278 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1279
1280 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1281 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
1282 (unsigned long)msg->msg_iov);
1283
1284#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1285 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1286 if (msg->msg_controllen)
1287 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1288 msg->msg_controllen);
1289 tprintf(", msg_flags=");
1290 printflags(msg_flags, msg->msg_flags, "MSG_???");
1291#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1292 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1293 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1294#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1295 tprintf("}");
1296}
1297
1298static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299printmsghdr(tcp, addr)
1300struct tcb *tcp;
1301long addr;
1302{
1303 struct msghdr msg;
1304
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001305 if (umove(tcp, addr, &msg) < 0) {
1306 tprintf("%#lx", addr);
1307 return;
1308 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001309 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310}
1311
Andreas Schwab0873f292010-02-12 21:39:12 +01001312#ifdef LINUX
1313static void
1314printmmsghdr(struct tcb *tcp, long addr)
1315{
1316 struct mmsghdr {
1317 struct msghdr msg_hdr;
1318 unsigned msg_len;
1319 } mmsg;
1320
1321 if (umove(tcp, addr, &mmsg) < 0) {
1322 tprintf("%#lx", addr);
1323 return;
1324 }
1325 tprintf("{");
1326 do_msghdr(tcp, &mmsg.msg_hdr);
1327 tprintf(", %u}", mmsg.msg_len);
1328}
1329#endif
1330
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331#endif /* HAVE_SENDMSG */
1332
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001333/*
1334 * low bits of the socket type define real socket type,
1335 * other bits are socket type flags.
1336 */
1337static void
1338tprint_sock_type(struct tcb *tcp, int flags)
1339{
1340 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1341
1342 if (str)
1343 {
1344 tprintf("%s", str);
1345 flags &= ~SOCK_TYPE_MASK;
1346 if (!flags)
1347 return;
1348 tprintf("|");
1349 }
1350 printflags(sock_type_flags, flags, "SOCK_???");
1351}
1352
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001354sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355{
1356 if (entering(tcp)) {
1357 printxval(domains, tcp->u_arg[0], "PF_???");
1358 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001359 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360 tprintf(", ");
1361 switch (tcp->u_arg[0]) {
1362 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001363#ifdef PF_INET6
1364 case PF_INET6:
1365#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1367 break;
1368#ifdef PF_IPX
1369 case PF_IPX:
1370 /* BTW: I don't believe this.. */
1371 tprintf("[");
1372 printxval(domains, tcp->u_arg[2], "PF_???");
1373 tprintf("]");
1374 break;
1375#endif /* PF_IPX */
1376 default:
1377 tprintf("%lu", tcp->u_arg[2]);
1378 break;
1379 }
1380 }
1381 return 0;
1382}
1383
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001384#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385int
John Hughesbdf48f52001-03-06 15:08:09 +00001386sys_so_socket(tcp)
1387struct tcb *tcp;
1388{
1389 if (entering(tcp)) {
1390 /* not sure really what these args are... but this
1391 * is how truss prints it
1392 */
1393 tprintf("%ld, %ld, %ld, ",
1394 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1395 printpath(tcp, tcp->u_arg[3]);
1396 tprintf(", %ld", tcp->u_arg[4]);
1397 }
1398 return 0;
1399}
1400
1401int
1402sys_so_socketpair(tcp)
1403struct tcb *tcp;
1404{
1405 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001406 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001407 tprintf("0x%lx", tcp->u_arg[0]);
1408 }
1409 return 0;
1410}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001411#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001412
1413int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414sys_bind(tcp)
1415struct tcb *tcp;
1416{
1417 if (entering(tcp)) {
1418 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001419 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 tprintf(", %lu", tcp->u_arg[2]);
1421 }
1422 return 0;
1423}
1424
1425int
1426sys_connect(tcp)
1427struct tcb *tcp;
1428{
1429 return sys_bind(tcp);
1430}
1431
1432int
1433sys_listen(tcp)
1434struct tcb *tcp;
1435{
1436 if (entering(tcp)) {
1437 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1438 }
1439 return 0;
1440}
1441
Paolo Bonzini705ff102009-08-14 12:34:05 +02001442static int
1443do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444{
1445 if (entering(tcp)) {
1446 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001447 return 0;
1448 }
1449 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450 tprintf("%#lx, NULL", tcp->u_arg[1]);
1451 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001452 int len;
1453 if (tcp->u_arg[1] == 0 || syserror(tcp)
1454 || umove (tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455 tprintf("%#lx", tcp->u_arg[1]);
1456 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001457 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 }
1459 tprintf(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001460 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001462 if (flags_arg >= 0) {
1463 tprintf(", ");
1464 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1465 "SOCK_???");
1466 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 return 0;
1468}
1469
1470int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001471sys_accept(struct tcb *tcp)
1472{
1473 return do_accept(tcp, -1);
1474}
1475
1476#ifdef LINUX
1477int
1478sys_accept4(struct tcb *tcp)
1479{
1480 return do_accept(tcp, 3);
1481}
1482#endif
1483
1484int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001485sys_send(tcp)
1486struct tcb *tcp;
1487{
1488 if (entering(tcp)) {
1489 tprintf("%ld, ", tcp->u_arg[0]);
1490 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1491 tprintf(", %lu, ", tcp->u_arg[2]);
1492 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001493 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494 }
1495 return 0;
1496}
1497
1498int
1499sys_sendto(tcp)
1500struct tcb *tcp;
1501{
1502 if (entering(tcp)) {
1503 tprintf("%ld, ", tcp->u_arg[0]);
1504 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1505 tprintf(", %lu, ", tcp->u_arg[2]);
1506 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001507 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508 /* to address */
1509 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001510 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511 /* to length */
1512 tprintf(", %lu", tcp->u_arg[5]);
1513 }
1514 return 0;
1515}
1516
1517#ifdef HAVE_SENDMSG
1518
1519int
1520sys_sendmsg(tcp)
1521struct tcb *tcp;
1522{
1523 if (entering(tcp)) {
1524 tprintf("%ld, ", tcp->u_arg[0]);
1525 printmsghdr(tcp, tcp->u_arg[1]);
1526 /* flags */
1527 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001528 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529 }
1530 return 0;
1531}
1532
1533#endif /* HAVE_SENDMSG */
1534
1535int
1536sys_recv(tcp)
1537struct tcb *tcp;
1538{
1539 if (entering(tcp)) {
1540 tprintf("%ld, ", tcp->u_arg[0]);
1541 } else {
1542 if (syserror(tcp))
1543 tprintf("%#lx", tcp->u_arg[1]);
1544 else
1545 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1546
1547 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001548 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001549 }
1550 return 0;
1551}
1552
1553int
1554sys_recvfrom(tcp)
1555struct tcb *tcp;
1556{
1557 int fromlen;
1558
1559 if (entering(tcp)) {
1560 tprintf("%ld, ", tcp->u_arg[0]);
1561 } else {
1562 if (syserror(tcp)) {
1563 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1564 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1565 tcp->u_arg[4], tcp->u_arg[5]);
1566 return 0;
1567 }
1568 /* buf */
1569 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1570 /* len */
1571 tprintf(", %lu, ", tcp->u_arg[2]);
1572 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001573 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574 /* from address, len */
1575 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1576 if (tcp->u_arg[4] == 0)
1577 tprintf(", NULL");
1578 else
1579 tprintf(", %#lx", tcp->u_arg[4]);
1580 if (tcp->u_arg[5] == 0)
1581 tprintf(", NULL");
1582 else
1583 tprintf(", %#lx", tcp->u_arg[5]);
1584 return 0;
1585 }
1586 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1587 tprintf(", {...}, [?]");
1588 return 0;
1589 }
1590 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001591 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 /* from length */
1593 tprintf(", [%u]", fromlen);
1594 }
1595 return 0;
1596}
1597
1598#ifdef HAVE_SENDMSG
1599
1600int
1601sys_recvmsg(tcp)
1602struct tcb *tcp;
1603{
1604 if (entering(tcp)) {
1605 tprintf("%ld, ", tcp->u_arg[0]);
1606 } else {
1607 if (syserror(tcp) || !verbose(tcp))
1608 tprintf("%#lx", tcp->u_arg[1]);
1609 else
1610 printmsghdr(tcp, tcp->u_arg[1]);
1611 /* flags */
1612 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001613 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 }
1615 return 0;
1616}
1617
Andreas Schwab0873f292010-02-12 21:39:12 +01001618#ifdef LINUX
1619int
1620sys_recvmmsg(struct tcb *tcp)
1621{
Dmitry V. Levine6591032010-03-29 20:45:48 +04001622 static char str[128];
Andreas Schwab0873f292010-02-12 21:39:12 +01001623 if (entering(tcp)) {
Dmitry V. Levine6591032010-03-29 20:45:48 +04001624
Andreas Schwab0873f292010-02-12 21:39:12 +01001625 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001626 if (verbose(tcp)) {
1627 sprint_timespec(str, tcp, tcp->u_arg[4]);
1628 tcp->auxstr = strdup(str);
1629 } else {
1630 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1631 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1632 tprintf(", ");
1633 print_timespec(tcp, tcp->u_arg[4]);
1634 }
1635 return 0;
1636 } else {
1637 if (verbose(tcp)) {
1638 if (syserror(tcp))
1639 tprintf("%#lx", tcp->u_arg[1]);
1640 else
1641 printmmsghdr(tcp, tcp->u_arg[1]);
1642 tprintf(", %ld, ", tcp->u_arg[2]);
1643 /* flags */
1644 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1645 /* timeout on entrance */
1646 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1647 free((void *) tcp->auxstr);
1648 tcp->auxstr = NULL;
1649 }
1650 if (syserror(tcp))
1651 return 0;
1652 if (tcp->u_rval == 0) {
1653 tcp->auxstr = "Timeout";
1654 return RVAL_STR;
1655 }
1656 if (!verbose(tcp))
1657 return 0;
1658 /* timeout on exit */
1659 strcpy(str, "left ");
1660 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1661 tcp->auxstr = str;
1662 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001663 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001664}
1665#endif
1666
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667#endif /* HAVE_SENDMSG */
1668
1669int
1670sys_shutdown(tcp)
1671struct tcb *tcp;
1672{
1673 if (entering(tcp)) {
1674 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1675 switch (tcp->u_arg[1]) {
1676 case 0:
1677 tprintf("%s", " /* receive */");
1678 break;
1679 case 1:
1680 tprintf("%s", " /* send */");
1681 break;
1682 case 2:
1683 tprintf("%s", " /* send and receive */");
1684 break;
1685 }
1686 }
1687 return 0;
1688}
1689
1690int
1691sys_getsockname(tcp)
1692struct tcb *tcp;
1693{
1694 return sys_accept(tcp);
1695}
1696
1697int
1698sys_getpeername(tcp)
1699struct tcb *tcp;
1700{
1701 return sys_accept(tcp);
1702}
1703
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001704static int
1705do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001707 if (exiting(tcp)) {
1708 if (syserror(tcp)) {
1709 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001710 } else {
1711#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1712 int fds[2];
1713
1714 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1715 tprintf("[...]");
1716 else
1717 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001718#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001719 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1720#else
1721 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001722#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001723 }
1724 if (flags_arg >= 0) {
1725 tprintf(", ");
1726 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1727 }
1728 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729 return 0;
1730}
1731
1732int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001733sys_pipe(struct tcb *tcp)
1734{
1735 return do_pipe(tcp, -1);
1736}
1737
1738#ifdef LINUX
1739int
1740sys_pipe2(struct tcb *tcp)
1741{
1742 return do_pipe(tcp, 1);
1743}
1744#endif
1745
1746int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001747sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748{
1749#ifdef LINUX
1750 int fds[2];
1751#endif
1752
1753 if (entering(tcp)) {
1754 printxval(domains, tcp->u_arg[0], "PF_???");
1755 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001756 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001757 tprintf(", ");
1758 switch (tcp->u_arg[0]) {
1759 case PF_INET:
1760 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1761 break;
1762#ifdef PF_IPX
1763 case PF_IPX:
1764 /* BTW: I don't believe this.. */
1765 tprintf("[");
1766 printxval(domains, tcp->u_arg[2], "PF_???");
1767 tprintf("]");
1768 break;
1769#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001770 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001771 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772 break;
1773 }
1774 } else {
1775 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001776 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 return 0;
1778 }
1779#ifdef LINUX
1780 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001781 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782 else
1783 tprintf(", [%u, %u]", fds[0], fds[1]);
1784#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001785#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001787#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788 }
1789 return 0;
1790}
1791
1792int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001793sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794{
1795 if (entering(tcp)) {
1796 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001797 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1798 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799 switch (tcp->u_arg[1]) {
1800 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802 break;
1803#ifdef SOL_IP
1804 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806 break;
1807#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001808#ifdef SOL_IPV6
1809 case SOL_IPV6:
1810 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1811 break;
1812#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001813#ifdef SOL_IPX
1814 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816 break;
1817#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001818#ifdef SOL_PACKET
1819 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001820 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001821 break;
1822#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823#ifdef SOL_TCP
1824 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826 break;
1827#endif
1828
1829 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1830 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001831 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001832 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 break;
1834 }
Dmitry V. Levin31289192009-11-06 18:05:40 +00001835 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001837 int len;
John Hughes93f7fcc2002-05-22 15:46:49 +00001838 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001839 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840 tcp->u_arg[3], tcp->u_arg[4]);
1841 return 0;
1842 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001843
1844 switch (tcp->u_arg[1]) {
1845 case SOL_SOCKET:
1846 switch (tcp->u_arg[2]) {
1847#ifdef SO_LINGER
1848 case SO_LINGER:
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001849 if (len == sizeof (struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001850 struct linger linger;
1851 if (umove (tcp,
1852 tcp->u_arg[3],
1853 &linger) < 0)
1854 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001855 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001856 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001857 linger.l_onoff,
1858 linger.l_linger,
1859 len);
1860 return 0;
1861 }
1862 break;
1863#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001864#ifdef SO_PEERCRED
1865 case SO_PEERCRED:
1866 if (len == sizeof (struct ucred)) {
1867 struct ucred uc;
1868 if (umove (tcp,
1869 tcp->u_arg[3],
1870 &uc) < 0)
1871 break;
1872 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1873 "[%d]",
1874 (long)uc.pid,
1875 (long)uc.uid,
1876 (long)uc.gid,
1877 len);
1878 return 0;
1879 }
1880 break;
1881#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001882 }
1883 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001884 case SOL_PACKET:
1885 switch (tcp->u_arg[2]) {
1886#ifdef PACKET_STATISTICS
1887 case PACKET_STATISTICS:
1888 if (len == sizeof(struct tpacket_stats)) {
1889 struct tpacket_stats stats;
1890 if (umove (tcp,
1891 tcp->u_arg[3],
1892 &stats) < 0)
1893 break;
1894 tprintf("{packets=%u, drops=%u}, "
1895 "[%d]",
1896 stats.tp_packets,
1897 stats.tp_drops,
1898 len);
1899 return 0;
1900 }
1901 break;
1902#endif
1903 }
1904 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001905 }
1906
John Hughes93f7fcc2002-05-22 15:46:49 +00001907 if (len == sizeof (int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001908 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001909 }
1910 else {
1911 printstr (tcp, tcp->u_arg[3], len);
1912 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001913 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 }
1915 return 0;
1916}
1917
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001918#if defined(ICMP_FILTER)
1919static void printicmpfilter(tcp, addr)
1920struct tcb *tcp;
1921long addr;
1922{
1923 struct icmp_filter filter;
1924
1925 if (!addr) {
1926 tprintf("NULL");
1927 return;
1928 }
1929 if (syserror(tcp) || !verbose(tcp)) {
1930 tprintf("%#lx", addr);
1931 return;
1932 }
1933 if (umove(tcp, addr, &filter) < 0) {
1934 tprintf("{...}");
1935 return;
1936 }
1937
1938 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001939 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001940 tprintf(")");
1941}
1942#endif /* ICMP_FILTER */
1943
John Hughes38ae88d2002-05-23 11:48:58 +00001944static int
1945printsockopt (tcp, level, name, addr, len)
1946struct tcb *tcp;
1947int level;
1948int name;
1949long addr;
1950int len;
1951{
1952 printxval(socketlayers, level, "SOL_??");
1953 tprintf (", ");
1954 switch (level) {
1955 case SOL_SOCKET:
1956 printxval(sockoptions, name, "SO_???");
1957 switch (name) {
1958#if defined(SO_LINGER)
1959 case SO_LINGER:
1960 if (len == sizeof (struct linger)) {
1961 struct linger linger;
1962 if (umove (tcp, addr, &linger) < 0)
1963 break;
1964 tprintf(", {onoff=%d, linger=%d}",
1965 linger.l_onoff,
1966 linger.l_linger);
1967 return 0;
1968 }
1969 break;
1970#endif
1971 }
1972 break;
1973#ifdef SOL_IP
1974 case SOL_IP:
1975 printxval(sockipoptions, name, "IP_???");
1976 break;
1977#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001978#ifdef SOL_IPV6
1979 case SOL_IPV6:
1980 printxval(sockipv6options, name, "IPV6_???");
1981 break;
1982#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001983#ifdef SOL_IPX
1984 case SOL_IPX:
1985 printxval(sockipxoptions, name, "IPX_???");
1986 break;
1987#endif
1988#ifdef SOL_PACKET
1989 case SOL_PACKET:
1990 printxval(sockpacketoptions, name, "PACKET_???");
1991 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001992 switch (name) {
1993#ifdef PACKET_RX_RING
1994 case PACKET_RX_RING:
1995#endif
1996#ifdef PACKET_TX_RING
1997 case PACKET_TX_RING:
1998#endif
1999#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2000 if (len == sizeof(struct tpacket_req)) {
2001 struct tpacket_req req;
2002 if (umove(tcp, addr, &req) < 0)
2003 break;
2004 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2005 req.tp_block_size,
2006 req.tp_block_nr,
2007 req.tp_frame_size,
2008 req.tp_frame_nr);
2009 return 0;
2010 }
2011 break;
2012#endif /* PACKET_RX_RING || PACKET_TX_RING */
2013 }
John Hughes38ae88d2002-05-23 11:48:58 +00002014 break;
2015#endif
2016#ifdef SOL_TCP
2017 case SOL_TCP:
2018 printxval(socktcpoptions, name, "TCP_???");
2019 break;
2020#endif
2021#ifdef SOL_RAW
2022 case SOL_RAW:
2023 printxval(sockrawoptions, name, "RAW_???");
2024 switch (name) {
2025#if defined(ICMP_FILTER)
2026 case ICMP_FILTER:
2027 tprintf(", ");
2028 printicmpfilter(tcp, addr);
2029 return 0;
2030#endif
2031 }
2032 break;
2033#endif
2034
Roland McGrath6d2b3492002-12-30 00:51:30 +00002035 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002036 * etc. still need work */
2037
2038 default:
2039 tprintf("%u", name);
2040 }
2041
2042 /* default arg printing */
2043
2044 tprintf (", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002045
John Hughes38ae88d2002-05-23 11:48:58 +00002046 if (len == sizeof (int)) {
Roland McGrath9814a942005-07-04 23:28:10 +00002047 printnum_int (tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002048 }
2049 else {
2050 printstr (tcp, addr, len);
2051 }
2052 return 0;
2053}
2054
2055
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002056#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002057
2058void
2059print_sock_optmgmt (tcp, addr, len)
2060struct tcb *tcp;
2061long addr;
2062int len;
2063{
2064 int c = 0;
2065 struct opthdr hdr;
2066
John Hughes2c4e3a82002-05-24 10:19:44 +00002067 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002068 if (umove(tcp, addr, &hdr) < 0) break;
2069 if (c++) {
2070 tprintf (", ");
2071 }
2072 else if (len > hdr.len + sizeof hdr) {
2073 tprintf ("[");
2074 }
2075 tprintf ("{");
2076 addr += sizeof hdr;
2077 len -= sizeof hdr;
2078 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002079 if (hdr.len > 0) {
2080 addr += hdr.len;
2081 len -= hdr.len;
2082 }
John Hughes38ae88d2002-05-23 11:48:58 +00002083 tprintf ("}");
2084 }
2085 if (len > 0) {
2086 if (c++) tprintf (", ");
2087 printstr (tcp, addr, len);
2088 }
2089 if (c > 1) tprintf ("]");
2090}
2091
2092#endif
2093
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094int
2095sys_setsockopt(tcp)
2096struct tcb *tcp;
2097{
2098 if (entering(tcp)) {
2099 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes38ae88d2002-05-23 11:48:58 +00002100 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
2101 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002102 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103 }
2104 return 0;
2105}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002106
2107#if UNIXWARE >= 7
2108
Roland McGrathd9f816f2004-09-04 03:39:20 +00002109static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002110 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2111 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2112 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2113 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2114 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2115 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
2116 { 0, NULL },
2117};
2118
2119
2120int
2121netlib_call(tcp, func)
2122struct tcb *tcp;
2123int (*func) ();
2124{
2125 if (entering(tcp)) {
2126 int i;
2127 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2128 tprintf(", ");
2129 --tcp->u_nargs;
2130 for (i = 0; i < tcp->u_nargs; i++)
2131 tcp->u_arg[i] = tcp->u_arg[i + 1];
2132 return func (tcp);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002133
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002134 }
2135
2136 return func (tcp);
2137}
2138
2139int
2140sys_xsocket(tcp)
2141struct tcb *tcp;
2142{
2143 return netlib_call (tcp, sys_socket);
2144}
2145
2146int
2147sys_xsocketpair(tcp)
2148struct tcb *tcp;
2149{
2150 return netlib_call (tcp, sys_socketpair);
2151}
2152
2153int
2154sys_xbind(tcp)
2155struct tcb *tcp;
2156{
2157 return netlib_call (tcp, sys_bind);
2158}
2159
2160int
2161sys_xconnect(tcp)
2162struct tcb *tcp;
2163{
2164 return netlib_call (tcp, sys_connect);
2165}
2166
2167int
2168sys_xlisten(tcp)
2169struct tcb *tcp;
2170{
2171 return netlib_call (tcp, sys_listen);
2172}
2173
2174int
2175sys_xaccept(tcp)
2176struct tcb *tcp;
2177{
2178 return netlib_call (tcp, sys_accept);
2179}
2180
2181int
2182sys_xsendmsg(tcp)
2183struct tcb *tcp;
2184{
2185 return netlib_call (tcp, sys_sendmsg);
2186}
2187
2188int
2189sys_xrecvmsg(tcp)
2190struct tcb *tcp;
2191{
2192 return netlib_call (tcp, sys_recvmsg);
2193}
2194
2195int
2196sys_xgetsockaddr(tcp)
2197struct tcb *tcp;
2198{
2199 if (entering(tcp)) {
2200 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2201 tprintf(", ");
2202 if (tcp->u_arg[1] == 0) {
2203 tprintf ("LOCALNAME, ");
2204 }
2205 else if (tcp->u_arg[1] == 1) {
2206 tprintf ("REMOTENAME, ");
2207 }
2208 else {
2209 tprintf ("%ld, ", tcp->u_arg [1]);
2210 }
2211 tprintf ("%ld, ", tcp->u_arg [2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002212 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002213 else {
2214 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2215 tprintf("%#lx", tcp->u_arg[3]);
2216 } else {
2217 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2218 }
2219 tprintf(", ");
2220 printnum(tcp, tcp->u_arg[4], "%lu");
2221 }
2222
2223 return 0;
2224
2225}
2226
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002227int
2228sys_xgetsockopt(tcp)
2229struct tcb *tcp;
2230{
2231 return netlib_call (tcp, sys_getsockopt);
2232}
2233
2234int
2235sys_xsetsockopt(tcp)
2236struct tcb *tcp;
2237{
2238 return netlib_call (tcp, sys_setsockopt);
2239}
2240
2241int
2242sys_xshutdown(tcp)
2243struct tcb *tcp;
2244{
2245 return netlib_call (tcp, sys_shutdown);
2246}
2247
Dmitry V. Levine5e60852009-12-31 22:50:49 +00002248#endif /* UNIXWARE */