blob: db88c6d6df91a62ca463007e7cc62953b4438d5c [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>
39#include <arpa/inet.h>
40#if defined(LINUX)
41#include <asm/types.h>
42#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
43# include <netipx/ipx.h>
44#else
45# include <linux/ipx.h>
46#endif
47#endif /* LINUX */
48
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000049#if defined (__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000050#if defined(HAVE_LINUX_IN6_H)
Wichert Akkerman505e1761999-11-01 19:39:08 +000051#include <linux/in6.h>
52#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000053#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000054
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000055#if defined(HAVE_SYS_UIO_H)
56#include <sys/uio.h>
57#endif
58
59#if defined(HAVE_LINUX_NETLINK_H)
60#include <linux/netlink.h>
61#endif
62
63#if defined(HAVE_LINUX_IF_PACKET_H)
64#include <linux/if_packet.h>
65#endif
66
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000067#if defined(HAVE_LINUX_ICMP_H)
68#include <linux/icmp.h>
69#endif
70
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#ifndef PF_UNSPEC
72#define PF_UNSPEC AF_UNSPEC
73#endif
74
Wichert Akkerman16a03d22000-08-10 02:14:04 +000075#if UNIXWARE >= 7
76#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
77#endif
78
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000079#ifdef LINUX
80/* Under Linux these are enums so we can't test for them with ifdef. */
81#define IPPROTO_EGP IPPROTO_EGP
82#define IPPROTO_PUP IPPROTO_PUP
83#define IPPROTO_IDP IPPROTO_IDP
84#define IPPROTO_IGMP IPPROTO_IGMP
85#define IPPROTO_RAW IPPROTO_RAW
86#define IPPROTO_MAX IPPROTO_MAX
87#endif
88
89static struct xlat domains[] = {
90 { PF_UNSPEC, "PF_UNSPEC" },
91 { PF_UNIX, "PF_UNIX" },
92 { PF_INET, "PF_INET" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000093#ifdef PF_NETLINK
94 { PF_NETLINK, "PF_NETLINK" },
95#endif
96#ifdef PF_PACKET
97 { PF_PACKET, "PF_PACKET" },
98#endif
99#ifdef PF_INET6
100 { PF_INET6, "PF_INET6" },
101#endif
102#ifdef PF_ATMSVC
103 { PF_ATMSVC, "PF_INET6" },
104#endif
105#ifdef PF_INET6
106 { PF_INET6, "PF_INET6" },
107#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#ifdef PF_LOCAL
109 { PF_LOCAL, "PS_LOCAL" },
110#endif
111#ifdef PF_ISO
112 { PF_ISO, "PF_ISO" },
113#endif
114#ifdef PF_AX25
115 { PF_AX25, "PF_AX25" },
116#endif
117#ifdef PF_IPX
118 { PF_IPX, "PF_IPX" },
119#endif
120#ifdef PF_APPLETALK
121 { PF_APPLETALK, "PF_APPLETALK" },
122#endif
123#ifdef PF_NETROM
124 { PF_NETROM, "PF_NETROM" },
125#endif
126#ifdef PF_BRIDGE
127 { PF_BRIDGE, "PF_BRIDGE" },
128#endif
129#ifdef PF_AAL5
130 { PF_AAL5, "PF_AAL5" },
131#endif
132#ifdef PF_X25
133 { PF_X25, "PF_X25" },
134#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135#ifdef PF_ROSE
136 { PF_ROSE, "PF_ROSE" },
137#endif
138#ifdef PF_DECNET
139 { PF_DECNET, "PF_DECNET" },
140#endif
141#ifdef PF_NETBEUI
142 { PF_NETBEUI, "PF_NETBEUI" },
143#endif
144#ifdef PF_IMPLINK
145 { PF_IMPLINK, "PF_IMPLINK" },
146#endif
147 { 0, NULL },
148};
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000149static struct xlat addrfams[] = {
150 { AF_UNSPEC, "AF_UNSPEC" },
151 { AF_UNIX, "AF_UNIX" },
152 { AF_INET, "AF_INET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000153#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000154 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000155#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000156 { AF_DECnet, "AF_DECnet" },
157#ifdef PF_ATMSVC
158 { AF_ATMSVC, "AF_ATMSVC" },
159#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000160#ifdef AF_PACKET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000161 { AF_PACKET, "AF_PACKET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000162#endif
163#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000164 { AF_NETLINK, "AF_NETLINK" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000165#endif
166#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000167 { AF_ISO, "AF_ISO" },
168#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000169#ifdef AF_IMPLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000170 { AF_IMPLINK, "AF_IMPLINK" },
171#endif
172 { 0, NULL },
173};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174static struct xlat socktypes[] = {
175 { SOCK_STREAM, "SOCK_STREAM" },
176 { SOCK_DGRAM, "SOCK_DGRAM" },
177#ifdef SOCK_RAW
178 { SOCK_RAW, "SOCK_RAW" },
179#endif
180#ifdef SOCK_SEQPACKET
181 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
182#endif
183#ifdef SOCK_RDM
184 { SOCK_RDM, "SOCK_RDM" },
185#endif
186#ifdef SOCK_PACKET
187 { SOCK_PACKET, "SOCK_PACKET" },
188#endif
189 { 0, NULL },
190};
191static struct xlat protocols[] = {
192 { IPPROTO_IP, "IPPROTO_IP" },
193 { IPPROTO_ICMP, "IPPROTO_ICMP" },
194 { IPPROTO_TCP, "IPPROTO_TCP" },
195 { IPPROTO_UDP, "IPPROTO_UDP" },
196#ifdef IPPROTO_GGP
197 { IPPROTO_GGP, "IPPROTO_GGP" },
198#endif
199#ifdef IPPROTO_EGP
200 { IPPROTO_EGP, "IPPROTO_EGP" },
201#endif
202#ifdef IPPROTO_PUP
203 { IPPROTO_PUP, "IPPROTO_PUP" },
204#endif
205#ifdef IPPROTO_IDP
206 { IPPROTO_IDP, "IPPROTO_IDP" },
207#endif
208#ifdef IPPROTO_IPV6
209 { IPPROTO_IPV6, "IPPROTO_IPV6" },
210#endif
211#ifdef IPPROTO_ICMPV6
212 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
213#endif
214#ifdef IPPROTO_IGMP
215 { IPPROTO_IGMP, "IPPROTO_IGMP" },
216#endif
217#ifdef IPPROTO_HELLO
218 { IPPROTO_HELLO,"IPPROTO_HELLO" },
219#endif
220#ifdef IPPROTO_ND
221 { IPPROTO_ND, "IPPROTO_ND" },
222#endif
223#ifdef IPPROTO_RAW
224 { IPPROTO_RAW, "IPPROTO_RAW" },
225#endif
226#ifdef IPPROTO_MAX
227 { IPPROTO_MAX, "IPPROTO_MAX" },
228#endif
229#ifdef IPPROTO_IPIP
230 { IPPROTO_IPIP, "IPPROTO_IPIP" },
231#endif
232 { 0, NULL },
233};
234static struct xlat msg_flags[] = {
235 { MSG_OOB, "MSG_OOB" },
236#ifdef MSG_DONTROUTE
237 { MSG_DONTROUTE,"MSG_DONTROUTE" },
238#endif
239#ifdef MSG_PEEK
240 { MSG_PEEK, "MSG_PEEK" },
241#endif
242#ifdef MSG_CTRUNC
243 { MSG_CTRUNC, "MSG_CTRUNC" },
244#endif
245#ifdef MSG_PROXY
246 { MSG_PROXY, "MSG_PROXY" },
247#endif
248#ifdef MSG_EOR
249 { MSG_EOR, "MSG_EOR" },
250#endif
251#ifdef MSG_WAITALL
252 { MSG_WAITALL, "MSG_WAITALL" },
253#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000254#ifdef MSG_TRUNC
255 { MSG_TRUNC, "MSG_TRUNC" },
256#endif
257#ifdef MSG_CTRUNC
258 { MSG_CTRUNC, "MSG_CTRUNC" },
259#endif
260#ifdef MSG_ERRQUEUE
261 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
262#endif
263#ifdef MSG_DONTWAIT
264 { MSG_DONTWAIT, "MSG_DONTWAIT" },
265#endif
266#ifdef MSG_CONFIRM
267 { MSG_CONFIRM, "MSG_CONFIRM" },
268#endif
269#ifdef MSG_PROBE
270 { MSG_PROBE, "MSG_PROBE" },
271#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 { 0, NULL },
273};
274
275static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000276#ifdef SO_PEERCRED
277 { SO_PEERCRED, "SO_PEERCRED" },
278#endif
279#ifdef SO_PASSCRED
280 { SO_PASSCRED, "SO_PASSCRED" },
281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282#ifdef SO_DEBUG
283 { SO_DEBUG, "SO_DEBUG" },
284#endif
285#ifdef SO_REUSEADDR
286 { SO_REUSEADDR, "SO_REUSEADDR" },
287#endif
288#ifdef SO_KEEPALIVE
289 { SO_KEEPALIVE, "SO_KEEPALIVE" },
290#endif
291#ifdef SO_DONTROUTE
292 { SO_DONTROUTE, "SO_DONTROUTE" },
293#endif
294#ifdef SO_BROADCAST
295 { SO_BROADCAST, "SO_BROADCAST" },
296#endif
297#ifdef SO_LINGER
298 { SO_LINGER, "SO_LINGER" },
299#endif
300#ifdef SO_OOBINLINE
301 { SO_OOBINLINE, "SO_OOBINLINE" },
302#endif
303#ifdef SO_TYPE
304 { SO_TYPE, "SO_TYPE" },
305#endif
306#ifdef SO_ERROR
307 { SO_ERROR, "SO_ERROR" },
308#endif
309#ifdef SO_SNDBUF
310 { SO_SNDBUF, "SO_SNDBUF" },
311#endif
312#ifdef SO_RCVBUF
313 { SO_RCVBUF, "SO_RCVBUF" },
314#endif
315#ifdef SO_NO_CHECK
316 { SO_NO_CHECK, "SO_NO_CHECK" },
317#endif
318#ifdef SO_PRIORITY
319 { SO_PRIORITY, "SO_PRIORITY" },
320#endif
321#ifdef SO_ACCEPTCONN
322 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
323#endif
324#ifdef SO_USELOOPBACK
325 { SO_USELOOPBACK,"SO_USELOOPBACK"},
326#endif
327#ifdef SO_SNDLOWAT
328 { SO_SNDLOWAT, "SO_SNDLOWAT" },
329#endif
330#ifdef SO_RCVLOWAT
331 { SO_RCVLOWAT, "SO_RCVLOWAT" },
332#endif
333#ifdef SO_SNDTIMEO
334 { SO_SNDTIMEO, "SO_SNDTIMEO" },
335#endif
336#ifdef SO_RCVTIMEO
337 { SO_RCVTIMEO, "SO_RCVTIMEO" },
338#endif
339#ifdef SO_BSDCOMPAT
340 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
341#endif
342#ifdef SO_REUSEPORT
343 { SO_REUSEPORT, "SO_REUSEPORT" },
344#endif
345#ifdef SO_RCVLOWAT
346 { SO_RCVLOWAT, "SO_RCVLOWAT" },
347#endif
348#ifdef SO_SNDLOWAT
349 { SO_SNDLOWAT, "SO_SNDLOWAT" },
350#endif
351#ifdef SO_RCVTIMEO
352 { SO_RCVTIMEO, "SO_RCVTIMEO" },
353#endif
354#ifdef SO_SNDTIMEO
355 { SO_SNDTIMEO, "SO_SNDTIMEO" },
356#endif
357 { 0, NULL },
358};
359
360#ifdef SOL_IP
361static struct xlat sockipoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000362 { IP_TOS, "IP_TOS" },
363 { IP_TTL, "IP_TTL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364#if defined(IP_HDRINCL)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000365 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366#endif
367#if defined(IP_OPTIONS)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000368 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000370 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
371#if defined(IP_RECVOPTIONS)
372 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
373#endif
374 { IP_RETOPTS, "IP_RETOPTS" },
375 { IP_PKTINFO, "IP_PKTINFO" },
376 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
377 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
378 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
379 { IP_RECVERR, "IP_RECVERR" },
380 { IP_RECVTTL, "IP_RECRECVTTL" },
381 { IP_RECVTOS, "IP_RECRECVTOS" },
382#if defined(IP_MTU)
383 { IP_MTU, "IP_MTU" },
384#endif
385 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
386 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
387 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
388 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
389 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
390 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391};
392#endif /* SOL_IP */
393
394#ifdef SOL_IPX
395static struct xlat sockipxoptions[] = {
396 { IPX_TYPE, "IPX_TYPE" },
397 { 0, NULL },
398};
399#endif /* SOL_IPX */
400
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000401#ifdef SOL_RAW
402static struct xlat sockrawoptions[] = {
403#if defined(ICMP_FILTER)
404 { ICMP_FILTER, "ICMP_FILTER" },
405#endif
406 { 0, NULL },
407};
408#endif /* SOL_RAW */
409
410#ifdef SOL_PACKET
411static struct xlat sockpacketoptions[] = {
412 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
413 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
414#if defined(PACKET_RECV_OUTPUT)
415 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
416#endif
417#if defined(PACKET_RX_RING)
418 { PACKET_RX_RING, "PACKET_RX_RING" },
419#endif
420#if defined(PACKET_STATISTICS)
421 { PACKET_STATISTICS, "PACKET_STATISTICS" },
422#endif
423 { 0, NULL },
424};
425#endif /* SOL_PACKET */
426
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427#ifdef SOL_TCP
428static struct xlat socktcpoptions[] = {
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000429 { TCP_NODELAY, "TCP_NODELAY" },
430 { TCP_MAXSEG, "TCP_MAXSEG" },
431#if defined(TCP_CORK)
432 { TCP_CORK, "TCP_CORK" },
433#endif
434 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435};
436#endif /* SOL_TCP */
437
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000438#ifdef SOL_RAW
439static struct xlat icmpfilterflags[] = {
440#if defined(ICMP_ECHOREPLY)
441 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
442#endif
443#if defined(ICMP_DEST_UNREACH)
444 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
445#endif
446#if defined(ICMP_SOURCE_QUENCH)
447 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
448#endif
449#if defined(ICMP_REDIRECT)
450 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
451#endif
452#if defined(ICMP_ECHO)
453 { (1<<ICMP_ECHO), "ICMP_ECHO" },
454#endif
455#if defined(ICMP_TIME_EXCEEDED)
456 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
457#endif
458#if defined(ICMP_PARAMETERPROB)
459 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
460#endif
461#if defined(ICMP_TIMESTAMP)
462 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
463#endif
464#if defined(ICMP_TIMESTAMPREPLY)
465 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
466#endif
467#if defined(ICMP_INFO_REQUEST)
468 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
469#endif
470#if defined(ICMP_INFO_REPLY)
471 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
472#endif
473#if defined(ICMP_ADDRESS)
474 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
475#endif
476#if defined(ICMP_ADDRESSREPLY)
477 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
478#endif
479 { 0, NULL },
480};
481#endif /* SOL_RAW */
482
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000483
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000485printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486struct tcb *tcp;
487long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000488int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000490 union {
491 char pad[128];
492 struct sockaddr sa;
493 struct sockaddr_in sin;
494 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000495#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000496 struct sockaddr_in6 sa6;
497#endif
498#if defined(LINUX) && defined(AF_IPX)
499 struct sockaddr_ipx sipx;
500#endif
501#ifdef AF_PACKET
502 struct sockaddr_ll ll;
503#endif
504#ifdef AF_NETLINK
505 struct sockaddr_nl nl;
506#endif
507 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000508 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509
510 if (addr == 0) {
511 tprintf("NULL");
512 return;
513 }
514 if (!verbose(tcp)) {
515 tprintf("%#lx", addr);
516 return;
517 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000518 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
519 addrlen=sizeof(addrbuf);
520
521 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 tprintf("{...}");
523 return;
524 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000525
526 tprintf("{sin_family=");
527 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
528 tprintf(", ");
529
530 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000532 if (addrlen==2) {
533 tprintf("<nil>");
534 } else if (addrbuf.sau.sun_path[0]) {
535 tprintf("path=\"%*.*s\"", addrlen-2, addrlen-2, addrbuf.sau.sun_path);
536 } else {
537 tprintf("path=@%*.*s", addrlen-3, addrlen-3, addrbuf.sau.sun_path+1);
538 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 break;
540 case AF_INET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000542 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000544#ifdef HAVE_INET_NTOP
545 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000546 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
547 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)}",
548 ntohs(addrbuf.sa6.sin6_port), string_addr, ntohl(addrbuf.sa6.sin6_flowinfo));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000549 break;
550#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000551#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000553 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554 int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 tprintf("{sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000556 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557 /* Yes, I know, this does not look too
558 * strace-ish, but otherwise the IPX
559 * addresses just look monstrous...
560 * Anyways, feel free if you don't like
561 * this way.. :)
562 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000563 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000565 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
566 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 }
568 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000569#endif /* AF_IPX && linux */
570#ifdef AF_PACKET
571 case AF_PACKET:
572 {
573 int i;
574 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
575 ntohs(addrbuf.ll.sll_protocol),
576 addrbuf.ll.sll_ifindex,
577 addrbuf.ll.sll_pkttype,
578 addrbuf.ll.sll_halen,
579 addrbuf.ll.sll_hatype);
580 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
581 tprintf("%02x", addrbuf.ll.sll_addr[i]);
582 }
583 break;
584
585#endif /* AF_APACKET */
586#ifdef AF_NETLINLK
587 case AF_NETLINK:
588 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
589 break;
590#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000592 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593
594 default:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000595 tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000597 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598 break;
599 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000600 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601}
602
603#if HAVE_SENDMSG
604
605static void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000606printiovec(tcp, iovec, len)
607struct tcb *tcp;
608struct iovec *iovec;
609long len;
610{
611 struct iovec *iov;
612 int i;
613
614 iov = (struct iovec *) malloc(len * sizeof *iov);
615 if (iov == NULL) {
616 fprintf(stderr, "No memory");
617 return;
618 }
619 if (umoven(tcp, (long)iovec,
620 len * sizeof *iov, (char *) iov) < 0) {
621 tprintf("%#lx", (unsigned long)iovec);
622 } else {
623 tprintf("[");
624 for (i = 0; i < len; i++) {
625 if (i)
626 tprintf(", ");
627 tprintf("{");
628 printstr(tcp, (long) iov[i].iov_base,
629 iov[i].iov_len);
630 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
631 }
632 tprintf("]");
633 }
634 free((char *) iov);
635}
636
637static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638printmsghdr(tcp, addr)
639struct tcb *tcp;
640long addr;
641{
642 struct msghdr msg;
643
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000644 if (umove(tcp, addr, &msg) < 0) {
645 tprintf("%#lx", addr);
646 return;
647 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000648 tprintf("{msg_name(%d)=", msg.msg_namelen);
649 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
650
651 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
652 printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
653
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000655 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
656 if (msg.msg_controllen)
657 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
658 tprintf(", msg_flags=");
659 if (printflags(msg_flags, msg.msg_flags)==0)
660 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000662 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
664#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000665 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666}
667
668#endif /* HAVE_SENDMSG */
669
670int
671sys_socket(tcp)
672struct tcb *tcp;
673{
674 if (entering(tcp)) {
675 printxval(domains, tcp->u_arg[0], "PF_???");
676 tprintf(", ");
677 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
678 tprintf(", ");
679 switch (tcp->u_arg[0]) {
680 case PF_INET:
681 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
682 break;
683#ifdef PF_IPX
684 case PF_IPX:
685 /* BTW: I don't believe this.. */
686 tprintf("[");
687 printxval(domains, tcp->u_arg[2], "PF_???");
688 tprintf("]");
689 break;
690#endif /* PF_IPX */
691 default:
692 tprintf("%lu", tcp->u_arg[2]);
693 break;
694 }
695 }
696 return 0;
697}
698
699int
700sys_bind(tcp)
701struct tcb *tcp;
702{
703 if (entering(tcp)) {
704 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000705 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 tprintf(", %lu", tcp->u_arg[2]);
707 }
708 return 0;
709}
710
711int
712sys_connect(tcp)
713struct tcb *tcp;
714{
715 return sys_bind(tcp);
716}
717
718int
719sys_listen(tcp)
720struct tcb *tcp;
721{
722 if (entering(tcp)) {
723 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
724 }
725 return 0;
726}
727
728int
729sys_accept(tcp)
730struct tcb *tcp;
731{
732 if (entering(tcp)) {
733 tprintf("%ld, ", tcp->u_arg[0]);
734 } else if (!tcp->u_arg[2])
735 tprintf("%#lx, NULL", tcp->u_arg[1]);
736 else {
737 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
738 tprintf("%#lx", tcp->u_arg[1]);
739 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000740 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741 }
742 tprintf(", ");
743 printnum(tcp, tcp->u_arg[2], "%lu");
744 }
745 return 0;
746}
747
748int
749sys_send(tcp)
750struct tcb *tcp;
751{
752 if (entering(tcp)) {
753 tprintf("%ld, ", tcp->u_arg[0]);
754 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
755 tprintf(", %lu, ", tcp->u_arg[2]);
756 /* flags */
757 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
758 tprintf("0");
759 }
760 return 0;
761}
762
763int
764sys_sendto(tcp)
765struct tcb *tcp;
766{
767 if (entering(tcp)) {
768 tprintf("%ld, ", tcp->u_arg[0]);
769 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
770 tprintf(", %lu, ", tcp->u_arg[2]);
771 /* flags */
772 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
773 tprintf("0");
774 /* to address */
775 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000776 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777 /* to length */
778 tprintf(", %lu", tcp->u_arg[5]);
779 }
780 return 0;
781}
782
783#ifdef HAVE_SENDMSG
784
785int
786sys_sendmsg(tcp)
787struct tcb *tcp;
788{
789 if (entering(tcp)) {
790 tprintf("%ld, ", tcp->u_arg[0]);
791 printmsghdr(tcp, tcp->u_arg[1]);
792 /* flags */
793 tprintf(", ");
794 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
795 tprintf("0");
796 }
797 return 0;
798}
799
800#endif /* HAVE_SENDMSG */
801
802int
803sys_recv(tcp)
804struct tcb *tcp;
805{
806 if (entering(tcp)) {
807 tprintf("%ld, ", tcp->u_arg[0]);
808 } else {
809 if (syserror(tcp))
810 tprintf("%#lx", tcp->u_arg[1]);
811 else
812 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
813
814 tprintf(", %lu, ", tcp->u_arg[2]);
815 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
816 tprintf("0");
817 }
818 return 0;
819}
820
821int
822sys_recvfrom(tcp)
823struct tcb *tcp;
824{
825 int fromlen;
826
827 if (entering(tcp)) {
828 tprintf("%ld, ", tcp->u_arg[0]);
829 } else {
830 if (syserror(tcp)) {
831 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
832 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
833 tcp->u_arg[4], tcp->u_arg[5]);
834 return 0;
835 }
836 /* buf */
837 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
838 /* len */
839 tprintf(", %lu, ", tcp->u_arg[2]);
840 /* flags */
841 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
842 tprintf("0");
843 /* from address, len */
844 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
845 if (tcp->u_arg[4] == 0)
846 tprintf(", NULL");
847 else
848 tprintf(", %#lx", tcp->u_arg[4]);
849 if (tcp->u_arg[5] == 0)
850 tprintf(", NULL");
851 else
852 tprintf(", %#lx", tcp->u_arg[5]);
853 return 0;
854 }
855 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
856 tprintf(", {...}, [?]");
857 return 0;
858 }
859 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000860 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 /* from length */
862 tprintf(", [%u]", fromlen);
863 }
864 return 0;
865}
866
867#ifdef HAVE_SENDMSG
868
869int
870sys_recvmsg(tcp)
871struct tcb *tcp;
872{
873 if (entering(tcp)) {
874 tprintf("%ld, ", tcp->u_arg[0]);
875 } else {
876 if (syserror(tcp) || !verbose(tcp))
877 tprintf("%#lx", tcp->u_arg[1]);
878 else
879 printmsghdr(tcp, tcp->u_arg[1]);
880 /* flags */
881 tprintf(", ");
882 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
883 tprintf("0");
884 }
885 return 0;
886}
887
888#endif /* HAVE_SENDMSG */
889
890int
891sys_shutdown(tcp)
892struct tcb *tcp;
893{
894 if (entering(tcp)) {
895 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
896 switch (tcp->u_arg[1]) {
897 case 0:
898 tprintf("%s", " /* receive */");
899 break;
900 case 1:
901 tprintf("%s", " /* send */");
902 break;
903 case 2:
904 tprintf("%s", " /* send and receive */");
905 break;
906 }
907 }
908 return 0;
909}
910
911int
912sys_getsockname(tcp)
913struct tcb *tcp;
914{
915 return sys_accept(tcp);
916}
917
918int
919sys_getpeername(tcp)
920struct tcb *tcp;
921{
922 return sys_accept(tcp);
923}
924
925int
926sys_pipe(tcp)
927struct tcb *tcp;
928{
929
930#if defined(LINUX) && !defined(SPARC)
931 int fds[2];
932
933 if (exiting(tcp)) {
934 if (syserror(tcp)) {
935 tprintf("%#lx", tcp->u_arg[0]);
936 return 0;
937 }
938 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
939 tprintf("[...]");
940 else
941 tprintf("[%u, %u]", fds[0], fds[1]);
942 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000943#elif defined(SPARC) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944 if (exiting(tcp))
945 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946#endif
947 return 0;
948}
949
950int
951sys_socketpair(tcp)
952struct tcb *tcp;
953{
954#ifdef LINUX
955 int fds[2];
956#endif
957
958 if (entering(tcp)) {
959 printxval(domains, tcp->u_arg[0], "PF_???");
960 tprintf(", ");
961 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
962 tprintf(", ");
963 switch (tcp->u_arg[0]) {
964 case PF_INET:
965 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
966 break;
967#ifdef PF_IPX
968 case PF_IPX:
969 /* BTW: I don't believe this.. */
970 tprintf("[");
971 printxval(domains, tcp->u_arg[2], "PF_???");
972 tprintf("]");
973 break;
974#endif /* PF_IPX */
975 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000976 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977 break;
978 }
979 } else {
980 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000981 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 return 0;
983 }
984#ifdef LINUX
985 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000986 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 else
988 tprintf(", [%u, %u]", fds[0], fds[1]);
989#endif /* LINUX */
990#ifdef SUNOS4
991 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
992#endif /* SUNOS4 */
993#ifdef SVR4
994 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
995#endif /* SVR4 */
996 }
997 return 0;
998}
999
1000int
1001sys_getsockopt(tcp)
1002struct tcb *tcp;
1003{
1004 if (entering(tcp)) {
1005 tprintf("%ld, ", tcp->u_arg[0]);
1006 switch (tcp->u_arg[1]) {
1007 case SOL_SOCKET:
1008 tprintf("SOL_SOCKET, ");
1009 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1010 tprintf(", ");
1011 break;
1012#ifdef SOL_IP
1013 case SOL_IP:
1014 tprintf("SOL_IP, ");
1015 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1016 tprintf(", ");
1017 break;
1018#endif
1019#ifdef SOL_IPX
1020 case SOL_IPX:
1021 tprintf("SOL_IPX, ");
1022 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1023 tprintf(", ");
1024 break;
1025#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001026#ifdef SOL_PACKET
1027 case SOL_PACKET:
1028 tprintf("SOL_PACKET, ");
1029 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1030 tprintf(", ");
1031 break;
1032#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033#ifdef SOL_TCP
1034 case SOL_TCP:
1035 tprintf("SOL_TCP, ");
1036 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1037 tprintf(", ");
1038 break;
1039#endif
1040
1041 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1042 * etc. still need work */
1043 default:
1044 /* XXX - should know socket family here */
1045 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001046 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047 break;
1048 }
1049 } else {
1050 if (syserror(tcp)) {
1051 tprintf("%#lx, %#lx",
1052 tcp->u_arg[3], tcp->u_arg[4]);
1053 return 0;
1054 }
1055 printnum(tcp, tcp->u_arg[3], "%ld");
1056 tprintf(", ");
1057 printnum(tcp, tcp->u_arg[4], "%ld");
1058 }
1059 return 0;
1060}
1061
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001062#if defined(ICMP_FILTER)
1063static void printicmpfilter(tcp, addr)
1064struct tcb *tcp;
1065long addr;
1066{
1067 struct icmp_filter filter;
1068
1069 if (!addr) {
1070 tprintf("NULL");
1071 return;
1072 }
1073 if (syserror(tcp) || !verbose(tcp)) {
1074 tprintf("%#lx", addr);
1075 return;
1076 }
1077 if (umove(tcp, addr, &filter) < 0) {
1078 tprintf("{...}");
1079 return;
1080 }
1081
1082 tprintf("~(");
1083 if (printflags(icmpfilterflags, ~filter.data) == 0)
1084 tprintf("0");
1085 tprintf(")");
1086}
1087#endif /* ICMP_FILTER */
1088
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089int
1090sys_setsockopt(tcp)
1091struct tcb *tcp;
1092{
1093 if (entering(tcp)) {
1094 tprintf("%ld, ", tcp->u_arg[0]);
1095 switch (tcp->u_arg[1]) {
1096 case SOL_SOCKET:
1097 tprintf("SOL_SOCKET, ");
1098 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1099 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001100 printnum(tcp, tcp->u_arg[3], "%ld");
1101 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 break;
1103#ifdef SOL_IP
1104 case SOL_IP:
1105 tprintf("SOL_IP, ");
1106 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1107 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001108 printnum(tcp, tcp->u_arg[3], "%ld");
1109 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110 break;
1111#endif
1112#ifdef SOL_IPX
1113 case SOL_IPX:
1114 tprintf("SOL_IPX, ");
1115 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1116 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001117 printnum(tcp, tcp->u_arg[3], "%ld");
1118 tprintf(", %lu", tcp->u_arg[4]);
1119 break;
1120#endif
1121#ifdef SOL_PACKET
1122 case SOL_PACKET:
1123 tprintf("SOL_PACKET, ");
1124 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1125 tprintf(", ");
1126 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1127 printnum(tcp, tcp->u_arg[3], "%ld");
1128 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129 break;
1130#endif
1131#ifdef SOL_TCP
1132 case SOL_TCP:
1133 tprintf("SOL_TCP, ");
1134 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1135 tprintf(", ");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001136 printnum(tcp, tcp->u_arg[3], "%ld");
1137 tprintf(", %lu", tcp->u_arg[4]);
1138 break;
1139#endif
1140#ifdef SOL_RAW
1141 case SOL_RAW:
1142 tprintf("SOL_RAW, ");
1143 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1144 tprintf(", ");
1145 switch (tcp->u_arg[2]) {
1146#if defined(ICMP_FILTER)
1147 case ICMP_FILTER:
1148 printicmpfilter(tcp, tcp->u_arg[3]);
1149 break;
1150#endif
1151 default:
1152 printnum(tcp, tcp->u_arg[3], "%ld");
1153 break;
1154 }
1155 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001156 break;
1157#endif
1158
1159 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1160 * etc. still need work */
1161 default:
1162 /* XXX - should know socket family here */
1163 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
1164 tprintf("%lu, ", tcp->u_arg[2]);
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001165 printnum(tcp, tcp->u_arg[3], "%ld");
1166 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001167 break;
1168 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 }
1170 return 0;
1171}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001172
1173#if UNIXWARE >= 7
1174
1175static struct xlat sock_version[] = {
1176 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1177 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1178 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1179 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1180 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1181 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1182 { 0, NULL },
1183};
1184
1185
1186int
1187netlib_call(tcp, func)
1188struct tcb *tcp;
1189int (*func) ();
1190{
1191 if (entering(tcp)) {
1192 int i;
1193 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1194 tprintf(", ");
1195 --tcp->u_nargs;
1196 for (i = 0; i < tcp->u_nargs; i++)
1197 tcp->u_arg[i] = tcp->u_arg[i + 1];
1198 return func (tcp);
1199
1200 }
1201
1202 return func (tcp);
1203}
1204
1205int
1206sys_xsocket(tcp)
1207struct tcb *tcp;
1208{
1209 return netlib_call (tcp, sys_socket);
1210}
1211
1212int
1213sys_xsocketpair(tcp)
1214struct tcb *tcp;
1215{
1216 return netlib_call (tcp, sys_socketpair);
1217}
1218
1219int
1220sys_xbind(tcp)
1221struct tcb *tcp;
1222{
1223 return netlib_call (tcp, sys_bind);
1224}
1225
1226int
1227sys_xconnect(tcp)
1228struct tcb *tcp;
1229{
1230 return netlib_call (tcp, sys_connect);
1231}
1232
1233int
1234sys_xlisten(tcp)
1235struct tcb *tcp;
1236{
1237 return netlib_call (tcp, sys_listen);
1238}
1239
1240int
1241sys_xaccept(tcp)
1242struct tcb *tcp;
1243{
1244 return netlib_call (tcp, sys_accept);
1245}
1246
1247int
1248sys_xsendmsg(tcp)
1249struct tcb *tcp;
1250{
1251 return netlib_call (tcp, sys_sendmsg);
1252}
1253
1254int
1255sys_xrecvmsg(tcp)
1256struct tcb *tcp;
1257{
1258 return netlib_call (tcp, sys_recvmsg);
1259}
1260
1261int
1262sys_xgetsockaddr(tcp)
1263struct tcb *tcp;
1264{
1265 if (entering(tcp)) {
1266 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1267 tprintf(", ");
1268 if (tcp->u_arg[1] == 0) {
1269 tprintf ("LOCALNAME, ");
1270 }
1271 else if (tcp->u_arg[1] == 1) {
1272 tprintf ("REMOTENAME, ");
1273 }
1274 else {
1275 tprintf ("%ld, ", tcp->u_arg [1]);
1276 }
1277 tprintf ("%ld, ", tcp->u_arg [2]);
1278 }
1279 else {
1280 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1281 tprintf("%#lx", tcp->u_arg[3]);
1282 } else {
1283 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1284 }
1285 tprintf(", ");
1286 printnum(tcp, tcp->u_arg[4], "%lu");
1287 }
1288
1289 return 0;
1290
1291}
1292
1293#if 0
1294
1295int
1296sys_xsetsockaddr(tcp)
1297struct tcb *tcp;
1298{
1299 return netlib_call (tcp, sys_setsockaddr);
1300}
1301
1302#endif
1303
1304int
1305sys_xgetsockopt(tcp)
1306struct tcb *tcp;
1307{
1308 return netlib_call (tcp, sys_getsockopt);
1309}
1310
1311int
1312sys_xsetsockopt(tcp)
1313struct tcb *tcp;
1314{
1315 return netlib_call (tcp, sys_setsockopt);
1316}
1317
1318int
1319sys_xshutdown(tcp)
1320struct tcb *tcp;
1321{
1322 return netlib_call (tcp, sys_shutdown);
1323}
1324
1325#endif