blob: 0c123e7f0450eeb1940485fb230662eb71ea8475 [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
279};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280static struct xlat protocols[] = {
281 { IPPROTO_IP, "IPPROTO_IP" },
282 { IPPROTO_ICMP, "IPPROTO_ICMP" },
283 { IPPROTO_TCP, "IPPROTO_TCP" },
284 { IPPROTO_UDP, "IPPROTO_UDP" },
285#ifdef IPPROTO_GGP
286 { IPPROTO_GGP, "IPPROTO_GGP" },
287#endif
288#ifdef IPPROTO_EGP
289 { IPPROTO_EGP, "IPPROTO_EGP" },
290#endif
291#ifdef IPPROTO_PUP
292 { IPPROTO_PUP, "IPPROTO_PUP" },
293#endif
294#ifdef IPPROTO_IDP
295 { IPPROTO_IDP, "IPPROTO_IDP" },
296#endif
297#ifdef IPPROTO_IPV6
298 { IPPROTO_IPV6, "IPPROTO_IPV6" },
299#endif
300#ifdef IPPROTO_ICMPV6
301 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
302#endif
303#ifdef IPPROTO_IGMP
304 { IPPROTO_IGMP, "IPPROTO_IGMP" },
305#endif
306#ifdef IPPROTO_HELLO
307 { IPPROTO_HELLO,"IPPROTO_HELLO" },
308#endif
309#ifdef IPPROTO_ND
310 { IPPROTO_ND, "IPPROTO_ND" },
311#endif
312#ifdef IPPROTO_RAW
313 { IPPROTO_RAW, "IPPROTO_RAW" },
314#endif
315#ifdef IPPROTO_MAX
316 { IPPROTO_MAX, "IPPROTO_MAX" },
317#endif
318#ifdef IPPROTO_IPIP
319 { IPPROTO_IPIP, "IPPROTO_IPIP" },
320#endif
321 { 0, NULL },
322};
323static struct xlat msg_flags[] = {
324 { MSG_OOB, "MSG_OOB" },
325#ifdef MSG_DONTROUTE
326 { MSG_DONTROUTE,"MSG_DONTROUTE" },
327#endif
328#ifdef MSG_PEEK
329 { MSG_PEEK, "MSG_PEEK" },
330#endif
331#ifdef MSG_CTRUNC
332 { MSG_CTRUNC, "MSG_CTRUNC" },
333#endif
334#ifdef MSG_PROXY
335 { MSG_PROXY, "MSG_PROXY" },
336#endif
337#ifdef MSG_EOR
338 { MSG_EOR, "MSG_EOR" },
339#endif
340#ifdef MSG_WAITALL
341 { MSG_WAITALL, "MSG_WAITALL" },
342#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000343#ifdef MSG_TRUNC
344 { MSG_TRUNC, "MSG_TRUNC" },
345#endif
346#ifdef MSG_CTRUNC
347 { MSG_CTRUNC, "MSG_CTRUNC" },
348#endif
349#ifdef MSG_ERRQUEUE
350 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
351#endif
352#ifdef MSG_DONTWAIT
353 { MSG_DONTWAIT, "MSG_DONTWAIT" },
354#endif
355#ifdef MSG_CONFIRM
356 { MSG_CONFIRM, "MSG_CONFIRM" },
357#endif
358#ifdef MSG_PROBE
359 { MSG_PROBE, "MSG_PROBE" },
360#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361 { 0, NULL },
362};
363
364static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000365#ifdef SO_PEERCRED
366 { SO_PEERCRED, "SO_PEERCRED" },
367#endif
368#ifdef SO_PASSCRED
369 { SO_PASSCRED, "SO_PASSCRED" },
370#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371#ifdef SO_DEBUG
372 { SO_DEBUG, "SO_DEBUG" },
373#endif
374#ifdef SO_REUSEADDR
375 { SO_REUSEADDR, "SO_REUSEADDR" },
376#endif
377#ifdef SO_KEEPALIVE
378 { SO_KEEPALIVE, "SO_KEEPALIVE" },
379#endif
380#ifdef SO_DONTROUTE
381 { SO_DONTROUTE, "SO_DONTROUTE" },
382#endif
383#ifdef SO_BROADCAST
384 { SO_BROADCAST, "SO_BROADCAST" },
385#endif
386#ifdef SO_LINGER
387 { SO_LINGER, "SO_LINGER" },
388#endif
389#ifdef SO_OOBINLINE
390 { SO_OOBINLINE, "SO_OOBINLINE" },
391#endif
392#ifdef SO_TYPE
393 { SO_TYPE, "SO_TYPE" },
394#endif
395#ifdef SO_ERROR
396 { SO_ERROR, "SO_ERROR" },
397#endif
398#ifdef SO_SNDBUF
399 { SO_SNDBUF, "SO_SNDBUF" },
400#endif
401#ifdef SO_RCVBUF
402 { SO_RCVBUF, "SO_RCVBUF" },
403#endif
404#ifdef SO_NO_CHECK
405 { SO_NO_CHECK, "SO_NO_CHECK" },
406#endif
407#ifdef SO_PRIORITY
408 { SO_PRIORITY, "SO_PRIORITY" },
409#endif
410#ifdef SO_ACCEPTCONN
411 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
412#endif
413#ifdef SO_USELOOPBACK
414 { SO_USELOOPBACK,"SO_USELOOPBACK"},
415#endif
416#ifdef SO_SNDLOWAT
417 { SO_SNDLOWAT, "SO_SNDLOWAT" },
418#endif
419#ifdef SO_RCVLOWAT
420 { SO_RCVLOWAT, "SO_RCVLOWAT" },
421#endif
422#ifdef SO_SNDTIMEO
423 { SO_SNDTIMEO, "SO_SNDTIMEO" },
424#endif
425#ifdef SO_RCVTIMEO
426 { SO_RCVTIMEO, "SO_RCVTIMEO" },
427#endif
428#ifdef SO_BSDCOMPAT
429 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
430#endif
431#ifdef SO_REUSEPORT
432 { SO_REUSEPORT, "SO_REUSEPORT" },
433#endif
434#ifdef SO_RCVLOWAT
435 { SO_RCVLOWAT, "SO_RCVLOWAT" },
436#endif
437#ifdef SO_SNDLOWAT
438 { SO_SNDLOWAT, "SO_SNDLOWAT" },
439#endif
440#ifdef SO_RCVTIMEO
441 { SO_RCVTIMEO, "SO_RCVTIMEO" },
442#endif
443#ifdef SO_SNDTIMEO
444 { SO_SNDTIMEO, "SO_SNDTIMEO" },
445#endif
446 { 0, NULL },
447};
448
449#ifdef SOL_IP
450static struct xlat sockipoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000451 { IP_TOS, "IP_TOS" },
452 { IP_TTL, "IP_TTL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453#if defined(IP_HDRINCL)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000454 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455#endif
456#if defined(IP_OPTIONS)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000457 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000459 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
460#if defined(IP_RECVOPTIONS)
461 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
462#endif
463 { IP_RETOPTS, "IP_RETOPTS" },
464 { IP_PKTINFO, "IP_PKTINFO" },
465 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
466 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
467 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
468 { IP_RECVERR, "IP_RECVERR" },
469 { IP_RECVTTL, "IP_RECRECVTTL" },
470 { IP_RECVTOS, "IP_RECRECVTOS" },
471#if defined(IP_MTU)
472 { IP_MTU, "IP_MTU" },
473#endif
474 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
475 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
476 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
477 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
478 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
479 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480};
481#endif /* SOL_IP */
482
483#ifdef SOL_IPX
484static struct xlat sockipxoptions[] = {
485 { IPX_TYPE, "IPX_TYPE" },
486 { 0, NULL },
487};
488#endif /* SOL_IPX */
489
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000490#ifdef SOL_RAW
491static struct xlat sockrawoptions[] = {
492#if defined(ICMP_FILTER)
493 { ICMP_FILTER, "ICMP_FILTER" },
494#endif
495 { 0, NULL },
496};
497#endif /* SOL_RAW */
498
499#ifdef SOL_PACKET
500static struct xlat sockpacketoptions[] = {
501 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
502 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
503#if defined(PACKET_RECV_OUTPUT)
504 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
505#endif
506#if defined(PACKET_RX_RING)
507 { PACKET_RX_RING, "PACKET_RX_RING" },
508#endif
509#if defined(PACKET_STATISTICS)
510 { PACKET_STATISTICS, "PACKET_STATISTICS" },
511#endif
512 { 0, NULL },
513};
514#endif /* SOL_PACKET */
515
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516#ifdef SOL_TCP
517static struct xlat socktcpoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000518 { TCP_NODELAY, "TCP_NODELAY" },
519 { TCP_MAXSEG, "TCP_MAXSEG" },
520#if defined(TCP_CORK)
521 { TCP_CORK, "TCP_CORK" },
522#endif
523 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524};
525#endif /* SOL_TCP */
526
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000527#ifdef SOL_RAW
528static struct xlat icmpfilterflags[] = {
529#if defined(ICMP_ECHOREPLY)
530 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
531#endif
532#if defined(ICMP_DEST_UNREACH)
533 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
534#endif
535#if defined(ICMP_SOURCE_QUENCH)
536 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
537#endif
538#if defined(ICMP_REDIRECT)
539 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
540#endif
541#if defined(ICMP_ECHO)
542 { (1<<ICMP_ECHO), "ICMP_ECHO" },
543#endif
544#if defined(ICMP_TIME_EXCEEDED)
545 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
546#endif
547#if defined(ICMP_PARAMETERPROB)
548 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
549#endif
550#if defined(ICMP_TIMESTAMP)
551 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
552#endif
553#if defined(ICMP_TIMESTAMPREPLY)
554 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
555#endif
556#if defined(ICMP_INFO_REQUEST)
557 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
558#endif
559#if defined(ICMP_INFO_REPLY)
560 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
561#endif
562#if defined(ICMP_ADDRESS)
563 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
564#endif
565#if defined(ICMP_ADDRESSREPLY)
566 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
567#endif
568 { 0, NULL },
569};
570#endif /* SOL_RAW */
571
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000572
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000574printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575struct tcb *tcp;
576long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000577int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000579 union {
580 char pad[128];
581 struct sockaddr sa;
582 struct sockaddr_in sin;
583 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000584#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000585 struct sockaddr_in6 sa6;
586#endif
587#if defined(LINUX) && defined(AF_IPX)
588 struct sockaddr_ipx sipx;
589#endif
590#ifdef AF_PACKET
591 struct sockaddr_ll ll;
592#endif
593#ifdef AF_NETLINK
594 struct sockaddr_nl nl;
595#endif
596 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000597 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598
599 if (addr == 0) {
600 tprintf("NULL");
601 return;
602 }
603 if (!verbose(tcp)) {
604 tprintf("%#lx", addr);
605 return;
606 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000607 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
608 addrlen=sizeof(addrbuf);
609
610 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611 tprintf("{...}");
612 return;
613 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000614
615 tprintf("{sin_family=");
616 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
617 tprintf(", ");
618
619 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000621 if (addrlen==2) {
622 tprintf("<nil>");
623 } else if (addrbuf.sau.sun_path[0]) {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000624 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000625 } else {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000626 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000627 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628 break;
629 case AF_INET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000631 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000633#ifdef HAVE_INET_NTOP
634 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000635 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000636 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
637 ntohs(addrbuf.sa6.sin6_port), string_addr,
638 addrbuf.sa6.sin6_flowinfo);
639#ifdef HAVE_SIN6_SCOPE_ID
640 {
641#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
642 int numericscope = 0;
643 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
644 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
645 char scopebuf[IFNAMSIZ + 1];
646
647 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
648 numericscope++;
649 else
650 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
651 } else
652 numericscope++;
653
654 if (numericscope)
655#endif
656 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
657 }
658#endif
659 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000660#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000661#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000663 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664 int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 tprintf("{sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000666 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 /* Yes, I know, this does not look too
668 * strace-ish, but otherwise the IPX
669 * addresses just look monstrous...
670 * Anyways, feel free if you don't like
671 * this way.. :)
672 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000673 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000675 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
676 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677 }
678 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000679#endif /* AF_IPX && linux */
680#ifdef AF_PACKET
681 case AF_PACKET:
682 {
683 int i;
684 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
685 ntohs(addrbuf.ll.sll_protocol),
686 addrbuf.ll.sll_ifindex,
687 addrbuf.ll.sll_pkttype,
688 addrbuf.ll.sll_halen,
689 addrbuf.ll.sll_hatype);
690 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
691 tprintf("%02x", addrbuf.ll.sll_addr[i]);
692 }
693 break;
694
695#endif /* AF_APACKET */
696#ifdef AF_NETLINLK
697 case AF_NETLINK:
698 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
699 break;
700#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000702 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703
704 default:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000705 tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000707 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 break;
709 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000710 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711}
712
713#if HAVE_SENDMSG
714
715static void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000716printiovec(tcp, iovec, len)
717struct tcb *tcp;
718struct iovec *iovec;
719long len;
720{
721 struct iovec *iov;
722 int i;
723
724 iov = (struct iovec *) malloc(len * sizeof *iov);
725 if (iov == NULL) {
726 fprintf(stderr, "No memory");
727 return;
728 }
729 if (umoven(tcp, (long)iovec,
730 len * sizeof *iov, (char *) iov) < 0) {
731 tprintf("%#lx", (unsigned long)iovec);
732 } else {
733 tprintf("[");
734 for (i = 0; i < len; i++) {
735 if (i)
736 tprintf(", ");
737 tprintf("{");
738 printstr(tcp, (long) iov[i].iov_base,
739 iov[i].iov_len);
740 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
741 }
742 tprintf("]");
743 }
744 free((char *) iov);
745}
746
747static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748printmsghdr(tcp, addr)
749struct tcb *tcp;
750long addr;
751{
752 struct msghdr msg;
753
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000754 if (umove(tcp, addr, &msg) < 0) {
755 tprintf("%#lx", addr);
756 return;
757 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000758 tprintf("{msg_name(%d)=", msg.msg_namelen);
759 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
760
761 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
762 printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
763
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000765 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
766 if (msg.msg_controllen)
767 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
768 tprintf(", msg_flags=");
769 if (printflags(msg_flags, msg.msg_flags)==0)
770 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000772 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000773 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
774#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000775 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776}
777
778#endif /* HAVE_SENDMSG */
779
780int
781sys_socket(tcp)
782struct tcb *tcp;
783{
784 if (entering(tcp)) {
785 printxval(domains, tcp->u_arg[0], "PF_???");
786 tprintf(", ");
787 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
788 tprintf(", ");
789 switch (tcp->u_arg[0]) {
790 case PF_INET:
791 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
792 break;
793#ifdef PF_IPX
794 case PF_IPX:
795 /* BTW: I don't believe this.. */
796 tprintf("[");
797 printxval(domains, tcp->u_arg[2], "PF_???");
798 tprintf("]");
799 break;
800#endif /* PF_IPX */
801 default:
802 tprintf("%lu", tcp->u_arg[2]);
803 break;
804 }
805 }
806 return 0;
807}
808
809int
810sys_bind(tcp)
811struct tcb *tcp;
812{
813 if (entering(tcp)) {
814 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000815 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 tprintf(", %lu", tcp->u_arg[2]);
817 }
818 return 0;
819}
820
821int
822sys_connect(tcp)
823struct tcb *tcp;
824{
825 return sys_bind(tcp);
826}
827
828int
829sys_listen(tcp)
830struct tcb *tcp;
831{
832 if (entering(tcp)) {
833 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
834 }
835 return 0;
836}
837
838int
839sys_accept(tcp)
840struct tcb *tcp;
841{
842 if (entering(tcp)) {
843 tprintf("%ld, ", tcp->u_arg[0]);
844 } else if (!tcp->u_arg[2])
845 tprintf("%#lx, NULL", tcp->u_arg[1]);
846 else {
847 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
848 tprintf("%#lx", tcp->u_arg[1]);
849 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000850 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 }
852 tprintf(", ");
853 printnum(tcp, tcp->u_arg[2], "%lu");
854 }
855 return 0;
856}
857
858int
859sys_send(tcp)
860struct tcb *tcp;
861{
862 if (entering(tcp)) {
863 tprintf("%ld, ", tcp->u_arg[0]);
864 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
865 tprintf(", %lu, ", tcp->u_arg[2]);
866 /* flags */
867 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
868 tprintf("0");
869 }
870 return 0;
871}
872
873int
874sys_sendto(tcp)
875struct tcb *tcp;
876{
877 if (entering(tcp)) {
878 tprintf("%ld, ", tcp->u_arg[0]);
879 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
880 tprintf(", %lu, ", tcp->u_arg[2]);
881 /* flags */
882 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
883 tprintf("0");
884 /* to address */
885 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000886 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887 /* to length */
888 tprintf(", %lu", tcp->u_arg[5]);
889 }
890 return 0;
891}
892
893#ifdef HAVE_SENDMSG
894
895int
896sys_sendmsg(tcp)
897struct tcb *tcp;
898{
899 if (entering(tcp)) {
900 tprintf("%ld, ", tcp->u_arg[0]);
901 printmsghdr(tcp, tcp->u_arg[1]);
902 /* flags */
903 tprintf(", ");
904 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
905 tprintf("0");
906 }
907 return 0;
908}
909
910#endif /* HAVE_SENDMSG */
911
912int
913sys_recv(tcp)
914struct tcb *tcp;
915{
916 if (entering(tcp)) {
917 tprintf("%ld, ", tcp->u_arg[0]);
918 } else {
919 if (syserror(tcp))
920 tprintf("%#lx", tcp->u_arg[1]);
921 else
922 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
923
924 tprintf(", %lu, ", tcp->u_arg[2]);
925 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
926 tprintf("0");
927 }
928 return 0;
929}
930
931int
932sys_recvfrom(tcp)
933struct tcb *tcp;
934{
935 int fromlen;
936
937 if (entering(tcp)) {
938 tprintf("%ld, ", tcp->u_arg[0]);
939 } else {
940 if (syserror(tcp)) {
941 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
942 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
943 tcp->u_arg[4], tcp->u_arg[5]);
944 return 0;
945 }
946 /* buf */
947 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
948 /* len */
949 tprintf(", %lu, ", tcp->u_arg[2]);
950 /* flags */
951 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
952 tprintf("0");
953 /* from address, len */
954 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
955 if (tcp->u_arg[4] == 0)
956 tprintf(", NULL");
957 else
958 tprintf(", %#lx", tcp->u_arg[4]);
959 if (tcp->u_arg[5] == 0)
960 tprintf(", NULL");
961 else
962 tprintf(", %#lx", tcp->u_arg[5]);
963 return 0;
964 }
965 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
966 tprintf(", {...}, [?]");
967 return 0;
968 }
969 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000970 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971 /* from length */
972 tprintf(", [%u]", fromlen);
973 }
974 return 0;
975}
976
977#ifdef HAVE_SENDMSG
978
979int
980sys_recvmsg(tcp)
981struct tcb *tcp;
982{
983 if (entering(tcp)) {
984 tprintf("%ld, ", tcp->u_arg[0]);
985 } else {
986 if (syserror(tcp) || !verbose(tcp))
987 tprintf("%#lx", tcp->u_arg[1]);
988 else
989 printmsghdr(tcp, tcp->u_arg[1]);
990 /* flags */
991 tprintf(", ");
992 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
993 tprintf("0");
994 }
995 return 0;
996}
997
998#endif /* HAVE_SENDMSG */
999
1000int
1001sys_shutdown(tcp)
1002struct tcb *tcp;
1003{
1004 if (entering(tcp)) {
1005 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1006 switch (tcp->u_arg[1]) {
1007 case 0:
1008 tprintf("%s", " /* receive */");
1009 break;
1010 case 1:
1011 tprintf("%s", " /* send */");
1012 break;
1013 case 2:
1014 tprintf("%s", " /* send and receive */");
1015 break;
1016 }
1017 }
1018 return 0;
1019}
1020
1021int
1022sys_getsockname(tcp)
1023struct tcb *tcp;
1024{
1025 return sys_accept(tcp);
1026}
1027
1028int
1029sys_getpeername(tcp)
1030struct tcb *tcp;
1031{
1032 return sys_accept(tcp);
1033}
1034
1035int
1036sys_pipe(tcp)
1037struct tcb *tcp;
1038{
1039
1040#if defined(LINUX) && !defined(SPARC)
1041 int fds[2];
1042
1043 if (exiting(tcp)) {
1044 if (syserror(tcp)) {
1045 tprintf("%#lx", tcp->u_arg[0]);
1046 return 0;
1047 }
1048 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1049 tprintf("[...]");
1050 else
1051 tprintf("[%u, %u]", fds[0], fds[1]);
1052 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001053#elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 if (exiting(tcp))
1055 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056#endif
1057 return 0;
1058}
1059
1060int
1061sys_socketpair(tcp)
1062struct tcb *tcp;
1063{
1064#ifdef LINUX
1065 int fds[2];
1066#endif
1067
1068 if (entering(tcp)) {
1069 printxval(domains, tcp->u_arg[0], "PF_???");
1070 tprintf(", ");
1071 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1072 tprintf(", ");
1073 switch (tcp->u_arg[0]) {
1074 case PF_INET:
1075 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1076 break;
1077#ifdef PF_IPX
1078 case PF_IPX:
1079 /* BTW: I don't believe this.. */
1080 tprintf("[");
1081 printxval(domains, tcp->u_arg[2], "PF_???");
1082 tprintf("]");
1083 break;
1084#endif /* PF_IPX */
1085 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001086 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087 break;
1088 }
1089 } else {
1090 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001091 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092 return 0;
1093 }
1094#ifdef LINUX
1095 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001096 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001097 else
1098 tprintf(", [%u, %u]", fds[0], fds[1]);
1099#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001100#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001102#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 }
1104 return 0;
1105}
1106
1107int
1108sys_getsockopt(tcp)
1109struct tcb *tcp;
1110{
1111 if (entering(tcp)) {
1112 tprintf("%ld, ", tcp->u_arg[0]);
1113 switch (tcp->u_arg[1]) {
1114 case SOL_SOCKET:
1115 tprintf("SOL_SOCKET, ");
1116 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1117 tprintf(", ");
1118 break;
1119#ifdef SOL_IP
1120 case SOL_IP:
1121 tprintf("SOL_IP, ");
1122 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1123 tprintf(", ");
1124 break;
1125#endif
1126#ifdef SOL_IPX
1127 case SOL_IPX:
1128 tprintf("SOL_IPX, ");
1129 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1130 tprintf(", ");
1131 break;
1132#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001133#ifdef SOL_PACKET
1134 case SOL_PACKET:
1135 tprintf("SOL_PACKET, ");
1136 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1137 tprintf(", ");
1138 break;
1139#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140#ifdef SOL_TCP
1141 case SOL_TCP:
1142 tprintf("SOL_TCP, ");
1143 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1144 tprintf(", ");
1145 break;
1146#endif
1147
1148 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1149 * etc. still need work */
1150 default:
1151 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001152 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001153 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001154 break;
1155 }
1156 } else {
1157 if (syserror(tcp)) {
1158 tprintf("%#lx, %#lx",
1159 tcp->u_arg[3], tcp->u_arg[4]);
1160 return 0;
1161 }
1162 printnum(tcp, tcp->u_arg[3], "%ld");
1163 tprintf(", ");
1164 printnum(tcp, tcp->u_arg[4], "%ld");
1165 }
1166 return 0;
1167}
1168
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001169#if defined(ICMP_FILTER)
1170static void printicmpfilter(tcp, addr)
1171struct tcb *tcp;
1172long addr;
1173{
1174 struct icmp_filter filter;
1175
1176 if (!addr) {
1177 tprintf("NULL");
1178 return;
1179 }
1180 if (syserror(tcp) || !verbose(tcp)) {
1181 tprintf("%#lx", addr);
1182 return;
1183 }
1184 if (umove(tcp, addr, &filter) < 0) {
1185 tprintf("{...}");
1186 return;
1187 }
1188
1189 tprintf("~(");
1190 if (printflags(icmpfilterflags, ~filter.data) == 0)
1191 tprintf("0");
1192 tprintf(")");
1193}
1194#endif /* ICMP_FILTER */
1195
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196int
1197sys_setsockopt(tcp)
1198struct tcb *tcp;
1199{
1200 if (entering(tcp)) {
1201 tprintf("%ld, ", tcp->u_arg[0]);
1202 switch (tcp->u_arg[1]) {
1203 case SOL_SOCKET:
1204 tprintf("SOL_SOCKET, ");
1205 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1206 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001207 printnum(tcp, tcp->u_arg[3], "%ld");
1208 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001209 break;
1210#ifdef SOL_IP
1211 case SOL_IP:
1212 tprintf("SOL_IP, ");
1213 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1214 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001215 printnum(tcp, tcp->u_arg[3], "%ld");
1216 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217 break;
1218#endif
1219#ifdef SOL_IPX
1220 case SOL_IPX:
1221 tprintf("SOL_IPX, ");
1222 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1223 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001224 printnum(tcp, tcp->u_arg[3], "%ld");
1225 tprintf(", %lu", tcp->u_arg[4]);
1226 break;
1227#endif
1228#ifdef SOL_PACKET
1229 case SOL_PACKET:
1230 tprintf("SOL_PACKET, ");
1231 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1232 tprintf(", ");
1233 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1234 printnum(tcp, tcp->u_arg[3], "%ld");
1235 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 break;
1237#endif
1238#ifdef SOL_TCP
1239 case SOL_TCP:
1240 tprintf("SOL_TCP, ");
1241 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1242 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001243 printnum(tcp, tcp->u_arg[3], "%ld");
1244 tprintf(", %lu", tcp->u_arg[4]);
1245 break;
1246#endif
1247#ifdef SOL_RAW
1248 case SOL_RAW:
1249 tprintf("SOL_RAW, ");
1250 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1251 tprintf(", ");
1252 switch (tcp->u_arg[2]) {
1253#if defined(ICMP_FILTER)
1254 case ICMP_FILTER:
1255 printicmpfilter(tcp, tcp->u_arg[3]);
1256 break;
1257#endif
1258 default:
1259 printnum(tcp, tcp->u_arg[3], "%ld");
1260 break;
1261 }
1262 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001263 break;
1264#endif
1265
1266 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1267 * etc. still need work */
1268 default:
1269 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001270 printxval(socketlayers, tcp->u_arg[1], "IPPROTO_???");
1271 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001272 printnum(tcp, tcp->u_arg[3], "%ld");
1273 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274 break;
1275 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276 }
1277 return 0;
1278}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001279
1280#if UNIXWARE >= 7
1281
1282static struct xlat sock_version[] = {
1283 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1284 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1285 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1286 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1287 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1288 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1289 { 0, NULL },
1290};
1291
1292
1293int
1294netlib_call(tcp, func)
1295struct tcb *tcp;
1296int (*func) ();
1297{
1298 if (entering(tcp)) {
1299 int i;
1300 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1301 tprintf(", ");
1302 --tcp->u_nargs;
1303 for (i = 0; i < tcp->u_nargs; i++)
1304 tcp->u_arg[i] = tcp->u_arg[i + 1];
1305 return func (tcp);
1306
1307 }
1308
1309 return func (tcp);
1310}
1311
1312int
1313sys_xsocket(tcp)
1314struct tcb *tcp;
1315{
1316 return netlib_call (tcp, sys_socket);
1317}
1318
1319int
1320sys_xsocketpair(tcp)
1321struct tcb *tcp;
1322{
1323 return netlib_call (tcp, sys_socketpair);
1324}
1325
1326int
1327sys_xbind(tcp)
1328struct tcb *tcp;
1329{
1330 return netlib_call (tcp, sys_bind);
1331}
1332
1333int
1334sys_xconnect(tcp)
1335struct tcb *tcp;
1336{
1337 return netlib_call (tcp, sys_connect);
1338}
1339
1340int
1341sys_xlisten(tcp)
1342struct tcb *tcp;
1343{
1344 return netlib_call (tcp, sys_listen);
1345}
1346
1347int
1348sys_xaccept(tcp)
1349struct tcb *tcp;
1350{
1351 return netlib_call (tcp, sys_accept);
1352}
1353
1354int
1355sys_xsendmsg(tcp)
1356struct tcb *tcp;
1357{
1358 return netlib_call (tcp, sys_sendmsg);
1359}
1360
1361int
1362sys_xrecvmsg(tcp)
1363struct tcb *tcp;
1364{
1365 return netlib_call (tcp, sys_recvmsg);
1366}
1367
1368int
1369sys_xgetsockaddr(tcp)
1370struct tcb *tcp;
1371{
1372 if (entering(tcp)) {
1373 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1374 tprintf(", ");
1375 if (tcp->u_arg[1] == 0) {
1376 tprintf ("LOCALNAME, ");
1377 }
1378 else if (tcp->u_arg[1] == 1) {
1379 tprintf ("REMOTENAME, ");
1380 }
1381 else {
1382 tprintf ("%ld, ", tcp->u_arg [1]);
1383 }
1384 tprintf ("%ld, ", tcp->u_arg [2]);
1385 }
1386 else {
1387 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1388 tprintf("%#lx", tcp->u_arg[3]);
1389 } else {
1390 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1391 }
1392 tprintf(", ");
1393 printnum(tcp, tcp->u_arg[4], "%lu");
1394 }
1395
1396 return 0;
1397
1398}
1399
1400#if 0
1401
1402int
1403sys_xsetsockaddr(tcp)
1404struct tcb *tcp;
1405{
1406 return netlib_call (tcp, sys_setsockaddr);
1407}
1408
1409#endif
1410
1411int
1412sys_xgetsockopt(tcp)
1413struct tcb *tcp;
1414{
1415 return netlib_call (tcp, sys_getsockopt);
1416}
1417
1418int
1419sys_xsetsockopt(tcp)
1420struct tcb *tcp;
1421{
1422 return netlib_call (tcp, sys_setsockopt);
1423}
1424
1425int
1426sys_xshutdown(tcp)
1427struct tcb *tcp;
1428{
1429 return netlib_call (tcp, sys_shutdown);
1430}
1431
1432#endif