blob: 3da89945d7d535f2b14d27692dbb6981a164f7f5 [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
119static struct xlat domains[] = {
120 { PF_UNSPEC, "PF_UNSPEC" },
121 { PF_UNIX, "PF_UNIX" },
122 { PF_INET, "PF_INET" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000123#ifdef PF_NETLINK
124 { PF_NETLINK, "PF_NETLINK" },
125#endif
126#ifdef PF_PACKET
127 { PF_PACKET, "PF_PACKET" },
128#endif
129#ifdef PF_INET6
130 { PF_INET6, "PF_INET6" },
131#endif
132#ifdef PF_ATMSVC
133 { PF_ATMSVC, "PF_INET6" },
134#endif
135#ifdef PF_INET6
136 { PF_INET6, "PF_INET6" },
137#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138#ifdef PF_LOCAL
139 { PF_LOCAL, "PS_LOCAL" },
140#endif
141#ifdef PF_ISO
142 { PF_ISO, "PF_ISO" },
143#endif
144#ifdef PF_AX25
145 { PF_AX25, "PF_AX25" },
146#endif
147#ifdef PF_IPX
148 { PF_IPX, "PF_IPX" },
149#endif
150#ifdef PF_APPLETALK
151 { PF_APPLETALK, "PF_APPLETALK" },
152#endif
153#ifdef PF_NETROM
154 { PF_NETROM, "PF_NETROM" },
155#endif
156#ifdef PF_BRIDGE
157 { PF_BRIDGE, "PF_BRIDGE" },
158#endif
159#ifdef PF_AAL5
160 { PF_AAL5, "PF_AAL5" },
161#endif
162#ifdef PF_X25
163 { PF_X25, "PF_X25" },
164#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165#ifdef PF_ROSE
166 { PF_ROSE, "PF_ROSE" },
167#endif
168#ifdef PF_DECNET
169 { PF_DECNET, "PF_DECNET" },
170#endif
171#ifdef PF_NETBEUI
172 { PF_NETBEUI, "PF_NETBEUI" },
173#endif
174#ifdef PF_IMPLINK
175 { PF_IMPLINK, "PF_IMPLINK" },
176#endif
177 { 0, NULL },
178};
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000179static struct xlat addrfams[] = {
180 { AF_UNSPEC, "AF_UNSPEC" },
181 { AF_UNIX, "AF_UNIX" },
182 { AF_INET, "AF_INET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000183#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000184 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000185#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000186 { AF_DECnet, "AF_DECnet" },
187#ifdef PF_ATMSVC
188 { AF_ATMSVC, "AF_ATMSVC" },
189#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000190#ifdef AF_PACKET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000191 { AF_PACKET, "AF_PACKET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000192#endif
193#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000194 { AF_NETLINK, "AF_NETLINK" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000195#endif
196#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000197 { AF_ISO, "AF_ISO" },
198#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000199#ifdef AF_IMPLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000200 { AF_IMPLINK, "AF_IMPLINK" },
201#endif
202 { 0, NULL },
203};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204static struct xlat socktypes[] = {
205 { SOCK_STREAM, "SOCK_STREAM" },
206 { SOCK_DGRAM, "SOCK_DGRAM" },
207#ifdef SOCK_RAW
208 { SOCK_RAW, "SOCK_RAW" },
209#endif
210#ifdef SOCK_SEQPACKET
211 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
212#endif
213#ifdef SOCK_RDM
214 { SOCK_RDM, "SOCK_RDM" },
215#endif
216#ifdef SOCK_PACKET
217 { SOCK_PACKET, "SOCK_PACKET" },
218#endif
219 { 0, NULL },
220};
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000221static struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000222#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000223 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000224#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000225#if defined(SOL_ICMP)
226 { SOL_ICMP, "SOL_ICMP" },
227#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000228#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000229 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000230#endif
231#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000232 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000233#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000234#if defined(SOL_IPV6)
235 { SOL_IPV6, "SOL_IPV6" },
236#endif
237#if defined(SOL_ICMPV6)
238 { SOL_ICMPV6, "SOL_ICMPV6" },
239#endif
240#if defined(SOL_RAW)
241 { SOL_RAW, "SOL_RAW" },
242#endif
243#if defined(SOL_IPX)
244 { SOL_IPX, "SOL_IPX" },
245#endif
246#if defined(SOL_IPX)
247 { SOL_IPX, "SOL_IPX" },
248#endif
249#if defined(SOL_AX25)
250 { SOL_AX25, "SOL_AX25" },
251#endif
252#if defined(SOL_ATALK)
253 { SOL_ATALK, "SOL_ATALK" },
254#endif
255#if defined(SOL_NETROM)
256 { SOL_NETROM, "SOL_NETROM" },
257#endif
258#if defined(SOL_ROSE)
259 { SOL_ROSE, "SOL_ROSE" },
260#endif
261#if defined(SOL_DECNET)
262 { SOL_DECNET, "SOL_DECNET" },
263#endif
264#if defined(SOL_X25)
265 { SOL_X25, "SOL_X25" },
266#endif
267#if defined(SOL_PACKET)
268 { SOL_PACKET, "SOL_PACKET" },
269#endif
270#if defined(SOL_ATM)
271 { SOL_ATM, "SOL_ATM" },
272#endif
273#if defined(SOL_AAL)
274 { SOL_AAL, "SOL_AAL" },
275#endif
276#if defined(SOL_IRDA)
277 { SOL_IRDA, "SOL_IRDA" },
278#endif
John Hughes61563572001-03-27 16:47:36 +0000279 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000280};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281static struct xlat protocols[] = {
282 { IPPROTO_IP, "IPPROTO_IP" },
283 { IPPROTO_ICMP, "IPPROTO_ICMP" },
284 { IPPROTO_TCP, "IPPROTO_TCP" },
285 { IPPROTO_UDP, "IPPROTO_UDP" },
286#ifdef IPPROTO_GGP
287 { IPPROTO_GGP, "IPPROTO_GGP" },
288#endif
289#ifdef IPPROTO_EGP
290 { IPPROTO_EGP, "IPPROTO_EGP" },
291#endif
292#ifdef IPPROTO_PUP
293 { IPPROTO_PUP, "IPPROTO_PUP" },
294#endif
295#ifdef IPPROTO_IDP
296 { IPPROTO_IDP, "IPPROTO_IDP" },
297#endif
298#ifdef IPPROTO_IPV6
299 { IPPROTO_IPV6, "IPPROTO_IPV6" },
300#endif
301#ifdef IPPROTO_ICMPV6
302 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
303#endif
304#ifdef IPPROTO_IGMP
305 { IPPROTO_IGMP, "IPPROTO_IGMP" },
306#endif
307#ifdef IPPROTO_HELLO
308 { IPPROTO_HELLO,"IPPROTO_HELLO" },
309#endif
310#ifdef IPPROTO_ND
311 { IPPROTO_ND, "IPPROTO_ND" },
312#endif
313#ifdef IPPROTO_RAW
314 { IPPROTO_RAW, "IPPROTO_RAW" },
315#endif
316#ifdef IPPROTO_MAX
317 { IPPROTO_MAX, "IPPROTO_MAX" },
318#endif
319#ifdef IPPROTO_IPIP
320 { IPPROTO_IPIP, "IPPROTO_IPIP" },
321#endif
322 { 0, NULL },
323};
324static struct xlat msg_flags[] = {
325 { MSG_OOB, "MSG_OOB" },
326#ifdef MSG_DONTROUTE
327 { MSG_DONTROUTE,"MSG_DONTROUTE" },
328#endif
329#ifdef MSG_PEEK
330 { MSG_PEEK, "MSG_PEEK" },
331#endif
332#ifdef MSG_CTRUNC
333 { MSG_CTRUNC, "MSG_CTRUNC" },
334#endif
335#ifdef MSG_PROXY
336 { MSG_PROXY, "MSG_PROXY" },
337#endif
338#ifdef MSG_EOR
339 { MSG_EOR, "MSG_EOR" },
340#endif
341#ifdef MSG_WAITALL
342 { MSG_WAITALL, "MSG_WAITALL" },
343#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000344#ifdef MSG_TRUNC
345 { MSG_TRUNC, "MSG_TRUNC" },
346#endif
347#ifdef MSG_CTRUNC
348 { MSG_CTRUNC, "MSG_CTRUNC" },
349#endif
350#ifdef MSG_ERRQUEUE
351 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
352#endif
353#ifdef MSG_DONTWAIT
354 { MSG_DONTWAIT, "MSG_DONTWAIT" },
355#endif
356#ifdef MSG_CONFIRM
357 { MSG_CONFIRM, "MSG_CONFIRM" },
358#endif
359#ifdef MSG_PROBE
360 { MSG_PROBE, "MSG_PROBE" },
361#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 { 0, NULL },
363};
364
365static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000366#ifdef SO_PEERCRED
367 { SO_PEERCRED, "SO_PEERCRED" },
368#endif
369#ifdef SO_PASSCRED
370 { SO_PASSCRED, "SO_PASSCRED" },
371#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372#ifdef SO_DEBUG
373 { SO_DEBUG, "SO_DEBUG" },
374#endif
375#ifdef SO_REUSEADDR
376 { SO_REUSEADDR, "SO_REUSEADDR" },
377#endif
378#ifdef SO_KEEPALIVE
379 { SO_KEEPALIVE, "SO_KEEPALIVE" },
380#endif
381#ifdef SO_DONTROUTE
382 { SO_DONTROUTE, "SO_DONTROUTE" },
383#endif
384#ifdef SO_BROADCAST
385 { SO_BROADCAST, "SO_BROADCAST" },
386#endif
387#ifdef SO_LINGER
388 { SO_LINGER, "SO_LINGER" },
389#endif
390#ifdef SO_OOBINLINE
391 { SO_OOBINLINE, "SO_OOBINLINE" },
392#endif
393#ifdef SO_TYPE
394 { SO_TYPE, "SO_TYPE" },
395#endif
396#ifdef SO_ERROR
397 { SO_ERROR, "SO_ERROR" },
398#endif
399#ifdef SO_SNDBUF
400 { SO_SNDBUF, "SO_SNDBUF" },
401#endif
402#ifdef SO_RCVBUF
403 { SO_RCVBUF, "SO_RCVBUF" },
404#endif
405#ifdef SO_NO_CHECK
406 { SO_NO_CHECK, "SO_NO_CHECK" },
407#endif
408#ifdef SO_PRIORITY
409 { SO_PRIORITY, "SO_PRIORITY" },
410#endif
411#ifdef SO_ACCEPTCONN
412 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
413#endif
414#ifdef SO_USELOOPBACK
415 { SO_USELOOPBACK,"SO_USELOOPBACK"},
416#endif
417#ifdef SO_SNDLOWAT
418 { SO_SNDLOWAT, "SO_SNDLOWAT" },
419#endif
420#ifdef SO_RCVLOWAT
421 { SO_RCVLOWAT, "SO_RCVLOWAT" },
422#endif
423#ifdef SO_SNDTIMEO
424 { SO_SNDTIMEO, "SO_SNDTIMEO" },
425#endif
426#ifdef SO_RCVTIMEO
427 { SO_RCVTIMEO, "SO_RCVTIMEO" },
428#endif
429#ifdef SO_BSDCOMPAT
430 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
431#endif
432#ifdef SO_REUSEPORT
433 { SO_REUSEPORT, "SO_REUSEPORT" },
434#endif
435#ifdef SO_RCVLOWAT
436 { SO_RCVLOWAT, "SO_RCVLOWAT" },
437#endif
438#ifdef SO_SNDLOWAT
439 { SO_SNDLOWAT, "SO_SNDLOWAT" },
440#endif
441#ifdef SO_RCVTIMEO
442 { SO_RCVTIMEO, "SO_RCVTIMEO" },
443#endif
444#ifdef SO_SNDTIMEO
445 { SO_SNDTIMEO, "SO_SNDTIMEO" },
446#endif
447 { 0, NULL },
448};
449
450#ifdef SOL_IP
451static struct xlat sockipoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000452 { IP_TOS, "IP_TOS" },
453 { IP_TTL, "IP_TTL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454#if defined(IP_HDRINCL)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000455 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456#endif
457#if defined(IP_OPTIONS)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000458 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000460 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
461#if defined(IP_RECVOPTIONS)
462 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
463#endif
464 { IP_RETOPTS, "IP_RETOPTS" },
465 { IP_PKTINFO, "IP_PKTINFO" },
466 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
467 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
468 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
469 { IP_RECVERR, "IP_RECVERR" },
470 { IP_RECVTTL, "IP_RECRECVTTL" },
471 { IP_RECVTOS, "IP_RECRECVTOS" },
472#if defined(IP_MTU)
473 { IP_MTU, "IP_MTU" },
474#endif
475 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
476 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
477 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
478 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
479 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
480 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481};
482#endif /* SOL_IP */
483
484#ifdef SOL_IPX
485static struct xlat sockipxoptions[] = {
486 { IPX_TYPE, "IPX_TYPE" },
487 { 0, NULL },
488};
489#endif /* SOL_IPX */
490
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000491#ifdef SOL_RAW
492static struct xlat sockrawoptions[] = {
493#if defined(ICMP_FILTER)
494 { ICMP_FILTER, "ICMP_FILTER" },
495#endif
496 { 0, NULL },
497};
498#endif /* SOL_RAW */
499
500#ifdef SOL_PACKET
501static struct xlat sockpacketoptions[] = {
502 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
503 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
504#if defined(PACKET_RECV_OUTPUT)
505 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
506#endif
507#if defined(PACKET_RX_RING)
508 { PACKET_RX_RING, "PACKET_RX_RING" },
509#endif
510#if defined(PACKET_STATISTICS)
511 { PACKET_STATISTICS, "PACKET_STATISTICS" },
512#endif
513 { 0, NULL },
514};
515#endif /* SOL_PACKET */
516
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517#ifdef SOL_TCP
518static struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000519 { TCP_NODELAY, "TCP_NODELAY" },
520 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000521#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000522 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000523#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000524#if defined(TCP_KEEPIDLE)
525 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
526#endif
527#if defined(TCP_KEEPINTVL)
528 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
529#endif
530#if defined(TCP_KEEPCNT)
531 { TCP_KEEPCNT, "TCP_KEEPCNT" },
532#endif
533#if defined(TCP_SYNCNT)
534 { TCP_SYNCNT, "TCP_SYNCNT" },
535#endif
536#if defined(TCP_LINGER2)
537 { TCP_LINGER2, "TCP_LINGER2" },
538#endif
539#if defined(TCP_DEFER_ACCEPT)
540 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
541#endif
542#if defined(TCP_WINDOW_CLAMP)
543 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
544#endif
545#if defined(TCP_INFO)
546 { TCP_INFO, "TCP_INFO" },
547#endif
548#if defined(TCP_QUICKACK)
549 { TCP_QUICKACK, "TCP_QUICKACK" },
550#endif
551 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552};
553#endif /* SOL_TCP */
554
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000555#ifdef SOL_RAW
556static struct xlat icmpfilterflags[] = {
557#if defined(ICMP_ECHOREPLY)
558 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
559#endif
560#if defined(ICMP_DEST_UNREACH)
561 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
562#endif
563#if defined(ICMP_SOURCE_QUENCH)
564 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
565#endif
566#if defined(ICMP_REDIRECT)
567 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
568#endif
569#if defined(ICMP_ECHO)
570 { (1<<ICMP_ECHO), "ICMP_ECHO" },
571#endif
572#if defined(ICMP_TIME_EXCEEDED)
573 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
574#endif
575#if defined(ICMP_PARAMETERPROB)
576 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
577#endif
578#if defined(ICMP_TIMESTAMP)
579 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
580#endif
581#if defined(ICMP_TIMESTAMPREPLY)
582 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
583#endif
584#if defined(ICMP_INFO_REQUEST)
585 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
586#endif
587#if defined(ICMP_INFO_REPLY)
588 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
589#endif
590#if defined(ICMP_ADDRESS)
591 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
592#endif
593#if defined(ICMP_ADDRESSREPLY)
594 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
595#endif
596 { 0, NULL },
597};
598#endif /* SOL_RAW */
599
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000600
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000602printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603struct tcb *tcp;
604long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000605int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000607 union {
608 char pad[128];
609 struct sockaddr sa;
610 struct sockaddr_in sin;
611 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000612#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000613 struct sockaddr_in6 sa6;
614#endif
615#if defined(LINUX) && defined(AF_IPX)
616 struct sockaddr_ipx sipx;
617#endif
618#ifdef AF_PACKET
619 struct sockaddr_ll ll;
620#endif
621#ifdef AF_NETLINK
622 struct sockaddr_nl nl;
623#endif
624 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000625 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626
627 if (addr == 0) {
628 tprintf("NULL");
629 return;
630 }
631 if (!verbose(tcp)) {
632 tprintf("%#lx", addr);
633 return;
634 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000635 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
636 addrlen=sizeof(addrbuf);
637
638 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 tprintf("{...}");
640 return;
641 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000642
John Hughes1fcb1d62001-09-18 15:56:53 +0000643 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000644 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
645 tprintf(", ");
646
647 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000649 if (addrlen==2) {
650 tprintf("<nil>");
651 } else if (addrbuf.sau.sun_path[0]) {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000652 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000653 } else {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000654 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000655 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 break;
657 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000658 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000659 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000661#ifdef HAVE_INET_NTOP
662 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000663 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000664 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
665 ntohs(addrbuf.sa6.sin6_port), string_addr,
666 addrbuf.sa6.sin6_flowinfo);
667#ifdef HAVE_SIN6_SCOPE_ID
668 {
669#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
670 int numericscope = 0;
671 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
672 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
673 char scopebuf[IFNAMSIZ + 1];
674
675 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
676 numericscope++;
677 else
678 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
679 } else
680 numericscope++;
681
682 if (numericscope)
683#endif
684 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
685 }
686#endif
687 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000688#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000689#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000691 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000693 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000694 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695 /* Yes, I know, this does not look too
696 * strace-ish, but otherwise the IPX
697 * addresses just look monstrous...
698 * Anyways, feel free if you don't like
699 * this way.. :)
700 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000701 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000703 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
704 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705 }
706 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000707#endif /* AF_IPX && linux */
708#ifdef AF_PACKET
709 case AF_PACKET:
710 {
711 int i;
712 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
713 ntohs(addrbuf.ll.sll_protocol),
714 addrbuf.ll.sll_ifindex,
715 addrbuf.ll.sll_pkttype,
716 addrbuf.ll.sll_halen,
717 addrbuf.ll.sll_hatype);
718 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
719 tprintf("%02x", addrbuf.ll.sll_addr[i]);
720 }
721 break;
722
723#endif /* AF_APACKET */
724#ifdef AF_NETLINLK
725 case AF_NETLINK:
726 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
727 break;
728#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000730 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731
732 default:
John Hughes1fcb1d62001-09-18 15:56:53 +0000733 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000735 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736 break;
737 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000738 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739}
740
741#if HAVE_SENDMSG
742
743static void
744printmsghdr(tcp, addr)
745struct tcb *tcp;
746long addr;
747{
748 struct msghdr msg;
749
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000750 if (umove(tcp, addr, &msg) < 0) {
751 tprintf("%#lx", addr);
752 return;
753 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000754 tprintf("{msg_name(%d)=", msg.msg_namelen);
755 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
756
757 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
John Hughes1d08dcf2001-07-10 13:48:44 +0000758 tprint_iov(tcp, msg.msg_iovlen, (long) msg.msg_iov);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000759
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000761 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
762 if (msg.msg_controllen)
763 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
764 tprintf(", msg_flags=");
765 if (printflags(msg_flags, msg.msg_flags)==0)
766 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000768 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
770#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000771 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000772}
773
774#endif /* HAVE_SENDMSG */
775
776int
777sys_socket(tcp)
778struct tcb *tcp;
779{
780 if (entering(tcp)) {
781 printxval(domains, tcp->u_arg[0], "PF_???");
782 tprintf(", ");
783 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
784 tprintf(", ");
785 switch (tcp->u_arg[0]) {
786 case PF_INET:
787 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
788 break;
789#ifdef PF_IPX
790 case PF_IPX:
791 /* BTW: I don't believe this.. */
792 tprintf("[");
793 printxval(domains, tcp->u_arg[2], "PF_???");
794 tprintf("]");
795 break;
796#endif /* PF_IPX */
797 default:
798 tprintf("%lu", tcp->u_arg[2]);
799 break;
800 }
801 }
802 return 0;
803}
804
805int
John Hughesbdf48f52001-03-06 15:08:09 +0000806sys_so_socket(tcp)
807struct tcb *tcp;
808{
809 if (entering(tcp)) {
810 /* not sure really what these args are... but this
811 * is how truss prints it
812 */
813 tprintf("%ld, %ld, %ld, ",
814 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
815 printpath(tcp, tcp->u_arg[3]);
816 tprintf(", %ld", tcp->u_arg[4]);
817 }
818 return 0;
819}
820
821int
822sys_so_socketpair(tcp)
823struct tcb *tcp;
824{
825 if (entering(tcp)) {
826 /* not sure what this arg is */
827 tprintf("0x%lx", tcp->u_arg[0]);
828 }
829 return 0;
830}
831
832int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833sys_bind(tcp)
834struct tcb *tcp;
835{
836 if (entering(tcp)) {
837 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000838 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 tprintf(", %lu", tcp->u_arg[2]);
840 }
841 return 0;
842}
843
844int
845sys_connect(tcp)
846struct tcb *tcp;
847{
848 return sys_bind(tcp);
849}
850
851int
852sys_listen(tcp)
853struct tcb *tcp;
854{
855 if (entering(tcp)) {
856 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
857 }
858 return 0;
859}
860
861int
862sys_accept(tcp)
863struct tcb *tcp;
864{
865 if (entering(tcp)) {
866 tprintf("%ld, ", tcp->u_arg[0]);
867 } else if (!tcp->u_arg[2])
868 tprintf("%#lx, NULL", tcp->u_arg[1]);
869 else {
870 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
871 tprintf("%#lx", tcp->u_arg[1]);
872 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000873 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874 }
875 tprintf(", ");
876 printnum(tcp, tcp->u_arg[2], "%lu");
877 }
878 return 0;
879}
880
881int
882sys_send(tcp)
883struct tcb *tcp;
884{
885 if (entering(tcp)) {
886 tprintf("%ld, ", tcp->u_arg[0]);
887 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
888 tprintf(", %lu, ", tcp->u_arg[2]);
889 /* flags */
890 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
891 tprintf("0");
892 }
893 return 0;
894}
895
896int
897sys_sendto(tcp)
898struct tcb *tcp;
899{
900 if (entering(tcp)) {
901 tprintf("%ld, ", tcp->u_arg[0]);
902 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
903 tprintf(", %lu, ", tcp->u_arg[2]);
904 /* flags */
905 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
906 tprintf("0");
907 /* to address */
908 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000909 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910 /* to length */
911 tprintf(", %lu", tcp->u_arg[5]);
912 }
913 return 0;
914}
915
916#ifdef HAVE_SENDMSG
917
918int
919sys_sendmsg(tcp)
920struct tcb *tcp;
921{
922 if (entering(tcp)) {
923 tprintf("%ld, ", tcp->u_arg[0]);
924 printmsghdr(tcp, tcp->u_arg[1]);
925 /* flags */
926 tprintf(", ");
927 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
928 tprintf("0");
929 }
930 return 0;
931}
932
933#endif /* HAVE_SENDMSG */
934
935int
936sys_recv(tcp)
937struct tcb *tcp;
938{
939 if (entering(tcp)) {
940 tprintf("%ld, ", tcp->u_arg[0]);
941 } else {
942 if (syserror(tcp))
943 tprintf("%#lx", tcp->u_arg[1]);
944 else
945 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
946
947 tprintf(", %lu, ", tcp->u_arg[2]);
948 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
949 tprintf("0");
950 }
951 return 0;
952}
953
954int
955sys_recvfrom(tcp)
956struct tcb *tcp;
957{
958 int fromlen;
959
960 if (entering(tcp)) {
961 tprintf("%ld, ", tcp->u_arg[0]);
962 } else {
963 if (syserror(tcp)) {
964 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
965 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
966 tcp->u_arg[4], tcp->u_arg[5]);
967 return 0;
968 }
969 /* buf */
970 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
971 /* len */
972 tprintf(", %lu, ", tcp->u_arg[2]);
973 /* flags */
974 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
975 tprintf("0");
976 /* from address, len */
977 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
978 if (tcp->u_arg[4] == 0)
979 tprintf(", NULL");
980 else
981 tprintf(", %#lx", tcp->u_arg[4]);
982 if (tcp->u_arg[5] == 0)
983 tprintf(", NULL");
984 else
985 tprintf(", %#lx", tcp->u_arg[5]);
986 return 0;
987 }
988 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
989 tprintf(", {...}, [?]");
990 return 0;
991 }
992 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000993 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994 /* from length */
995 tprintf(", [%u]", fromlen);
996 }
997 return 0;
998}
999
1000#ifdef HAVE_SENDMSG
1001
1002int
1003sys_recvmsg(tcp)
1004struct tcb *tcp;
1005{
1006 if (entering(tcp)) {
1007 tprintf("%ld, ", tcp->u_arg[0]);
1008 } else {
1009 if (syserror(tcp) || !verbose(tcp))
1010 tprintf("%#lx", tcp->u_arg[1]);
1011 else
1012 printmsghdr(tcp, tcp->u_arg[1]);
1013 /* flags */
1014 tprintf(", ");
1015 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1016 tprintf("0");
1017 }
1018 return 0;
1019}
1020
1021#endif /* HAVE_SENDMSG */
1022
1023int
1024sys_shutdown(tcp)
1025struct tcb *tcp;
1026{
1027 if (entering(tcp)) {
1028 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1029 switch (tcp->u_arg[1]) {
1030 case 0:
1031 tprintf("%s", " /* receive */");
1032 break;
1033 case 1:
1034 tprintf("%s", " /* send */");
1035 break;
1036 case 2:
1037 tprintf("%s", " /* send and receive */");
1038 break;
1039 }
1040 }
1041 return 0;
1042}
1043
1044int
1045sys_getsockname(tcp)
1046struct tcb *tcp;
1047{
1048 return sys_accept(tcp);
1049}
1050
1051int
1052sys_getpeername(tcp)
1053struct tcb *tcp;
1054{
1055 return sys_accept(tcp);
1056}
1057
1058int
1059sys_pipe(tcp)
1060struct tcb *tcp;
1061{
1062
1063#if defined(LINUX) && !defined(SPARC)
1064 int fds[2];
1065
1066 if (exiting(tcp)) {
1067 if (syserror(tcp)) {
1068 tprintf("%#lx", tcp->u_arg[0]);
1069 return 0;
1070 }
1071 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1072 tprintf("[...]");
1073 else
1074 tprintf("[%u, %u]", fds[0], fds[1]);
1075 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001076#elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077 if (exiting(tcp))
1078 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079#endif
1080 return 0;
1081}
1082
1083int
1084sys_socketpair(tcp)
1085struct tcb *tcp;
1086{
1087#ifdef LINUX
1088 int fds[2];
1089#endif
1090
1091 if (entering(tcp)) {
1092 printxval(domains, tcp->u_arg[0], "PF_???");
1093 tprintf(", ");
1094 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1095 tprintf(", ");
1096 switch (tcp->u_arg[0]) {
1097 case PF_INET:
1098 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1099 break;
1100#ifdef PF_IPX
1101 case PF_IPX:
1102 /* BTW: I don't believe this.. */
1103 tprintf("[");
1104 printxval(domains, tcp->u_arg[2], "PF_???");
1105 tprintf("]");
1106 break;
1107#endif /* PF_IPX */
1108 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001109 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110 break;
1111 }
1112 } else {
1113 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001114 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 return 0;
1116 }
1117#ifdef LINUX
1118 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001119 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120 else
1121 tprintf(", [%u, %u]", fds[0], fds[1]);
1122#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001123#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001124 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001125#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 }
1127 return 0;
1128}
1129
1130int
1131sys_getsockopt(tcp)
1132struct tcb *tcp;
1133{
1134 if (entering(tcp)) {
1135 tprintf("%ld, ", tcp->u_arg[0]);
1136 switch (tcp->u_arg[1]) {
1137 case SOL_SOCKET:
1138 tprintf("SOL_SOCKET, ");
1139 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1140 tprintf(", ");
1141 break;
1142#ifdef SOL_IP
1143 case SOL_IP:
1144 tprintf("SOL_IP, ");
1145 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1146 tprintf(", ");
1147 break;
1148#endif
1149#ifdef SOL_IPX
1150 case SOL_IPX:
1151 tprintf("SOL_IPX, ");
1152 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1153 tprintf(", ");
1154 break;
1155#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001156#ifdef SOL_PACKET
1157 case SOL_PACKET:
1158 tprintf("SOL_PACKET, ");
1159 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1160 tprintf(", ");
1161 break;
1162#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001163#ifdef SOL_TCP
1164 case SOL_TCP:
1165 tprintf("SOL_TCP, ");
1166 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1167 tprintf(", ");
1168 break;
1169#endif
1170
1171 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1172 * etc. still need work */
1173 default:
1174 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001175 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001176 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001177 break;
1178 }
1179 } else {
1180 if (syserror(tcp)) {
1181 tprintf("%#lx, %#lx",
1182 tcp->u_arg[3], tcp->u_arg[4]);
1183 return 0;
1184 }
1185 printnum(tcp, tcp->u_arg[3], "%ld");
1186 tprintf(", ");
1187 printnum(tcp, tcp->u_arg[4], "%ld");
1188 }
1189 return 0;
1190}
1191
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001192#if defined(ICMP_FILTER)
1193static void printicmpfilter(tcp, addr)
1194struct tcb *tcp;
1195long addr;
1196{
1197 struct icmp_filter filter;
1198
1199 if (!addr) {
1200 tprintf("NULL");
1201 return;
1202 }
1203 if (syserror(tcp) || !verbose(tcp)) {
1204 tprintf("%#lx", addr);
1205 return;
1206 }
1207 if (umove(tcp, addr, &filter) < 0) {
1208 tprintf("{...}");
1209 return;
1210 }
1211
1212 tprintf("~(");
1213 if (printflags(icmpfilterflags, ~filter.data) == 0)
1214 tprintf("0");
1215 tprintf(")");
1216}
1217#endif /* ICMP_FILTER */
1218
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219int
1220sys_setsockopt(tcp)
1221struct tcb *tcp;
1222{
1223 if (entering(tcp)) {
1224 tprintf("%ld, ", tcp->u_arg[0]);
1225 switch (tcp->u_arg[1]) {
1226 case SOL_SOCKET:
1227 tprintf("SOL_SOCKET, ");
1228 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1229 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001230 printnum(tcp, tcp->u_arg[3], "%ld");
1231 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232 break;
1233#ifdef SOL_IP
1234 case SOL_IP:
1235 tprintf("SOL_IP, ");
1236 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1237 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001238 printnum(tcp, tcp->u_arg[3], "%ld");
1239 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240 break;
1241#endif
1242#ifdef SOL_IPX
1243 case SOL_IPX:
1244 tprintf("SOL_IPX, ");
1245 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1246 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001247 printnum(tcp, tcp->u_arg[3], "%ld");
1248 tprintf(", %lu", tcp->u_arg[4]);
1249 break;
1250#endif
1251#ifdef SOL_PACKET
1252 case SOL_PACKET:
1253 tprintf("SOL_PACKET, ");
1254 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1255 tprintf(", ");
1256 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1257 printnum(tcp, tcp->u_arg[3], "%ld");
1258 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259 break;
1260#endif
1261#ifdef SOL_TCP
1262 case SOL_TCP:
1263 tprintf("SOL_TCP, ");
1264 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1265 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001266 printnum(tcp, tcp->u_arg[3], "%ld");
1267 tprintf(", %lu", tcp->u_arg[4]);
1268 break;
1269#endif
1270#ifdef SOL_RAW
1271 case SOL_RAW:
1272 tprintf("SOL_RAW, ");
1273 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1274 tprintf(", ");
1275 switch (tcp->u_arg[2]) {
1276#if defined(ICMP_FILTER)
1277 case ICMP_FILTER:
1278 printicmpfilter(tcp, tcp->u_arg[3]);
1279 break;
1280#endif
1281 default:
1282 printnum(tcp, tcp->u_arg[3], "%ld");
1283 break;
1284 }
1285 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286 break;
1287#endif
1288
1289 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1290 * etc. still need work */
1291 default:
1292 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001293 printxval(socketlayers, tcp->u_arg[1], "IPPROTO_???");
1294 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001295 printnum(tcp, tcp->u_arg[3], "%ld");
1296 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 break;
1298 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 }
1300 return 0;
1301}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001302
1303#if UNIXWARE >= 7
1304
1305static struct xlat sock_version[] = {
1306 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1307 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1308 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1309 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1310 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1311 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1312 { 0, NULL },
1313};
1314
1315
1316int
1317netlib_call(tcp, func)
1318struct tcb *tcp;
1319int (*func) ();
1320{
1321 if (entering(tcp)) {
1322 int i;
1323 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1324 tprintf(", ");
1325 --tcp->u_nargs;
1326 for (i = 0; i < tcp->u_nargs; i++)
1327 tcp->u_arg[i] = tcp->u_arg[i + 1];
1328 return func (tcp);
1329
1330 }
1331
1332 return func (tcp);
1333}
1334
1335int
1336sys_xsocket(tcp)
1337struct tcb *tcp;
1338{
1339 return netlib_call (tcp, sys_socket);
1340}
1341
1342int
1343sys_xsocketpair(tcp)
1344struct tcb *tcp;
1345{
1346 return netlib_call (tcp, sys_socketpair);
1347}
1348
1349int
1350sys_xbind(tcp)
1351struct tcb *tcp;
1352{
1353 return netlib_call (tcp, sys_bind);
1354}
1355
1356int
1357sys_xconnect(tcp)
1358struct tcb *tcp;
1359{
1360 return netlib_call (tcp, sys_connect);
1361}
1362
1363int
1364sys_xlisten(tcp)
1365struct tcb *tcp;
1366{
1367 return netlib_call (tcp, sys_listen);
1368}
1369
1370int
1371sys_xaccept(tcp)
1372struct tcb *tcp;
1373{
1374 return netlib_call (tcp, sys_accept);
1375}
1376
1377int
1378sys_xsendmsg(tcp)
1379struct tcb *tcp;
1380{
1381 return netlib_call (tcp, sys_sendmsg);
1382}
1383
1384int
1385sys_xrecvmsg(tcp)
1386struct tcb *tcp;
1387{
1388 return netlib_call (tcp, sys_recvmsg);
1389}
1390
1391int
1392sys_xgetsockaddr(tcp)
1393struct tcb *tcp;
1394{
1395 if (entering(tcp)) {
1396 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1397 tprintf(", ");
1398 if (tcp->u_arg[1] == 0) {
1399 tprintf ("LOCALNAME, ");
1400 }
1401 else if (tcp->u_arg[1] == 1) {
1402 tprintf ("REMOTENAME, ");
1403 }
1404 else {
1405 tprintf ("%ld, ", tcp->u_arg [1]);
1406 }
1407 tprintf ("%ld, ", tcp->u_arg [2]);
1408 }
1409 else {
1410 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1411 tprintf("%#lx", tcp->u_arg[3]);
1412 } else {
1413 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1414 }
1415 tprintf(", ");
1416 printnum(tcp, tcp->u_arg[4], "%lu");
1417 }
1418
1419 return 0;
1420
1421}
1422
1423#if 0
1424
1425int
1426sys_xsetsockaddr(tcp)
1427struct tcb *tcp;
1428{
1429 return netlib_call (tcp, sys_setsockaddr);
1430}
1431
1432#endif
1433
1434int
1435sys_xgetsockopt(tcp)
1436struct tcb *tcp;
1437{
1438 return netlib_call (tcp, sys_getsockopt);
1439}
1440
1441int
1442sys_xsetsockopt(tcp)
1443struct tcb *tcp;
1444{
1445 return netlib_call (tcp, sys_setsockopt);
1446}
1447
1448int
1449sys_xshutdown(tcp)
1450struct tcb *tcp;
1451{
1452 return netlib_call (tcp, sys_shutdown);
1453}
1454
1455#endif