blob: 066965a61057d9e6200430a4c445dada313bfb16 [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>
38#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000039#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000040#include <netinet/tcp.h>
41#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#ifdef HAVE_NETINET_UDP_H
43#include <netinet/udp.h>
44#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <arpa/inet.h>
46#if defined(LINUX)
47#include <asm/types.h>
48#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
49# include <netipx/ipx.h>
50#else
51# include <linux/ipx.h>
52#endif
53#endif /* LINUX */
54
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000055#if defined (__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000056#if defined(HAVE_LINUX_IN6_H)
Wichert Akkerman505e1761999-11-01 19:39:08 +000057#include <linux/in6.h>
58#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000059#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000060
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000061#if defined(HAVE_SYS_UIO_H)
62#include <sys/uio.h>
63#endif
64
65#if defined(HAVE_LINUX_NETLINK_H)
66#include <linux/netlink.h>
67#endif
68
69#if defined(HAVE_LINUX_IF_PACKET_H)
70#include <linux/if_packet.h>
71#endif
72
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000073#if defined(HAVE_LINUX_ICMP_H)
74#include <linux/icmp.h>
75#endif
76
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077#ifndef PF_UNSPEC
78#define PF_UNSPEC AF_UNSPEC
79#endif
80
Wichert Akkerman16a03d22000-08-10 02:14:04 +000081#if UNIXWARE >= 7
82#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
83#endif
84
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085#ifdef LINUX
86/* Under Linux these are enums so we can't test for them with ifdef. */
87#define IPPROTO_EGP IPPROTO_EGP
88#define IPPROTO_PUP IPPROTO_PUP
89#define IPPROTO_IDP IPPROTO_IDP
90#define IPPROTO_IGMP IPPROTO_IGMP
91#define IPPROTO_RAW IPPROTO_RAW
92#define IPPROTO_MAX IPPROTO_MAX
93#endif
94
95static struct xlat domains[] = {
96 { PF_UNSPEC, "PF_UNSPEC" },
97 { PF_UNIX, "PF_UNIX" },
98 { PF_INET, "PF_INET" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000099#ifdef PF_NETLINK
100 { PF_NETLINK, "PF_NETLINK" },
101#endif
102#ifdef PF_PACKET
103 { PF_PACKET, "PF_PACKET" },
104#endif
105#ifdef PF_INET6
106 { PF_INET6, "PF_INET6" },
107#endif
108#ifdef PF_ATMSVC
109 { PF_ATMSVC, "PF_INET6" },
110#endif
111#ifdef PF_INET6
112 { PF_INET6, "PF_INET6" },
113#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114#ifdef PF_LOCAL
115 { PF_LOCAL, "PS_LOCAL" },
116#endif
117#ifdef PF_ISO
118 { PF_ISO, "PF_ISO" },
119#endif
120#ifdef PF_AX25
121 { PF_AX25, "PF_AX25" },
122#endif
123#ifdef PF_IPX
124 { PF_IPX, "PF_IPX" },
125#endif
126#ifdef PF_APPLETALK
127 { PF_APPLETALK, "PF_APPLETALK" },
128#endif
129#ifdef PF_NETROM
130 { PF_NETROM, "PF_NETROM" },
131#endif
132#ifdef PF_BRIDGE
133 { PF_BRIDGE, "PF_BRIDGE" },
134#endif
135#ifdef PF_AAL5
136 { PF_AAL5, "PF_AAL5" },
137#endif
138#ifdef PF_X25
139 { PF_X25, "PF_X25" },
140#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#ifdef PF_ROSE
142 { PF_ROSE, "PF_ROSE" },
143#endif
144#ifdef PF_DECNET
145 { PF_DECNET, "PF_DECNET" },
146#endif
147#ifdef PF_NETBEUI
148 { PF_NETBEUI, "PF_NETBEUI" },
149#endif
150#ifdef PF_IMPLINK
151 { PF_IMPLINK, "PF_IMPLINK" },
152#endif
153 { 0, NULL },
154};
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000155static struct xlat addrfams[] = {
156 { AF_UNSPEC, "AF_UNSPEC" },
157 { AF_UNIX, "AF_UNIX" },
158 { AF_INET, "AF_INET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000159#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000160 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000161#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000162 { AF_DECnet, "AF_DECnet" },
163#ifdef PF_ATMSVC
164 { AF_ATMSVC, "AF_ATMSVC" },
165#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000166#ifdef AF_PACKET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000167 { AF_PACKET, "AF_PACKET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000168#endif
169#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000170 { AF_NETLINK, "AF_NETLINK" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000171#endif
172#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000173 { AF_ISO, "AF_ISO" },
174#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000175#ifdef AF_IMPLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000176 { AF_IMPLINK, "AF_IMPLINK" },
177#endif
178 { 0, NULL },
179};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180static struct xlat socktypes[] = {
181 { SOCK_STREAM, "SOCK_STREAM" },
182 { SOCK_DGRAM, "SOCK_DGRAM" },
183#ifdef SOCK_RAW
184 { SOCK_RAW, "SOCK_RAW" },
185#endif
186#ifdef SOCK_SEQPACKET
187 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
188#endif
189#ifdef SOCK_RDM
190 { SOCK_RDM, "SOCK_RDM" },
191#endif
192#ifdef SOCK_PACKET
193 { SOCK_PACKET, "SOCK_PACKET" },
194#endif
195 { 0, NULL },
196};
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000197static struct xlat socketlayers[] = {
198 { SOL_IP, "SOL_IP" },
199#if defined(SOL_ICMP)
200 { SOL_ICMP, "SOL_ICMP" },
201#endif
202 { SOL_TCP, "SOL_TCP" },
203 { SOL_UDP, "SOL_UDP" },
204#if defined(SOL_IPV6)
205 { SOL_IPV6, "SOL_IPV6" },
206#endif
207#if defined(SOL_ICMPV6)
208 { SOL_ICMPV6, "SOL_ICMPV6" },
209#endif
210#if defined(SOL_RAW)
211 { SOL_RAW, "SOL_RAW" },
212#endif
213#if defined(SOL_IPX)
214 { SOL_IPX, "SOL_IPX" },
215#endif
216#if defined(SOL_IPX)
217 { SOL_IPX, "SOL_IPX" },
218#endif
219#if defined(SOL_AX25)
220 { SOL_AX25, "SOL_AX25" },
221#endif
222#if defined(SOL_ATALK)
223 { SOL_ATALK, "SOL_ATALK" },
224#endif
225#if defined(SOL_NETROM)
226 { SOL_NETROM, "SOL_NETROM" },
227#endif
228#if defined(SOL_ROSE)
229 { SOL_ROSE, "SOL_ROSE" },
230#endif
231#if defined(SOL_DECNET)
232 { SOL_DECNET, "SOL_DECNET" },
233#endif
234#if defined(SOL_X25)
235 { SOL_X25, "SOL_X25" },
236#endif
237#if defined(SOL_PACKET)
238 { SOL_PACKET, "SOL_PACKET" },
239#endif
240#if defined(SOL_ATM)
241 { SOL_ATM, "SOL_ATM" },
242#endif
243#if defined(SOL_AAL)
244 { SOL_AAL, "SOL_AAL" },
245#endif
246#if defined(SOL_IRDA)
247 { SOL_IRDA, "SOL_IRDA" },
248#endif
249};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250static struct xlat protocols[] = {
251 { IPPROTO_IP, "IPPROTO_IP" },
252 { IPPROTO_ICMP, "IPPROTO_ICMP" },
253 { IPPROTO_TCP, "IPPROTO_TCP" },
254 { IPPROTO_UDP, "IPPROTO_UDP" },
255#ifdef IPPROTO_GGP
256 { IPPROTO_GGP, "IPPROTO_GGP" },
257#endif
258#ifdef IPPROTO_EGP
259 { IPPROTO_EGP, "IPPROTO_EGP" },
260#endif
261#ifdef IPPROTO_PUP
262 { IPPROTO_PUP, "IPPROTO_PUP" },
263#endif
264#ifdef IPPROTO_IDP
265 { IPPROTO_IDP, "IPPROTO_IDP" },
266#endif
267#ifdef IPPROTO_IPV6
268 { IPPROTO_IPV6, "IPPROTO_IPV6" },
269#endif
270#ifdef IPPROTO_ICMPV6
271 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
272#endif
273#ifdef IPPROTO_IGMP
274 { IPPROTO_IGMP, "IPPROTO_IGMP" },
275#endif
276#ifdef IPPROTO_HELLO
277 { IPPROTO_HELLO,"IPPROTO_HELLO" },
278#endif
279#ifdef IPPROTO_ND
280 { IPPROTO_ND, "IPPROTO_ND" },
281#endif
282#ifdef IPPROTO_RAW
283 { IPPROTO_RAW, "IPPROTO_RAW" },
284#endif
285#ifdef IPPROTO_MAX
286 { IPPROTO_MAX, "IPPROTO_MAX" },
287#endif
288#ifdef IPPROTO_IPIP
289 { IPPROTO_IPIP, "IPPROTO_IPIP" },
290#endif
291 { 0, NULL },
292};
293static struct xlat msg_flags[] = {
294 { MSG_OOB, "MSG_OOB" },
295#ifdef MSG_DONTROUTE
296 { MSG_DONTROUTE,"MSG_DONTROUTE" },
297#endif
298#ifdef MSG_PEEK
299 { MSG_PEEK, "MSG_PEEK" },
300#endif
301#ifdef MSG_CTRUNC
302 { MSG_CTRUNC, "MSG_CTRUNC" },
303#endif
304#ifdef MSG_PROXY
305 { MSG_PROXY, "MSG_PROXY" },
306#endif
307#ifdef MSG_EOR
308 { MSG_EOR, "MSG_EOR" },
309#endif
310#ifdef MSG_WAITALL
311 { MSG_WAITALL, "MSG_WAITALL" },
312#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000313#ifdef MSG_TRUNC
314 { MSG_TRUNC, "MSG_TRUNC" },
315#endif
316#ifdef MSG_CTRUNC
317 { MSG_CTRUNC, "MSG_CTRUNC" },
318#endif
319#ifdef MSG_ERRQUEUE
320 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
321#endif
322#ifdef MSG_DONTWAIT
323 { MSG_DONTWAIT, "MSG_DONTWAIT" },
324#endif
325#ifdef MSG_CONFIRM
326 { MSG_CONFIRM, "MSG_CONFIRM" },
327#endif
328#ifdef MSG_PROBE
329 { MSG_PROBE, "MSG_PROBE" },
330#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 { 0, NULL },
332};
333
334static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335#ifdef SO_PEERCRED
336 { SO_PEERCRED, "SO_PEERCRED" },
337#endif
338#ifdef SO_PASSCRED
339 { SO_PASSCRED, "SO_PASSCRED" },
340#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341#ifdef SO_DEBUG
342 { SO_DEBUG, "SO_DEBUG" },
343#endif
344#ifdef SO_REUSEADDR
345 { SO_REUSEADDR, "SO_REUSEADDR" },
346#endif
347#ifdef SO_KEEPALIVE
348 { SO_KEEPALIVE, "SO_KEEPALIVE" },
349#endif
350#ifdef SO_DONTROUTE
351 { SO_DONTROUTE, "SO_DONTROUTE" },
352#endif
353#ifdef SO_BROADCAST
354 { SO_BROADCAST, "SO_BROADCAST" },
355#endif
356#ifdef SO_LINGER
357 { SO_LINGER, "SO_LINGER" },
358#endif
359#ifdef SO_OOBINLINE
360 { SO_OOBINLINE, "SO_OOBINLINE" },
361#endif
362#ifdef SO_TYPE
363 { SO_TYPE, "SO_TYPE" },
364#endif
365#ifdef SO_ERROR
366 { SO_ERROR, "SO_ERROR" },
367#endif
368#ifdef SO_SNDBUF
369 { SO_SNDBUF, "SO_SNDBUF" },
370#endif
371#ifdef SO_RCVBUF
372 { SO_RCVBUF, "SO_RCVBUF" },
373#endif
374#ifdef SO_NO_CHECK
375 { SO_NO_CHECK, "SO_NO_CHECK" },
376#endif
377#ifdef SO_PRIORITY
378 { SO_PRIORITY, "SO_PRIORITY" },
379#endif
380#ifdef SO_ACCEPTCONN
381 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
382#endif
383#ifdef SO_USELOOPBACK
384 { SO_USELOOPBACK,"SO_USELOOPBACK"},
385#endif
386#ifdef SO_SNDLOWAT
387 { SO_SNDLOWAT, "SO_SNDLOWAT" },
388#endif
389#ifdef SO_RCVLOWAT
390 { SO_RCVLOWAT, "SO_RCVLOWAT" },
391#endif
392#ifdef SO_SNDTIMEO
393 { SO_SNDTIMEO, "SO_SNDTIMEO" },
394#endif
395#ifdef SO_RCVTIMEO
396 { SO_RCVTIMEO, "SO_RCVTIMEO" },
397#endif
398#ifdef SO_BSDCOMPAT
399 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
400#endif
401#ifdef SO_REUSEPORT
402 { SO_REUSEPORT, "SO_REUSEPORT" },
403#endif
404#ifdef SO_RCVLOWAT
405 { SO_RCVLOWAT, "SO_RCVLOWAT" },
406#endif
407#ifdef SO_SNDLOWAT
408 { SO_SNDLOWAT, "SO_SNDLOWAT" },
409#endif
410#ifdef SO_RCVTIMEO
411 { SO_RCVTIMEO, "SO_RCVTIMEO" },
412#endif
413#ifdef SO_SNDTIMEO
414 { SO_SNDTIMEO, "SO_SNDTIMEO" },
415#endif
416 { 0, NULL },
417};
418
419#ifdef SOL_IP
420static struct xlat sockipoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000421 { IP_TOS, "IP_TOS" },
422 { IP_TTL, "IP_TTL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423#if defined(IP_HDRINCL)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000424 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425#endif
426#if defined(IP_OPTIONS)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000427 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000429 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
430#if defined(IP_RECVOPTIONS)
431 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
432#endif
433 { IP_RETOPTS, "IP_RETOPTS" },
434 { IP_PKTINFO, "IP_PKTINFO" },
435 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
436 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
437 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
438 { IP_RECVERR, "IP_RECVERR" },
439 { IP_RECVTTL, "IP_RECRECVTTL" },
440 { IP_RECVTOS, "IP_RECRECVTOS" },
441#if defined(IP_MTU)
442 { IP_MTU, "IP_MTU" },
443#endif
444 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
445 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
446 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
447 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
448 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
449 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450};
451#endif /* SOL_IP */
452
453#ifdef SOL_IPX
454static struct xlat sockipxoptions[] = {
455 { IPX_TYPE, "IPX_TYPE" },
456 { 0, NULL },
457};
458#endif /* SOL_IPX */
459
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000460#ifdef SOL_RAW
461static struct xlat sockrawoptions[] = {
462#if defined(ICMP_FILTER)
463 { ICMP_FILTER, "ICMP_FILTER" },
464#endif
465 { 0, NULL },
466};
467#endif /* SOL_RAW */
468
469#ifdef SOL_PACKET
470static struct xlat sockpacketoptions[] = {
471 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
472 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
473#if defined(PACKET_RECV_OUTPUT)
474 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
475#endif
476#if defined(PACKET_RX_RING)
477 { PACKET_RX_RING, "PACKET_RX_RING" },
478#endif
479#if defined(PACKET_STATISTICS)
480 { PACKET_STATISTICS, "PACKET_STATISTICS" },
481#endif
482 { 0, NULL },
483};
484#endif /* SOL_PACKET */
485
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486#ifdef SOL_TCP
487static struct xlat socktcpoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000488 { TCP_NODELAY, "TCP_NODELAY" },
489 { TCP_MAXSEG, "TCP_MAXSEG" },
490#if defined(TCP_CORK)
491 { TCP_CORK, "TCP_CORK" },
492#endif
493 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494};
495#endif /* SOL_TCP */
496
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000497#ifdef SOL_RAW
498static struct xlat icmpfilterflags[] = {
499#if defined(ICMP_ECHOREPLY)
500 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
501#endif
502#if defined(ICMP_DEST_UNREACH)
503 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
504#endif
505#if defined(ICMP_SOURCE_QUENCH)
506 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
507#endif
508#if defined(ICMP_REDIRECT)
509 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
510#endif
511#if defined(ICMP_ECHO)
512 { (1<<ICMP_ECHO), "ICMP_ECHO" },
513#endif
514#if defined(ICMP_TIME_EXCEEDED)
515 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
516#endif
517#if defined(ICMP_PARAMETERPROB)
518 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
519#endif
520#if defined(ICMP_TIMESTAMP)
521 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
522#endif
523#if defined(ICMP_TIMESTAMPREPLY)
524 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
525#endif
526#if defined(ICMP_INFO_REQUEST)
527 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
528#endif
529#if defined(ICMP_INFO_REPLY)
530 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
531#endif
532#if defined(ICMP_ADDRESS)
533 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
534#endif
535#if defined(ICMP_ADDRESSREPLY)
536 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
537#endif
538 { 0, NULL },
539};
540#endif /* SOL_RAW */
541
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000542
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000544printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545struct tcb *tcp;
546long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000547int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000549 union {
550 char pad[128];
551 struct sockaddr sa;
552 struct sockaddr_in sin;
553 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000554#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000555 struct sockaddr_in6 sa6;
556#endif
557#if defined(LINUX) && defined(AF_IPX)
558 struct sockaddr_ipx sipx;
559#endif
560#ifdef AF_PACKET
561 struct sockaddr_ll ll;
562#endif
563#ifdef AF_NETLINK
564 struct sockaddr_nl nl;
565#endif
566 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000567 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568
569 if (addr == 0) {
570 tprintf("NULL");
571 return;
572 }
573 if (!verbose(tcp)) {
574 tprintf("%#lx", addr);
575 return;
576 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000577 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
578 addrlen=sizeof(addrbuf);
579
580 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 tprintf("{...}");
582 return;
583 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000584
585 tprintf("{sin_family=");
586 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
587 tprintf(", ");
588
589 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000591 if (addrlen==2) {
592 tprintf("<nil>");
593 } else if (addrbuf.sau.sun_path[0]) {
594 tprintf("path=\"%*.*s\"", addrlen-2, addrlen-2, addrbuf.sau.sun_path);
595 } else {
596 tprintf("path=@%*.*s", addrlen-3, addrlen-3, addrbuf.sau.sun_path+1);
597 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598 break;
599 case AF_INET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000601 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000603#ifdef HAVE_INET_NTOP
604 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000605 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
606 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)}",
607 ntohs(addrbuf.sa6.sin6_port), string_addr, ntohl(addrbuf.sa6.sin6_flowinfo));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000608 break;
609#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000610#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000612 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613 int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614 tprintf("{sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000615 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616 /* Yes, I know, this does not look too
617 * strace-ish, but otherwise the IPX
618 * addresses just look monstrous...
619 * Anyways, feel free if you don't like
620 * this way.. :)
621 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000622 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000624 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
625 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626 }
627 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000628#endif /* AF_IPX && linux */
629#ifdef AF_PACKET
630 case AF_PACKET:
631 {
632 int i;
633 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
634 ntohs(addrbuf.ll.sll_protocol),
635 addrbuf.ll.sll_ifindex,
636 addrbuf.ll.sll_pkttype,
637 addrbuf.ll.sll_halen,
638 addrbuf.ll.sll_hatype);
639 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
640 tprintf("%02x", addrbuf.ll.sll_addr[i]);
641 }
642 break;
643
644#endif /* AF_APACKET */
645#ifdef AF_NETLINLK
646 case AF_NETLINK:
647 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
648 break;
649#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000651 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652
653 default:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000654 tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000656 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 break;
658 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000659 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660}
661
662#if HAVE_SENDMSG
663
664static void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000665printiovec(tcp, iovec, len)
666struct tcb *tcp;
667struct iovec *iovec;
668long len;
669{
670 struct iovec *iov;
671 int i;
672
673 iov = (struct iovec *) malloc(len * sizeof *iov);
674 if (iov == NULL) {
675 fprintf(stderr, "No memory");
676 return;
677 }
678 if (umoven(tcp, (long)iovec,
679 len * sizeof *iov, (char *) iov) < 0) {
680 tprintf("%#lx", (unsigned long)iovec);
681 } else {
682 tprintf("[");
683 for (i = 0; i < len; i++) {
684 if (i)
685 tprintf(", ");
686 tprintf("{");
687 printstr(tcp, (long) iov[i].iov_base,
688 iov[i].iov_len);
689 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
690 }
691 tprintf("]");
692 }
693 free((char *) iov);
694}
695
696static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697printmsghdr(tcp, addr)
698struct tcb *tcp;
699long addr;
700{
701 struct msghdr msg;
702
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000703 if (umove(tcp, addr, &msg) < 0) {
704 tprintf("%#lx", addr);
705 return;
706 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000707 tprintf("{msg_name(%d)=", msg.msg_namelen);
708 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
709
710 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
711 printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
712
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000714 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
715 if (msg.msg_controllen)
716 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
717 tprintf(", msg_flags=");
718 if (printflags(msg_flags, msg.msg_flags)==0)
719 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000721 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
723#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000724 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725}
726
727#endif /* HAVE_SENDMSG */
728
729int
730sys_socket(tcp)
731struct tcb *tcp;
732{
733 if (entering(tcp)) {
734 printxval(domains, tcp->u_arg[0], "PF_???");
735 tprintf(", ");
736 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
737 tprintf(", ");
738 switch (tcp->u_arg[0]) {
739 case PF_INET:
740 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
741 break;
742#ifdef PF_IPX
743 case PF_IPX:
744 /* BTW: I don't believe this.. */
745 tprintf("[");
746 printxval(domains, tcp->u_arg[2], "PF_???");
747 tprintf("]");
748 break;
749#endif /* PF_IPX */
750 default:
751 tprintf("%lu", tcp->u_arg[2]);
752 break;
753 }
754 }
755 return 0;
756}
757
758int
759sys_bind(tcp)
760struct tcb *tcp;
761{
762 if (entering(tcp)) {
763 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000764 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765 tprintf(", %lu", tcp->u_arg[2]);
766 }
767 return 0;
768}
769
770int
771sys_connect(tcp)
772struct tcb *tcp;
773{
774 return sys_bind(tcp);
775}
776
777int
778sys_listen(tcp)
779struct tcb *tcp;
780{
781 if (entering(tcp)) {
782 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
783 }
784 return 0;
785}
786
787int
788sys_accept(tcp)
789struct tcb *tcp;
790{
791 if (entering(tcp)) {
792 tprintf("%ld, ", tcp->u_arg[0]);
793 } else if (!tcp->u_arg[2])
794 tprintf("%#lx, NULL", tcp->u_arg[1]);
795 else {
796 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
797 tprintf("%#lx", tcp->u_arg[1]);
798 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000799 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800 }
801 tprintf(", ");
802 printnum(tcp, tcp->u_arg[2], "%lu");
803 }
804 return 0;
805}
806
807int
808sys_send(tcp)
809struct tcb *tcp;
810{
811 if (entering(tcp)) {
812 tprintf("%ld, ", tcp->u_arg[0]);
813 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
814 tprintf(", %lu, ", tcp->u_arg[2]);
815 /* flags */
816 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
817 tprintf("0");
818 }
819 return 0;
820}
821
822int
823sys_sendto(tcp)
824struct tcb *tcp;
825{
826 if (entering(tcp)) {
827 tprintf("%ld, ", tcp->u_arg[0]);
828 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
829 tprintf(", %lu, ", tcp->u_arg[2]);
830 /* flags */
831 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
832 tprintf("0");
833 /* to address */
834 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000835 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836 /* to length */
837 tprintf(", %lu", tcp->u_arg[5]);
838 }
839 return 0;
840}
841
842#ifdef HAVE_SENDMSG
843
844int
845sys_sendmsg(tcp)
846struct tcb *tcp;
847{
848 if (entering(tcp)) {
849 tprintf("%ld, ", tcp->u_arg[0]);
850 printmsghdr(tcp, tcp->u_arg[1]);
851 /* flags */
852 tprintf(", ");
853 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
854 tprintf("0");
855 }
856 return 0;
857}
858
859#endif /* HAVE_SENDMSG */
860
861int
862sys_recv(tcp)
863struct tcb *tcp;
864{
865 if (entering(tcp)) {
866 tprintf("%ld, ", tcp->u_arg[0]);
867 } else {
868 if (syserror(tcp))
869 tprintf("%#lx", tcp->u_arg[1]);
870 else
871 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
872
873 tprintf(", %lu, ", tcp->u_arg[2]);
874 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
875 tprintf("0");
876 }
877 return 0;
878}
879
880int
881sys_recvfrom(tcp)
882struct tcb *tcp;
883{
884 int fromlen;
885
886 if (entering(tcp)) {
887 tprintf("%ld, ", tcp->u_arg[0]);
888 } else {
889 if (syserror(tcp)) {
890 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
891 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
892 tcp->u_arg[4], tcp->u_arg[5]);
893 return 0;
894 }
895 /* buf */
896 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
897 /* len */
898 tprintf(", %lu, ", tcp->u_arg[2]);
899 /* flags */
900 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
901 tprintf("0");
902 /* from address, len */
903 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
904 if (tcp->u_arg[4] == 0)
905 tprintf(", NULL");
906 else
907 tprintf(", %#lx", tcp->u_arg[4]);
908 if (tcp->u_arg[5] == 0)
909 tprintf(", NULL");
910 else
911 tprintf(", %#lx", tcp->u_arg[5]);
912 return 0;
913 }
914 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
915 tprintf(", {...}, [?]");
916 return 0;
917 }
918 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000919 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920 /* from length */
921 tprintf(", [%u]", fromlen);
922 }
923 return 0;
924}
925
926#ifdef HAVE_SENDMSG
927
928int
929sys_recvmsg(tcp)
930struct tcb *tcp;
931{
932 if (entering(tcp)) {
933 tprintf("%ld, ", tcp->u_arg[0]);
934 } else {
935 if (syserror(tcp) || !verbose(tcp))
936 tprintf("%#lx", tcp->u_arg[1]);
937 else
938 printmsghdr(tcp, tcp->u_arg[1]);
939 /* flags */
940 tprintf(", ");
941 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
942 tprintf("0");
943 }
944 return 0;
945}
946
947#endif /* HAVE_SENDMSG */
948
949int
950sys_shutdown(tcp)
951struct tcb *tcp;
952{
953 if (entering(tcp)) {
954 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
955 switch (tcp->u_arg[1]) {
956 case 0:
957 tprintf("%s", " /* receive */");
958 break;
959 case 1:
960 tprintf("%s", " /* send */");
961 break;
962 case 2:
963 tprintf("%s", " /* send and receive */");
964 break;
965 }
966 }
967 return 0;
968}
969
970int
971sys_getsockname(tcp)
972struct tcb *tcp;
973{
974 return sys_accept(tcp);
975}
976
977int
978sys_getpeername(tcp)
979struct tcb *tcp;
980{
981 return sys_accept(tcp);
982}
983
984int
985sys_pipe(tcp)
986struct tcb *tcp;
987{
988
989#if defined(LINUX) && !defined(SPARC)
990 int fds[2];
991
992 if (exiting(tcp)) {
993 if (syserror(tcp)) {
994 tprintf("%#lx", tcp->u_arg[0]);
995 return 0;
996 }
997 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
998 tprintf("[...]");
999 else
1000 tprintf("[%u, %u]", fds[0], fds[1]);
1001 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001002#elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001003 if (exiting(tcp))
1004 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005#endif
1006 return 0;
1007}
1008
1009int
1010sys_socketpair(tcp)
1011struct tcb *tcp;
1012{
1013#ifdef LINUX
1014 int fds[2];
1015#endif
1016
1017 if (entering(tcp)) {
1018 printxval(domains, tcp->u_arg[0], "PF_???");
1019 tprintf(", ");
1020 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1021 tprintf(", ");
1022 switch (tcp->u_arg[0]) {
1023 case PF_INET:
1024 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1025 break;
1026#ifdef PF_IPX
1027 case PF_IPX:
1028 /* BTW: I don't believe this.. */
1029 tprintf("[");
1030 printxval(domains, tcp->u_arg[2], "PF_???");
1031 tprintf("]");
1032 break;
1033#endif /* PF_IPX */
1034 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001035 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036 break;
1037 }
1038 } else {
1039 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001040 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 return 0;
1042 }
1043#ifdef LINUX
1044 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001045 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046 else
1047 tprintf(", [%u, %u]", fds[0], fds[1]);
1048#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001049#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001051#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 }
1053 return 0;
1054}
1055
1056int
1057sys_getsockopt(tcp)
1058struct tcb *tcp;
1059{
1060 if (entering(tcp)) {
1061 tprintf("%ld, ", tcp->u_arg[0]);
1062 switch (tcp->u_arg[1]) {
1063 case SOL_SOCKET:
1064 tprintf("SOL_SOCKET, ");
1065 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1066 tprintf(", ");
1067 break;
1068#ifdef SOL_IP
1069 case SOL_IP:
1070 tprintf("SOL_IP, ");
1071 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1072 tprintf(", ");
1073 break;
1074#endif
1075#ifdef SOL_IPX
1076 case SOL_IPX:
1077 tprintf("SOL_IPX, ");
1078 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1079 tprintf(", ");
1080 break;
1081#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001082#ifdef SOL_PACKET
1083 case SOL_PACKET:
1084 tprintf("SOL_PACKET, ");
1085 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1086 tprintf(", ");
1087 break;
1088#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089#ifdef SOL_TCP
1090 case SOL_TCP:
1091 tprintf("SOL_TCP, ");
1092 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1093 tprintf(", ");
1094 break;
1095#endif
1096
1097 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1098 * etc. still need work */
1099 default:
1100 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001101 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001102 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 break;
1104 }
1105 } else {
1106 if (syserror(tcp)) {
1107 tprintf("%#lx, %#lx",
1108 tcp->u_arg[3], tcp->u_arg[4]);
1109 return 0;
1110 }
1111 printnum(tcp, tcp->u_arg[3], "%ld");
1112 tprintf(", ");
1113 printnum(tcp, tcp->u_arg[4], "%ld");
1114 }
1115 return 0;
1116}
1117
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001118#if defined(ICMP_FILTER)
1119static void printicmpfilter(tcp, addr)
1120struct tcb *tcp;
1121long addr;
1122{
1123 struct icmp_filter filter;
1124
1125 if (!addr) {
1126 tprintf("NULL");
1127 return;
1128 }
1129 if (syserror(tcp) || !verbose(tcp)) {
1130 tprintf("%#lx", addr);
1131 return;
1132 }
1133 if (umove(tcp, addr, &filter) < 0) {
1134 tprintf("{...}");
1135 return;
1136 }
1137
1138 tprintf("~(");
1139 if (printflags(icmpfilterflags, ~filter.data) == 0)
1140 tprintf("0");
1141 tprintf(")");
1142}
1143#endif /* ICMP_FILTER */
1144
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001145int
1146sys_setsockopt(tcp)
1147struct tcb *tcp;
1148{
1149 if (entering(tcp)) {
1150 tprintf("%ld, ", tcp->u_arg[0]);
1151 switch (tcp->u_arg[1]) {
1152 case SOL_SOCKET:
1153 tprintf("SOL_SOCKET, ");
1154 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1155 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001156 printnum(tcp, tcp->u_arg[3], "%ld");
1157 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158 break;
1159#ifdef SOL_IP
1160 case SOL_IP:
1161 tprintf("SOL_IP, ");
1162 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1163 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001164 printnum(tcp, tcp->u_arg[3], "%ld");
1165 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001166 break;
1167#endif
1168#ifdef SOL_IPX
1169 case SOL_IPX:
1170 tprintf("SOL_IPX, ");
1171 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1172 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001173 printnum(tcp, tcp->u_arg[3], "%ld");
1174 tprintf(", %lu", tcp->u_arg[4]);
1175 break;
1176#endif
1177#ifdef SOL_PACKET
1178 case SOL_PACKET:
1179 tprintf("SOL_PACKET, ");
1180 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1181 tprintf(", ");
1182 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1183 printnum(tcp, tcp->u_arg[3], "%ld");
1184 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185 break;
1186#endif
1187#ifdef SOL_TCP
1188 case SOL_TCP:
1189 tprintf("SOL_TCP, ");
1190 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1191 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001192 printnum(tcp, tcp->u_arg[3], "%ld");
1193 tprintf(", %lu", tcp->u_arg[4]);
1194 break;
1195#endif
1196#ifdef SOL_RAW
1197 case SOL_RAW:
1198 tprintf("SOL_RAW, ");
1199 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1200 tprintf(", ");
1201 switch (tcp->u_arg[2]) {
1202#if defined(ICMP_FILTER)
1203 case ICMP_FILTER:
1204 printicmpfilter(tcp, tcp->u_arg[3]);
1205 break;
1206#endif
1207 default:
1208 printnum(tcp, tcp->u_arg[3], "%ld");
1209 break;
1210 }
1211 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001212 break;
1213#endif
1214
1215 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1216 * etc. still need work */
1217 default:
1218 /* XXX - should know socket family here */
Wichert Akkermanefdecac2000-11-26 03:59:21 +00001219 printxval(socketlayers, tcp->u_arg[1], "IPPROTO_???");
1220 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001221 printnum(tcp, tcp->u_arg[3], "%ld");
1222 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223 break;
1224 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225 }
1226 return 0;
1227}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001228
1229#if UNIXWARE >= 7
1230
1231static struct xlat sock_version[] = {
1232 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1233 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1234 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1235 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1236 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1237 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1238 { 0, NULL },
1239};
1240
1241
1242int
1243netlib_call(tcp, func)
1244struct tcb *tcp;
1245int (*func) ();
1246{
1247 if (entering(tcp)) {
1248 int i;
1249 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1250 tprintf(", ");
1251 --tcp->u_nargs;
1252 for (i = 0; i < tcp->u_nargs; i++)
1253 tcp->u_arg[i] = tcp->u_arg[i + 1];
1254 return func (tcp);
1255
1256 }
1257
1258 return func (tcp);
1259}
1260
1261int
1262sys_xsocket(tcp)
1263struct tcb *tcp;
1264{
1265 return netlib_call (tcp, sys_socket);
1266}
1267
1268int
1269sys_xsocketpair(tcp)
1270struct tcb *tcp;
1271{
1272 return netlib_call (tcp, sys_socketpair);
1273}
1274
1275int
1276sys_xbind(tcp)
1277struct tcb *tcp;
1278{
1279 return netlib_call (tcp, sys_bind);
1280}
1281
1282int
1283sys_xconnect(tcp)
1284struct tcb *tcp;
1285{
1286 return netlib_call (tcp, sys_connect);
1287}
1288
1289int
1290sys_xlisten(tcp)
1291struct tcb *tcp;
1292{
1293 return netlib_call (tcp, sys_listen);
1294}
1295
1296int
1297sys_xaccept(tcp)
1298struct tcb *tcp;
1299{
1300 return netlib_call (tcp, sys_accept);
1301}
1302
1303int
1304sys_xsendmsg(tcp)
1305struct tcb *tcp;
1306{
1307 return netlib_call (tcp, sys_sendmsg);
1308}
1309
1310int
1311sys_xrecvmsg(tcp)
1312struct tcb *tcp;
1313{
1314 return netlib_call (tcp, sys_recvmsg);
1315}
1316
1317int
1318sys_xgetsockaddr(tcp)
1319struct tcb *tcp;
1320{
1321 if (entering(tcp)) {
1322 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1323 tprintf(", ");
1324 if (tcp->u_arg[1] == 0) {
1325 tprintf ("LOCALNAME, ");
1326 }
1327 else if (tcp->u_arg[1] == 1) {
1328 tprintf ("REMOTENAME, ");
1329 }
1330 else {
1331 tprintf ("%ld, ", tcp->u_arg [1]);
1332 }
1333 tprintf ("%ld, ", tcp->u_arg [2]);
1334 }
1335 else {
1336 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1337 tprintf("%#lx", tcp->u_arg[3]);
1338 } else {
1339 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1340 }
1341 tprintf(", ");
1342 printnum(tcp, tcp->u_arg[4], "%lu");
1343 }
1344
1345 return 0;
1346
1347}
1348
1349#if 0
1350
1351int
1352sys_xsetsockaddr(tcp)
1353struct tcb *tcp;
1354{
1355 return netlib_call (tcp, sys_setsockaddr);
1356}
1357
1358#endif
1359
1360int
1361sys_xgetsockopt(tcp)
1362struct tcb *tcp;
1363{
1364 return netlib_call (tcp, sys_getsockopt);
1365}
1366
1367int
1368sys_xsetsockopt(tcp)
1369struct tcb *tcp;
1370{
1371 return netlib_call (tcp, sys_setsockopt);
1372}
1373
1374int
1375sys_xshutdown(tcp)
1376struct tcb *tcp;
1377{
1378 return netlib_call (tcp, sys_shutdown);
1379}
1380
1381#endif