blob: 103278d545a2c2b3e70e8169a5d2f33f7f6f6ad8 [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
323#ifdef SOCK_SEQPACKET
324 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
325#endif
326#ifdef SOCK_RDM
327 { SOCK_RDM, "SOCK_RDM" },
328#endif
329#ifdef SOCK_PACKET
330 { SOCK_PACKET, "SOCK_PACKET" },
331#endif
332 { 0, NULL },
333};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000334static const struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000335#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000336 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000337#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000338#if defined(SOL_ICMP)
339 { SOL_ICMP, "SOL_ICMP" },
340#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000341#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000342 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000343#endif
344#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000345 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000346#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000347#if defined(SOL_IPV6)
348 { SOL_IPV6, "SOL_IPV6" },
349#endif
350#if defined(SOL_ICMPV6)
351 { SOL_ICMPV6, "SOL_ICMPV6" },
352#endif
353#if defined(SOL_RAW)
354 { SOL_RAW, "SOL_RAW" },
355#endif
356#if defined(SOL_IPX)
357 { SOL_IPX, "SOL_IPX" },
358#endif
359#if defined(SOL_IPX)
360 { SOL_IPX, "SOL_IPX" },
361#endif
362#if defined(SOL_AX25)
363 { SOL_AX25, "SOL_AX25" },
364#endif
365#if defined(SOL_ATALK)
366 { SOL_ATALK, "SOL_ATALK" },
367#endif
368#if defined(SOL_NETROM)
369 { SOL_NETROM, "SOL_NETROM" },
370#endif
371#if defined(SOL_ROSE)
372 { SOL_ROSE, "SOL_ROSE" },
373#endif
374#if defined(SOL_DECNET)
375 { SOL_DECNET, "SOL_DECNET" },
376#endif
377#if defined(SOL_X25)
378 { SOL_X25, "SOL_X25" },
379#endif
380#if defined(SOL_PACKET)
381 { SOL_PACKET, "SOL_PACKET" },
382#endif
383#if defined(SOL_ATM)
384 { SOL_ATM, "SOL_ATM" },
385#endif
386#if defined(SOL_AAL)
387 { SOL_AAL, "SOL_AAL" },
388#endif
389#if defined(SOL_IRDA)
390 { SOL_IRDA, "SOL_IRDA" },
391#endif
John Hughes61563572001-03-27 16:47:36 +0000392 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000393};
John Hughes93f7fcc2002-05-22 15:46:49 +0000394/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
395 falls into "protocols" array below!!!! This is intended!!! ***/
Roland McGrathd9f816f2004-09-04 03:39:20 +0000396static const struct xlat protocols[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 { IPPROTO_IP, "IPPROTO_IP" },
398 { IPPROTO_ICMP, "IPPROTO_ICMP" },
399 { IPPROTO_TCP, "IPPROTO_TCP" },
400 { IPPROTO_UDP, "IPPROTO_UDP" },
401#ifdef IPPROTO_GGP
402 { IPPROTO_GGP, "IPPROTO_GGP" },
403#endif
404#ifdef IPPROTO_EGP
405 { IPPROTO_EGP, "IPPROTO_EGP" },
406#endif
407#ifdef IPPROTO_PUP
408 { IPPROTO_PUP, "IPPROTO_PUP" },
409#endif
410#ifdef IPPROTO_IDP
411 { IPPROTO_IDP, "IPPROTO_IDP" },
412#endif
413#ifdef IPPROTO_IPV6
414 { IPPROTO_IPV6, "IPPROTO_IPV6" },
415#endif
416#ifdef IPPROTO_ICMPV6
417 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
418#endif
419#ifdef IPPROTO_IGMP
420 { IPPROTO_IGMP, "IPPROTO_IGMP" },
421#endif
422#ifdef IPPROTO_HELLO
423 { IPPROTO_HELLO,"IPPROTO_HELLO" },
424#endif
425#ifdef IPPROTO_ND
426 { IPPROTO_ND, "IPPROTO_ND" },
427#endif
428#ifdef IPPROTO_RAW
429 { IPPROTO_RAW, "IPPROTO_RAW" },
430#endif
431#ifdef IPPROTO_MAX
432 { IPPROTO_MAX, "IPPROTO_MAX" },
433#endif
434#ifdef IPPROTO_IPIP
435 { IPPROTO_IPIP, "IPPROTO_IPIP" },
436#endif
437 { 0, NULL },
438};
Roland McGrathd9f816f2004-09-04 03:39:20 +0000439static const struct xlat msg_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440 { MSG_OOB, "MSG_OOB" },
441#ifdef MSG_DONTROUTE
442 { MSG_DONTROUTE,"MSG_DONTROUTE" },
443#endif
444#ifdef MSG_PEEK
445 { MSG_PEEK, "MSG_PEEK" },
446#endif
447#ifdef MSG_CTRUNC
448 { MSG_CTRUNC, "MSG_CTRUNC" },
449#endif
450#ifdef MSG_PROXY
451 { MSG_PROXY, "MSG_PROXY" },
452#endif
453#ifdef MSG_EOR
454 { MSG_EOR, "MSG_EOR" },
455#endif
456#ifdef MSG_WAITALL
457 { MSG_WAITALL, "MSG_WAITALL" },
458#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000459#ifdef MSG_TRUNC
460 { MSG_TRUNC, "MSG_TRUNC" },
461#endif
462#ifdef MSG_CTRUNC
463 { MSG_CTRUNC, "MSG_CTRUNC" },
464#endif
465#ifdef MSG_ERRQUEUE
466 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
467#endif
468#ifdef MSG_DONTWAIT
469 { MSG_DONTWAIT, "MSG_DONTWAIT" },
470#endif
471#ifdef MSG_CONFIRM
472 { MSG_CONFIRM, "MSG_CONFIRM" },
473#endif
474#ifdef MSG_PROBE
475 { MSG_PROBE, "MSG_PROBE" },
476#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000477#ifdef MSG_FIN
478 { MSG_FIN, "MSG_FIN" },
479#endif
480#ifdef MSG_SYN
481 { MSG_SYN, "MSG_SYN" },
482#endif
483#ifdef MSG_RST
484 { MSG_RST, "MSG_RST" },
485#endif
486#ifdef MSG_NOSIGNAL
487 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
488#endif
489#ifdef MSG_MORE
490 { MSG_MORE, "MSG_MORE" },
491#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 { 0, NULL },
493};
494
Roland McGrathd9f816f2004-09-04 03:39:20 +0000495static const struct xlat sockoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496#ifdef SO_ACCEPTCONN
Roland McGrath1bf43732004-08-31 07:16:14 +0000497 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
John Hughes38ae88d2002-05-23 11:48:58 +0000498#endif
499#ifdef SO_ALLRAW
500 { SO_ALLRAW, "SO_ALLRAW" },
501#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000502#ifdef SO_ATTACH_FILTER
503 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
504#endif
505#ifdef SO_BINDTODEVICE
506 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
507#endif
508#ifdef SO_BROADCAST
509 { SO_BROADCAST, "SO_BROADCAST" },
510#endif
511#ifdef SO_BSDCOMPAT
512 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
513#endif
514#ifdef SO_DEBUG
515 { SO_DEBUG, "SO_DEBUG" },
516#endif
517#ifdef SO_DETACH_FILTER
518 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
519#endif
520#ifdef SO_DONTROUTE
521 { SO_DONTROUTE, "SO_DONTROUTE" },
522#endif
523#ifdef SO_ERROR
524 { SO_ERROR, "SO_ERROR" },
525#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000526#ifdef SO_ICS
527 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528#endif
Roland McGrath1bf43732004-08-31 07:16:14 +0000529#ifdef SO_IMASOCKET
530 { SO_IMASOCKET, "SO_IMASOCKET" },
531#endif
532#ifdef SO_KEEPALIVE
533 { SO_KEEPALIVE, "SO_KEEPALIVE" },
534#endif
535#ifdef SO_LINGER
536 { SO_LINGER, "SO_LINGER" },
537#endif
538#ifdef SO_LISTENING
539 { SO_LISTENING, "SO_LISTENING" },
540#endif
541#ifdef SO_MGMT
542 { SO_MGMT, "SO_MGMT" },
543#endif
544#ifdef SO_NO_CHECK
545 { SO_NO_CHECK, "SO_NO_CHECK" },
546#endif
547#ifdef SO_OOBINLINE
548 { SO_OOBINLINE, "SO_OOBINLINE" },
549#endif
550#ifdef SO_ORDREL
551 { SO_ORDREL, "SO_ORDREL" },
552#endif
553#ifdef SO_PARALLELSVR
554 { SO_PARALLELSVR, "SO_PARALLELSVR" },
555#endif
556#ifdef SO_PASSCRED
557 { SO_PASSCRED, "SO_PASSCRED" },
558#endif
559#ifdef SO_PEERCRED
560 { SO_PEERCRED, "SO_PEERCRED" },
561#endif
562#ifdef SO_PEERNAME
563 { SO_PEERNAME, "SO_PEERNAME" },
564#endif
565#ifdef SO_PEERSEC
566 { SO_PEERSEC, "SO_PEERSEC" },
567#endif
568#ifdef SO_PRIORITY
569 { SO_PRIORITY, "SO_PRIORITY" },
570#endif
571#ifdef SO_PROTOTYPE
572 { SO_PROTOTYPE, "SO_PROTOTYPE" },
573#endif
574#ifdef SO_RCVBUF
575 { SO_RCVBUF, "SO_RCVBUF" },
576#endif
577#ifdef SO_RCVLOWAT
578 { SO_RCVLOWAT, "SO_RCVLOWAT" },
579#endif
580#ifdef SO_RCVTIMEO
581 { SO_RCVTIMEO, "SO_RCVTIMEO" },
582#endif
583#ifdef SO_RDWR
584 { SO_RDWR, "SO_RDWR" },
585#endif
586#ifdef SO_REUSEADDR
587 { SO_REUSEADDR, "SO_REUSEADDR" },
588#endif
589#ifdef SO_REUSEPORT
590 { SO_REUSEPORT, "SO_REUSEPORT" },
591#endif
592#ifdef SO_SECURITY_AUTHENTICATION
593 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
594#endif
595#ifdef SO_SECURITY_ENCRYPTION_NETWORK
596 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
597#endif
598#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
599 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
600#endif
601#ifdef SO_SEMA
602 { SO_SEMA, "SO_SEMA" },
603#endif
604#ifdef SO_SNDBUF
605 { SO_SNDBUF, "SO_SNDBUF" },
606#endif
607#ifdef SO_SNDLOWAT
608 { SO_SNDLOWAT, "SO_SNDLOWAT" },
609#endif
610#ifdef SO_SNDTIMEO
611 { SO_SNDTIMEO, "SO_SNDTIMEO" },
612#endif
613#ifdef SO_TIMESTAMP
614 { SO_TIMESTAMP, "SO_TIMESTAMP" },
615#endif
616#ifdef SO_TYPE
617 { SO_TYPE, "SO_TYPE" },
618#endif
619#ifdef SO_USELOOPBACK
620 { SO_USELOOPBACK, "SO_USELOOPBACK" },
621#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622 { 0, NULL },
623};
624
John Hughes93f7fcc2002-05-22 15:46:49 +0000625#if !defined (SOL_IP) && defined (IPPROTO_IP)
626#define SOL_IP IPPROTO_IP
627#endif
628
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629#ifdef SOL_IP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000630static const struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000631#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000632 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000633#endif
634#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000635 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000636#endif
637#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000638 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000640#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000641 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000643#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000644 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000645#endif
646#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000647 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
648#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000649#ifdef IP_RECVOPTS
650 { IP_RECVOPTS, "IP_RECVOPTS" },
651#endif
652#ifdef IP_RECVRETOPTS
653 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
654#endif
655#ifdef IP_RECVDSTADDR
656 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
657#endif
658#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000659 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000660#endif
661#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000662 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000663#endif
664#ifdef IP_PKTOPTIONS
665 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
666#endif
667#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000668 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000669#endif
670#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000671 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000672#endif
673#ifdef IP_RECVTTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000674 { IP_RECVTTL, "IP_RECRECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000675#endif
676#ifdef IP_RECVTOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000677 { IP_RECVTOS, "IP_RECRECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000678#endif
679#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000680 { IP_MTU, "IP_MTU" },
681#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000682#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000683 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000684#endif
685#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000686 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000687#endif
688#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000689 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000690#endif
691#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000692 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000693#endif
694#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000695 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000696#endif
697#ifdef IP_BROADCAST_IF
698 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
699#endif
700#ifdef IP_RECVIFINDEX
701 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
702#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +0000703#ifdef IP_MSFILTER
704 { IP_MSFILTER, "IP_MSFILTER" },
705#endif
706#ifdef MCAST_MSFILTER
707 { MCAST_MSFILTER, "MCAST_MSFILTER" },
708#endif
709#ifdef IP_FREEBIND
710 { IP_FREEBIND, "IP_FREEBIND" },
711#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000712 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713};
714#endif /* SOL_IP */
715
Roland McGrath4f6ba692004-08-31 07:01:26 +0000716#ifdef SOL_IPV6
Roland McGrathd9f816f2004-09-04 03:39:20 +0000717static const struct xlat sockipv6options[] = {
Roland McGrath4f6ba692004-08-31 07:01:26 +0000718#ifdef IPV6_ADDRFORM
719 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
720#endif
721#ifdef MCAST_FILTER
722 { MCAST_FILTER, "MCAST_FILTER" },
723#endif
724#ifdef IPV6_PKTOPTIONS
725 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
726#endif
727#ifdef IPV6_MTU
728 { IPV6_MTU, "IPV6_MTU" },
729#endif
730#ifdef IPV6_V6ONLY
731 { IPV6_V6ONLY, "IPV6_V6ONLY" },
732#endif
733#ifdef IPV6_PKTINFO
734 { IPV6_PKTINFO, "IPV6_PKTINFO" },
735#endif
736#ifdef IPV6_HOPLIMIT
737 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
738#endif
739#ifdef IPV6_RTHDR
740 { IPV6_RTHDR, "IPV6_RTHDR" },
741#endif
742#ifdef IPV6_HOPOPTS
743 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
744#endif
745#ifdef IPV6_DSTOPTS
746 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
747#endif
748#ifdef IPV6_FLOWINFO
749 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
750#endif
751#ifdef IPV6_UNICAST_HOPS
752 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
753#endif
754#ifdef IPV6_MULTICAST_HOPS
755 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
756#endif
757#ifdef IPV6_MULTICAST_LOOP
758 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
759#endif
760#ifdef IPV6_MULTICAST_IF
761 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
762#endif
763#ifdef IPV6_MTU_DISCOVER
764 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
765#endif
766#ifdef IPV6_RECVERR
767 { IPV6_RECVERR, "IPV6_RECVERR" },
768#endif
769#ifdef IPV6_FLOWINFO_SEND
770 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
771#endif
772 { 0, NULL },
773};
774#endif /* SOL_IPV6 */
775
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776#ifdef SOL_IPX
Roland McGrathd9f816f2004-09-04 03:39:20 +0000777static const struct xlat sockipxoptions[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 { IPX_TYPE, "IPX_TYPE" },
779 { 0, NULL },
780};
781#endif /* SOL_IPX */
782
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000783#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000784static const struct xlat sockrawoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000785#if defined(ICMP_FILTER)
786 { ICMP_FILTER, "ICMP_FILTER" },
787#endif
788 { 0, NULL },
789};
790#endif /* SOL_RAW */
791
792#ifdef SOL_PACKET
Roland McGrathd9f816f2004-09-04 03:39:20 +0000793static const struct xlat sockpacketoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000794 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
795 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
796#if defined(PACKET_RECV_OUTPUT)
797 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
798#endif
799#if defined(PACKET_RX_RING)
800 { PACKET_RX_RING, "PACKET_RX_RING" },
801#endif
802#if defined(PACKET_STATISTICS)
803 { PACKET_STATISTICS, "PACKET_STATISTICS" },
804#endif
805 { 0, NULL },
806};
807#endif /* SOL_PACKET */
808
John Hughes93f7fcc2002-05-22 15:46:49 +0000809#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
810#define SOL_TCP IPPROTO_TCP
811#endif
812
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813#ifdef SOL_TCP
Roland McGrathd9f816f2004-09-04 03:39:20 +0000814static const struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000815 { TCP_NODELAY, "TCP_NODELAY" },
816 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000817#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000818 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000819#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000820#if defined(TCP_KEEPIDLE)
821 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
822#endif
823#if defined(TCP_KEEPINTVL)
824 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
825#endif
826#if defined(TCP_KEEPCNT)
827 { TCP_KEEPCNT, "TCP_KEEPCNT" },
828#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000829#if defined(TCP_NKEEP)
830 { TCP_NKEEP, "TCP_NKEEP" },
831#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000832#if defined(TCP_SYNCNT)
833 { TCP_SYNCNT, "TCP_SYNCNT" },
834#endif
835#if defined(TCP_LINGER2)
836 { TCP_LINGER2, "TCP_LINGER2" },
837#endif
838#if defined(TCP_DEFER_ACCEPT)
839 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
840#endif
841#if defined(TCP_WINDOW_CLAMP)
842 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
843#endif
844#if defined(TCP_INFO)
845 { TCP_INFO, "TCP_INFO" },
846#endif
847#if defined(TCP_QUICKACK)
848 { TCP_QUICKACK, "TCP_QUICKACK" },
849#endif
850 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851};
852#endif /* SOL_TCP */
853
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000854#ifdef SOL_RAW
Roland McGrathd9f816f2004-09-04 03:39:20 +0000855static const struct xlat icmpfilterflags[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000856#if defined(ICMP_ECHOREPLY)
857 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
858#endif
859#if defined(ICMP_DEST_UNREACH)
860 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
861#endif
862#if defined(ICMP_SOURCE_QUENCH)
863 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
864#endif
865#if defined(ICMP_REDIRECT)
866 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
867#endif
868#if defined(ICMP_ECHO)
869 { (1<<ICMP_ECHO), "ICMP_ECHO" },
870#endif
871#if defined(ICMP_TIME_EXCEEDED)
872 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
873#endif
874#if defined(ICMP_PARAMETERPROB)
875 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
876#endif
877#if defined(ICMP_TIMESTAMP)
878 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
879#endif
880#if defined(ICMP_TIMESTAMPREPLY)
881 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
882#endif
883#if defined(ICMP_INFO_REQUEST)
884 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
885#endif
886#if defined(ICMP_INFO_REPLY)
887 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
888#endif
889#if defined(ICMP_ADDRESS)
890 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
891#endif
892#if defined(ICMP_ADDRESSREPLY)
893 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
894#endif
895 { 0, NULL },
896};
897#endif /* SOL_RAW */
898
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000899#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Roland McGrathd9f816f2004-09-04 03:39:20 +0000900static const struct xlat af_packet_types[] = {
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000901#if defined(PACKET_HOST)
902 { PACKET_HOST, "PACKET_HOST" },
903#endif
904#if defined(PACKET_BROADCAST)
905 { PACKET_BROADCAST, "PACKET_BROADCAST" },
906#endif
907#if defined(PACKET_MULTICAST)
908 { PACKET_MULTICAST, "PACKET_MULTICAST" },
909#endif
910#if defined(PACKET_OTHERHOST)
911 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
912#endif
913#if defined(PACKET_OUTGOING)
914 { PACKET_OUTGOING, "PACKET_OUTGOING" },
915#endif
916#if defined(PACKET_LOOPBACK)
917 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
918#endif
919#if defined(PACKET_FASTROUTE)
920 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
921#endif
922 { 0, NULL },
923};
924#endif /* defined(AF_PACKET) */
925
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000926
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000928printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929struct tcb *tcp;
930long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000931int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000932{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000933 union {
934 char pad[128];
935 struct sockaddr sa;
936 struct sockaddr_in sin;
937 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000938#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000939 struct sockaddr_in6 sa6;
940#endif
941#if defined(LINUX) && defined(AF_IPX)
942 struct sockaddr_ipx sipx;
943#endif
944#ifdef AF_PACKET
945 struct sockaddr_ll ll;
946#endif
947#ifdef AF_NETLINK
948 struct sockaddr_nl nl;
949#endif
950 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000951 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952
953 if (addr == 0) {
954 tprintf("NULL");
955 return;
956 }
957 if (!verbose(tcp)) {
958 tprintf("%#lx", addr);
959 return;
960 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000961 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
962 addrlen=sizeof(addrbuf);
963
964 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965 tprintf("{...}");
966 return;
967 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000968
John Hughes1fcb1d62001-09-18 15:56:53 +0000969 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000970 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
971 tprintf(", ");
972
973 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000975 if (addrlen==2) {
976 tprintf("<nil>");
977 } else if (addrbuf.sau.sun_path[0]) {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000978 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000979 } else {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000980 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000981 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 break;
983 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000984 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000985 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000987#ifdef HAVE_INET_NTOP
988 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000989 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000990 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
991 ntohs(addrbuf.sa6.sin6_port), string_addr,
992 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000993#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000994 {
995#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
996 int numericscope = 0;
997 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
998 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
999 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +00001000
Wichert Akkermanf1850652001-02-16 20:29:03 +00001001 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1002 numericscope++;
1003 else
1004 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1005 } else
1006 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +00001007
Wichert Akkermanf1850652001-02-16 20:29:03 +00001008 if (numericscope)
1009#endif
1010 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1011 }
1012#endif
1013 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +00001014#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +00001015#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001017 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +00001019 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001020 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 /* Yes, I know, this does not look too
1022 * strace-ish, but otherwise the IPX
1023 * addresses just look monstrous...
1024 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +00001025 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001027 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001029 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1030 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 }
1032 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001033#endif /* AF_IPX && linux */
1034#ifdef AF_PACKET
1035 case AF_PACKET:
1036 {
1037 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001038 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001039 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +00001040 addrbuf.ll.sll_ifindex);
1041 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1042 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001043 addrbuf.ll.sll_halen,
1044 addrbuf.ll.sll_hatype);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001045 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001046 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1047 }
1048 break;
1049
1050#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +00001051#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001052 case AF_NETLINK:
1053 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1054 break;
1055#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001057 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058
1059 default:
John Hughes1fcb1d62001-09-18 15:56:53 +00001060 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001061 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001062 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 break;
1064 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001065 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066}
1067
1068#if HAVE_SENDMSG
Roland McGrath50770822004-10-06 22:11:51 +00001069static const struct xlat scmvals[] = {
1070#ifdef SCM_RIGHTS
1071 { SCM_RIGHTS, "SCM_RIGHTS" },
1072#endif
1073#ifdef SCM_CREDENTIALS
1074 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1075#endif
1076 { 0, NULL }
1077};
1078
1079static void
1080printcmsghdr(tcp, addr, len)
1081struct tcb *tcp;
1082unsigned long addr;
1083unsigned long len;
1084{
1085 union {
1086 char msg_control[len];
1087 struct cmsghdr cmsg;
1088 } u;
1089 if (umoven(tcp, addr, len, u.msg_control) < 0) {
1090 tprintf(", msg_control=%#lx", addr);
1091 return;
1092 }
1093
1094 tprintf(", {cmsg_len=%zu, cmsg_level=", u.cmsg.cmsg_len);
1095 printxval(socketlayers, u.cmsg.cmsg_level, "SOL_???");
1096 tprintf(", cmsg_type=");
1097
1098 if (u.cmsg.cmsg_level == SOL_SOCKET) {
1099 printxval(scmvals, u.cmsg.cmsg_type, "SCM_???");
Roland McGrath96ad7b82005-02-02 03:11:32 +00001100
Roland McGrath50770822004-10-06 22:11:51 +00001101 if (u.cmsg.cmsg_type == SCM_RIGHTS) {
1102 int *fds = (int *) CMSG_DATA (&u.cmsg);
1103 int first = 1;
1104 tprintf(", {");
1105 while ((char *) fds < (u.msg_control
1106 + u.cmsg.cmsg_len)) {
1107 if (!first)
1108 tprintf(", ");
1109 tprintf("%d", *fds++);
1110 first = 0;
1111 }
1112 tprintf("}}");
1113 return;
1114 }
1115 if (u.cmsg.cmsg_type == SCM_CREDENTIALS
1116 && CMSG_LEN(sizeof(struct ucred)) <= u.cmsg.cmsg_len) {
1117 struct ucred *uc = (struct ucred *) CMSG_DATA (&u.cmsg);
1118 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1119 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1120 return;
1121 }
1122 }
1123 tprintf(", ...}");
1124}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125
1126static void
1127printmsghdr(tcp, addr)
1128struct tcb *tcp;
1129long addr;
1130{
1131 struct msghdr msg;
1132
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001133 if (umove(tcp, addr, &msg) < 0) {
1134 tprintf("%#lx", addr);
1135 return;
1136 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001137 tprintf("{msg_name(%d)=", msg.msg_namelen);
1138 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
1139
1140 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
John Hughes1d08dcf2001-07-10 13:48:44 +00001141 tprint_iov(tcp, msg.msg_iovlen, (long) msg.msg_iov);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001142
Roland McGrath6d2b3492002-12-30 00:51:30 +00001143#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001144 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145 if (msg.msg_controllen)
Roland McGrath50770822004-10-06 22:11:51 +00001146 printcmsghdr(tcp, (unsigned long) msg.msg_control,
1147 msg.msg_controllen);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001148 tprintf(", msg_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001149 printflags(msg_flags, msg.msg_flags, "MSG_???");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001151 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001152 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001153#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001154 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001155}
1156
1157#endif /* HAVE_SENDMSG */
1158
1159int
1160sys_socket(tcp)
1161struct tcb *tcp;
1162{
1163 if (entering(tcp)) {
1164 printxval(domains, tcp->u_arg[0], "PF_???");
1165 tprintf(", ");
1166 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1167 tprintf(", ");
1168 switch (tcp->u_arg[0]) {
1169 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +00001170#ifdef PF_INET6
1171 case PF_INET6:
1172#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001173 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1174 break;
1175#ifdef PF_IPX
1176 case PF_IPX:
1177 /* BTW: I don't believe this.. */
1178 tprintf("[");
1179 printxval(domains, tcp->u_arg[2], "PF_???");
1180 tprintf("]");
1181 break;
1182#endif /* PF_IPX */
1183 default:
1184 tprintf("%lu", tcp->u_arg[2]);
1185 break;
1186 }
1187 }
1188 return 0;
1189}
1190
1191int
John Hughesbdf48f52001-03-06 15:08:09 +00001192sys_so_socket(tcp)
1193struct tcb *tcp;
1194{
1195 if (entering(tcp)) {
1196 /* not sure really what these args are... but this
1197 * is how truss prints it
1198 */
1199 tprintf("%ld, %ld, %ld, ",
1200 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1201 printpath(tcp, tcp->u_arg[3]);
1202 tprintf(", %ld", tcp->u_arg[4]);
1203 }
1204 return 0;
1205}
1206
1207int
1208sys_so_socketpair(tcp)
1209struct tcb *tcp;
1210{
1211 if (entering(tcp)) {
1212 /* not sure what this arg is */
1213 tprintf("0x%lx", tcp->u_arg[0]);
1214 }
1215 return 0;
1216}
1217
1218int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219sys_bind(tcp)
1220struct tcb *tcp;
1221{
1222 if (entering(tcp)) {
1223 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001224 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225 tprintf(", %lu", tcp->u_arg[2]);
1226 }
1227 return 0;
1228}
1229
1230int
1231sys_connect(tcp)
1232struct tcb *tcp;
1233{
1234 return sys_bind(tcp);
1235}
1236
1237int
1238sys_listen(tcp)
1239struct tcb *tcp;
1240{
1241 if (entering(tcp)) {
1242 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1243 }
1244 return 0;
1245}
1246
1247int
1248sys_accept(tcp)
1249struct tcb *tcp;
1250{
1251 if (entering(tcp)) {
1252 tprintf("%ld, ", tcp->u_arg[0]);
1253 } else if (!tcp->u_arg[2])
1254 tprintf("%#lx, NULL", tcp->u_arg[1]);
1255 else {
1256 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
1257 tprintf("%#lx", tcp->u_arg[1]);
1258 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001259 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 }
1261 tprintf(", ");
1262 printnum(tcp, tcp->u_arg[2], "%lu");
1263 }
1264 return 0;
1265}
1266
1267int
1268sys_send(tcp)
1269struct tcb *tcp;
1270{
1271 if (entering(tcp)) {
1272 tprintf("%ld, ", tcp->u_arg[0]);
1273 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1274 tprintf(", %lu, ", tcp->u_arg[2]);
1275 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001276 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 }
1278 return 0;
1279}
1280
1281int
1282sys_sendto(tcp)
1283struct tcb *tcp;
1284{
1285 if (entering(tcp)) {
1286 tprintf("%ld, ", tcp->u_arg[0]);
1287 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1288 tprintf(", %lu, ", tcp->u_arg[2]);
1289 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001290 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001291 /* to address */
1292 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001293 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 /* to length */
1295 tprintf(", %lu", tcp->u_arg[5]);
1296 }
1297 return 0;
1298}
1299
1300#ifdef HAVE_SENDMSG
1301
1302int
1303sys_sendmsg(tcp)
1304struct tcb *tcp;
1305{
1306 if (entering(tcp)) {
1307 tprintf("%ld, ", tcp->u_arg[0]);
1308 printmsghdr(tcp, tcp->u_arg[1]);
1309 /* flags */
1310 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001311 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 }
1313 return 0;
1314}
1315
1316#endif /* HAVE_SENDMSG */
1317
1318int
1319sys_recv(tcp)
1320struct tcb *tcp;
1321{
1322 if (entering(tcp)) {
1323 tprintf("%ld, ", tcp->u_arg[0]);
1324 } else {
1325 if (syserror(tcp))
1326 tprintf("%#lx", tcp->u_arg[1]);
1327 else
1328 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1329
1330 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +00001331 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 }
1333 return 0;
1334}
1335
1336int
1337sys_recvfrom(tcp)
1338struct tcb *tcp;
1339{
1340 int fromlen;
1341
1342 if (entering(tcp)) {
1343 tprintf("%ld, ", tcp->u_arg[0]);
1344 } else {
1345 if (syserror(tcp)) {
1346 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1347 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1348 tcp->u_arg[4], tcp->u_arg[5]);
1349 return 0;
1350 }
1351 /* buf */
1352 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1353 /* len */
1354 tprintf(", %lu, ", tcp->u_arg[2]);
1355 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +00001356 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357 /* from address, len */
1358 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1359 if (tcp->u_arg[4] == 0)
1360 tprintf(", NULL");
1361 else
1362 tprintf(", %#lx", tcp->u_arg[4]);
1363 if (tcp->u_arg[5] == 0)
1364 tprintf(", NULL");
1365 else
1366 tprintf(", %#lx", tcp->u_arg[5]);
1367 return 0;
1368 }
1369 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1370 tprintf(", {...}, [?]");
1371 return 0;
1372 }
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 /* from length */
1376 tprintf(", [%u]", fromlen);
1377 }
1378 return 0;
1379}
1380
1381#ifdef HAVE_SENDMSG
1382
1383int
1384sys_recvmsg(tcp)
1385struct tcb *tcp;
1386{
1387 if (entering(tcp)) {
1388 tprintf("%ld, ", tcp->u_arg[0]);
1389 } else {
1390 if (syserror(tcp) || !verbose(tcp))
1391 tprintf("%#lx", tcp->u_arg[1]);
1392 else
1393 printmsghdr(tcp, tcp->u_arg[1]);
1394 /* flags */
1395 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001396 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 }
1398 return 0;
1399}
1400
1401#endif /* HAVE_SENDMSG */
1402
1403int
1404sys_shutdown(tcp)
1405struct tcb *tcp;
1406{
1407 if (entering(tcp)) {
1408 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1409 switch (tcp->u_arg[1]) {
1410 case 0:
1411 tprintf("%s", " /* receive */");
1412 break;
1413 case 1:
1414 tprintf("%s", " /* send */");
1415 break;
1416 case 2:
1417 tprintf("%s", " /* send and receive */");
1418 break;
1419 }
1420 }
1421 return 0;
1422}
1423
1424int
1425sys_getsockname(tcp)
1426struct tcb *tcp;
1427{
1428 return sys_accept(tcp);
1429}
1430
1431int
1432sys_getpeername(tcp)
1433struct tcb *tcp;
1434{
1435 return sys_accept(tcp);
1436}
1437
1438int
1439sys_pipe(tcp)
1440struct tcb *tcp;
1441{
1442
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001443#if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444 int fds[2];
1445
1446 if (exiting(tcp)) {
1447 if (syserror(tcp)) {
1448 tprintf("%#lx", tcp->u_arg[0]);
1449 return 0;
1450 }
1451 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1452 tprintf("[...]");
1453 else
1454 tprintf("[%u, %u]", fds[0], fds[1]);
1455 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001456#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457 if (exiting(tcp))
1458 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459#endif
1460 return 0;
1461}
1462
1463int
1464sys_socketpair(tcp)
1465struct tcb *tcp;
1466{
1467#ifdef LINUX
1468 int fds[2];
1469#endif
1470
1471 if (entering(tcp)) {
1472 printxval(domains, tcp->u_arg[0], "PF_???");
1473 tprintf(", ");
1474 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1475 tprintf(", ");
1476 switch (tcp->u_arg[0]) {
1477 case PF_INET:
1478 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1479 break;
1480#ifdef PF_IPX
1481 case PF_IPX:
1482 /* BTW: I don't believe this.. */
1483 tprintf("[");
1484 printxval(domains, tcp->u_arg[2], "PF_???");
1485 tprintf("]");
1486 break;
1487#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001488 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001489 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490 break;
1491 }
1492 } else {
1493 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001494 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495 return 0;
1496 }
1497#ifdef LINUX
1498 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001499 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500 else
1501 tprintf(", [%u, %u]", fds[0], fds[1]);
1502#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001503#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001504 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001505#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001506 }
1507 return 0;
1508}
1509
1510int
1511sys_getsockopt(tcp)
1512struct tcb *tcp;
1513{
1514 if (entering(tcp)) {
1515 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001516 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1517 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001518 switch (tcp->u_arg[1]) {
1519 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521 break;
1522#ifdef SOL_IP
1523 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001524 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525 break;
1526#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001527#ifdef SOL_IPV6
1528 case SOL_IPV6:
1529 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1530 break;
1531#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001532#ifdef SOL_IPX
1533 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001534 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535 break;
1536#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001537#ifdef SOL_PACKET
1538 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001539 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001540 break;
1541#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542#ifdef SOL_TCP
1543 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545 break;
1546#endif
1547
1548 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1549 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001550 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001551 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001552 break;
1553 }
1554 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001555 int len;
John Hughes93f7fcc2002-05-22 15:46:49 +00001556 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1557 tprintf(", %#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558 tcp->u_arg[3], tcp->u_arg[4]);
1559 return 0;
1560 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001561
1562 switch (tcp->u_arg[1]) {
1563 case SOL_SOCKET:
1564 switch (tcp->u_arg[2]) {
1565#ifdef SO_LINGER
1566 case SO_LINGER:
1567 if (len == sizeof (struct linger)) {
1568 struct linger linger;
1569 if (umove (tcp,
1570 tcp->u_arg[3],
1571 &linger) < 0)
1572 break;
1573 tprintf(", {onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001574 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001575 linger.l_onoff,
1576 linger.l_linger,
1577 len);
1578 return 0;
1579 }
1580 break;
1581#endif
1582 }
1583 break;
1584 }
1585
1586 tprintf (", ");
1587 if (len == sizeof (int)) {
1588 printnum(tcp, tcp->u_arg[3], "%ld");
1589 }
1590 else {
1591 printstr (tcp, tcp->u_arg[3], len);
1592 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001593 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 }
1595 return 0;
1596}
1597
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001598#if defined(ICMP_FILTER)
1599static void printicmpfilter(tcp, addr)
1600struct tcb *tcp;
1601long addr;
1602{
1603 struct icmp_filter filter;
1604
1605 if (!addr) {
1606 tprintf("NULL");
1607 return;
1608 }
1609 if (syserror(tcp) || !verbose(tcp)) {
1610 tprintf("%#lx", addr);
1611 return;
1612 }
1613 if (umove(tcp, addr, &filter) < 0) {
1614 tprintf("{...}");
1615 return;
1616 }
1617
1618 tprintf("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001619 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001620 tprintf(")");
1621}
1622#endif /* ICMP_FILTER */
1623
John Hughes38ae88d2002-05-23 11:48:58 +00001624static int
1625printsockopt (tcp, level, name, addr, len)
1626struct tcb *tcp;
1627int level;
1628int name;
1629long addr;
1630int len;
1631{
1632 printxval(socketlayers, level, "SOL_??");
1633 tprintf (", ");
1634 switch (level) {
1635 case SOL_SOCKET:
1636 printxval(sockoptions, name, "SO_???");
1637 switch (name) {
1638#if defined(SO_LINGER)
1639 case SO_LINGER:
1640 if (len == sizeof (struct linger)) {
1641 struct linger linger;
1642 if (umove (tcp, addr, &linger) < 0)
1643 break;
1644 tprintf(", {onoff=%d, linger=%d}",
1645 linger.l_onoff,
1646 linger.l_linger);
1647 return 0;
1648 }
1649 break;
1650#endif
1651 }
1652 break;
1653#ifdef SOL_IP
1654 case SOL_IP:
1655 printxval(sockipoptions, name, "IP_???");
1656 break;
1657#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001658#ifdef SOL_IPV6
1659 case SOL_IPV6:
1660 printxval(sockipv6options, name, "IPV6_???");
1661 break;
1662#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001663#ifdef SOL_IPX
1664 case SOL_IPX:
1665 printxval(sockipxoptions, name, "IPX_???");
1666 break;
1667#endif
1668#ifdef SOL_PACKET
1669 case SOL_PACKET:
1670 printxval(sockpacketoptions, name, "PACKET_???");
1671 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1672 break;
1673#endif
1674#ifdef SOL_TCP
1675 case SOL_TCP:
1676 printxval(socktcpoptions, name, "TCP_???");
1677 break;
1678#endif
1679#ifdef SOL_RAW
1680 case SOL_RAW:
1681 printxval(sockrawoptions, name, "RAW_???");
1682 switch (name) {
1683#if defined(ICMP_FILTER)
1684 case ICMP_FILTER:
1685 tprintf(", ");
1686 printicmpfilter(tcp, addr);
1687 return 0;
1688#endif
1689 }
1690 break;
1691#endif
1692
Roland McGrath6d2b3492002-12-30 00:51:30 +00001693 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001694 * etc. still need work */
1695
1696 default:
1697 tprintf("%u", name);
1698 }
1699
1700 /* default arg printing */
1701
1702 tprintf (", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001703
John Hughes38ae88d2002-05-23 11:48:58 +00001704 if (len == sizeof (int)) {
1705 printnum(tcp, addr, "%ld");
1706 }
1707 else {
1708 printstr (tcp, addr, len);
1709 }
1710 return 0;
1711}
1712
1713
Roland McGrathc3ca0d82003-01-14 07:53:38 +00001714#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00001715
1716void
1717print_sock_optmgmt (tcp, addr, len)
1718struct tcb *tcp;
1719long addr;
1720int len;
1721{
1722 int c = 0;
1723 struct opthdr hdr;
1724
John Hughes2c4e3a82002-05-24 10:19:44 +00001725 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00001726 if (umove(tcp, addr, &hdr) < 0) break;
1727 if (c++) {
1728 tprintf (", ");
1729 }
1730 else if (len > hdr.len + sizeof hdr) {
1731 tprintf ("[");
1732 }
1733 tprintf ("{");
1734 addr += sizeof hdr;
1735 len -= sizeof hdr;
1736 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00001737 if (hdr.len > 0) {
1738 addr += hdr.len;
1739 len -= hdr.len;
1740 }
John Hughes38ae88d2002-05-23 11:48:58 +00001741 tprintf ("}");
1742 }
1743 if (len > 0) {
1744 if (c++) tprintf (", ");
1745 printstr (tcp, addr, len);
1746 }
1747 if (c > 1) tprintf ("]");
1748}
1749
1750#endif
1751
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001752int
1753sys_setsockopt(tcp)
1754struct tcb *tcp;
1755{
1756 if (entering(tcp)) {
1757 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes38ae88d2002-05-23 11:48:58 +00001758 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1759 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001760 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001761 }
1762 return 0;
1763}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001764
1765#if UNIXWARE >= 7
1766
Roland McGrathd9f816f2004-09-04 03:39:20 +00001767static const struct xlat sock_version[] = {
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001768 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1769 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1770 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1771 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1772 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1773 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1774 { 0, NULL },
1775};
1776
1777
1778int
1779netlib_call(tcp, func)
1780struct tcb *tcp;
1781int (*func) ();
1782{
1783 if (entering(tcp)) {
1784 int i;
1785 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1786 tprintf(", ");
1787 --tcp->u_nargs;
1788 for (i = 0; i < tcp->u_nargs; i++)
1789 tcp->u_arg[i] = tcp->u_arg[i + 1];
1790 return func (tcp);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001791
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001792 }
1793
1794 return func (tcp);
1795}
1796
1797int
1798sys_xsocket(tcp)
1799struct tcb *tcp;
1800{
1801 return netlib_call (tcp, sys_socket);
1802}
1803
1804int
1805sys_xsocketpair(tcp)
1806struct tcb *tcp;
1807{
1808 return netlib_call (tcp, sys_socketpair);
1809}
1810
1811int
1812sys_xbind(tcp)
1813struct tcb *tcp;
1814{
1815 return netlib_call (tcp, sys_bind);
1816}
1817
1818int
1819sys_xconnect(tcp)
1820struct tcb *tcp;
1821{
1822 return netlib_call (tcp, sys_connect);
1823}
1824
1825int
1826sys_xlisten(tcp)
1827struct tcb *tcp;
1828{
1829 return netlib_call (tcp, sys_listen);
1830}
1831
1832int
1833sys_xaccept(tcp)
1834struct tcb *tcp;
1835{
1836 return netlib_call (tcp, sys_accept);
1837}
1838
1839int
1840sys_xsendmsg(tcp)
1841struct tcb *tcp;
1842{
1843 return netlib_call (tcp, sys_sendmsg);
1844}
1845
1846int
1847sys_xrecvmsg(tcp)
1848struct tcb *tcp;
1849{
1850 return netlib_call (tcp, sys_recvmsg);
1851}
1852
1853int
1854sys_xgetsockaddr(tcp)
1855struct tcb *tcp;
1856{
1857 if (entering(tcp)) {
1858 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1859 tprintf(", ");
1860 if (tcp->u_arg[1] == 0) {
1861 tprintf ("LOCALNAME, ");
1862 }
1863 else if (tcp->u_arg[1] == 1) {
1864 tprintf ("REMOTENAME, ");
1865 }
1866 else {
1867 tprintf ("%ld, ", tcp->u_arg [1]);
1868 }
1869 tprintf ("%ld, ", tcp->u_arg [2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001870 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001871 else {
1872 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1873 tprintf("%#lx", tcp->u_arg[3]);
1874 } else {
1875 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1876 }
1877 tprintf(", ");
1878 printnum(tcp, tcp->u_arg[4], "%lu");
1879 }
1880
1881 return 0;
1882
1883}
1884
1885#if 0
1886
1887int
1888sys_xsetsockaddr(tcp)
1889struct tcb *tcp;
1890{
1891 return netlib_call (tcp, sys_setsockaddr);
1892}
1893
1894#endif
1895
1896int
1897sys_xgetsockopt(tcp)
1898struct tcb *tcp;
1899{
1900 return netlib_call (tcp, sys_getsockopt);
1901}
1902
1903int
1904sys_xsetsockopt(tcp)
1905struct tcb *tcp;
1906{
1907 return netlib_call (tcp, sys_setsockopt);
1908}
1909
1910int
1911sys_xshutdown(tcp)
1912struct tcb *tcp;
1913{
1914 return netlib_call (tcp, sys_shutdown);
1915}
1916
1917#endif