blob: 9d2b9f9e583db21def43fa7c8ed17c875d3a430f [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/stat.h>
36#include <sys/socket.h>
37#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000038
39#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40#define in6_addr in6_addr_libc
41#define ipv6_mreq ipv6_mreq_libc
42#define sockaddr_in6 sockaddr_in6_libc
43#endif
44
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000047#include <netinet/tcp.h>
48#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000049#ifdef HAVE_NETINET_UDP_H
50#include <netinet/udp.h>
51#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000053#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054#if defined(LINUX)
55#include <asm/types.h>
56#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
57# include <netipx/ipx.h>
58#else
59# include <linux/ipx.h>
60#endif
61#endif /* LINUX */
62
Wichert Akkermanf1850652001-02-16 20:29:03 +000063#if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000064#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000065#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
66#undef in6_addr
67#undef ipv6_mreq
68#undef sockaddr_in6
69#define in6_addr in6_addr_kernel
70#define ipv6_mreq ipv6_mreq_kernel
71#define sockaddr_in6 sockaddr_in6_kernel
72#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000073#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000074#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
75#undef in6_addr
76#undef ipv6_mreq
77#undef sockaddr_in6
78#define in6_addr in6_addr_libc
79#define ipv6_mreq ipv6_mreq_libc
80#define sockaddr_in6 sockaddr_in6_kernel
81#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000082#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000083#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000084
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#if defined(HAVE_SYS_UIO_H)
86#include <sys/uio.h>
87#endif
88
89#if defined(HAVE_LINUX_NETLINK_H)
90#include <linux/netlink.h>
91#endif
92
93#if defined(HAVE_LINUX_IF_PACKET_H)
94#include <linux/if_packet.h>
95#endif
96
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000097#if defined(HAVE_LINUX_ICMP_H)
98#include <linux/icmp.h>
99#endif
100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101#ifndef PF_UNSPEC
102#define PF_UNSPEC AF_UNSPEC
103#endif
104
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000105#if UNIXWARE >= 7
106#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
107#endif
108
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#ifdef LINUX
110/* Under Linux these are enums so we can't test for them with ifdef. */
111#define IPPROTO_EGP IPPROTO_EGP
112#define IPPROTO_PUP IPPROTO_PUP
113#define IPPROTO_IDP IPPROTO_IDP
114#define IPPROTO_IGMP IPPROTO_IGMP
115#define IPPROTO_RAW IPPROTO_RAW
116#define IPPROTO_MAX IPPROTO_MAX
117#endif
118
Roland McGrathd9f816f2004-09-04 03:39:20 +0000119static const struct xlat domains[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000120#ifdef PF_AAL5
121 { PF_AAL5, "PF_AAL5" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#endif
123#ifdef PF_APPLETALK
124 { PF_APPLETALK, "PF_APPLETALK" },
125#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000126#ifdef PF_ASH
127 { PF_ASH, "PF_ASH" },
128#endif
129#ifdef PF_ATMPVC
130 { PF_ATMPVC, "PF_ATMPVC" },
131#endif
132#ifdef PF_ATMSVC
133 { PF_ATMSVC, "PF_ATMSVC" },
134#endif
135#ifdef PF_AX25
136 { PF_AX25, "PF_AX25" },
137#endif
138#ifdef PF_BLUETOOTH
139 { PF_BLUETOOTH, "PF_BLUETOOTH" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140#endif
141#ifdef PF_BRIDGE
142 { PF_BRIDGE, "PF_BRIDGE" },
143#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000144#ifdef PF_DECnet
145 { PF_DECnet, "PF_DECnet" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146#endif
147#ifdef PF_DECNET
148 { PF_DECNET, "PF_DECNET" },
149#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000150#ifdef PF_ECONET
151 { PF_ECONET, "PF_ECONET" },
152#endif
153#ifdef PF_FILE
154 { PF_FILE, "PF_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#endif
156#ifdef PF_IMPLINK
157 { PF_IMPLINK, "PF_IMPLINK" },
158#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000159#ifdef PF_INET
160 { PF_INET, "PF_INET" },
161#endif
162#ifdef PF_INET6
163 { PF_INET6, "PF_INET6" },
164#endif
165#ifdef PF_IPX
166 { PF_IPX, "PF_IPX" },
167#endif
168#ifdef PF_IRDA
169 { PF_IRDA, "PF_IRDA" },
170#endif
171#ifdef PF_ISO
172 { PF_ISO, "PF_ISO" },
173#endif
174#ifdef PF_KEY
175 { PF_KEY, "PF_KEY" },
176#endif
177#ifdef PF_UNIX
178 { PF_UNIX, "PF_UNIX" },
179#endif
180#ifdef PF_LOCAL
181 { PF_LOCAL, "PF_LOCAL" },
182#endif
183#ifdef PF_NETBEUI
184 { PF_NETBEUI, "PF_NETBEUI" },
185#endif
186#ifdef PF_NETLINK
187 { PF_NETLINK, "PF_NETLINK" },
188#endif
189#ifdef PF_NETROM
190 { PF_NETROM, "PF_NETROM" },
191#endif
192#ifdef PF_PACKET
193 { PF_PACKET, "PF_PACKET" },
194#endif
195#ifdef PF_PPPOX
196 { PF_PPPOX, "PF_PPPOX" },
197#endif
198#ifdef PF_ROSE
199 { PF_ROSE, "PF_ROSE" },
200#endif
201#ifdef PF_ROUTE
202 { PF_ROUTE, "PF_ROUTE" },
203#endif
204#ifdef PF_SECURITY
205 { PF_SECURITY, "PF_SECURITY" },
206#endif
207#ifdef PF_SNA
208 { PF_SNA, "PF_SNA" },
209#endif
210#ifdef PF_UNSPEC
211 { PF_UNSPEC, "PF_UNSPEC" },
212#endif
213#ifdef PF_WANPIPE
214 { PF_WANPIPE, "PF_WANPIPE" },
215#endif
216#ifdef PF_X25
217 { PF_X25, "PF_X25" },
218#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 { 0, NULL },
220};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000221const struct xlat addrfams[] = {
Roland McGrath5a8146a2004-06-04 02:24:14 +0000222#ifdef AF_APPLETALK
223 { AF_APPLETALK, "AF_APPLETALK" },
224#endif
225#ifdef AF_ASH
226 { AF_ASH, "AF_ASH" },
227#endif
228#ifdef AF_ATMPVC
229 { AF_ATMPVC, "AF_ATMPVC" },
230#endif
231#ifdef AF_ATMSVC
232 { AF_ATMSVC, "AF_ATMSVC" },
233#endif
234#ifdef AF_AX25
235 { AF_AX25, "AF_AX25" },
236#endif
237#ifdef AF_BLUETOOTH
238 { AF_BLUETOOTH, "AF_BLUETOOTH" },
239#endif
240#ifdef AF_BRIDGE
241 { AF_BRIDGE, "AF_BRIDGE" },
242#endif
243#ifdef AF_DECnet
244 { AF_DECnet, "AF_DECnet" },
245#endif
246#ifdef AF_ECONET
247 { AF_ECONET, "AF_ECONET" },
248#endif
249#ifdef AF_FILE
250 { AF_FILE, "AF_FILE" },
251#endif
252#ifdef AF_IMPLINK
253 { AF_IMPLINK, "AF_IMPLINK" },
254#endif
255#ifdef AF_INET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000256 { AF_INET, "AF_INET" },
Roland McGrath5a8146a2004-06-04 02:24:14 +0000257#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000258#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000260#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000261#ifdef AF_IPX
262 { AF_IPX, "AF_IPX" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000263#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000264#ifdef AF_IRDA
265 { AF_IRDA, "AF_IRDA" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000266#endif
267#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000268 { AF_ISO, "AF_ISO" },
269#endif
Roland McGrath5a8146a2004-06-04 02:24:14 +0000270#ifdef AF_KEY
271 { AF_KEY, "AF_KEY" },
272#endif
273#ifdef AF_UNIX
274 { AF_UNIX, "AF_UNIX" },
275#endif
276#ifdef AF_LOCAL
277 { AF_LOCAL, "AF_LOCAL" },
278#endif
279#ifdef AF_NETBEUI
280 { AF_NETBEUI, "AF_NETBEUI" },
281#endif
282#ifdef AF_NETLINK
283 { AF_NETLINK, "AF_NETLINK" },
284#endif
285#ifdef AF_NETROM
286 { AF_NETROM, "AF_NETROM" },
287#endif
288#ifdef AF_PACKET
289 { AF_PACKET, "AF_PACKET" },
290#endif
291#ifdef AF_PPPOX
292 { AF_PPPOX, "AF_PPPOX" },
293#endif
294#ifdef AF_ROSE
295 { AF_ROSE, "AF_ROSE" },
296#endif
297#ifdef AF_ROUTE
298 { AF_ROUTE, "AF_ROUTE" },
299#endif
300#ifdef AF_SECURITY
301 { AF_SECURITY, "AF_SECURITY" },
302#endif
303#ifdef AF_SNA
304 { AF_SNA, "AF_SNA" },
305#endif
306#ifdef AF_UNSPEC
307 { AF_UNSPEC, "AF_UNSPEC" },
308#endif
309#ifdef AF_WANPIPE
310 { AF_WANPIPE, "AF_WANPIPE" },
311#endif
312#ifdef AF_X25
313 { AF_X25, "AF_X25" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000314#endif
315 { 0, NULL },
316};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000317static const struct xlat socktypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 { SOCK_STREAM, "SOCK_STREAM" },
319 { SOCK_DGRAM, "SOCK_DGRAM" },
320#ifdef SOCK_RAW
321 { SOCK_RAW, "SOCK_RAW" },
322#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000323#ifdef SOCK_RDM
324 { SOCK_RDM, "SOCK_RDM" },
325#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326#ifdef SOCK_SEQPACKET
327 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
328#endif
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000329#ifdef SOCK_DCCP
330 { SOCK_DCCP, "SOCK_DCCP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331#endif
332#ifdef SOCK_PACKET
333 { SOCK_PACKET, "SOCK_PACKET" },
334#endif
335 { 0, NULL },
336};
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000337const struct xlat sock_type_flags[] = {
338#ifdef SOCK_CLOEXEC
339 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
340#endif
341#ifdef SOCK_NONBLOCK
342 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
343#endif
344 { 0, NULL },
345};
346#ifndef SOCK_TYPE_MASK
347# define SOCK_TYPE_MASK 0xf
348#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000349static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000350#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000351 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000352#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000353#if defined(SOL_ICMP)
354 { SOL_ICMP, "SOL_ICMP" },
355#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000356#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000357 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000358#endif
359#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000360 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000361#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000362#if defined(SOL_IPV6)
363 { SOL_IPV6, "SOL_IPV6" },
364#endif
365#if defined(SOL_ICMPV6)
366 { SOL_ICMPV6, "SOL_ICMPV6" },
367#endif
368#if defined(SOL_RAW)
369 { SOL_RAW, "SOL_RAW" },
370#endif
371#if defined(SOL_IPX)
372 { SOL_IPX, "SOL_IPX" },
373#endif
374#if defined(SOL_IPX)
375 { SOL_IPX, "SOL_IPX" },
376#endif
377#if defined(SOL_AX25)
378 { SOL_AX25, "SOL_AX25" },
379#endif
380#if defined(SOL_ATALK)
381 { SOL_ATALK, "SOL_ATALK" },
382#endif
383#if defined(SOL_NETROM)
384 { SOL_NETROM, "SOL_NETROM" },
385#endif
386#if defined(SOL_ROSE)
387 { SOL_ROSE, "SOL_ROSE" },
388#endif
389#if defined(SOL_DECNET)
390 { SOL_DECNET, "SOL_DECNET" },
391#endif
392#if defined(SOL_X25)
393 { SOL_X25, "SOL_X25" },
394#endif
395#if defined(SOL_PACKET)
396 { SOL_PACKET, "SOL_PACKET" },
397#endif
398#if defined(SOL_ATM)
399 { SOL_ATM, "SOL_ATM" },
400#endif
401#if defined(SOL_AAL)
402 { SOL_AAL, "SOL_AAL" },
403#endif
404#if defined(SOL_IRDA)
405 { SOL_IRDA, "SOL_IRDA" },
406#endif
John Hughes61563572001-03-27 16:47:36 +0000407 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000408};
John Hughes93f7fcc2002-05-22 15:46:49 +0000409/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
410 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000411static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 { IPPROTO_IP, "IPPROTO_IP" },
413 { IPPROTO_ICMP, "IPPROTO_ICMP" },
414 { IPPROTO_TCP, "IPPROTO_TCP" },
415 { IPPROTO_UDP, "IPPROTO_UDP" },
416#ifdef IPPROTO_GGP
417 { IPPROTO_GGP, "IPPROTO_GGP" },
418#endif
419#ifdef IPPROTO_EGP
420 { IPPROTO_EGP, "IPPROTO_EGP" },
421#endif
422#ifdef IPPROTO_PUP
423 { IPPROTO_PUP, "IPPROTO_PUP" },
424#endif
425#ifdef IPPROTO_IDP
426 { IPPROTO_IDP, "IPPROTO_IDP" },
427#endif
428#ifdef IPPROTO_IPV6
429 { IPPROTO_IPV6, "IPPROTO_IPV6" },
430#endif
431#ifdef IPPROTO_ICMPV6
432 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
433#endif
434#ifdef IPPROTO_IGMP
435 { IPPROTO_IGMP, "IPPROTO_IGMP" },
436#endif
437#ifdef IPPROTO_HELLO
438 { IPPROTO_HELLO,"IPPROTO_HELLO" },
439#endif
440#ifdef IPPROTO_ND
441 { IPPROTO_ND, "IPPROTO_ND" },
442#endif
443#ifdef IPPROTO_RAW
444 { IPPROTO_RAW, "IPPROTO_RAW" },
445#endif
446#ifdef IPPROTO_MAX
447 { IPPROTO_MAX, "IPPROTO_MAX" },
448#endif
449#ifdef IPPROTO_IPIP
450 { IPPROTO_IPIP, "IPPROTO_IPIP" },
451#endif
452 { 0, NULL },
453};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000454static const struct xlat msg_flags[] = {
Roland McGrath71d3d662007-08-07 01:00:26 +0000455 { MSG_OOB, "MSG_OOB" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456#ifdef MSG_DONTROUTE
Roland McGrath71d3d662007-08-07 01:00:26 +0000457 { MSG_DONTROUTE, "MSG_DONTROUTE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458#endif
459#ifdef MSG_PEEK
Roland McGrath71d3d662007-08-07 01:00:26 +0000460 { MSG_PEEK, "MSG_PEEK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461#endif
462#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000463 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464#endif
465#ifdef MSG_PROXY
Roland McGrath71d3d662007-08-07 01:00:26 +0000466 { MSG_PROXY, "MSG_PROXY" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467#endif
468#ifdef MSG_EOR
Roland McGrath71d3d662007-08-07 01:00:26 +0000469 { MSG_EOR, "MSG_EOR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470#endif
471#ifdef MSG_WAITALL
Roland McGrath71d3d662007-08-07 01:00:26 +0000472 { MSG_WAITALL, "MSG_WAITALL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000474#ifdef MSG_TRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000475 { MSG_TRUNC, "MSG_TRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000476#endif
477#ifdef MSG_CTRUNC
Roland McGrath71d3d662007-08-07 01:00:26 +0000478 { MSG_CTRUNC, "MSG_CTRUNC" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000479#endif
480#ifdef MSG_ERRQUEUE
Roland McGrath71d3d662007-08-07 01:00:26 +0000481 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000482#endif
483#ifdef MSG_DONTWAIT
Roland McGrath71d3d662007-08-07 01:00:26 +0000484 { MSG_DONTWAIT, "MSG_DONTWAIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000485#endif
486#ifdef MSG_CONFIRM
Roland McGrath71d3d662007-08-07 01:00:26 +0000487 { MSG_CONFIRM, "MSG_CONFIRM" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000488#endif
489#ifdef MSG_PROBE
Roland McGrath71d3d662007-08-07 01:00:26 +0000490 { MSG_PROBE, "MSG_PROBE" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000491#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000492#ifdef MSG_FIN
Roland McGrath71d3d662007-08-07 01:00:26 +0000493 { MSG_FIN, "MSG_FIN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000494#endif
495#ifdef MSG_SYN
Roland McGrath71d3d662007-08-07 01:00:26 +0000496 { MSG_SYN, "MSG_SYN" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000497#endif
498#ifdef MSG_RST
Roland McGrath71d3d662007-08-07 01:00:26 +0000499 { MSG_RST, "MSG_RST" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000500#endif
501#ifdef MSG_NOSIGNAL
Roland McGrath71d3d662007-08-07 01:00:26 +0000502 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000503#endif
504#ifdef MSG_MORE
Roland McGrath71d3d662007-08-07 01:00:26 +0000505 { MSG_MORE, "MSG_MORE" },
Roland McGrath05e5e792004-04-14 02:53:54 +0000506#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000507#ifdef MSG_CMSG_CLOEXEC
508 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
509#endif
510 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511};
512
Roland McGrathd9f816f2004-09-04 03:39:20 +0000513static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000515 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000516#endif
517#ifdef SO_ALLRAW
518 { SO_ALLRAW, "SO_ALLRAW" },
519#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000520#ifdef SO_ATTACH_FILTER
521 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
522#endif
523#ifdef SO_BINDTODEVICE
524 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
525#endif
526#ifdef SO_BROADCAST
527 { SO_BROADCAST, "SO_BROADCAST" },
528#endif
529#ifdef SO_BSDCOMPAT
530 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
531#endif
532#ifdef SO_DEBUG
533 { SO_DEBUG, "SO_DEBUG" },
534#endif
535#ifdef SO_DETACH_FILTER
536 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
537#endif
538#ifdef SO_DONTROUTE
539 { SO_DONTROUTE, "SO_DONTROUTE" },
540#endif
541#ifdef SO_ERROR
542 { SO_ERROR, "SO_ERROR" },
543#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000544#ifdef SO_ICS
545 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000547#ifdef SO_IMASOCKET
548 { SO_IMASOCKET, "SO_IMASOCKET" },
549#endif
550#ifdef SO_KEEPALIVE
551 { SO_KEEPALIVE, "SO_KEEPALIVE" },
552#endif
553#ifdef SO_LINGER
554 { SO_LINGER, "SO_LINGER" },
555#endif
556#ifdef SO_LISTENING
557 { SO_LISTENING, "SO_LISTENING" },
558#endif
559#ifdef SO_MGMT
560 { SO_MGMT, "SO_MGMT" },
561#endif
562#ifdef SO_NO_CHECK
563 { SO_NO_CHECK, "SO_NO_CHECK" },
564#endif
565#ifdef SO_OOBINLINE
566 { SO_OOBINLINE, "SO_OOBINLINE" },
567#endif
568#ifdef SO_ORDREL
569 { SO_ORDREL, "SO_ORDREL" },
570#endif
571#ifdef SO_PARALLELSVR
572 { SO_PARALLELSVR, "SO_PARALLELSVR" },
573#endif
574#ifdef SO_PASSCRED
575 { SO_PASSCRED, "SO_PASSCRED" },
576#endif
577#ifdef SO_PEERCRED
578 { SO_PEERCRED, "SO_PEERCRED" },
579#endif
580#ifdef SO_PEERNAME
581 { SO_PEERNAME, "SO_PEERNAME" },
582#endif
583#ifdef SO_PEERSEC
584 { SO_PEERSEC, "SO_PEERSEC" },
585#endif
586#ifdef SO_PRIORITY
587 { SO_PRIORITY, "SO_PRIORITY" },
588#endif
589#ifdef SO_PROTOTYPE
590 { SO_PROTOTYPE, "SO_PROTOTYPE" },
591#endif
592#ifdef SO_RCVBUF
593 { SO_RCVBUF, "SO_RCVBUF" },
594#endif
595#ifdef SO_RCVLOWAT
596 { SO_RCVLOWAT, "SO_RCVLOWAT" },
597#endif
598#ifdef SO_RCVTIMEO
599 { SO_RCVTIMEO, "SO_RCVTIMEO" },
600#endif
601#ifdef SO_RDWR
602 { SO_RDWR, "SO_RDWR" },
603#endif
604#ifdef SO_REUSEADDR
605 { SO_REUSEADDR, "SO_REUSEADDR" },
606#endif
607#ifdef SO_REUSEPORT
608 { SO_REUSEPORT, "SO_REUSEPORT" },
609#endif
610#ifdef SO_SECURITY_AUTHENTICATION
611 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
612#endif
613#ifdef SO_SECURITY_ENCRYPTION_NETWORK
614 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
615#endif
616#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
617 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
618#endif
619#ifdef SO_SEMA
620 { SO_SEMA, "SO_SEMA" },
621#endif
622#ifdef SO_SNDBUF
623 { SO_SNDBUF, "SO_SNDBUF" },
624#endif
625#ifdef SO_SNDLOWAT
626 { SO_SNDLOWAT, "SO_SNDLOWAT" },
627#endif
628#ifdef SO_SNDTIMEO
629 { SO_SNDTIMEO, "SO_SNDTIMEO" },
630#endif
631#ifdef SO_TIMESTAMP
632 { SO_TIMESTAMP, "SO_TIMESTAMP" },
633#endif
634#ifdef SO_TYPE
635 { SO_TYPE, "SO_TYPE" },
636#endif
637#ifdef SO_USELOOPBACK
638 { SO_USELOOPBACK, "SO_USELOOPBACK" },
639#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 { 0, NULL },
641};
642
John Hughes93f7fcc2002-05-22 15:46:49 +0000643#if !defined (SOL_IP) && defined (IPPROTO_IP)
644#define SOL_IP IPPROTO_IP
645#endif
646
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000648static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000649#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000650 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000651#endif
652#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000653 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000654#endif
655#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000656 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000658#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000659 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000661#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000662 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000663#endif
664#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000665 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
666#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000667#ifdef IP_RECVOPTS
668 { IP_RECVOPTS, "IP_RECVOPTS" },
669#endif
670#ifdef IP_RECVRETOPTS
671 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
672#endif
673#ifdef IP_RECVDSTADDR
674 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
675#endif
676#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000677 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000678#endif
679#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000680 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000681#endif
682#ifdef IP_PKTOPTIONS
683 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
684#endif
685#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000686 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000687#endif
688#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000689 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000690#endif
691#ifdef IP_RECVTTL
Roland McGrath04ac03a2005-07-04 23:30:27 +0000692 { IP_RECVTTL, "IP_RECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000693#endif
694#ifdef IP_RECVTOS
Roland McGrath04ac03a2005-07-04 23:30:27 +0000695 { IP_RECVTOS, "IP_RECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000696#endif
697#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000698 { IP_MTU, "IP_MTU" },
699#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000700#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000701 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000702#endif
703#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000704 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000705#endif
706#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000707 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000708#endif
709#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000710 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000711#endif
712#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000713 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000714#endif
715#ifdef IP_BROADCAST_IF
716 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
717#endif
718#ifdef IP_RECVIFINDEX
719 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
720#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000721#ifdef IP_MSFILTER
722 { IP_MSFILTER, "IP_MSFILTER" },
723#endif
724#ifdef MCAST_MSFILTER
725 { MCAST_MSFILTER, "MCAST_MSFILTER" },
726#endif
727#ifdef IP_FREEBIND
728 { IP_FREEBIND, "IP_FREEBIND" },
729#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000730 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731};
732#endif /* SOL_IP */
733
Roland McGrath4f6ba692004-08-31 07:01:26 +0000734#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000735static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000736#ifdef IPV6_ADDRFORM
737 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
738#endif
739#ifdef MCAST_FILTER
740 { MCAST_FILTER, "MCAST_FILTER" },
741#endif
742#ifdef IPV6_PKTOPTIONS
743 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
744#endif
745#ifdef IPV6_MTU
746 { IPV6_MTU, "IPV6_MTU" },
747#endif
748#ifdef IPV6_V6ONLY
749 { IPV6_V6ONLY, "IPV6_V6ONLY" },
750#endif
751#ifdef IPV6_PKTINFO
752 { IPV6_PKTINFO, "IPV6_PKTINFO" },
753#endif
754#ifdef IPV6_HOPLIMIT
755 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
756#endif
757#ifdef IPV6_RTHDR
758 { IPV6_RTHDR, "IPV6_RTHDR" },
759#endif
760#ifdef IPV6_HOPOPTS
761 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
762#endif
763#ifdef IPV6_DSTOPTS
764 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
765#endif
766#ifdef IPV6_FLOWINFO
767 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
768#endif
769#ifdef IPV6_UNICAST_HOPS
770 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
771#endif
772#ifdef IPV6_MULTICAST_HOPS
773 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
774#endif
775#ifdef IPV6_MULTICAST_LOOP
776 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
777#endif
778#ifdef IPV6_MULTICAST_IF
779 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
780#endif
781#ifdef IPV6_MTU_DISCOVER
782 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
783#endif
784#ifdef IPV6_RECVERR
785 { IPV6_RECVERR, "IPV6_RECVERR" },
786#endif
787#ifdef IPV6_FLOWINFO_SEND
788 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
789#endif
Roland McGrathc0b9e372005-07-04 23:33:38 +0000790#ifdef IPV6_ADD_MEMBERSHIP
791 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
792#endif
793#ifdef IPV6_DROP_MEMBERSHIP
794 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
795#endif
796#ifdef IPV6_ROUTER_ALERT
797 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
798#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000799 { 0, NULL },
800};
801#endif /* SOL_IPV6 */
802
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000803#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000804static const struct xlat sockipxoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000805 { IPX_TYPE, "IPX_TYPE" },
806 { 0, NULL },
807};
808#endif /* SOL_IPX */
809
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000810#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000811static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000812#if defined(ICMP_FILTER)
813 { ICMP_FILTER, "ICMP_FILTER" },
814#endif
815 { 0, NULL },
816};
817#endif /* SOL_RAW */
818
819#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000820static const struct xlat sockpacketoptions[] = {
Roland McGrathc294b8f2007-11-01 21:37:33 +0000821#ifdef PACKET_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000822 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
Roland McGrathc294b8f2007-11-01 21:37:33 +0000823#endif
824#ifdef PACKET_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000825 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
Roland McGrathc294b8f2007-11-01 21:37:33 +0000826#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000827#if defined(PACKET_RECV_OUTPUT)
828 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
829#endif
830#if defined(PACKET_RX_RING)
831 { PACKET_RX_RING, "PACKET_RX_RING" },
832#endif
833#if defined(PACKET_STATISTICS)
834 { PACKET_STATISTICS, "PACKET_STATISTICS" },
835#endif
836 { 0, NULL },
837};
838#endif /* SOL_PACKET */
839
John Hughes93f7fcc2002-05-22 15:46:49 +0000840#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
841#define SOL_TCP IPPROTO_TCP
842#endif
843
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000844#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000845static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000846 { TCP_NODELAY, "TCP_NODELAY" },
847 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000848#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000849 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000850#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000851#if defined(TCP_KEEPIDLE)
852 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
853#endif
854#if defined(TCP_KEEPINTVL)
855 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
856#endif
857#if defined(TCP_KEEPCNT)
858 { TCP_KEEPCNT, "TCP_KEEPCNT" },
859#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000860#if defined(TCP_NKEEP)
861 { TCP_NKEEP, "TCP_NKEEP" },
862#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000863#if defined(TCP_SYNCNT)
864 { TCP_SYNCNT, "TCP_SYNCNT" },
865#endif
866#if defined(TCP_LINGER2)
867 { TCP_LINGER2, "TCP_LINGER2" },
868#endif
869#if defined(TCP_DEFER_ACCEPT)
870 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
871#endif
872#if defined(TCP_WINDOW_CLAMP)
873 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
874#endif
875#if defined(TCP_INFO)
876 { TCP_INFO, "TCP_INFO" },
877#endif
878#if defined(TCP_QUICKACK)
879 { TCP_QUICKACK, "TCP_QUICKACK" },
880#endif
881 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882};
883#endif /* SOL_TCP */
884
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000885#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000886static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000887#if defined(ICMP_ECHOREPLY)
888 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
889#endif
890#if defined(ICMP_DEST_UNREACH)
891 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
892#endif
893#if defined(ICMP_SOURCE_QUENCH)
894 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
895#endif
896#if defined(ICMP_REDIRECT)
897 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
898#endif
899#if defined(ICMP_ECHO)
900 { (1<<ICMP_ECHO), "ICMP_ECHO" },
901#endif
902#if defined(ICMP_TIME_EXCEEDED)
903 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
904#endif
905#if defined(ICMP_PARAMETERPROB)
906 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
907#endif
908#if defined(ICMP_TIMESTAMP)
909 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
910#endif
911#if defined(ICMP_TIMESTAMPREPLY)
912 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
913#endif
914#if defined(ICMP_INFO_REQUEST)
915 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
916#endif
917#if defined(ICMP_INFO_REPLY)
918 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
919#endif
920#if defined(ICMP_ADDRESS)
921 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
922#endif
923#if defined(ICMP_ADDRESSREPLY)
924 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
925#endif
926 { 0, NULL },
927};
928#endif /* SOL_RAW */
929
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000930#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +0000931static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000932#if defined(PACKET_HOST)
933 { PACKET_HOST, "PACKET_HOST" },
934#endif
935#if defined(PACKET_BROADCAST)
936 { PACKET_BROADCAST, "PACKET_BROADCAST" },
937#endif
938#if defined(PACKET_MULTICAST)
939 { PACKET_MULTICAST, "PACKET_MULTICAST" },
940#endif
941#if defined(PACKET_OTHERHOST)
942 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
943#endif
944#if defined(PACKET_OUTGOING)
945 { PACKET_OUTGOING, "PACKET_OUTGOING" },
946#endif
947#if defined(PACKET_LOOPBACK)
948 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
949#endif
950#if defined(PACKET_FASTROUTE)
951 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
952#endif
953 { 0, NULL },
954};
955#endif /* defined(AF_PACKET) */
956
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000957
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000959printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000961 union {
962 char pad[128];
963 struct sockaddr sa;
964 struct sockaddr_in sin;
965 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000966#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000967 struct sockaddr_in6 sa6;
968#endif
969#if defined(LINUX) && defined(AF_IPX)
970 struct sockaddr_ipx sipx;
971#endif
972#ifdef AF_PACKET
973 struct sockaddr_ll ll;
974#endif
975#ifdef AF_NETLINK
976 struct sockaddr_nl nl;
977#endif
978 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000979 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980
981 if (addr == 0) {
982 tprintf("NULL");
983 return;
984 }
985 if (!verbose(tcp)) {
986 tprintf("%#lx", addr);
987 return;
988 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000989
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000990 if (addrlen < 2 || addrlen > sizeof(addrbuf))
991 addrlen = sizeof(addrbuf);
992
993 memset(&addrbuf, 0, sizeof(addrbuf));
994 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 tprintf("{...}");
996 return;
997 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000998 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000999
John Hughes1fcb1d62001-09-18 15:56:53 +00001000 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001001 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1002 tprintf(", ");
1003
1004 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001006 if (addrlen == 2) {
1007 tprintf("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001008 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001009 tprintf("path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001010 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001011 } else {
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +00001012 tprintf("path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +00001013 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001014 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 break;
1016 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +00001017 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001018 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001020#ifdef HAVE_INET_NTOP
1021 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001022 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +00001023 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1024 ntohs(addrbuf.sa6.sin6_port), string_addr,
1025 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001026#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +00001027 {
1028#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1029 int numericscope = 0;
1030 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1031 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1032 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001033
Wichert Akkermanf1850652001-02-16 20:29:03 +00001034 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1035 numericscope++;
1036 else
1037 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1038 } else
1039 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001040
Wichert Akkermanf1850652001-02-16 20:29:03 +00001041 if (numericscope)
1042#endif
1043 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1044 }
1045#endif
1046 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001047#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001048#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001049 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001050 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001052 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001053 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 /* Yes, I know, this does not look too
1055 * strace-ish, but otherwise the IPX
1056 * addresses just look monstrous...
1057 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001058 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001060 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001062 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1063 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064 }
1065 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001066#endif /* AF_IPX && linux */
1067#ifdef AF_PACKET
1068 case AF_PACKET:
1069 {
1070 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001071 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001072 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001073 addrbuf.ll.sll_ifindex);
1074 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1075 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001076 addrbuf.ll.sll_halen,
1077 addrbuf.ll.sll_hatype);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001078 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001079 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1080 }
1081 break;
1082
1083#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001084#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001085 case AF_NETLINK:
1086 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1087 break;
1088#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001090 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091
1092 default:
John Hughes1fcb1d62001-09-18 15:56:53 +00001093 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001095 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096 break;
1097 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001098 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099}
1100
1101#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001102static const struct xlat scmvals[] = {
1103#ifdef SCM_RIGHTS
1104 { SCM_RIGHTS, "SCM_RIGHTS" },
1105#endif
1106#ifdef SCM_CREDENTIALS
1107 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1108#endif
1109 { 0, NULL }
1110};
1111
1112static void
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001113printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
Roland McGrath50770822004-10-06 22:11:51 +00001114{
Roland McGrathaa524c82005-06-01 19:22:06 +00001115 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1116 NULL : malloc(len);
1117 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +00001118 tprintf(", msg_control=%#lx", addr);
Roland McGrathaa524c82005-06-01 19:22:06 +00001119 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001120 return;
1121 }
1122
Denys Vlasenko132c52a2009-03-23 13:12:46 +00001123 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
Roland McGrathaa524c82005-06-01 19:22:06 +00001124 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
Roland McGrath50770822004-10-06 22:11:51 +00001125 tprintf(", cmsg_type=");
1126
Roland McGrathaa524c82005-06-01 19:22:06 +00001127 if (cmsg->cmsg_level == SOL_SOCKET) {
1128 unsigned long cmsg_len;
Roland McGrath96ad7b82005-02-02 03:11:32 +00001129
Roland McGrathaa524c82005-06-01 19:22:06 +00001130 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1131 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1132
1133 if (cmsg->cmsg_type == SCM_RIGHTS
1134 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1135 int *fds = (int *) CMSG_DATA (cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001136 int first = 1;
Roland McGrathaa524c82005-06-01 19:22:06 +00001137
Roland McGrath50770822004-10-06 22:11:51 +00001138 tprintf(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +00001139 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
Roland McGrath50770822004-10-06 22:11:51 +00001140 if (!first)
1141 tprintf(", ");
1142 tprintf("%d", *fds++);
1143 first = 0;
1144 }
1145 tprintf("}}");
Roland McGrathaa524c82005-06-01 19:22:06 +00001146 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001147 return;
1148 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001149 if (cmsg->cmsg_type == SCM_CREDENTIALS
1150 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1151 struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1152
Roland McGrath50770822004-10-06 22:11:51 +00001153 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1154 (long)uc->pid, (long)uc->uid, (long)uc->gid);
Roland McGrathaa524c82005-06-01 19:22:06 +00001155 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001156 return;
1157 }
1158 }
Roland McGrathaa524c82005-06-01 19:22:06 +00001159 free(cmsg);
Roland McGrath50770822004-10-06 22:11:51 +00001160 tprintf(", ...}");
1161}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162
1163static void
1164printmsghdr(tcp, addr)
1165struct tcb *tcp;
1166long addr;
1167{
1168 struct msghdr msg;
1169
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001170 if (umove(tcp, addr, &msg) < 0) {
1171 tprintf("%#lx", addr);
1172 return;
1173 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001174 tprintf("{msg_name(%d)=", msg.msg_namelen);
1175 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
1176
1177 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
Roland McGrathaa524c82005-06-01 19:22:06 +00001178 tprint_iov(tcp, (unsigned long)msg.msg_iovlen,
1179 (unsigned long)msg.msg_iov);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001180
Roland McGrath6d2b3492002-12-30 00:51:30 +00001181#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001182 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001183 if (msg.msg_controllen)
Roland McGrath50770822004-10-06 22:11:51 +00001184 printcmsghdr(tcp, (unsigned long) msg.msg_control,
1185 msg.msg_controllen);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001186 tprintf(", msg_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001187 printflags(msg_flags, msg.msg_flags, "MSG_???");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001188#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001189 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001191#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001192 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001193}
1194
1195#endif /* HAVE_SENDMSG */
1196
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001197/*
1198 * low bits of the socket type define real socket type,
1199 * other bits are socket type flags.
1200 */
1201static void
1202tprint_sock_type(struct tcb *tcp, int flags)
1203{
1204 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1205
1206 if (str)
1207 {
1208 tprintf("%s", str);
1209 flags &= ~SOCK_TYPE_MASK;
1210 if (!flags)
1211 return;
1212 tprintf("|");
1213 }
1214 printflags(sock_type_flags, flags, "SOCK_???");
1215}
1216
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001218sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219{
1220 if (entering(tcp)) {
1221 printxval(domains, tcp->u_arg[0], "PF_???");
1222 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001223 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224 tprintf(", ");
1225 switch (tcp->u_arg[0]) {
1226 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001227#ifdef PF_INET6
1228 case PF_INET6:
1229#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001230 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1231 break;
1232#ifdef PF_IPX
1233 case PF_IPX:
1234 /* BTW: I don't believe this.. */
1235 tprintf("[");
1236 printxval(domains, tcp->u_arg[2], "PF_???");
1237 tprintf("]");
1238 break;
1239#endif /* PF_IPX */
1240 default:
1241 tprintf("%lu", tcp->u_arg[2]);
1242 break;
1243 }
1244 }
1245 return 0;
1246}
1247
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001248#ifdef SVR4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249int
John Hughesbdf48f52001-03-06 15:08:09 +00001250sys_so_socket(tcp)
1251struct tcb *tcp;
1252{
1253 if (entering(tcp)) {
1254 /* not sure really what these args are... but this
1255 * is how truss prints it
1256 */
1257 tprintf("%ld, %ld, %ld, ",
1258 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1259 printpath(tcp, tcp->u_arg[3]);
1260 tprintf(", %ld", tcp->u_arg[4]);
1261 }
1262 return 0;
1263}
1264
1265int
1266sys_so_socketpair(tcp)
1267struct tcb *tcp;
1268{
1269 if (entering(tcp)) {
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001270 /* not sure what this arg is */
John Hughesbdf48f52001-03-06 15:08:09 +00001271 tprintf("0x%lx", tcp->u_arg[0]);
1272 }
1273 return 0;
1274}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001275#endif /* SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00001276
1277int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278sys_bind(tcp)
1279struct tcb *tcp;
1280{
1281 if (entering(tcp)) {
1282 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001283 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284 tprintf(", %lu", tcp->u_arg[2]);
1285 }
1286 return 0;
1287}
1288
1289int
1290sys_connect(tcp)
1291struct tcb *tcp;
1292{
1293 return sys_bind(tcp);
1294}
1295
1296int
1297sys_listen(tcp)
1298struct tcb *tcp;
1299{
1300 if (entering(tcp)) {
1301 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1302 }
1303 return 0;
1304}
1305
Paolo Bonzini705ff102009-08-14 12:34:05 +02001306static int
1307do_accept(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308{
1309 if (entering(tcp)) {
1310 tprintf("%ld, ", tcp->u_arg[0]);
Paolo Bonzini705ff102009-08-14 12:34:05 +02001311 return 0;
1312 }
1313 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 tprintf("%#lx, NULL", tcp->u_arg[1]);
1315 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001316 int len;
1317 if (tcp->u_arg[1] == 0 || syserror(tcp)
1318 || umove (tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319 tprintf("%#lx", tcp->u_arg[1]);
1320 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001321 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001322 }
1323 tprintf(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +00001324 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325 }
Paolo Bonzini705ff102009-08-14 12:34:05 +02001326 if (flags_arg >= 0) {
1327 tprintf(", ");
1328 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1329 "SOCK_???");
1330 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 return 0;
1332}
1333
1334int
Paolo Bonzini705ff102009-08-14 12:34:05 +02001335sys_accept(struct tcb *tcp)
1336{
1337 return do_accept(tcp, -1);
1338}
1339
1340#ifdef LINUX
1341int
1342sys_accept4(struct tcb *tcp)
1343{
1344 return do_accept(tcp, 3);
1345}
1346#endif
1347
1348int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349sys_send(tcp)
1350struct tcb *tcp;
1351{
1352 if (entering(tcp)) {
1353 tprintf("%ld, ", tcp->u_arg[0]);
1354 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1355 tprintf(", %lu, ", tcp->u_arg[2]);
1356 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001357 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 }
1359 return 0;
1360}
1361
1362int
1363sys_sendto(tcp)
1364struct tcb *tcp;
1365{
1366 if (entering(tcp)) {
1367 tprintf("%ld, ", tcp->u_arg[0]);
1368 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1369 tprintf(", %lu, ", tcp->u_arg[2]);
1370 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001371 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 /* to address */
1373 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001374 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375 /* to length */
1376 tprintf(", %lu", tcp->u_arg[5]);
1377 }
1378 return 0;
1379}
1380
1381#ifdef HAVE_SENDMSG
1382
1383int
1384sys_sendmsg(tcp)
1385struct tcb *tcp;
1386{
1387 if (entering(tcp)) {
1388 tprintf("%ld, ", tcp->u_arg[0]);
1389 printmsghdr(tcp, tcp->u_arg[1]);
1390 /* flags */
1391 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001392 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 }
1394 return 0;
1395}
1396
1397#endif /* HAVE_SENDMSG */
1398
1399int
1400sys_recv(tcp)
1401struct tcb *tcp;
1402{
1403 if (entering(tcp)) {
1404 tprintf("%ld, ", tcp->u_arg[0]);
1405 } else {
1406 if (syserror(tcp))
1407 tprintf("%#lx", tcp->u_arg[1]);
1408 else
1409 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1410
1411 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001412 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 }
1414 return 0;
1415}
1416
1417int
1418sys_recvfrom(tcp)
1419struct tcb *tcp;
1420{
1421 int fromlen;
1422
1423 if (entering(tcp)) {
1424 tprintf("%ld, ", tcp->u_arg[0]);
1425 } else {
1426 if (syserror(tcp)) {
1427 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1428 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1429 tcp->u_arg[4], tcp->u_arg[5]);
1430 return 0;
1431 }
1432 /* buf */
1433 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1434 /* len */
1435 tprintf(", %lu, ", tcp->u_arg[2]);
1436 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001437 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438 /* from address, len */
1439 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1440 if (tcp->u_arg[4] == 0)
1441 tprintf(", NULL");
1442 else
1443 tprintf(", %#lx", tcp->u_arg[4]);
1444 if (tcp->u_arg[5] == 0)
1445 tprintf(", NULL");
1446 else
1447 tprintf(", %#lx", tcp->u_arg[5]);
1448 return 0;
1449 }
1450 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1451 tprintf(", {...}, [?]");
1452 return 0;
1453 }
1454 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001455 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456 /* from length */
1457 tprintf(", [%u]", fromlen);
1458 }
1459 return 0;
1460}
1461
1462#ifdef HAVE_SENDMSG
1463
1464int
1465sys_recvmsg(tcp)
1466struct tcb *tcp;
1467{
1468 if (entering(tcp)) {
1469 tprintf("%ld, ", tcp->u_arg[0]);
1470 } else {
1471 if (syserror(tcp) || !verbose(tcp))
1472 tprintf("%#lx", tcp->u_arg[1]);
1473 else
1474 printmsghdr(tcp, tcp->u_arg[1]);
1475 /* flags */
1476 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001477 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478 }
1479 return 0;
1480}
1481
1482#endif /* HAVE_SENDMSG */
1483
1484int
1485sys_shutdown(tcp)
1486struct tcb *tcp;
1487{
1488 if (entering(tcp)) {
1489 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1490 switch (tcp->u_arg[1]) {
1491 case 0:
1492 tprintf("%s", " /* receive */");
1493 break;
1494 case 1:
1495 tprintf("%s", " /* send */");
1496 break;
1497 case 2:
1498 tprintf("%s", " /* send and receive */");
1499 break;
1500 }
1501 }
1502 return 0;
1503}
1504
1505int
1506sys_getsockname(tcp)
1507struct tcb *tcp;
1508{
1509 return sys_accept(tcp);
1510}
1511
1512int
1513sys_getpeername(tcp)
1514struct tcb *tcp;
1515{
1516 return sys_accept(tcp);
1517}
1518
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001519static int
1520do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001522 if (exiting(tcp)) {
1523 if (syserror(tcp)) {
1524 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001525 } else {
1526#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1527 int fds[2];
1528
1529 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1530 tprintf("[...]");
1531 else
1532 tprintf("[%u, %u]", fds[0], fds[1]);
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001533#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001534 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1535#else
1536 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001538 }
1539 if (flags_arg >= 0) {
1540 tprintf(", ");
1541 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1542 }
1543 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 return 0;
1545}
1546
1547int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001548sys_pipe(struct tcb *tcp)
1549{
1550 return do_pipe(tcp, -1);
1551}
1552
1553#ifdef LINUX
1554int
1555sys_pipe2(struct tcb *tcp)
1556{
1557 return do_pipe(tcp, 1);
1558}
1559#endif
1560
1561int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001562sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001563{
1564#ifdef LINUX
1565 int fds[2];
1566#endif
1567
1568 if (entering(tcp)) {
1569 printxval(domains, tcp->u_arg[0], "PF_???");
1570 tprintf(", ");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001571 tprint_sock_type(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 tprintf(", ");
1573 switch (tcp->u_arg[0]) {
1574 case PF_INET:
1575 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1576 break;
1577#ifdef PF_IPX
1578 case PF_IPX:
1579 /* BTW: I don't believe this.. */
1580 tprintf("[");
1581 printxval(domains, tcp->u_arg[2], "PF_???");
1582 tprintf("]");
1583 break;
1584#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001585 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001586 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587 break;
1588 }
1589 } else {
1590 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001591 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 return 0;
1593 }
1594#ifdef LINUX
1595 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001596 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 else
1598 tprintf(", [%u, %u]", fds[0], fds[1]);
1599#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001600#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001601 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001602#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 }
1604 return 0;
1605}
1606
1607int
1608sys_getsockopt(tcp)
1609struct tcb *tcp;
1610{
1611 if (entering(tcp)) {
1612 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001613 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1614 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 switch (tcp->u_arg[1]) {
1616 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001617 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 break;
1619#ifdef SOL_IP
1620 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622 break;
1623#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001624#ifdef SOL_IPV6
1625 case SOL_IPV6:
1626 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1627 break;
1628#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629#ifdef SOL_IPX
1630 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 break;
1633#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001634#ifdef SOL_PACKET
1635 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001636 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001637 break;
1638#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639#ifdef SOL_TCP
1640 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642 break;
1643#endif
1644
1645 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1646 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001647 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001648 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001649 break;
1650 }
1651 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001652 int len;
John Hughes93f7fcc2002-05-22 15:46:49 +00001653 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1654 tprintf(", %#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 tcp->u_arg[3], tcp->u_arg[4]);
1656 return 0;
1657 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001658
1659 switch (tcp->u_arg[1]) {
1660 case SOL_SOCKET:
1661 switch (tcp->u_arg[2]) {
1662#ifdef SO_LINGER
1663 case SO_LINGER:
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001664 if (len == sizeof (struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001665 struct linger linger;
1666 if (umove (tcp,
1667 tcp->u_arg[3],
1668 &linger) < 0)
1669 break;
1670 tprintf(", {onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001671 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001672 linger.l_onoff,
1673 linger.l_linger,
1674 len);
1675 return 0;
1676 }
1677 break;
1678#endif
1679 }
1680 break;
1681 }
1682
1683 tprintf (", ");
1684 if (len == sizeof (int)) {
1685 printnum(tcp, tcp->u_arg[3], "%ld");
1686 }
1687 else {
1688 printstr (tcp, tcp->u_arg[3], len);
1689 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001690 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691 }
1692 return 0;
1693}
1694
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001695#if defined(ICMP_FILTER)
1696static void printicmpfilter(tcp, addr)
1697struct tcb *tcp;
1698long addr;
1699{
1700 struct icmp_filter filter;
1701
1702 if (!addr) {
1703 tprintf("NULL");
1704 return;
1705 }
1706 if (syserror(tcp) || !verbose(tcp)) {
1707 tprintf("%#lx", addr);
1708 return;
1709 }
1710 if (umove(tcp, addr, &filter) < 0) {
1711 tprintf("{...}");
1712 return;
1713 }
1714
1715 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001716 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001717 tprintf(")");
1718}
1719#endif /* ICMP_FILTER */
1720
John Hughes38ae88d2002-05-23 11:48:58 +00001721static int
1722printsockopt (tcp, level, name, addr, len)
1723struct tcb *tcp;
1724int level;
1725int name;
1726long addr;
1727int len;
1728{
1729 printxval(socketlayers, level, "SOL_??");
1730 tprintf (", ");
1731 switch (level) {
1732 case SOL_SOCKET:
1733 printxval(sockoptions, name, "SO_???");
1734 switch (name) {
1735#if defined(SO_LINGER)
1736 case SO_LINGER:
1737 if (len == sizeof (struct linger)) {
1738 struct linger linger;
1739 if (umove (tcp, addr, &linger) < 0)
1740 break;
1741 tprintf(", {onoff=%d, linger=%d}",
1742 linger.l_onoff,
1743 linger.l_linger);
1744 return 0;
1745 }
1746 break;
1747#endif
1748 }
1749 break;
1750#ifdef SOL_IP
1751 case SOL_IP:
1752 printxval(sockipoptions, name, "IP_???");
1753 break;
1754#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001755#ifdef SOL_IPV6
1756 case SOL_IPV6:
1757 printxval(sockipv6options, name, "IPV6_???");
1758 break;
1759#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001760#ifdef SOL_IPX
1761 case SOL_IPX:
1762 printxval(sockipxoptions, name, "IPX_???");
1763 break;
1764#endif
1765#ifdef SOL_PACKET
1766 case SOL_PACKET:
1767 printxval(sockpacketoptions, name, "PACKET_???");
1768 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1769 break;
1770#endif
1771#ifdef SOL_TCP
1772 case SOL_TCP:
1773 printxval(socktcpoptions, name, "TCP_???");
1774 break;
1775#endif
1776#ifdef SOL_RAW
1777 case SOL_RAW:
1778 printxval(sockrawoptions, name, "RAW_???");
1779 switch (name) {
1780#if defined(ICMP_FILTER)
1781 case ICMP_FILTER:
1782 tprintf(", ");
1783 printicmpfilter(tcp, addr);
1784 return 0;
1785#endif
1786 }
1787 break;
1788#endif
1789
Roland McGrath6d2b3492002-12-30 00:51:30 +00001790 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001791 * etc. still need work */
1792
1793 default:
1794 tprintf("%u", name);
1795 }
1796
1797 /* default arg printing */
1798
1799 tprintf (", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001800
John Hughes38ae88d2002-05-23 11:48:58 +00001801 if (len == sizeof (int)) {
Roland McGrath9814a942005-07-04 23:28:10 +00001802 printnum_int (tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001803 }
1804 else {
1805 printstr (tcp, addr, len);
1806 }
1807 return 0;
1808}
1809
1810
Roland McGrathc3ca0d82003-01-14 07:53:38 +00001811#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00001812
1813void
1814print_sock_optmgmt (tcp, addr, len)
1815struct tcb *tcp;
1816long addr;
1817int len;
1818{
1819 int c = 0;
1820 struct opthdr hdr;
1821
John Hughes2c4e3a82002-05-24 10:19:44 +00001822 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00001823 if (umove(tcp, addr, &hdr) < 0) break;
1824 if (c++) {
1825 tprintf (", ");
1826 }
1827 else if (len > hdr.len + sizeof hdr) {
1828 tprintf ("[");
1829 }
1830 tprintf ("{");
1831 addr += sizeof hdr;
1832 len -= sizeof hdr;
1833 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00001834 if (hdr.len > 0) {
1835 addr += hdr.len;
1836 len -= hdr.len;
1837 }
John Hughes38ae88d2002-05-23 11:48:58 +00001838 tprintf ("}");
1839 }
1840 if (len > 0) {
1841 if (c++) tprintf (", ");
1842 printstr (tcp, addr, len);
1843 }
1844 if (c > 1) tprintf ("]");
1845}
1846
1847#endif
1848
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849int
1850sys_setsockopt(tcp)
1851struct tcb *tcp;
1852{
1853 if (entering(tcp)) {
1854 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes38ae88d2002-05-23 11:48:58 +00001855 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1856 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001857 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858 }
1859 return 0;
1860}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001861
1862#if UNIXWARE >= 7
1863
Roland McGrathd9f816f2004-09-04 03:39:20 +00001864static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001865 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1866 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1867 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1868 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1869 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1870 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1871 { 0, NULL },
1872};
1873
1874
1875int
1876netlib_call(tcp, func)
1877struct tcb *tcp;
1878int (*func) ();
1879{
1880 if (entering(tcp)) {
1881 int i;
1882 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1883 tprintf(", ");
1884 --tcp->u_nargs;
1885 for (i = 0; i < tcp->u_nargs; i++)
1886 tcp->u_arg[i] = tcp->u_arg[i + 1];
1887 return func (tcp);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001888
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001889 }
1890
1891 return func (tcp);
1892}
1893
1894int
1895sys_xsocket(tcp)
1896struct tcb *tcp;
1897{
1898 return netlib_call (tcp, sys_socket);
1899}
1900
1901int
1902sys_xsocketpair(tcp)
1903struct tcb *tcp;
1904{
1905 return netlib_call (tcp, sys_socketpair);
1906}
1907
1908int
1909sys_xbind(tcp)
1910struct tcb *tcp;
1911{
1912 return netlib_call (tcp, sys_bind);
1913}
1914
1915int
1916sys_xconnect(tcp)
1917struct tcb *tcp;
1918{
1919 return netlib_call (tcp, sys_connect);
1920}
1921
1922int
1923sys_xlisten(tcp)
1924struct tcb *tcp;
1925{
1926 return netlib_call (tcp, sys_listen);
1927}
1928
1929int
1930sys_xaccept(tcp)
1931struct tcb *tcp;
1932{
1933 return netlib_call (tcp, sys_accept);
1934}
1935
1936int
1937sys_xsendmsg(tcp)
1938struct tcb *tcp;
1939{
1940 return netlib_call (tcp, sys_sendmsg);
1941}
1942
1943int
1944sys_xrecvmsg(tcp)
1945struct tcb *tcp;
1946{
1947 return netlib_call (tcp, sys_recvmsg);
1948}
1949
1950int
1951sys_xgetsockaddr(tcp)
1952struct tcb *tcp;
1953{
1954 if (entering(tcp)) {
1955 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1956 tprintf(", ");
1957 if (tcp->u_arg[1] == 0) {
1958 tprintf ("LOCALNAME, ");
1959 }
1960 else if (tcp->u_arg[1] == 1) {
1961 tprintf ("REMOTENAME, ");
1962 }
1963 else {
1964 tprintf ("%ld, ", tcp->u_arg [1]);
1965 }
1966 tprintf ("%ld, ", tcp->u_arg [2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001967 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001968 else {
1969 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1970 tprintf("%#lx", tcp->u_arg[3]);
1971 } else {
1972 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1973 }
1974 tprintf(", ");
1975 printnum(tcp, tcp->u_arg[4], "%lu");
1976 }
1977
1978 return 0;
1979
1980}
1981
1982#if 0
1983
1984int
1985sys_xsetsockaddr(tcp)
1986struct tcb *tcp;
1987{
1988 return netlib_call (tcp, sys_setsockaddr);
1989}
1990
1991#endif
1992
1993int
1994sys_xgetsockopt(tcp)
1995struct tcb *tcp;
1996{
1997 return netlib_call (tcp, sys_getsockopt);
1998}
1999
2000int
2001sys_xsetsockopt(tcp)
2002struct tcb *tcp;
2003{
2004 return netlib_call (tcp, sys_setsockopt);
2005}
2006
2007int
2008sys_xshutdown(tcp)
2009struct tcb *tcp;
2010{
2011 return netlib_call (tcp, sys_shutdown);
2012}
2013
2014#endif