blob: 51a599762b3a1ca43b95c812e84079f6691db7cc [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/stat.h>
36#include <sys/socket.h>
37#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000038
39#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40#define in6_addr in6_addr_libc
41#define ipv6_mreq ipv6_mreq_libc
42#define sockaddr_in6 sockaddr_in6_libc
43#endif
44
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000047#include <netinet/tcp.h>
48#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000049#ifdef HAVE_NETINET_UDP_H
50#include <netinet/udp.h>
51#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010052#ifdef HAVE_NETINET_SCTP_H
53#include <netinet/sctp.h>
54#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000056#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#if defined(LINUX)
58#include <asm/types.h>
59#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
60# include <netipx/ipx.h>
61#else
62# include <linux/ipx.h>
63#endif
64#endif /* LINUX */
65
Wichert Akkermanf1850652001-02-16 20:29:03 +000066#if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000067#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000068#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
69#undef in6_addr
70#undef ipv6_mreq
71#undef sockaddr_in6
72#define in6_addr in6_addr_kernel
73#define ipv6_mreq ipv6_mreq_kernel
74#define sockaddr_in6 sockaddr_in6_kernel
75#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000076#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000077#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
78#undef in6_addr
79#undef ipv6_mreq
80#undef sockaddr_in6
81#define in6_addr in6_addr_libc
82#define ipv6_mreq ipv6_mreq_libc
83#define sockaddr_in6 sockaddr_in6_kernel
84#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000085#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000086#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000087
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000088#if defined(HAVE_SYS_UIO_H)
89#include <sys/uio.h>
90#endif
91
92#if defined(HAVE_LINUX_NETLINK_H)
93#include <linux/netlink.h>
94#endif
95
96#if defined(HAVE_LINUX_IF_PACKET_H)
97#include <linux/if_packet.h>
98#endif
99
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000100#if defined(HAVE_LINUX_ICMP_H)
101#include <linux/icmp.h>
102#endif
103
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104#ifndef PF_UNSPEC
105#define PF_UNSPEC AF_UNSPEC
106#endif
107
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000108#if UNIXWARE >= 7
109#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
110#endif
111
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#ifdef LINUX
113/* Under Linux these are enums so we can't test for them with ifdef. */
114#define IPPROTO_EGP IPPROTO_EGP
115#define IPPROTO_PUP IPPROTO_PUP
116#define IPPROTO_IDP IPPROTO_IDP
117#define IPPROTO_IGMP IPPROTO_IGMP
118#define IPPROTO_RAW IPPROTO_RAW
119#define IPPROTO_MAX IPPROTO_MAX
120#endif
121
Roland McGrathd9f816f2004-09-04 03:39:20 +0000122static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000123#ifdef PF_AAL5
124 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125#endif
126#ifdef PF_APPLETALK
127 { PF_APPLETALK, "PF_APPLETALK" },
128#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000129#ifdef PF_ASH
130 { PF_ASH, "PF_ASH" },
131#endif
132#ifdef PF_ATMPVC
133 { PF_ATMPVC, "PF_ATMPVC" },
134#endif
135#ifdef PF_ATMSVC
136 { PF_ATMSVC, "PF_ATMSVC" },
137#endif
138#ifdef PF_AX25
139 { PF_AX25, "PF_AX25" },
140#endif
141#ifdef PF_BLUETOOTH
142 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143#endif
144#ifdef PF_BRIDGE
145 { PF_BRIDGE, "PF_BRIDGE" },
146#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000147#ifdef PF_DECnet
148 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149#endif
150#ifdef PF_DECNET
151 { PF_DECNET, "PF_DECNET" },
152#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000153#ifdef PF_ECONET
154 { PF_ECONET, "PF_ECONET" },
155#endif
156#ifdef PF_FILE
157 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158#endif
159#ifdef PF_IMPLINK
160 { PF_IMPLINK, "PF_IMPLINK" },
161#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000162#ifdef PF_INET
163 { PF_INET, "PF_INET" },
164#endif
165#ifdef PF_INET6
166 { PF_INET6, "PF_INET6" },
167#endif
168#ifdef PF_IPX
169 { PF_IPX, "PF_IPX" },
170#endif
171#ifdef PF_IRDA
172 { PF_IRDA, "PF_IRDA" },
173#endif
174#ifdef PF_ISO
175 { PF_ISO, "PF_ISO" },
176#endif
177#ifdef PF_KEY
178 { PF_KEY, "PF_KEY" },
179#endif
180#ifdef PF_UNIX
181 { PF_UNIX, "PF_UNIX" },
182#endif
183#ifdef PF_LOCAL
184 { PF_LOCAL, "PF_LOCAL" },
185#endif
186#ifdef PF_NETBEUI
187 { PF_NETBEUI, "PF_NETBEUI" },
188#endif
189#ifdef PF_NETLINK
190 { PF_NETLINK, "PF_NETLINK" },
191#endif
192#ifdef PF_NETROM
193 { PF_NETROM, "PF_NETROM" },
194#endif
195#ifdef PF_PACKET
196 { PF_PACKET, "PF_PACKET" },
197#endif
198#ifdef PF_PPPOX
199 { PF_PPPOX, "PF_PPPOX" },
200#endif
201#ifdef PF_ROSE
202 { PF_ROSE, "PF_ROSE" },
203#endif
204#ifdef PF_ROUTE
205 { PF_ROUTE, "PF_ROUTE" },
206#endif
207#ifdef PF_SECURITY
208 { PF_SECURITY, "PF_SECURITY" },
209#endif
210#ifdef PF_SNA
211 { PF_SNA, "PF_SNA" },
212#endif
213#ifdef PF_UNSPEC
214 { PF_UNSPEC, "PF_UNSPEC" },
215#endif
216#ifdef PF_WANPIPE
217 { PF_WANPIPE, "PF_WANPIPE" },
218#endif
219#ifdef PF_X25
220 { PF_X25, "PF_X25" },
221#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { 0, NULL },
223};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000224const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000225#ifdef AF_APPLETALK
226 { AF_APPLETALK, "AF_APPLETALK" },
227#endif
228#ifdef AF_ASH
229 { AF_ASH, "AF_ASH" },
230#endif
231#ifdef AF_ATMPVC
232 { AF_ATMPVC, "AF_ATMPVC" },
233#endif
234#ifdef AF_ATMSVC
235 { AF_ATMSVC, "AF_ATMSVC" },
236#endif
237#ifdef AF_AX25
238 { AF_AX25, "AF_AX25" },
239#endif
240#ifdef AF_BLUETOOTH
241 { AF_BLUETOOTH, "AF_BLUETOOTH" },
242#endif
243#ifdef AF_BRIDGE
244 { AF_BRIDGE, "AF_BRIDGE" },
245#endif
246#ifdef AF_DECnet
247 { AF_DECnet, "AF_DECnet" },
248#endif
249#ifdef AF_ECONET
250 { AF_ECONET, "AF_ECONET" },
251#endif
252#ifdef AF_FILE
253 { AF_FILE, "AF_FILE" },
254#endif
255#ifdef AF_IMPLINK
256 { AF_IMPLINK, "AF_IMPLINK" },
257#endif
258#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000260#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000261#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000262 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000263#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000264#ifdef AF_IPX
265 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000266#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000267#ifdef AF_IRDA
268 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000269#endif
270#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000271 { AF_ISO, "AF_ISO" },
272#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000273#ifdef AF_KEY
274 { AF_KEY, "AF_KEY" },
275#endif
276#ifdef AF_UNIX
277 { AF_UNIX, "AF_UNIX" },
278#endif
279#ifdef AF_LOCAL
280 { AF_LOCAL, "AF_LOCAL" },
281#endif
282#ifdef AF_NETBEUI
283 { AF_NETBEUI, "AF_NETBEUI" },
284#endif
285#ifdef AF_NETLINK
286 { AF_NETLINK, "AF_NETLINK" },
287#endif
288#ifdef AF_NETROM
289 { AF_NETROM, "AF_NETROM" },
290#endif
291#ifdef AF_PACKET
292 { AF_PACKET, "AF_PACKET" },
293#endif
294#ifdef AF_PPPOX
295 { AF_PPPOX, "AF_PPPOX" },
296#endif
297#ifdef AF_ROSE
298 { AF_ROSE, "AF_ROSE" },
299#endif
300#ifdef AF_ROUTE
301 { AF_ROUTE, "AF_ROUTE" },
302#endif
303#ifdef AF_SECURITY
304 { AF_SECURITY, "AF_SECURITY" },
305#endif
306#ifdef AF_SNA
307 { AF_SNA, "AF_SNA" },
308#endif
309#ifdef AF_UNSPEC
310 { AF_UNSPEC, "AF_UNSPEC" },
311#endif
312#ifdef AF_WANPIPE
313 { AF_WANPIPE, "AF_WANPIPE" },
314#endif
315#ifdef AF_X25
316 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000317#endif
318 { 0, NULL },
319};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000320static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 { SOCK_STREAM, "SOCK_STREAM" },
322 { SOCK_DGRAM, "SOCK_DGRAM" },
323#ifdef SOCK_RAW
324 { SOCK_RAW, "SOCK_RAW" },
325#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000326#ifdef SOCK_RDM
327 { SOCK_RDM, "SOCK_RDM" },
328#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329#ifdef SOCK_SEQPACKET
330 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
331#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000332#ifdef SOCK_DCCP
333 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334#endif
335#ifdef SOCK_PACKET
336 { SOCK_PACKET, "SOCK_PACKET" },
337#endif
338 { 0, NULL },
339};
Dmitry V. Levind475c062011-03-03 01:02:41 +0000340static const struct xlat sock_type_flags[] = {
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000341#ifdef SOCK_CLOEXEC
342 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
343#endif
344#ifdef SOCK_NONBLOCK
345 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
346#endif
347 { 0, NULL },
348};
349#ifndef SOCK_TYPE_MASK
350# define SOCK_TYPE_MASK 0xf
351#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000352static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000353#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000354 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000355#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000356#if defined(SOL_ICMP)
357 { SOL_ICMP, "SOL_ICMP" },
358#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000359#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000361#endif
362#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000363 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000364#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000365#if defined(SOL_IPV6)
366 { SOL_IPV6, "SOL_IPV6" },
367#endif
368#if defined(SOL_ICMPV6)
369 { SOL_ICMPV6, "SOL_ICMPV6" },
370#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100371#if defined(SOL_SCTP)
372 { SOL_SCTP, "SOL_SCTP" },
373#endif
374#if defined(SOL_UDPLITE)
375 { SOL_UDPLITE, "SOL_UDPLITE" },
376#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000377#if defined(SOL_RAW)
378 { SOL_RAW, "SOL_RAW" },
379#endif
380#if defined(SOL_IPX)
381 { SOL_IPX, "SOL_IPX" },
382#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000383#if defined(SOL_AX25)
384 { SOL_AX25, "SOL_AX25" },
385#endif
386#if defined(SOL_ATALK)
387 { SOL_ATALK, "SOL_ATALK" },
388#endif
389#if defined(SOL_NETROM)
390 { SOL_NETROM, "SOL_NETROM" },
391#endif
392#if defined(SOL_ROSE)
393 { SOL_ROSE, "SOL_ROSE" },
394#endif
395#if defined(SOL_DECNET)
396 { SOL_DECNET, "SOL_DECNET" },
397#endif
398#if defined(SOL_X25)
399 { SOL_X25, "SOL_X25" },
400#endif
401#if defined(SOL_PACKET)
402 { SOL_PACKET, "SOL_PACKET" },
403#endif
404#if defined(SOL_ATM)
405 { SOL_ATM, "SOL_ATM" },
406#endif
407#if defined(SOL_AAL)
408 { SOL_AAL, "SOL_AAL" },
409#endif
410#if defined(SOL_IRDA)
411 { SOL_IRDA, "SOL_IRDA" },
412#endif
Holger Hans Peter Freytherce9e0f42011-01-14 11:08:11 +0100413#if defined(SOL_NETBEUI)
414 { SOL_NETBEUI, "SOL_NETBEUI" },
415#endif
416#if defined(SOL_LLC)
417 { SOL_LLC, "SOL_LLC" },
418#endif
419#if defined(SOL_DCCP)
420 { SOL_DCCP, "SOL_DCCP" },
421#endif
422#if defined(SOL_NETLINK)
423 { SOL_NETLINK, "SOL_NETLINK" },
424#endif
425#if defined(SOL_TIPC)
426 { SOL_TIPC, "SOL_TIPC" },
427#endif
428#if defined(SOL_RXRPC)
429 { SOL_RXRPC, "SOL_RXRPC" },
430#endif
431#if defined(SOL_PPPOL2TP)
432 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
433#endif
434#if defined(SOL_BLUETOOTH)
435 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
436#endif
437#if defined(SOL_PNPIPE)
438 { SOL_PNPIPE, "SOL_PNPIPE" },
439#endif
440#if defined(SOL_RDS)
441 { SOL_RDS, "SOL_RDS" },
442#endif
443#if defined(SOL_IUVC)
444 { SOL_IUCV, "SOL_IUCV" },
445#endif
446#if defined(SOL_CAIF)
447 { SOL_CAIF, "SOL_CAIF" },
448#endif
John Hughes61563572001-03-27 16:47:36 +0000449 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Dmitry V. Levind475c062011-03-03 01:02:41 +0000450 /* The SOL_* array should remain not NULL-terminated. */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000451};
John Hughes93f7fcc2002-05-22 15:46:49 +0000452/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
453 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000454static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 { IPPROTO_IP, "IPPROTO_IP" },
456 { IPPROTO_ICMP, "IPPROTO_ICMP" },
457 { IPPROTO_TCP, "IPPROTO_TCP" },
458 { IPPROTO_UDP, "IPPROTO_UDP" },
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000459#ifdef IPPROTO_IGMP
460 { IPPROTO_IGMP, "IPPROTO_IGMP" },
461#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462#ifdef IPPROTO_GGP
463 { IPPROTO_GGP, "IPPROTO_GGP" },
464#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000465#ifdef IPPROTO_IPIP
466 { IPPROTO_IPIP, "IPPROTO_IPIP" },
467#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468#ifdef IPPROTO_EGP
469 { IPPROTO_EGP, "IPPROTO_EGP" },
470#endif
471#ifdef IPPROTO_PUP
472 { IPPROTO_PUP, "IPPROTO_PUP" },
473#endif
474#ifdef IPPROTO_IDP
475 { IPPROTO_IDP, "IPPROTO_IDP" },
476#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000477#ifdef IPPROTO_TP
478 { IPPROTO_TP, "IPPROTO_TP" },
479#endif
480#ifdef IPPROTO_DCCP
481 { IPPROTO_DCCP, "IPPROTO_DCCP" },
482#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483#ifdef IPPROTO_IPV6
484 { IPPROTO_IPV6, "IPPROTO_IPV6" },
485#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000486#ifdef IPPROTO_ROUTING
487 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000489#ifdef IPPROTO_FRAGMENT
490 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
491#endif
492#ifdef IPPROTO_RSVP
493 { IPPROTO_RSVP, "IPPROTO_RSVP" },
494#endif
495#ifdef IPPROTO_GRE
496 { IPPROTO_GRE, "IPPROTO_GRE" },
497#endif
498#ifdef IPPROTO_ESP
499 { IPPROTO_ESP, "IPPROTO_ESP" },
500#endif
501#ifdef IPPROTO_AH
502 { IPPROTO_AH, "IPPROTO_AH" },
503#endif
504#ifdef IPPROTO_ICMPV6
505 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
506#endif
507#ifdef IPPROTO_NONE
508 { IPPROTO_NONE, "IPPROTO_NONE" },
509#endif
510#ifdef IPPROTO_DSTOPTS
511 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512#endif
513#ifdef IPPROTO_HELLO
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000514 { IPPROTO_HELLO, "IPPROTO_HELLO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515#endif
516#ifdef IPPROTO_ND
517 { IPPROTO_ND, "IPPROTO_ND" },
518#endif
Dmitry V. Levind48c6b92011-01-10 01:14:38 +0000519#ifdef IPPROTO_MTP
520 { IPPROTO_MTP, "IPPROTO_MTP" },
521#endif
522#ifdef IPPROTO_ENCAP
523 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
524#endif
525#ifdef IPPROTO_PIM
526 { IPPROTO_PIM, "IPPROTO_PIM" },
527#endif
528#ifdef IPPROTO_COMP
529 { IPPROTO_COMP, "IPPROTO_COMP" },
530#endif
531#ifdef IPPROTO_SCTP
532 { IPPROTO_SCTP, "IPPROTO_SCTP" },
533#endif
534#ifdef IPPROTO_UDPLITE
535 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
536#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537#ifdef IPPROTO_RAW
538 { IPPROTO_RAW, "IPPROTO_RAW" },
539#endif
540#ifdef IPPROTO_MAX
541 { IPPROTO_MAX, "IPPROTO_MAX" },
542#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 { 0, NULL },
544};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000545static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000546 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000548 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#endif
550#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000551 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552#endif
553#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000554 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555#endif
556#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000557 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558#endif
559#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000560 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561#endif
562#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000563 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000566 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000567#endif
568#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000569 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000570#endif
571#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000572 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000573#endif
574#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000575 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000576#endif
577#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000578 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000579#endif
580#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000581 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000582#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000583#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000584 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000585#endif
586#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000587 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000588#endif
589#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000590 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000591#endif
592#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000593 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000594#endif
595#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000596 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000597#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000598#ifdef MSG_CMSG_CLOEXEC
599 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
600#endif
601 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602};
603
Roland McGrathd9f816f2004-09-04 03:39:20 +0000604static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000605#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000606 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000607#endif
608#ifdef SO_ALLRAW
609 { SO_ALLRAW, "SO_ALLRAW" },
610#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000611#ifdef SO_ATTACH_FILTER
612 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
613#endif
614#ifdef SO_BINDTODEVICE
615 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
616#endif
617#ifdef SO_BROADCAST
618 { SO_BROADCAST, "SO_BROADCAST" },
619#endif
620#ifdef SO_BSDCOMPAT
621 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
622#endif
623#ifdef SO_DEBUG
624 { SO_DEBUG, "SO_DEBUG" },
625#endif
626#ifdef SO_DETACH_FILTER
627 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
628#endif
629#ifdef SO_DONTROUTE
630 { SO_DONTROUTE, "SO_DONTROUTE" },
631#endif
632#ifdef SO_ERROR
633 { SO_ERROR, "SO_ERROR" },
634#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000635#ifdef SO_ICS
636 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000638#ifdef SO_IMASOCKET
639 { SO_IMASOCKET, "SO_IMASOCKET" },
640#endif
641#ifdef SO_KEEPALIVE
642 { SO_KEEPALIVE, "SO_KEEPALIVE" },
643#endif
644#ifdef SO_LINGER
645 { SO_LINGER, "SO_LINGER" },
646#endif
647#ifdef SO_LISTENING
648 { SO_LISTENING, "SO_LISTENING" },
649#endif
650#ifdef SO_MGMT
651 { SO_MGMT, "SO_MGMT" },
652#endif
653#ifdef SO_NO_CHECK
654 { SO_NO_CHECK, "SO_NO_CHECK" },
655#endif
656#ifdef SO_OOBINLINE
657 { SO_OOBINLINE, "SO_OOBINLINE" },
658#endif
659#ifdef SO_ORDREL
660 { SO_ORDREL, "SO_ORDREL" },
661#endif
662#ifdef SO_PARALLELSVR
663 { SO_PARALLELSVR, "SO_PARALLELSVR" },
664#endif
665#ifdef SO_PASSCRED
666 { SO_PASSCRED, "SO_PASSCRED" },
667#endif
668#ifdef SO_PEERCRED
669 { SO_PEERCRED, "SO_PEERCRED" },
670#endif
671#ifdef SO_PEERNAME
672 { SO_PEERNAME, "SO_PEERNAME" },
673#endif
674#ifdef SO_PEERSEC
675 { SO_PEERSEC, "SO_PEERSEC" },
676#endif
677#ifdef SO_PRIORITY
678 { SO_PRIORITY, "SO_PRIORITY" },
679#endif
680#ifdef SO_PROTOTYPE
681 { SO_PROTOTYPE, "SO_PROTOTYPE" },
682#endif
683#ifdef SO_RCVBUF
684 { SO_RCVBUF, "SO_RCVBUF" },
685#endif
686#ifdef SO_RCVLOWAT
687 { SO_RCVLOWAT, "SO_RCVLOWAT" },
688#endif
689#ifdef SO_RCVTIMEO
690 { SO_RCVTIMEO, "SO_RCVTIMEO" },
691#endif
692#ifdef SO_RDWR
693 { SO_RDWR, "SO_RDWR" },
694#endif
695#ifdef SO_REUSEADDR
696 { SO_REUSEADDR, "SO_REUSEADDR" },
697#endif
698#ifdef SO_REUSEPORT
699 { SO_REUSEPORT, "SO_REUSEPORT" },
700#endif
701#ifdef SO_SECURITY_AUTHENTICATION
702 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
703#endif
704#ifdef SO_SECURITY_ENCRYPTION_NETWORK
705 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
706#endif
707#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
708 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
709#endif
710#ifdef SO_SEMA
711 { SO_SEMA, "SO_SEMA" },
712#endif
713#ifdef SO_SNDBUF
714 { SO_SNDBUF, "SO_SNDBUF" },
715#endif
716#ifdef SO_SNDLOWAT
717 { SO_SNDLOWAT, "SO_SNDLOWAT" },
718#endif
719#ifdef SO_SNDTIMEO
720 { SO_SNDTIMEO, "SO_SNDTIMEO" },
721#endif
722#ifdef SO_TIMESTAMP
723 { SO_TIMESTAMP, "SO_TIMESTAMP" },
724#endif
725#ifdef SO_TYPE
726 { SO_TYPE, "SO_TYPE" },
727#endif
728#ifdef SO_USELOOPBACK
729 { SO_USELOOPBACK, "SO_USELOOPBACK" },
730#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 { 0, NULL },
732};
733
John Hughes93f7fcc2002-05-22 15:46:49 +0000734#if !defined (SOL_IP) && defined (IPPROTO_IP)
735#define SOL_IP IPPROTO_IP
736#endif
737
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000739static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000740#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000741 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000742#endif
743#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000744 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000745#endif
746#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000747 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000749#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000750 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000752#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000753 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000754#endif
755#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000756 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
757#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000758#ifdef IP_RECVOPTS
759 { IP_RECVOPTS, "IP_RECVOPTS" },
760#endif
761#ifdef IP_RECVRETOPTS
762 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
763#endif
764#ifdef IP_RECVDSTADDR
765 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
766#endif
767#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000768 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000769#endif
770#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000771 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000772#endif
773#ifdef IP_PKTOPTIONS
774 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
775#endif
776#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000777 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000778#endif
779#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000780 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000781#endif
782#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000783 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000784#endif
785#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000786 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000787#endif
788#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000789 { IP_MTU, "IP_MTU" },
790#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000791#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000792 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000793#endif
794#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000795 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000796#endif
797#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000798 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000799#endif
800#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000801 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000802#endif
803#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000804 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000805#endif
806#ifdef IP_BROADCAST_IF
807 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
808#endif
809#ifdef IP_RECVIFINDEX
810 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
811#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000812#ifdef IP_MSFILTER
813 { IP_MSFILTER, "IP_MSFILTER" },
814#endif
815#ifdef MCAST_MSFILTER
816 { MCAST_MSFILTER, "MCAST_MSFILTER" },
817#endif
818#ifdef IP_FREEBIND
819 { IP_FREEBIND, "IP_FREEBIND" },
820#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000821 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822};
823#endif /* SOL_IP */
824
Roland McGrath4f6ba692004-08-31 07:01:26 +0000825#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000826static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000827#ifdef IPV6_ADDRFORM
828 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
829#endif
830#ifdef MCAST_FILTER
831 { MCAST_FILTER, "MCAST_FILTER" },
832#endif
833#ifdef IPV6_PKTOPTIONS
834 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
835#endif
836#ifdef IPV6_MTU
837 { IPV6_MTU, "IPV6_MTU" },
838#endif
839#ifdef IPV6_V6ONLY
840 { IPV6_V6ONLY, "IPV6_V6ONLY" },
841#endif
842#ifdef IPV6_PKTINFO
843 { IPV6_PKTINFO, "IPV6_PKTINFO" },
844#endif
845#ifdef IPV6_HOPLIMIT
846 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
847#endif
848#ifdef IPV6_RTHDR
849 { IPV6_RTHDR, "IPV6_RTHDR" },
850#endif
851#ifdef IPV6_HOPOPTS
852 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
853#endif
854#ifdef IPV6_DSTOPTS
855 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
856#endif
857#ifdef IPV6_FLOWINFO
858 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
859#endif
860#ifdef IPV6_UNICAST_HOPS
861 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
862#endif
863#ifdef IPV6_MULTICAST_HOPS
864 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
865#endif
866#ifdef IPV6_MULTICAST_LOOP
867 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
868#endif
869#ifdef IPV6_MULTICAST_IF
870 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
871#endif
872#ifdef IPV6_MTU_DISCOVER
873 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
874#endif
875#ifdef IPV6_RECVERR
876 { IPV6_RECVERR, "IPV6_RECVERR" },
877#endif
878#ifdef IPV6_FLOWINFO_SEND
879 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
880#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000881#ifdef IPV6_ADD_MEMBERSHIP
882 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
883#endif
884#ifdef IPV6_DROP_MEMBERSHIP
885 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
886#endif
887#ifdef IPV6_ROUTER_ALERT
888 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
889#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000890 { 0, NULL },
891};
892#endif /* SOL_IPV6 */
893
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000895static const struct xlat sockipxoptions[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200896 { IPX_TYPE, "IPX_TYPE" },
897 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898};
899#endif /* SOL_IPX */
900
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000901#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000902static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000903#if defined(ICMP_FILTER)
904 { ICMP_FILTER, "ICMP_FILTER" },
905#endif
906 { 0, NULL },
907};
908#endif /* SOL_RAW */
909
910#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000911static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000912#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000913 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000914#endif
915#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000916 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000917#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000918#if defined(PACKET_RECV_OUTPUT)
919 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
920#endif
921#if defined(PACKET_RX_RING)
922 { PACKET_RX_RING, "PACKET_RX_RING" },
923#endif
924#if defined(PACKET_STATISTICS)
925 { PACKET_STATISTICS, "PACKET_STATISTICS" },
926#endif
Dmitry V. Levinca75bd62009-11-13 12:51:04 +0000927#if defined(PACKET_COPY_THRESH)
928 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
929#endif
930#if defined(PACKET_AUXDATA)
931 { PACKET_AUXDATA, "PACKET_AUXDATA" },
932#endif
933#if defined(PACKET_ORIGDEV)
934 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
935#endif
936#if defined(PACKET_VERSION)
937 { PACKET_VERSION, "PACKET_VERSION" },
938#endif
939#if defined(PACKET_HDRLEN)
940 { PACKET_HDRLEN, "PACKET_HDRLEN" },
941#endif
942#if defined(PACKET_RESERVE)
943 { PACKET_RESERVE, "PACKET_RESERVE" },
944#endif
945#if defined(PACKET_TX_RING)
946 { PACKET_TX_RING, "PACKET_TX_RING" },
947#endif
948#if defined(PACKET_LOSS)
949 { PACKET_LOSS, "PACKET_LOSS" },
950#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000951 { 0, NULL },
952};
953#endif /* SOL_PACKET */
954
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100955#ifdef SOL_SCTP
956static const struct xlat socksctpoptions[] = {
957#if defined(SCTP_RTOINFO)
958 { SCTP_RTOINFO, "SCTP_RTOINFO" },
959#endif
960#if defined(SCTP_ASSOCINFO)
961 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
962#endif
963#if defined(SCTP_INITMSG)
964 { SCTP_INITMSG, "SCTP_INITMSG" },
965#endif
966#if defined(SCTP_NODELAY)
967 { SCTP_NODELAY, "SCTP_NODELAY" },
968#endif
969#if defined(SCTP_AUTOCLOSE)
970 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
971#endif
972#if defined(SCTP_SET_PEER_PRIMARY_ADDR)
973 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
974#endif
975#if defined(SCTP_PRIMARY_ADDR)
976 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
977#endif
978#if defined(SCTP_ADAPTATION_LAYER)
979 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
980#endif
981#if defined(SCTP_DISABLE_FRAGMENTS)
982 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
983#endif
984#if defined(SCTP_PEER_ADDR_PARAMS)
985 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
986#endif
987#if defined(SCTP_DEFAULT_SEND_PARAM)
988 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
989#endif
990#if defined(SCTP_EVENTS)
991 { SCTP_EVENTS, "SCTP_EVENTS" },
992#endif
993#if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
994 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
995#endif
996#if defined(SCTP_MAXSEG)
997 { SCTP_MAXSEG, "SCTP_MAXSEG" },
998#endif
999#if defined(SCTP_STATUS)
1000 { SCTP_STATUS, "SCTP_STATUS" },
1001#endif
1002#if defined(SCTP_GET_PEER_ADDR_INFO)
1003 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
1004#endif
1005#if defined(SCTP_DELAYED_ACK)
1006 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1007#endif
1008#if defined(SCTP_CONTEXT)
1009 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1010#endif
1011#if defined(SCTP_FRAGMENT_INTERLEAVE)
1012 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1013#endif
1014#if defined(SCTP_PARTIAL_DELIVERY_POINT)
1015 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1016#endif
1017#if defined(SCTP_MAX_BURST)
1018 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1019#endif
1020#if defined(SCTP_AUTH_CHUNK)
1021 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1022#endif
1023#if defined(SCTP_HMAC_IDENT)
1024 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1025#endif
1026#if defined(SCTP_AUTH_KEY)
1027 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1028#endif
1029#if defined(SCTP_AUTH_ACTIVE_KEY)
1030 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1031#endif
1032#if defined(SCTP_AUTH_DELETE_KEY)
1033 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1034#endif
1035#if defined(SCTP_PEER_AUTH_CHUNKS)
1036 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1037#endif
1038#if defined(SCTP_LOCAL_AUTH_CHUNKS)
1039 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1040#endif
1041#if defined(SCTP_GET_ASSOC_NUMBER)
1042 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1043#endif
1044
1045 /* linux specific things */
1046#if defined(SCTP_SOCKOPT_BINDX_ADD)
1047 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1048#endif
1049#if defined(SCTP_SOCKOPT_BINDX_REM)
1050 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1051#endif
1052#if defined(SCTP_SOCKOPT_PEELOFF)
1053 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1054#endif
1055#if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1056 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1057#endif
1058#if defined(SCTP_GET_PEER_ADDRS_OLD)
1059 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1060#endif
1061#if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1062 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1063#endif
1064#if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1065 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1066#endif
1067#if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1068 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1069#endif
1070#if defined(SCTP_GET_PEER_ADDRS)
1071 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1072#endif
1073#if defined(SCTP_GET_LOCAL_ADDRS)
1074 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1075#endif
1076
1077 { 0, NULL },
1078};
1079#endif
1080
John Hughes93f7fcc2002-05-22 15:46:49 +00001081#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
1082#define SOL_TCP IPPROTO_TCP
1083#endif
1084
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +00001086static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001087 { TCP_NODELAY, "TCP_NODELAY" },
1088 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001089#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001090 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001091#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001092#if defined(TCP_KEEPIDLE)
1093 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1094#endif
1095#if defined(TCP_KEEPINTVL)
1096 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1097#endif
1098#if defined(TCP_KEEPCNT)
1099 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1100#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001101#if defined(TCP_NKEEP)
1102 { TCP_NKEEP, "TCP_NKEEP" },
1103#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +00001104#if defined(TCP_SYNCNT)
1105 { TCP_SYNCNT, "TCP_SYNCNT" },
1106#endif
1107#if defined(TCP_LINGER2)
1108 { TCP_LINGER2, "TCP_LINGER2" },
1109#endif
1110#if defined(TCP_DEFER_ACCEPT)
1111 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1112#endif
1113#if defined(TCP_WINDOW_CLAMP)
1114 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1115#endif
1116#if defined(TCP_INFO)
1117 { TCP_INFO, "TCP_INFO" },
1118#endif
1119#if defined(TCP_QUICKACK)
1120 { TCP_QUICKACK, "TCP_QUICKACK" },
1121#endif
1122 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001123};
1124#endif /* SOL_TCP */
1125
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001126#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +00001127static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001128#if defined(ICMP_ECHOREPLY)
1129 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1130#endif
1131#if defined(ICMP_DEST_UNREACH)
1132 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1133#endif
1134#if defined(ICMP_SOURCE_QUENCH)
1135 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1136#endif
1137#if defined(ICMP_REDIRECT)
1138 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1139#endif
1140#if defined(ICMP_ECHO)
1141 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1142#endif
1143#if defined(ICMP_TIME_EXCEEDED)
1144 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1145#endif
1146#if defined(ICMP_PARAMETERPROB)
1147 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1148#endif
1149#if defined(ICMP_TIMESTAMP)
1150 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1151#endif
1152#if defined(ICMP_TIMESTAMPREPLY)
1153 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1154#endif
1155#if defined(ICMP_INFO_REQUEST)
1156 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1157#endif
1158#if defined(ICMP_INFO_REPLY)
1159 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1160#endif
1161#if defined(ICMP_ADDRESS)
1162 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1163#endif
1164#if defined(ICMP_ADDRESSREPLY)
1165 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1166#endif
1167 { 0, NULL },
1168};
1169#endif /* SOL_RAW */
1170
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001171#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +00001172static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001173#if defined(PACKET_HOST)
1174 { PACKET_HOST, "PACKET_HOST" },
1175#endif
1176#if defined(PACKET_BROADCAST)
1177 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1178#endif
1179#if defined(PACKET_MULTICAST)
1180 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1181#endif
1182#if defined(PACKET_OTHERHOST)
1183 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1184#endif
1185#if defined(PACKET_OUTGOING)
1186 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1187#endif
1188#if defined(PACKET_LOOPBACK)
1189 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1190#endif
1191#if defined(PACKET_FASTROUTE)
1192 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1193#endif
1194 { 0, NULL },
1195};
1196#endif /* defined(AF_PACKET) */
1197
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001198
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001200printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001202 union {
1203 char pad[128];
1204 struct sockaddr sa;
1205 struct sockaddr_in sin;
1206 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001207#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001208 struct sockaddr_in6 sa6;
1209#endif
1210#if defined(LINUX) && defined(AF_IPX)
1211 struct sockaddr_ipx sipx;
1212#endif
1213#ifdef AF_PACKET
1214 struct sockaddr_ll ll;
1215#endif
1216#ifdef AF_NETLINK
1217 struct sockaddr_nl nl;
1218#endif
1219 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001220 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221
1222 if (addr == 0) {
1223 tprintf("NULL");
1224 return;
1225 }
1226 if (!verbose(tcp)) {
1227 tprintf("%#lx", addr);
1228 return;
1229 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001230
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001231 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1232 addrlen = sizeof(addrbuf);
1233
1234 memset(&addrbuf, 0, sizeof(addrbuf));
1235 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 tprintf("{...}");
1237 return;
1238 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001239 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001240
John Hughes1fcb1d62001-09-18 15:56:53 +00001241 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001242 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1243 tprintf(", ");
1244
1245 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001247 if (addrlen == 2) {
1248 tprintf("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001249 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001250 tprintf("path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001251 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001252 } else {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001253 tprintf("path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001254 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001255 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256 break;
1257 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001258 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001259 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001261#ifdef HAVE_INET_NTOP
1262 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001263 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001264 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1265 ntohs(addrbuf.sa6.sin6_port), string_addr,
1266 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001267#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001268 {
1269#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001270 int numericscope = 0;
1271 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1272 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1273 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001274
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001275 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1276 numericscope++;
1277 else
1278 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1279 } else
1280 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001281
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001282 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +00001283#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001284 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +00001285 }
1286#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001287 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001288#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001289#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001291 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001293 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001294 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 /* Yes, I know, this does not look too
1296 * strace-ish, but otherwise the IPX
1297 * addresses just look monstrous...
1298 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001299 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001301 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001302 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001303 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1304 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 }
1306 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001307#endif /* AF_IPX && linux */
1308#ifdef AF_PACKET
1309 case AF_PACKET:
1310 {
1311 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001312 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001313 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001314 addrbuf.ll.sll_ifindex);
1315 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1316 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001317 addrbuf.ll.sll_halen,
1318 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001319 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001320 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1321 }
1322 break;
1323
1324#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001325#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001326 case AF_NETLINK:
1327 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1328 break;
1329#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001331 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332
1333 default:
John Hughes1fcb1d62001-09-18 15:56:53 +00001334 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001336 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001337 break;
1338 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001339 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340}
1341
1342#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001343static const struct xlat scmvals[] = {
1344#ifdef SCM_RIGHTS
1345 { SCM_RIGHTS, "SCM_RIGHTS" },
1346#endif
1347#ifdef SCM_CREDENTIALS
1348 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1349#endif
1350 { 0, NULL }
1351};
1352
1353static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001354printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001355{
Roland McGrathaa524c82005-06-01 19:22:06 +00001356 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1357 NULL : malloc(len);
1358 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001359 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001360 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001361 return;
1362 }
1363
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001364 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001365 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Roland McGrath50770822004-10-06 22:11:51 +00001366 tprintf(", cmsg_type=");
1367
Roland McGrathaa524c82005-06-01 19:22:06 +00001368 if (cmsg->cmsg_level == SOL_SOCKET) {
1369 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001370
Roland McGrathaa524c82005-06-01 19:22:06 +00001371 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1372 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1373
1374 if (cmsg->cmsg_type == SCM_RIGHTS
1375 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001376 int *fds = (int *) CMSG_DATA(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001377 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001378
Roland McGrath50770822004-10-06 22:11:51 +00001379 tprintf(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001380 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001381 if (!first)
1382 tprintf(", ");
1383 tprintf("%d", *fds++);
1384 first = 0;
1385 }
1386 tprintf("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001387 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001388 return;
1389 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001390 if (cmsg->cmsg_type == SCM_CREDENTIALS
1391 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001392 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
Roland McGrathaa524c82005-06-01 19:22:06 +00001393
Roland McGrath50770822004-10-06 22:11:51 +00001394 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1395 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001396 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001397 return;
1398 }
1399 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001400 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001401 tprintf(", ...}");
1402}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403
1404static void
Andreas Schwab0873f292010-02-12 21:39:12 +01001405do_msghdr(struct tcb *tcp, struct msghdr *msg)
1406{
1407 tprintf("{msg_name(%d)=", msg->msg_namelen);
1408 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1409
1410 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1411 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
Dmitry V. Levin88849682011-06-13 22:58:44 +00001412 (unsigned long)msg->msg_iov, 1);
Andreas Schwab0873f292010-02-12 21:39:12 +01001413
1414#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1415 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1416 if (msg->msg_controllen)
1417 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1418 msg->msg_controllen);
1419 tprintf(", msg_flags=");
1420 printflags(msg_flags, msg->msg_flags, "MSG_???");
1421#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1422 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1423 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1424#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1425 tprintf("}");
1426}
1427
1428static void
Denys Vlasenko12014262011-05-30 14:00:14 +02001429printmsghdr(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001430{
1431 struct msghdr msg;
1432
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001433 if (umove(tcp, addr, &msg) < 0) {
1434 tprintf("%#lx", addr);
1435 return;
1436 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001437 do_msghdr(tcp, &msg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438}
1439
Andreas Schwab0873f292010-02-12 21:39:12 +01001440#ifdef LINUX
1441static void
1442printmmsghdr(struct tcb *tcp, long addr)
1443{
1444 struct mmsghdr {
1445 struct msghdr msg_hdr;
1446 unsigned msg_len;
1447 } mmsg;
1448
1449 if (umove(tcp, addr, &mmsg) < 0) {
1450 tprintf("%#lx", addr);
1451 return;
1452 }
1453 tprintf("{");
1454 do_msghdr(tcp, &mmsg.msg_hdr);
1455 tprintf(", %u}", mmsg.msg_len);
1456}
1457#endif
1458
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459#endif /* HAVE_SENDMSG */
1460
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001461/*
1462 * low bits of the socket type define real socket type,
1463 * other bits are socket type flags.
1464 */
1465static void
1466tprint_sock_type(struct tcb *tcp, int flags)
1467{
1468 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1469
Denys Vlasenko7b609d52011-06-22 14:32:43 +02001470 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +02001471 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001472 flags &= ~SOCK_TYPE_MASK;
1473 if (!flags)
1474 return;
1475 tprintf("|");
1476 }
1477 printflags(sock_type_flags, flags, "SOCK_???");
1478}
1479
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001481sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482{
1483 if (entering(tcp)) {
1484 printxval(domains, tcp->u_arg[0], "PF_???");
1485 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001486 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 tprintf(", ");
1488 switch (tcp->u_arg[0]) {
1489 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001490#ifdef PF_INET6
1491 case PF_INET6:
1492#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1494 break;
1495#ifdef PF_IPX
1496 case PF_IPX:
1497 /* BTW: I don't believe this.. */
1498 tprintf("[");
1499 printxval(domains, tcp->u_arg[2], "PF_???");
1500 tprintf("]");
1501 break;
1502#endif /* PF_IPX */
1503 default:
1504 tprintf("%lu", tcp->u_arg[2]);
1505 break;
1506 }
1507 }
1508 return 0;
1509}
1510
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001511#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512int
Denys Vlasenko12014262011-05-30 14:00:14 +02001513sys_so_socket(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001514{
1515 if (entering(tcp)) {
1516 /* not sure really what these args are... but this
1517 * is how truss prints it
1518 */
1519 tprintf("%ld, %ld, %ld, ",
1520 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1521 printpath(tcp, tcp->u_arg[3]);
1522 tprintf(", %ld", tcp->u_arg[4]);
1523 }
1524 return 0;
1525}
1526
1527int
Denys Vlasenko12014262011-05-30 14:00:14 +02001528sys_so_socketpair(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001529{
1530 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001531 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001532 tprintf("0x%lx", tcp->u_arg[0]);
1533 }
1534 return 0;
1535}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001536#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001537
1538int
Denys Vlasenko12014262011-05-30 14:00:14 +02001539sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001540{
1541 if (entering(tcp)) {
1542 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001543 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 tprintf(", %lu", tcp->u_arg[2]);
1545 }
1546 return 0;
1547}
1548
1549int
Denys Vlasenko12014262011-05-30 14:00:14 +02001550sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551{
1552 return sys_bind(tcp);
1553}
1554
1555int
Denys Vlasenko12014262011-05-30 14:00:14 +02001556sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001557{
1558 if (entering(tcp)) {
1559 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1560 }
1561 return 0;
1562}
1563
Paolo Bonzini705ff102009-08-14 12:34:05 +02001564static int
1565do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566{
1567 if (entering(tcp)) {
1568 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001569 return 0;
1570 }
1571 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 tprintf("%#lx, NULL", tcp->u_arg[1]);
1573 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001574 int len;
1575 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001576 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577 tprintf("%#lx", tcp->u_arg[1]);
1578 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001579 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 }
1581 tprintf(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001582 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001584 if (flags_arg >= 0) {
1585 tprintf(", ");
1586 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1587 "SOCK_???");
1588 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001589 return 0;
1590}
1591
1592int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001593sys_accept(struct tcb *tcp)
1594{
1595 return do_accept(tcp, -1);
1596}
1597
1598#ifdef LINUX
1599int
1600sys_accept4(struct tcb *tcp)
1601{
1602 return do_accept(tcp, 3);
1603}
1604#endif
1605
1606int
Denys Vlasenko12014262011-05-30 14:00:14 +02001607sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608{
1609 if (entering(tcp)) {
1610 tprintf("%ld, ", tcp->u_arg[0]);
1611 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1612 tprintf(", %lu, ", tcp->u_arg[2]);
1613 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001614 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 }
1616 return 0;
1617}
1618
1619int
Denys Vlasenko12014262011-05-30 14:00:14 +02001620sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621{
1622 if (entering(tcp)) {
1623 tprintf("%ld, ", tcp->u_arg[0]);
1624 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1625 tprintf(", %lu, ", tcp->u_arg[2]);
1626 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001627 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628 /* to address */
1629 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001630 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 /* to length */
1632 tprintf(", %lu", tcp->u_arg[5]);
1633 }
1634 return 0;
1635}
1636
1637#ifdef HAVE_SENDMSG
1638
1639int
Denys Vlasenko12014262011-05-30 14:00:14 +02001640sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641{
1642 if (entering(tcp)) {
1643 tprintf("%ld, ", tcp->u_arg[0]);
1644 printmsghdr(tcp, tcp->u_arg[1]);
1645 /* flags */
1646 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001647 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001648 }
1649 return 0;
1650}
1651
1652#endif /* HAVE_SENDMSG */
1653
1654int
Denys Vlasenko12014262011-05-30 14:00:14 +02001655sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656{
1657 if (entering(tcp)) {
1658 tprintf("%ld, ", tcp->u_arg[0]);
1659 } else {
1660 if (syserror(tcp))
1661 tprintf("%#lx", tcp->u_arg[1]);
1662 else
1663 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1664
1665 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001666 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667 }
1668 return 0;
1669}
1670
1671int
Denys Vlasenko12014262011-05-30 14:00:14 +02001672sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673{
1674 int fromlen;
1675
1676 if (entering(tcp)) {
1677 tprintf("%ld, ", tcp->u_arg[0]);
1678 } else {
1679 if (syserror(tcp)) {
1680 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1681 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1682 tcp->u_arg[4], tcp->u_arg[5]);
1683 return 0;
1684 }
1685 /* buf */
1686 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1687 /* len */
1688 tprintf(", %lu, ", tcp->u_arg[2]);
1689 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001690 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691 /* from address, len */
1692 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1693 if (tcp->u_arg[4] == 0)
1694 tprintf(", NULL");
1695 else
1696 tprintf(", %#lx", tcp->u_arg[4]);
1697 if (tcp->u_arg[5] == 0)
1698 tprintf(", NULL");
1699 else
1700 tprintf(", %#lx", tcp->u_arg[5]);
1701 return 0;
1702 }
1703 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1704 tprintf(", {...}, [?]");
1705 return 0;
1706 }
1707 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001708 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001709 /* from length */
1710 tprintf(", [%u]", fromlen);
1711 }
1712 return 0;
1713}
1714
1715#ifdef HAVE_SENDMSG
1716
1717int
Denys Vlasenko12014262011-05-30 14:00:14 +02001718sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719{
1720 if (entering(tcp)) {
1721 tprintf("%ld, ", tcp->u_arg[0]);
1722 } else {
1723 if (syserror(tcp) || !verbose(tcp))
1724 tprintf("%#lx", tcp->u_arg[1]);
1725 else
1726 printmsghdr(tcp, tcp->u_arg[1]);
1727 /* flags */
1728 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001729 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730 }
1731 return 0;
1732}
1733
Andreas Schwab0873f292010-02-12 21:39:12 +01001734#ifdef LINUX
1735int
1736sys_recvmmsg(struct tcb *tcp)
1737{
Dmitry V. Levine6591032010-03-29 20:45:48 +04001738 static char str[128];
Andreas Schwab0873f292010-02-12 21:39:12 +01001739 if (entering(tcp)) {
Dmitry V. Levine6591032010-03-29 20:45:48 +04001740
Andreas Schwab0873f292010-02-12 21:39:12 +01001741 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001742 if (verbose(tcp)) {
1743 sprint_timespec(str, tcp, tcp->u_arg[4]);
1744 tcp->auxstr = strdup(str);
1745 } else {
1746 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1747 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1748 tprintf(", ");
1749 print_timespec(tcp, tcp->u_arg[4]);
1750 }
1751 return 0;
1752 } else {
1753 if (verbose(tcp)) {
1754 if (syserror(tcp))
1755 tprintf("%#lx", tcp->u_arg[1]);
1756 else
1757 printmmsghdr(tcp, tcp->u_arg[1]);
1758 tprintf(", %ld, ", tcp->u_arg[2]);
1759 /* flags */
1760 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1761 /* timeout on entrance */
1762 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1763 free((void *) tcp->auxstr);
1764 tcp->auxstr = NULL;
1765 }
1766 if (syserror(tcp))
1767 return 0;
1768 if (tcp->u_rval == 0) {
1769 tcp->auxstr = "Timeout";
1770 return RVAL_STR;
1771 }
1772 if (!verbose(tcp))
1773 return 0;
1774 /* timeout on exit */
1775 strcpy(str, "left ");
1776 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1777 tcp->auxstr = str;
1778 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001779 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001780}
1781#endif
1782
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783#endif /* HAVE_SENDMSG */
1784
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001785static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001786 { 0, "SHUT_RD" },
1787 { 1, "SHUT_WR" },
1788 { 2, "SHUT_RDWR" },
1789 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001790};
1791
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001792int
Denys Vlasenko12014262011-05-30 14:00:14 +02001793sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001794{
1795 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001796 tprintf("%ld, ", tcp->u_arg[0]);
1797 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 }
1799 return 0;
1800}
1801
1802int
Denys Vlasenko12014262011-05-30 14:00:14 +02001803sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804{
1805 return sys_accept(tcp);
1806}
1807
1808int
Denys Vlasenko12014262011-05-30 14:00:14 +02001809sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810{
1811 return sys_accept(tcp);
1812}
1813
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001814static int
1815do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817 if (exiting(tcp)) {
1818 if (syserror(tcp)) {
1819 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001820 } else {
1821#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1822 int fds[2];
1823
1824 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1825 tprintf("[...]");
1826 else
1827 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001828#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001829 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1830#else
1831 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001833 }
1834 if (flags_arg >= 0) {
1835 tprintf(", ");
1836 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1837 }
1838 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839 return 0;
1840}
1841
1842int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001843sys_pipe(struct tcb *tcp)
1844{
1845 return do_pipe(tcp, -1);
1846}
1847
1848#ifdef LINUX
1849int
1850sys_pipe2(struct tcb *tcp)
1851{
1852 return do_pipe(tcp, 1);
1853}
1854#endif
1855
1856int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001857sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858{
1859#ifdef LINUX
1860 int fds[2];
1861#endif
1862
1863 if (entering(tcp)) {
1864 printxval(domains, tcp->u_arg[0], "PF_???");
1865 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001866 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867 tprintf(", ");
1868 switch (tcp->u_arg[0]) {
1869 case PF_INET:
1870 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1871 break;
1872#ifdef PF_IPX
1873 case PF_IPX:
1874 /* BTW: I don't believe this.. */
1875 tprintf("[");
1876 printxval(domains, tcp->u_arg[2], "PF_???");
1877 tprintf("]");
1878 break;
1879#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001880 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001881 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882 break;
1883 }
1884 } else {
1885 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001886 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887 return 0;
1888 }
1889#ifdef LINUX
1890 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001891 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 else
1893 tprintf(", [%u, %u]", fds[0], fds[1]);
1894#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001895#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001897#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001898 }
1899 return 0;
1900}
1901
1902int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001903sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904{
1905 if (entering(tcp)) {
1906 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001907 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001908 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001909 switch (tcp->u_arg[1]) {
1910 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 break;
1913#ifdef SOL_IP
1914 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 break;
1917#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001918#ifdef SOL_IPV6
1919 case SOL_IPV6:
1920 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1921 break;
1922#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923#ifdef SOL_IPX
1924 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 break;
1927#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001928#ifdef SOL_PACKET
1929 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001930 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001931 break;
1932#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933#ifdef SOL_TCP
1934 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 break;
1937#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001938#ifdef SOL_SCTP
1939 case SOL_SCTP:
1940 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1941 break;
1942#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943
1944 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1945 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001946 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001947 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001948 break;
1949 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001950 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001952 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001953 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001954 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001955 tcp->u_arg[3], tcp->u_arg[4]);
1956 return 0;
1957 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001958
1959 switch (tcp->u_arg[1]) {
1960 case SOL_SOCKET:
1961 switch (tcp->u_arg[2]) {
1962#ifdef SO_LINGER
1963 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001964 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001965 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001966 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001967 tcp->u_arg[3],
1968 &linger) < 0)
1969 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001970 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001971 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001972 linger.l_onoff,
1973 linger.l_linger,
1974 len);
1975 return 0;
1976 }
1977 break;
1978#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001979#ifdef SO_PEERCRED
1980 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001981 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001982 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001983 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001984 tcp->u_arg[3],
1985 &uc) < 0)
1986 break;
1987 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1988 "[%d]",
1989 (long)uc.pid,
1990 (long)uc.uid,
1991 (long)uc.gid,
1992 len);
1993 return 0;
1994 }
1995 break;
1996#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001997 }
1998 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001999 case SOL_PACKET:
2000 switch (tcp->u_arg[2]) {
2001#ifdef PACKET_STATISTICS
2002 case PACKET_STATISTICS:
2003 if (len == sizeof(struct tpacket_stats)) {
2004 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002005 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002006 tcp->u_arg[3],
2007 &stats) < 0)
2008 break;
2009 tprintf("{packets=%u, drops=%u}, "
2010 "[%d]",
2011 stats.tp_packets,
2012 stats.tp_drops,
2013 len);
2014 return 0;
2015 }
2016 break;
2017#endif
2018 }
2019 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002020 }
2021
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002022 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002023 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002024 }
2025 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002026 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002027 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002028 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029 }
2030 return 0;
2031}
2032
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002033#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002034static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002035{
2036 struct icmp_filter filter;
2037
2038 if (!addr) {
2039 tprintf("NULL");
2040 return;
2041 }
2042 if (syserror(tcp) || !verbose(tcp)) {
2043 tprintf("%#lx", addr);
2044 return;
2045 }
2046 if (umove(tcp, addr, &filter) < 0) {
2047 tprintf("{...}");
2048 return;
2049 }
2050
2051 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002052 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002053 tprintf(")");
2054}
2055#endif /* ICMP_FILTER */
2056
John Hughes38ae88d2002-05-23 11:48:58 +00002057static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002058printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002059{
2060 printxval(socketlayers, level, "SOL_??");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002061 tprintf(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002062 switch (level) {
2063 case SOL_SOCKET:
2064 printxval(sockoptions, name, "SO_???");
2065 switch (name) {
2066#if defined(SO_LINGER)
2067 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002068 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002069 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002070 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002071 break;
2072 tprintf(", {onoff=%d, linger=%d}",
2073 linger.l_onoff,
2074 linger.l_linger);
2075 return 0;
2076 }
2077 break;
2078#endif
2079 }
2080 break;
2081#ifdef SOL_IP
2082 case SOL_IP:
2083 printxval(sockipoptions, name, "IP_???");
2084 break;
2085#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002086#ifdef SOL_IPV6
2087 case SOL_IPV6:
2088 printxval(sockipv6options, name, "IPV6_???");
2089 break;
2090#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002091#ifdef SOL_IPX
2092 case SOL_IPX:
2093 printxval(sockipxoptions, name, "IPX_???");
2094 break;
2095#endif
2096#ifdef SOL_PACKET
2097 case SOL_PACKET:
2098 printxval(sockpacketoptions, name, "PACKET_???");
2099 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002100 switch (name) {
2101#ifdef PACKET_RX_RING
2102 case PACKET_RX_RING:
2103#endif
2104#ifdef PACKET_TX_RING
2105 case PACKET_TX_RING:
2106#endif
2107#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2108 if (len == sizeof(struct tpacket_req)) {
2109 struct tpacket_req req;
2110 if (umove(tcp, addr, &req) < 0)
2111 break;
2112 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2113 req.tp_block_size,
2114 req.tp_block_nr,
2115 req.tp_frame_size,
2116 req.tp_frame_nr);
2117 return 0;
2118 }
2119 break;
2120#endif /* PACKET_RX_RING || PACKET_TX_RING */
2121 }
John Hughes38ae88d2002-05-23 11:48:58 +00002122 break;
2123#endif
2124#ifdef SOL_TCP
2125 case SOL_TCP:
2126 printxval(socktcpoptions, name, "TCP_???");
2127 break;
2128#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002129#ifdef SOL_SCTP
2130 case SOL_SCTP:
2131 printxval(socksctpoptions, name, "SCTP_???");
2132 break;
2133#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002134#ifdef SOL_RAW
2135 case SOL_RAW:
2136 printxval(sockrawoptions, name, "RAW_???");
2137 switch (name) {
2138#if defined(ICMP_FILTER)
2139 case ICMP_FILTER:
2140 tprintf(", ");
2141 printicmpfilter(tcp, addr);
2142 return 0;
2143#endif
2144 }
2145 break;
2146#endif
2147
Roland McGrath6d2b3492002-12-30 00:51:30 +00002148 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002149 * etc. still need work */
2150
2151 default:
2152 tprintf("%u", name);
2153 }
2154
2155 /* default arg printing */
2156
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002157 tprintf(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002158
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002159 if (len == sizeof(int)) {
2160 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002161 }
2162 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002163 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002164 }
2165 return 0;
2166}
2167
2168
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002169#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002170
2171void
Denys Vlasenko12014262011-05-30 14:00:14 +02002172print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002173{
2174 int c = 0;
2175 struct opthdr hdr;
2176
John Hughes2c4e3a82002-05-24 10:19:44 +00002177 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002178 if (umove(tcp, addr, &hdr) < 0) break;
2179 if (c++) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002180 tprintf(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002181 }
2182 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002183 tprintf("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002184 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002185 tprintf("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002186 addr += sizeof hdr;
2187 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002188 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002189 if (hdr.len > 0) {
2190 addr += hdr.len;
2191 len -= hdr.len;
2192 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002193 tprintf("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002194 }
2195 if (len > 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002196 if (c++) tprintf(", ");
2197 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002198 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002199 if (c > 1) tprintf("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002200}
2201
2202#endif
2203
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204int
Denys Vlasenko12014262011-05-30 14:00:14 +02002205sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206{
2207 if (entering(tcp)) {
2208 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002209 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002210 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002211 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 }
2213 return 0;
2214}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002215
2216#if UNIXWARE >= 7
2217
Roland McGrathd9f816f2004-09-04 03:39:20 +00002218static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002219 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2220 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2221 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2222 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2223 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2224 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002225 { 0, NULL },
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002226};
2227
2228
2229int
Denys Vlasenko12014262011-05-30 14:00:14 +02002230netlib_call(struct tcb *tcp, int (*func)())
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002231{
2232 if (entering(tcp)) {
2233 int i;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002234 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002235 tprintf(", ");
2236 --tcp->u_nargs;
2237 for (i = 0; i < tcp->u_nargs; i++)
2238 tcp->u_arg[i] = tcp->u_arg[i + 1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002239 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002240 }
2241
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002242 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002243}
2244
2245int
Denys Vlasenko12014262011-05-30 14:00:14 +02002246sys_xsocket(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002247{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002248 return netlib_call(tcp, sys_socket);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002249}
2250
2251int
Denys Vlasenko12014262011-05-30 14:00:14 +02002252sys_xsocketpair(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002253{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002254 return netlib_call(tcp, sys_socketpair);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002255}
2256
2257int
Denys Vlasenko12014262011-05-30 14:00:14 +02002258sys_xbind(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002259{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002260 return netlib_call(tcp, sys_bind);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002261}
2262
2263int
Denys Vlasenko12014262011-05-30 14:00:14 +02002264sys_xconnect(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002265{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002266 return netlib_call(tcp, sys_connect);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002267}
2268
2269int
Denys Vlasenko12014262011-05-30 14:00:14 +02002270sys_xlisten(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002271{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002272 return netlib_call(tcp, sys_listen);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002273}
2274
2275int
Denys Vlasenko12014262011-05-30 14:00:14 +02002276sys_xaccept(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002277{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002278 return netlib_call(tcp, sys_accept);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002279}
2280
2281int
Denys Vlasenko12014262011-05-30 14:00:14 +02002282sys_xsendmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002283{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002284 return netlib_call(tcp, sys_sendmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002285}
2286
2287int
Denys Vlasenko12014262011-05-30 14:00:14 +02002288sys_xrecvmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002289{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002290 return netlib_call(tcp, sys_recvmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002291}
2292
2293int
Denys Vlasenko12014262011-05-30 14:00:14 +02002294sys_xgetsockaddr(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002295{
2296 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002297 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002298 tprintf(", ");
2299 if (tcp->u_arg[1] == 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002300 tprintf("LOCALNAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002301 }
2302 else if (tcp->u_arg[1] == 1) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002303 tprintf("REMOTENAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002304 }
2305 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002306 tprintf("%ld, ", tcp->u_arg[1]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002307 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002308 tprintf("%ld, ", tcp->u_arg[2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002309 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002310 else {
2311 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2312 tprintf("%#lx", tcp->u_arg[3]);
2313 } else {
2314 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2315 }
2316 tprintf(", ");
2317 printnum(tcp, tcp->u_arg[4], "%lu");
2318 }
2319
2320 return 0;
2321
2322}
2323
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002324int
Denys Vlasenko12014262011-05-30 14:00:14 +02002325sys_xgetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002326{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002327 return netlib_call(tcp, sys_getsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002328}
2329
2330int
Denys Vlasenko12014262011-05-30 14:00:14 +02002331sys_xsetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002332{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002333 return netlib_call(tcp, sys_setsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002334}
2335
2336int
Denys Vlasenko12014262011-05-30 14:00:14 +02002337sys_xshutdown(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002338{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002339 return netlib_call(tcp, sys_shutdown);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002340}
2341
Dmitry V. Levine5e60852009-12-31 22:50:49 +00002342#endif /* UNIXWARE */