blob: 0d8e22d8e510ac59e9ab2a4bcba4fdc4e72e6bae [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,
1412 (unsigned long)msg->msg_iov);
1413
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
1470 if (str)
1471 {
1472 tprintf("%s", str);
1473 flags &= ~SOCK_TYPE_MASK;
1474 if (!flags)
1475 return;
1476 tprintf("|");
1477 }
1478 printflags(sock_type_flags, flags, "SOCK_???");
1479}
1480
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001481int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001482sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001483{
1484 if (entering(tcp)) {
1485 printxval(domains, tcp->u_arg[0], "PF_???");
1486 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001487 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001488 tprintf(", ");
1489 switch (tcp->u_arg[0]) {
1490 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001491#ifdef PF_INET6
1492 case PF_INET6:
1493#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1495 break;
1496#ifdef PF_IPX
1497 case PF_IPX:
1498 /* BTW: I don't believe this.. */
1499 tprintf("[");
1500 printxval(domains, tcp->u_arg[2], "PF_???");
1501 tprintf("]");
1502 break;
1503#endif /* PF_IPX */
1504 default:
1505 tprintf("%lu", tcp->u_arg[2]);
1506 break;
1507 }
1508 }
1509 return 0;
1510}
1511
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001512#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513int
Denys Vlasenko12014262011-05-30 14:00:14 +02001514sys_so_socket(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001515{
1516 if (entering(tcp)) {
1517 /* not sure really what these args are... but this
1518 * is how truss prints it
1519 */
1520 tprintf("%ld, %ld, %ld, ",
1521 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1522 printpath(tcp, tcp->u_arg[3]);
1523 tprintf(", %ld", tcp->u_arg[4]);
1524 }
1525 return 0;
1526}
1527
1528int
Denys Vlasenko12014262011-05-30 14:00:14 +02001529sys_so_socketpair(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00001530{
1531 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001532 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001533 tprintf("0x%lx", tcp->u_arg[0]);
1534 }
1535 return 0;
1536}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001537#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001538
1539int
Denys Vlasenko12014262011-05-30 14:00:14 +02001540sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541{
1542 if (entering(tcp)) {
1543 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001544 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545 tprintf(", %lu", tcp->u_arg[2]);
1546 }
1547 return 0;
1548}
1549
1550int
Denys Vlasenko12014262011-05-30 14:00:14 +02001551sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001552{
1553 return sys_bind(tcp);
1554}
1555
1556int
Denys Vlasenko12014262011-05-30 14:00:14 +02001557sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558{
1559 if (entering(tcp)) {
1560 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1561 }
1562 return 0;
1563}
1564
Paolo Bonzini705ff102009-08-14 12:34:05 +02001565static int
1566do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001567{
1568 if (entering(tcp)) {
1569 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001570 return 0;
1571 }
1572 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001573 tprintf("%#lx, NULL", tcp->u_arg[1]);
1574 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001575 int len;
1576 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001577 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578 tprintf("%#lx", tcp->u_arg[1]);
1579 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001580 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 }
1582 tprintf(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001583 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001585 if (flags_arg >= 0) {
1586 tprintf(", ");
1587 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1588 "SOCK_???");
1589 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590 return 0;
1591}
1592
1593int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001594sys_accept(struct tcb *tcp)
1595{
1596 return do_accept(tcp, -1);
1597}
1598
1599#ifdef LINUX
1600int
1601sys_accept4(struct tcb *tcp)
1602{
1603 return do_accept(tcp, 3);
1604}
1605#endif
1606
1607int
Denys Vlasenko12014262011-05-30 14:00:14 +02001608sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609{
1610 if (entering(tcp)) {
1611 tprintf("%ld, ", tcp->u_arg[0]);
1612 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1613 tprintf(", %lu, ", tcp->u_arg[2]);
1614 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001615 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616 }
1617 return 0;
1618}
1619
1620int
Denys Vlasenko12014262011-05-30 14:00:14 +02001621sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622{
1623 if (entering(tcp)) {
1624 tprintf("%ld, ", tcp->u_arg[0]);
1625 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1626 tprintf(", %lu, ", tcp->u_arg[2]);
1627 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001628 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629 /* to address */
1630 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001631 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 /* to length */
1633 tprintf(", %lu", tcp->u_arg[5]);
1634 }
1635 return 0;
1636}
1637
1638#ifdef HAVE_SENDMSG
1639
1640int
Denys Vlasenko12014262011-05-30 14:00:14 +02001641sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642{
1643 if (entering(tcp)) {
1644 tprintf("%ld, ", tcp->u_arg[0]);
1645 printmsghdr(tcp, tcp->u_arg[1]);
1646 /* flags */
1647 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001648 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001649 }
1650 return 0;
1651}
1652
1653#endif /* HAVE_SENDMSG */
1654
1655int
Denys Vlasenko12014262011-05-30 14:00:14 +02001656sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657{
1658 if (entering(tcp)) {
1659 tprintf("%ld, ", tcp->u_arg[0]);
1660 } else {
1661 if (syserror(tcp))
1662 tprintf("%#lx", tcp->u_arg[1]);
1663 else
1664 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1665
1666 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001667 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 }
1669 return 0;
1670}
1671
1672int
Denys Vlasenko12014262011-05-30 14:00:14 +02001673sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674{
1675 int fromlen;
1676
1677 if (entering(tcp)) {
1678 tprintf("%ld, ", tcp->u_arg[0]);
1679 } else {
1680 if (syserror(tcp)) {
1681 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1682 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1683 tcp->u_arg[4], tcp->u_arg[5]);
1684 return 0;
1685 }
1686 /* buf */
1687 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1688 /* len */
1689 tprintf(", %lu, ", tcp->u_arg[2]);
1690 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001691 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001692 /* from address, len */
1693 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1694 if (tcp->u_arg[4] == 0)
1695 tprintf(", NULL");
1696 else
1697 tprintf(", %#lx", tcp->u_arg[4]);
1698 if (tcp->u_arg[5] == 0)
1699 tprintf(", NULL");
1700 else
1701 tprintf(", %#lx", tcp->u_arg[5]);
1702 return 0;
1703 }
1704 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1705 tprintf(", {...}, [?]");
1706 return 0;
1707 }
1708 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001709 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710 /* from length */
1711 tprintf(", [%u]", fromlen);
1712 }
1713 return 0;
1714}
1715
1716#ifdef HAVE_SENDMSG
1717
1718int
Denys Vlasenko12014262011-05-30 14:00:14 +02001719sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001720{
1721 if (entering(tcp)) {
1722 tprintf("%ld, ", tcp->u_arg[0]);
1723 } else {
1724 if (syserror(tcp) || !verbose(tcp))
1725 tprintf("%#lx", tcp->u_arg[1]);
1726 else
1727 printmsghdr(tcp, tcp->u_arg[1]);
1728 /* flags */
1729 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001730 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001731 }
1732 return 0;
1733}
1734
Andreas Schwab0873f292010-02-12 21:39:12 +01001735#ifdef LINUX
1736int
1737sys_recvmmsg(struct tcb *tcp)
1738{
Dmitry V. Levine6591032010-03-29 20:45:48 +04001739 static char str[128];
Andreas Schwab0873f292010-02-12 21:39:12 +01001740 if (entering(tcp)) {
Dmitry V. Levine6591032010-03-29 20:45:48 +04001741
Andreas Schwab0873f292010-02-12 21:39:12 +01001742 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001743 if (verbose(tcp)) {
1744 sprint_timespec(str, tcp, tcp->u_arg[4]);
1745 tcp->auxstr = strdup(str);
1746 } else {
1747 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1748 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1749 tprintf(", ");
1750 print_timespec(tcp, tcp->u_arg[4]);
1751 }
1752 return 0;
1753 } else {
1754 if (verbose(tcp)) {
1755 if (syserror(tcp))
1756 tprintf("%#lx", tcp->u_arg[1]);
1757 else
1758 printmmsghdr(tcp, tcp->u_arg[1]);
1759 tprintf(", %ld, ", tcp->u_arg[2]);
1760 /* flags */
1761 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1762 /* timeout on entrance */
1763 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1764 free((void *) tcp->auxstr);
1765 tcp->auxstr = NULL;
1766 }
1767 if (syserror(tcp))
1768 return 0;
1769 if (tcp->u_rval == 0) {
1770 tcp->auxstr = "Timeout";
1771 return RVAL_STR;
1772 }
1773 if (!verbose(tcp))
1774 return 0;
1775 /* timeout on exit */
1776 strcpy(str, "left ");
1777 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1778 tcp->auxstr = str;
1779 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001780 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001781}
1782#endif
1783
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784#endif /* HAVE_SENDMSG */
1785
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001786static const struct xlat shutdown_modes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001787 { 0, "SHUT_RD" },
1788 { 1, "SHUT_WR" },
1789 { 2, "SHUT_RDWR" },
1790 { 0, NULL }
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001791};
1792
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001793int
Denys Vlasenko12014262011-05-30 14:00:14 +02001794sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795{
1796 if (entering(tcp)) {
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001797 tprintf("%ld, ", tcp->u_arg[0]);
1798 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799 }
1800 return 0;
1801}
1802
1803int
Denys Vlasenko12014262011-05-30 14:00:14 +02001804sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805{
1806 return sys_accept(tcp);
1807}
1808
1809int
Denys Vlasenko12014262011-05-30 14:00:14 +02001810sys_getpeername(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811{
1812 return sys_accept(tcp);
1813}
1814
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001815static int
1816do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001818 if (exiting(tcp)) {
1819 if (syserror(tcp)) {
1820 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001821 } else {
1822#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1823 int fds[2];
1824
1825 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1826 tprintf("[...]");
1827 else
1828 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001829#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001830 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1831#else
1832 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001834 }
1835 if (flags_arg >= 0) {
1836 tprintf(", ");
1837 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1838 }
1839 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840 return 0;
1841}
1842
1843int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001844sys_pipe(struct tcb *tcp)
1845{
1846 return do_pipe(tcp, -1);
1847}
1848
1849#ifdef LINUX
1850int
1851sys_pipe2(struct tcb *tcp)
1852{
1853 return do_pipe(tcp, 1);
1854}
1855#endif
1856
1857int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001858sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001859{
1860#ifdef LINUX
1861 int fds[2];
1862#endif
1863
1864 if (entering(tcp)) {
1865 printxval(domains, tcp->u_arg[0], "PF_???");
1866 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001867 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868 tprintf(", ");
1869 switch (tcp->u_arg[0]) {
1870 case PF_INET:
1871 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1872 break;
1873#ifdef PF_IPX
1874 case PF_IPX:
1875 /* BTW: I don't believe this.. */
1876 tprintf("[");
1877 printxval(domains, tcp->u_arg[2], "PF_???");
1878 tprintf("]");
1879 break;
1880#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001881 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001882 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 break;
1884 }
1885 } else {
1886 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001887 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888 return 0;
1889 }
1890#ifdef LINUX
1891 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001892 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 else
1894 tprintf(", [%u, %u]", fds[0], fds[1]);
1895#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001896#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001898#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899 }
1900 return 0;
1901}
1902
1903int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001904sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905{
1906 if (entering(tcp)) {
1907 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001908 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001909 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 switch (tcp->u_arg[1]) {
1911 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001913 break;
1914#ifdef SOL_IP
1915 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 break;
1918#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001919#ifdef SOL_IPV6
1920 case SOL_IPV6:
1921 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1922 break;
1923#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924#ifdef SOL_IPX
1925 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927 break;
1928#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001929#ifdef SOL_PACKET
1930 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001931 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001932 break;
1933#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934#ifdef SOL_TCP
1935 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 break;
1938#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001939#ifdef SOL_SCTP
1940 case SOL_SCTP:
1941 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1942 break;
1943#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944
1945 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1946 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001947 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001948 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001949 break;
1950 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001951 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001953 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001954 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001955 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 tcp->u_arg[3], tcp->u_arg[4]);
1957 return 0;
1958 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001959
1960 switch (tcp->u_arg[1]) {
1961 case SOL_SOCKET:
1962 switch (tcp->u_arg[2]) {
1963#ifdef SO_LINGER
1964 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001965 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001966 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001967 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001968 tcp->u_arg[3],
1969 &linger) < 0)
1970 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001971 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001972 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001973 linger.l_onoff,
1974 linger.l_linger,
1975 len);
1976 return 0;
1977 }
1978 break;
1979#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001980#ifdef SO_PEERCRED
1981 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001982 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001983 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001984 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001985 tcp->u_arg[3],
1986 &uc) < 0)
1987 break;
1988 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1989 "[%d]",
1990 (long)uc.pid,
1991 (long)uc.uid,
1992 (long)uc.gid,
1993 len);
1994 return 0;
1995 }
1996 break;
1997#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001998 }
1999 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002000 case SOL_PACKET:
2001 switch (tcp->u_arg[2]) {
2002#ifdef PACKET_STATISTICS
2003 case PACKET_STATISTICS:
2004 if (len == sizeof(struct tpacket_stats)) {
2005 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002006 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002007 tcp->u_arg[3],
2008 &stats) < 0)
2009 break;
2010 tprintf("{packets=%u, drops=%u}, "
2011 "[%d]",
2012 stats.tp_packets,
2013 stats.tp_drops,
2014 len);
2015 return 0;
2016 }
2017 break;
2018#endif
2019 }
2020 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00002021 }
2022
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002023 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00002024 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00002025 }
2026 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002027 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00002028 }
Roland McGrathfc544db2005-02-02 02:48:57 +00002029 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030 }
2031 return 0;
2032}
2033
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002034#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02002035static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002036{
2037 struct icmp_filter filter;
2038
2039 if (!addr) {
2040 tprintf("NULL");
2041 return;
2042 }
2043 if (syserror(tcp) || !verbose(tcp)) {
2044 tprintf("%#lx", addr);
2045 return;
2046 }
2047 if (umove(tcp, addr, &filter) < 0) {
2048 tprintf("{...}");
2049 return;
2050 }
2051
2052 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00002053 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00002054 tprintf(")");
2055}
2056#endif /* ICMP_FILTER */
2057
John Hughes38ae88d2002-05-23 11:48:58 +00002058static int
Denys Vlasenko12014262011-05-30 14:00:14 +02002059printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002060{
2061 printxval(socketlayers, level, "SOL_??");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002062 tprintf(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002063 switch (level) {
2064 case SOL_SOCKET:
2065 printxval(sockoptions, name, "SO_???");
2066 switch (name) {
2067#if defined(SO_LINGER)
2068 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002069 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00002070 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002071 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00002072 break;
2073 tprintf(", {onoff=%d, linger=%d}",
2074 linger.l_onoff,
2075 linger.l_linger);
2076 return 0;
2077 }
2078 break;
2079#endif
2080 }
2081 break;
2082#ifdef SOL_IP
2083 case SOL_IP:
2084 printxval(sockipoptions, name, "IP_???");
2085 break;
2086#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00002087#ifdef SOL_IPV6
2088 case SOL_IPV6:
2089 printxval(sockipv6options, name, "IPV6_???");
2090 break;
2091#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002092#ifdef SOL_IPX
2093 case SOL_IPX:
2094 printxval(sockipxoptions, name, "IPX_???");
2095 break;
2096#endif
2097#ifdef SOL_PACKET
2098 case SOL_PACKET:
2099 printxval(sockpacketoptions, name, "PACKET_???");
2100 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00002101 switch (name) {
2102#ifdef PACKET_RX_RING
2103 case PACKET_RX_RING:
2104#endif
2105#ifdef PACKET_TX_RING
2106 case PACKET_TX_RING:
2107#endif
2108#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2109 if (len == sizeof(struct tpacket_req)) {
2110 struct tpacket_req req;
2111 if (umove(tcp, addr, &req) < 0)
2112 break;
2113 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2114 req.tp_block_size,
2115 req.tp_block_nr,
2116 req.tp_frame_size,
2117 req.tp_frame_nr);
2118 return 0;
2119 }
2120 break;
2121#endif /* PACKET_RX_RING || PACKET_TX_RING */
2122 }
John Hughes38ae88d2002-05-23 11:48:58 +00002123 break;
2124#endif
2125#ifdef SOL_TCP
2126 case SOL_TCP:
2127 printxval(socktcpoptions, name, "TCP_???");
2128 break;
2129#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01002130#ifdef SOL_SCTP
2131 case SOL_SCTP:
2132 printxval(socksctpoptions, name, "SCTP_???");
2133 break;
2134#endif
John Hughes38ae88d2002-05-23 11:48:58 +00002135#ifdef SOL_RAW
2136 case SOL_RAW:
2137 printxval(sockrawoptions, name, "RAW_???");
2138 switch (name) {
2139#if defined(ICMP_FILTER)
2140 case ICMP_FILTER:
2141 tprintf(", ");
2142 printicmpfilter(tcp, addr);
2143 return 0;
2144#endif
2145 }
2146 break;
2147#endif
2148
Roland McGrath6d2b3492002-12-30 00:51:30 +00002149 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00002150 * etc. still need work */
2151
2152 default:
2153 tprintf("%u", name);
2154 }
2155
2156 /* default arg printing */
2157
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002158 tprintf(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00002159
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002160 if (len == sizeof(int)) {
2161 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00002162 }
2163 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002164 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002165 }
2166 return 0;
2167}
2168
2169
Roland McGrathc3ca0d82003-01-14 07:53:38 +00002170#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00002171
2172void
Denys Vlasenko12014262011-05-30 14:00:14 +02002173print_sock_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00002174{
2175 int c = 0;
2176 struct opthdr hdr;
2177
John Hughes2c4e3a82002-05-24 10:19:44 +00002178 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00002179 if (umove(tcp, addr, &hdr) < 0) break;
2180 if (c++) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002181 tprintf(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00002182 }
2183 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002184 tprintf("[");
John Hughes38ae88d2002-05-23 11:48:58 +00002185 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002186 tprintf("{");
John Hughes38ae88d2002-05-23 11:48:58 +00002187 addr += sizeof hdr;
2188 len -= sizeof hdr;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002189 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00002190 if (hdr.len > 0) {
2191 addr += hdr.len;
2192 len -= hdr.len;
2193 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002194 tprintf("}");
John Hughes38ae88d2002-05-23 11:48:58 +00002195 }
2196 if (len > 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002197 if (c++) tprintf(", ");
2198 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00002199 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002200 if (c > 1) tprintf("]");
John Hughes38ae88d2002-05-23 11:48:58 +00002201}
2202
2203#endif
2204
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205int
Denys Vlasenko12014262011-05-30 14:00:14 +02002206sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207{
2208 if (entering(tcp)) {
2209 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002210 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00002211 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00002212 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 }
2214 return 0;
2215}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002216
2217#if UNIXWARE >= 7
2218
Roland McGrathd9f816f2004-09-04 03:39:20 +00002219static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002220 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2221 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2222 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2223 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2224 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2225 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002226 { 0, NULL },
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002227};
2228
2229
2230int
Denys Vlasenko12014262011-05-30 14:00:14 +02002231netlib_call(struct tcb *tcp, int (*func)())
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002232{
2233 if (entering(tcp)) {
2234 int i;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002235 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002236 tprintf(", ");
2237 --tcp->u_nargs;
2238 for (i = 0; i < tcp->u_nargs; i++)
2239 tcp->u_arg[i] = tcp->u_arg[i + 1];
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002240 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002241 }
2242
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002243 return func(tcp);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002244}
2245
2246int
Denys Vlasenko12014262011-05-30 14:00:14 +02002247sys_xsocket(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002248{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002249 return netlib_call(tcp, sys_socket);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002250}
2251
2252int
Denys Vlasenko12014262011-05-30 14:00:14 +02002253sys_xsocketpair(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002254{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002255 return netlib_call(tcp, sys_socketpair);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002256}
2257
2258int
Denys Vlasenko12014262011-05-30 14:00:14 +02002259sys_xbind(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002260{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002261 return netlib_call(tcp, sys_bind);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002262}
2263
2264int
Denys Vlasenko12014262011-05-30 14:00:14 +02002265sys_xconnect(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002266{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002267 return netlib_call(tcp, sys_connect);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002268}
2269
2270int
Denys Vlasenko12014262011-05-30 14:00:14 +02002271sys_xlisten(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002272{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002273 return netlib_call(tcp, sys_listen);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002274}
2275
2276int
Denys Vlasenko12014262011-05-30 14:00:14 +02002277sys_xaccept(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002278{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002279 return netlib_call(tcp, sys_accept);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002280}
2281
2282int
Denys Vlasenko12014262011-05-30 14:00:14 +02002283sys_xsendmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002284{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002285 return netlib_call(tcp, sys_sendmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002286}
2287
2288int
Denys Vlasenko12014262011-05-30 14:00:14 +02002289sys_xrecvmsg(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002290{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002291 return netlib_call(tcp, sys_recvmsg);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002292}
2293
2294int
Denys Vlasenko12014262011-05-30 14:00:14 +02002295sys_xgetsockaddr(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002296{
2297 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002298 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002299 tprintf(", ");
2300 if (tcp->u_arg[1] == 0) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002301 tprintf("LOCALNAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002302 }
2303 else if (tcp->u_arg[1] == 1) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002304 tprintf("REMOTENAME, ");
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002305 }
2306 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002307 tprintf("%ld, ", tcp->u_arg[1]);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002308 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002309 tprintf("%ld, ", tcp->u_arg[2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00002310 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002311 else {
2312 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2313 tprintf("%#lx", tcp->u_arg[3]);
2314 } else {
2315 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2316 }
2317 tprintf(", ");
2318 printnum(tcp, tcp->u_arg[4], "%lu");
2319 }
2320
2321 return 0;
2322
2323}
2324
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002325int
Denys Vlasenko12014262011-05-30 14:00:14 +02002326sys_xgetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002327{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002328 return netlib_call(tcp, sys_getsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002329}
2330
2331int
Denys Vlasenko12014262011-05-30 14:00:14 +02002332sys_xsetsockopt(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002333{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002334 return netlib_call(tcp, sys_setsockopt);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002335}
2336
2337int
Denys Vlasenko12014262011-05-30 14:00:14 +02002338sys_xshutdown(struct tcb *tcp)
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002339{
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002340 return netlib_call(tcp, sys_shutdown);
Wichert Akkerman16a03d22000-08-10 02:14:04 +00002341}
2342
Dmitry V. Levine5e60852009-12-31 22:50:49 +00002343#endif /* UNIXWARE */