blob: 068f84cfba9be3d01ca9e704866fab237d8ce238 [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 Akkermanb0c598f2002-04-01 12:48:06 +0000600#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
601static struct xlat af_packet_types[] = {
602#if defined(PACKET_HOST)
603 { PACKET_HOST, "PACKET_HOST" },
604#endif
605#if defined(PACKET_BROADCAST)
606 { PACKET_BROADCAST, "PACKET_BROADCAST" },
607#endif
608#if defined(PACKET_MULTICAST)
609 { PACKET_MULTICAST, "PACKET_MULTICAST" },
610#endif
611#if defined(PACKET_OTHERHOST)
612 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
613#endif
614#if defined(PACKET_OUTGOING)
615 { PACKET_OUTGOING, "PACKET_OUTGOING" },
616#endif
617#if defined(PACKET_LOOPBACK)
618 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
619#endif
620#if defined(PACKET_FASTROUTE)
621 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
622#endif
623 { 0, NULL },
624};
625#endif /* defined(AF_PACKET) */
626
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000627
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000629printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630struct tcb *tcp;
631long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000632int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000634 union {
635 char pad[128];
636 struct sockaddr sa;
637 struct sockaddr_in sin;
638 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000639#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000640 struct sockaddr_in6 sa6;
641#endif
642#if defined(LINUX) && defined(AF_IPX)
643 struct sockaddr_ipx sipx;
644#endif
645#ifdef AF_PACKET
646 struct sockaddr_ll ll;
647#endif
648#ifdef AF_NETLINK
649 struct sockaddr_nl nl;
650#endif
651 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000652 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653
654 if (addr == 0) {
655 tprintf("NULL");
656 return;
657 }
658 if (!verbose(tcp)) {
659 tprintf("%#lx", addr);
660 return;
661 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000662 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
663 addrlen=sizeof(addrbuf);
664
665 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666 tprintf("{...}");
667 return;
668 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000669
John Hughes1fcb1d62001-09-18 15:56:53 +0000670 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000671 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
672 tprintf(", ");
673
674 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000676 if (addrlen==2) {
677 tprintf("<nil>");
678 } else if (addrbuf.sau.sun_path[0]) {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000679 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000680 } else {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000681 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000682 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683 break;
684 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000685 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000686 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000688#ifdef HAVE_INET_NTOP
689 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000690 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000691 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
692 ntohs(addrbuf.sa6.sin6_port), string_addr,
693 addrbuf.sa6.sin6_flowinfo);
694#ifdef HAVE_SIN6_SCOPE_ID
695 {
696#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
697 int numericscope = 0;
698 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
699 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
700 char scopebuf[IFNAMSIZ + 1];
701
702 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
703 numericscope++;
704 else
705 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
706 } else
707 numericscope++;
708
709 if (numericscope)
710#endif
711 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
712 }
713#endif
714 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000715#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000716#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000718 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000720 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000721 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 /* Yes, I know, this does not look too
723 * strace-ish, but otherwise the IPX
724 * addresses just look monstrous...
725 * Anyways, feel free if you don't like
726 * this way.. :)
727 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000728 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000730 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
731 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732 }
733 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000734#endif /* AF_IPX && linux */
735#ifdef AF_PACKET
736 case AF_PACKET:
737 {
738 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000739 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000740 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000741 addrbuf.ll.sll_ifindex);
742 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
743 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000744 addrbuf.ll.sll_halen,
745 addrbuf.ll.sll_hatype);
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000746 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000747 tprintf("%02x", addrbuf.ll.sll_addr[i]);
748 }
749 break;
750
751#endif /* AF_APACKET */
752#ifdef AF_NETLINLK
753 case AF_NETLINK:
754 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
755 break;
756#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000758 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759
760 default:
John Hughes1fcb1d62001-09-18 15:56:53 +0000761 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000763 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 break;
765 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000766 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767}
768
769#if HAVE_SENDMSG
770
771static void
772printmsghdr(tcp, addr)
773struct tcb *tcp;
774long addr;
775{
776 struct msghdr msg;
777
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000778 if (umove(tcp, addr, &msg) < 0) {
779 tprintf("%#lx", addr);
780 return;
781 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000782 tprintf("{msg_name(%d)=", msg.msg_namelen);
783 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
784
785 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
John Hughes1d08dcf2001-07-10 13:48:44 +0000786 tprint_iov(tcp, msg.msg_iovlen, (long) msg.msg_iov);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000787
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000789 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
790 if (msg.msg_controllen)
791 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
792 tprintf(", msg_flags=");
793 if (printflags(msg_flags, msg.msg_flags)==0)
794 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000796 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000797 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
798#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000799 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800}
801
802#endif /* HAVE_SENDMSG */
803
804int
805sys_socket(tcp)
806struct tcb *tcp;
807{
808 if (entering(tcp)) {
809 printxval(domains, tcp->u_arg[0], "PF_???");
810 tprintf(", ");
811 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
812 tprintf(", ");
813 switch (tcp->u_arg[0]) {
814 case PF_INET:
815 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
816 break;
817#ifdef PF_IPX
818 case PF_IPX:
819 /* BTW: I don't believe this.. */
820 tprintf("[");
821 printxval(domains, tcp->u_arg[2], "PF_???");
822 tprintf("]");
823 break;
824#endif /* PF_IPX */
825 default:
826 tprintf("%lu", tcp->u_arg[2]);
827 break;
828 }
829 }
830 return 0;
831}
832
833int
John Hughesbdf48f52001-03-06 15:08:09 +0000834sys_so_socket(tcp)
835struct tcb *tcp;
836{
837 if (entering(tcp)) {
838 /* not sure really what these args are... but this
839 * is how truss prints it
840 */
841 tprintf("%ld, %ld, %ld, ",
842 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
843 printpath(tcp, tcp->u_arg[3]);
844 tprintf(", %ld", tcp->u_arg[4]);
845 }
846 return 0;
847}
848
849int
850sys_so_socketpair(tcp)
851struct tcb *tcp;
852{
853 if (entering(tcp)) {
854 /* not sure what this arg is */
855 tprintf("0x%lx", tcp->u_arg[0]);
856 }
857 return 0;
858}
859
860int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861sys_bind(tcp)
862struct tcb *tcp;
863{
864 if (entering(tcp)) {
865 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000866 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867 tprintf(", %lu", tcp->u_arg[2]);
868 }
869 return 0;
870}
871
872int
873sys_connect(tcp)
874struct tcb *tcp;
875{
876 return sys_bind(tcp);
877}
878
879int
880sys_listen(tcp)
881struct tcb *tcp;
882{
883 if (entering(tcp)) {
884 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
885 }
886 return 0;
887}
888
889int
890sys_accept(tcp)
891struct tcb *tcp;
892{
893 if (entering(tcp)) {
894 tprintf("%ld, ", tcp->u_arg[0]);
895 } else if (!tcp->u_arg[2])
896 tprintf("%#lx, NULL", tcp->u_arg[1]);
897 else {
898 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
899 tprintf("%#lx", tcp->u_arg[1]);
900 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000901 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000902 }
903 tprintf(", ");
904 printnum(tcp, tcp->u_arg[2], "%lu");
905 }
906 return 0;
907}
908
909int
910sys_send(tcp)
911struct tcb *tcp;
912{
913 if (entering(tcp)) {
914 tprintf("%ld, ", tcp->u_arg[0]);
915 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
916 tprintf(", %lu, ", tcp->u_arg[2]);
917 /* flags */
918 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
919 tprintf("0");
920 }
921 return 0;
922}
923
924int
925sys_sendto(tcp)
926struct tcb *tcp;
927{
928 if (entering(tcp)) {
929 tprintf("%ld, ", tcp->u_arg[0]);
930 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
931 tprintf(", %lu, ", tcp->u_arg[2]);
932 /* flags */
933 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
934 tprintf("0");
935 /* to address */
936 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000937 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938 /* to length */
939 tprintf(", %lu", tcp->u_arg[5]);
940 }
941 return 0;
942}
943
944#ifdef HAVE_SENDMSG
945
946int
947sys_sendmsg(tcp)
948struct tcb *tcp;
949{
950 if (entering(tcp)) {
951 tprintf("%ld, ", tcp->u_arg[0]);
952 printmsghdr(tcp, tcp->u_arg[1]);
953 /* flags */
954 tprintf(", ");
955 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
956 tprintf("0");
957 }
958 return 0;
959}
960
961#endif /* HAVE_SENDMSG */
962
963int
964sys_recv(tcp)
965struct tcb *tcp;
966{
967 if (entering(tcp)) {
968 tprintf("%ld, ", tcp->u_arg[0]);
969 } else {
970 if (syserror(tcp))
971 tprintf("%#lx", tcp->u_arg[1]);
972 else
973 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
974
975 tprintf(", %lu, ", tcp->u_arg[2]);
976 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
977 tprintf("0");
978 }
979 return 0;
980}
981
982int
983sys_recvfrom(tcp)
984struct tcb *tcp;
985{
986 int fromlen;
987
988 if (entering(tcp)) {
989 tprintf("%ld, ", tcp->u_arg[0]);
990 } else {
991 if (syserror(tcp)) {
992 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
993 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
994 tcp->u_arg[4], tcp->u_arg[5]);
995 return 0;
996 }
997 /* buf */
998 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
999 /* len */
1000 tprintf(", %lu, ", tcp->u_arg[2]);
1001 /* flags */
1002 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1003 tprintf("0");
1004 /* from address, len */
1005 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1006 if (tcp->u_arg[4] == 0)
1007 tprintf(", NULL");
1008 else
1009 tprintf(", %#lx", tcp->u_arg[4]);
1010 if (tcp->u_arg[5] == 0)
1011 tprintf(", NULL");
1012 else
1013 tprintf(", %#lx", tcp->u_arg[5]);
1014 return 0;
1015 }
1016 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1017 tprintf(", {...}, [?]");
1018 return 0;
1019 }
1020 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001021 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 /* from length */
1023 tprintf(", [%u]", fromlen);
1024 }
1025 return 0;
1026}
1027
1028#ifdef HAVE_SENDMSG
1029
1030int
1031sys_recvmsg(tcp)
1032struct tcb *tcp;
1033{
1034 if (entering(tcp)) {
1035 tprintf("%ld, ", tcp->u_arg[0]);
1036 } else {
1037 if (syserror(tcp) || !verbose(tcp))
1038 tprintf("%#lx", tcp->u_arg[1]);
1039 else
1040 printmsghdr(tcp, tcp->u_arg[1]);
1041 /* flags */
1042 tprintf(", ");
1043 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1044 tprintf("0");
1045 }
1046 return 0;
1047}
1048
1049#endif /* HAVE_SENDMSG */
1050
1051int
1052sys_shutdown(tcp)
1053struct tcb *tcp;
1054{
1055 if (entering(tcp)) {
1056 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1057 switch (tcp->u_arg[1]) {
1058 case 0:
1059 tprintf("%s", " /* receive */");
1060 break;
1061 case 1:
1062 tprintf("%s", " /* send */");
1063 break;
1064 case 2:
1065 tprintf("%s", " /* send and receive */");
1066 break;
1067 }
1068 }
1069 return 0;
1070}
1071
1072int
1073sys_getsockname(tcp)
1074struct tcb *tcp;
1075{
1076 return sys_accept(tcp);
1077}
1078
1079int
1080sys_getpeername(tcp)
1081struct tcb *tcp;
1082{
1083 return sys_accept(tcp);
1084}
1085
1086int
1087sys_pipe(tcp)
1088struct tcb *tcp;
1089{
1090
1091#if defined(LINUX) && !defined(SPARC)
1092 int fds[2];
1093
1094 if (exiting(tcp)) {
1095 if (syserror(tcp)) {
1096 tprintf("%#lx", tcp->u_arg[0]);
1097 return 0;
1098 }
1099 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1100 tprintf("[...]");
1101 else
1102 tprintf("[%u, %u]", fds[0], fds[1]);
1103 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001104#elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 if (exiting(tcp))
1106 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107#endif
1108 return 0;
1109}
1110
1111int
1112sys_socketpair(tcp)
1113struct tcb *tcp;
1114{
1115#ifdef LINUX
1116 int fds[2];
1117#endif
1118
1119 if (entering(tcp)) {
1120 printxval(domains, tcp->u_arg[0], "PF_???");
1121 tprintf(", ");
1122 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1123 tprintf(", ");
1124 switch (tcp->u_arg[0]) {
1125 case PF_INET:
1126 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1127 break;
1128#ifdef PF_IPX
1129 case PF_IPX:
1130 /* BTW: I don't believe this.. */
1131 tprintf("[");
1132 printxval(domains, tcp->u_arg[2], "PF_???");
1133 tprintf("]");
1134 break;
1135#endif /* PF_IPX */
1136 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001137 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001138 break;
1139 }
1140 } else {
1141 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001142 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001143 return 0;
1144 }
1145#ifdef LINUX
1146 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001147 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 else
1149 tprintf(", [%u, %u]", fds[0], fds[1]);
1150#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001151#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001152 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001153#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001154 }
1155 return 0;
1156}
1157
1158int
1159sys_getsockopt(tcp)
1160struct tcb *tcp;
1161{
1162 if (entering(tcp)) {
1163 tprintf("%ld, ", tcp->u_arg[0]);
1164 switch (tcp->u_arg[1]) {
1165 case SOL_SOCKET:
1166 tprintf("SOL_SOCKET, ");
1167 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1168 tprintf(", ");
1169 break;
1170#ifdef SOL_IP
1171 case SOL_IP:
1172 tprintf("SOL_IP, ");
1173 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1174 tprintf(", ");
1175 break;
1176#endif
1177#ifdef SOL_IPX
1178 case SOL_IPX:
1179 tprintf("SOL_IPX, ");
1180 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1181 tprintf(", ");
1182 break;
1183#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001184#ifdef SOL_PACKET
1185 case SOL_PACKET:
1186 tprintf("SOL_PACKET, ");
1187 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1188 tprintf(", ");
1189 break;
1190#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001191#ifdef SOL_TCP
1192 case SOL_TCP:
1193 tprintf("SOL_TCP, ");
1194 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1195 tprintf(", ");
1196 break;
1197#endif
1198
1199 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1200 * etc. still need work */
1201 default:
1202 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001203 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001204 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205 break;
1206 }
1207 } else {
1208 if (syserror(tcp)) {
1209 tprintf("%#lx, %#lx",
1210 tcp->u_arg[3], tcp->u_arg[4]);
1211 return 0;
1212 }
1213 printnum(tcp, tcp->u_arg[3], "%ld");
1214 tprintf(", ");
1215 printnum(tcp, tcp->u_arg[4], "%ld");
1216 }
1217 return 0;
1218}
1219
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001220#if defined(ICMP_FILTER)
1221static void printicmpfilter(tcp, addr)
1222struct tcb *tcp;
1223long addr;
1224{
1225 struct icmp_filter filter;
1226
1227 if (!addr) {
1228 tprintf("NULL");
1229 return;
1230 }
1231 if (syserror(tcp) || !verbose(tcp)) {
1232 tprintf("%#lx", addr);
1233 return;
1234 }
1235 if (umove(tcp, addr, &filter) < 0) {
1236 tprintf("{...}");
1237 return;
1238 }
1239
1240 tprintf("~(");
1241 if (printflags(icmpfilterflags, ~filter.data) == 0)
1242 tprintf("0");
1243 tprintf(")");
1244}
1245#endif /* ICMP_FILTER */
1246
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247int
1248sys_setsockopt(tcp)
1249struct tcb *tcp;
1250{
1251 if (entering(tcp)) {
1252 tprintf("%ld, ", tcp->u_arg[0]);
1253 switch (tcp->u_arg[1]) {
1254 case SOL_SOCKET:
1255 tprintf("SOL_SOCKET, ");
1256 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1257 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001258 printnum(tcp, tcp->u_arg[3], "%ld");
1259 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 break;
1261#ifdef SOL_IP
1262 case SOL_IP:
1263 tprintf("SOL_IP, ");
1264 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1265 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001266 printnum(tcp, tcp->u_arg[3], "%ld");
1267 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 break;
1269#endif
1270#ifdef SOL_IPX
1271 case SOL_IPX:
1272 tprintf("SOL_IPX, ");
1273 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1274 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001275 printnum(tcp, tcp->u_arg[3], "%ld");
1276 tprintf(", %lu", tcp->u_arg[4]);
1277 break;
1278#endif
1279#ifdef SOL_PACKET
1280 case SOL_PACKET:
1281 tprintf("SOL_PACKET, ");
1282 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1283 tprintf(", ");
1284 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1285 printnum(tcp, tcp->u_arg[3], "%ld");
1286 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 break;
1288#endif
1289#ifdef SOL_TCP
1290 case SOL_TCP:
1291 tprintf("SOL_TCP, ");
1292 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1293 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001294 printnum(tcp, tcp->u_arg[3], "%ld");
1295 tprintf(", %lu", tcp->u_arg[4]);
1296 break;
1297#endif
1298#ifdef SOL_RAW
1299 case SOL_RAW:
1300 tprintf("SOL_RAW, ");
1301 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1302 tprintf(", ");
1303 switch (tcp->u_arg[2]) {
1304#if defined(ICMP_FILTER)
1305 case ICMP_FILTER:
1306 printicmpfilter(tcp, tcp->u_arg[3]);
1307 break;
1308#endif
1309 default:
1310 printnum(tcp, tcp->u_arg[3], "%ld");
1311 break;
1312 }
1313 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 break;
1315#endif
1316
1317 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1318 * etc. still need work */
1319 default:
1320 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001321 printxval(socketlayers, tcp->u_arg[1], "IPPROTO_???");
1322 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001323 printnum(tcp, tcp->u_arg[3], "%ld");
1324 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325 break;
1326 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001327 }
1328 return 0;
1329}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001330
1331#if UNIXWARE >= 7
1332
1333static struct xlat sock_version[] = {
1334 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1335 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1336 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1337 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1338 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1339 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1340 { 0, NULL },
1341};
1342
1343
1344int
1345netlib_call(tcp, func)
1346struct tcb *tcp;
1347int (*func) ();
1348{
1349 if (entering(tcp)) {
1350 int i;
1351 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1352 tprintf(", ");
1353 --tcp->u_nargs;
1354 for (i = 0; i < tcp->u_nargs; i++)
1355 tcp->u_arg[i] = tcp->u_arg[i + 1];
1356 return func (tcp);
1357
1358 }
1359
1360 return func (tcp);
1361}
1362
1363int
1364sys_xsocket(tcp)
1365struct tcb *tcp;
1366{
1367 return netlib_call (tcp, sys_socket);
1368}
1369
1370int
1371sys_xsocketpair(tcp)
1372struct tcb *tcp;
1373{
1374 return netlib_call (tcp, sys_socketpair);
1375}
1376
1377int
1378sys_xbind(tcp)
1379struct tcb *tcp;
1380{
1381 return netlib_call (tcp, sys_bind);
1382}
1383
1384int
1385sys_xconnect(tcp)
1386struct tcb *tcp;
1387{
1388 return netlib_call (tcp, sys_connect);
1389}
1390
1391int
1392sys_xlisten(tcp)
1393struct tcb *tcp;
1394{
1395 return netlib_call (tcp, sys_listen);
1396}
1397
1398int
1399sys_xaccept(tcp)
1400struct tcb *tcp;
1401{
1402 return netlib_call (tcp, sys_accept);
1403}
1404
1405int
1406sys_xsendmsg(tcp)
1407struct tcb *tcp;
1408{
1409 return netlib_call (tcp, sys_sendmsg);
1410}
1411
1412int
1413sys_xrecvmsg(tcp)
1414struct tcb *tcp;
1415{
1416 return netlib_call (tcp, sys_recvmsg);
1417}
1418
1419int
1420sys_xgetsockaddr(tcp)
1421struct tcb *tcp;
1422{
1423 if (entering(tcp)) {
1424 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1425 tprintf(", ");
1426 if (tcp->u_arg[1] == 0) {
1427 tprintf ("LOCALNAME, ");
1428 }
1429 else if (tcp->u_arg[1] == 1) {
1430 tprintf ("REMOTENAME, ");
1431 }
1432 else {
1433 tprintf ("%ld, ", tcp->u_arg [1]);
1434 }
1435 tprintf ("%ld, ", tcp->u_arg [2]);
1436 }
1437 else {
1438 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1439 tprintf("%#lx", tcp->u_arg[3]);
1440 } else {
1441 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1442 }
1443 tprintf(", ");
1444 printnum(tcp, tcp->u_arg[4], "%lu");
1445 }
1446
1447 return 0;
1448
1449}
1450
1451#if 0
1452
1453int
1454sys_xsetsockaddr(tcp)
1455struct tcb *tcp;
1456{
1457 return netlib_call (tcp, sys_setsockaddr);
1458}
1459
1460#endif
1461
1462int
1463sys_xgetsockopt(tcp)
1464struct tcb *tcp;
1465{
1466 return netlib_call (tcp, sys_getsockopt);
1467}
1468
1469int
1470sys_xsetsockopt(tcp)
1471struct tcb *tcp;
1472{
1473 return netlib_call (tcp, sys_setsockopt);
1474}
1475
1476int
1477sys_xshutdown(tcp)
1478struct tcb *tcp;
1479{
1480 return netlib_call (tcp, sys_shutdown);
1481}
1482
1483#endif