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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
40 #include <asm/types.h>
41 #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
42 # include <netipx/ipx.h>
44 # include <linux/ipx.h>
49 #define PF_UNSPEC AF_UNSPEC
53 /* Under Linux these are enums so we can't test for them with ifdef. */
54 #define IPPROTO_EGP IPPROTO_EGP
55 #define IPPROTO_PUP IPPROTO_PUP
56 #define IPPROTO_IDP IPPROTO_IDP
57 #define IPPROTO_IGMP IPPROTO_IGMP
58 #define IPPROTO_RAW IPPROTO_RAW
59 #define IPPROTO_MAX IPPROTO_MAX
62 static struct xlat domains[] = {
63 { PF_UNSPEC, "PF_UNSPEC" },
64 { PF_UNIX, "PF_UNIX" },
65 { PF_INET, "PF_INET" },
67 { PF_LOCAL, "PS_LOCAL" },
73 { PF_AX25, "PF_AX25" },
79 { PF_APPLETALK, "PF_APPLETALK" },
82 { PF_NETROM, "PF_NETROM" },
85 { PF_BRIDGE, "PF_BRIDGE" },
88 { PF_AAL5, "PF_AAL5" },
94 { PF_INET6, "PF_INET6" },
97 { PF_ROSE, "PF_ROSE" },
100 { PF_DECNET, "PF_DECNET" },
103 { PF_NETBEUI, "PF_NETBEUI" },
106 { PF_IMPLINK, "PF_IMPLINK" },
110 static struct xlat socktypes[] = {
111 { SOCK_STREAM, "SOCK_STREAM" },
112 { SOCK_DGRAM, "SOCK_DGRAM" },
114 { SOCK_RAW, "SOCK_RAW" },
116 #ifdef SOCK_SEQPACKET
117 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
120 { SOCK_RDM, "SOCK_RDM" },
123 { SOCK_PACKET, "SOCK_PACKET" },
127 static struct xlat protocols[] = {
128 { IPPROTO_IP, "IPPROTO_IP" },
129 { IPPROTO_ICMP, "IPPROTO_ICMP" },
130 { IPPROTO_TCP, "IPPROTO_TCP" },
131 { IPPROTO_UDP, "IPPROTO_UDP" },
133 { IPPROTO_GGP, "IPPROTO_GGP" },
136 { IPPROTO_EGP, "IPPROTO_EGP" },
139 { IPPROTO_PUP, "IPPROTO_PUP" },
142 { IPPROTO_IDP, "IPPROTO_IDP" },
145 { IPPROTO_IPV6, "IPPROTO_IPV6" },
147 #ifdef IPPROTO_ICMPV6
148 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
151 { IPPROTO_IGMP, "IPPROTO_IGMP" },
154 { IPPROTO_HELLO,"IPPROTO_HELLO" },
157 { IPPROTO_ND, "IPPROTO_ND" },
160 { IPPROTO_RAW, "IPPROTO_RAW" },
163 { IPPROTO_MAX, "IPPROTO_MAX" },
166 { IPPROTO_IPIP, "IPPROTO_IPIP" },
170 static struct xlat msg_flags[] = {
171 { MSG_OOB, "MSG_OOB" },
173 { MSG_DONTROUTE,"MSG_DONTROUTE" },
176 { MSG_PEEK, "MSG_PEEK" },
179 { MSG_CTRUNC, "MSG_CTRUNC" },
182 { MSG_PROXY, "MSG_PROXY" },
185 { MSG_EOR, "MSG_EOR" },
188 { MSG_WAITALL, "MSG_WAITALL" },
193 static struct xlat sockoptions[] = {
195 { SO_DEBUG, "SO_DEBUG" },
198 { SO_REUSEADDR, "SO_REUSEADDR" },
201 { SO_KEEPALIVE, "SO_KEEPALIVE" },
204 { SO_DONTROUTE, "SO_DONTROUTE" },
207 { SO_BROADCAST, "SO_BROADCAST" },
210 { SO_LINGER, "SO_LINGER" },
213 { SO_OOBINLINE, "SO_OOBINLINE" },
216 { SO_TYPE, "SO_TYPE" },
219 { SO_ERROR, "SO_ERROR" },
222 { SO_SNDBUF, "SO_SNDBUF" },
225 { SO_RCVBUF, "SO_RCVBUF" },
228 { SO_NO_CHECK, "SO_NO_CHECK" },
231 { SO_PRIORITY, "SO_PRIORITY" },
234 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
236 #ifdef SO_USELOOPBACK
237 { SO_USELOOPBACK,"SO_USELOOPBACK"},
240 { SO_SNDLOWAT, "SO_SNDLOWAT" },
243 { SO_RCVLOWAT, "SO_RCVLOWAT" },
246 { SO_SNDTIMEO, "SO_SNDTIMEO" },
249 { SO_RCVTIMEO, "SO_RCVTIMEO" },
252 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
255 { SO_REUSEPORT, "SO_REUSEPORT" },
258 { SO_RCVLOWAT, "SO_RCVLOWAT" },
261 { SO_SNDLOWAT, "SO_SNDLOWAT" },
264 { SO_RCVTIMEO, "SO_RCVTIMEO" },
267 { SO_SNDTIMEO, "SO_SNDTIMEO" },
273 static struct xlat sockipoptions[] = {
274 { IP_TOS, "IP_TOS" },
275 { IP_TTL, "IP_TTL" },
276 #if defined(IP_HDRINCL)
277 { IP_HDRINCL, "IP_HDRINCL" },
279 #if defined(IP_OPTIONS)
280 { IP_OPTIONS, "IP_OPTIONS" },
282 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
283 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
284 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
285 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
286 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
292 static struct xlat sockipxoptions[] = {
293 { IPX_TYPE, "IPX_TYPE" },
299 static struct xlat socktcpoptions[] = {
300 { TCP_NODELAY, "TCP_NODELAY" },
301 { TCP_MAXSEG, "TCP_MAXSEG" },
312 struct sockaddr_in *sin = (struct sockaddr_in *) &sa;
313 struct sockaddr_un sau;
315 struct sockaddr_ipx sipx;
323 tprintf("%#lx", addr);
326 if (umove(tcp, addr, &sa) < 0) {
330 switch (sa.sa_family) {
332 if (umove(tcp, addr, &sau) < 0)
333 tprintf("{sun_family=AF_UNIX, ...}");
335 tprintf("{sun_family=AF_UNIX, sun_path=\"%s\"}",
339 tprintf("{sin_family=AF_INET, ");
340 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
341 ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
343 #if defined(AF_IPX) && defined(linux)
345 if (umove(tcp, addr, &sipx)<0)
346 tprintf("{sipx_family=AF_IPX, ...}");
349 tprintf("{sipx_family=AF_IPX, ");
350 tprintf("{sipx_port=htons(%u), ",
351 ntohs(sipx.sipx_port));
352 /* Yes, I know, this does not look too
353 * strace-ish, but otherwise the IPX
354 * addresses just look monstrous...
355 * Anyways, feel free if you don't like
358 tprintf("%08lx:", (unsigned long)ntohl(sipx.sipx_network));
359 for (i = 0; i<IPX_NODE_LEN; i++)
360 tprintf("%02x", sipx.sipx_node[i]);
361 tprintf("/[%02x]", sipx.sipx_type);
365 #endif /* AF_IPX && linux */
366 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
367 AF_X25 AF_INET6 AF_ROSE still need to be done */
370 tprintf("{sa_family=%u, sa_data=", sa.sa_family);
371 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
381 printmsghdr(tcp, addr)
387 if (umove(tcp, addr, &msg) < 0) {
388 tprintf("%#lx", addr);
391 tprintf("{msg_name=");
392 printstr(tcp, (long) msg.msg_name, msg.msg_namelen);
393 tprintf(", msg_namelen=%u, msg_iov=%#lx, msg_iovlen=%u, ",
395 (unsigned long) msg.msg_iov, msg.msg_iovlen);
396 #ifdef HAVE_MSG_CONTROL
397 tprintf("msg_control=%#lx, msg_controllen=%u, msg_flags=%#x}",
398 (unsigned long) msg.msg_control, msg.msg_controllen,
400 #else /* !HAVE_MSG_CONTROL */
401 tprintf("msg_accrights=%#lx, msg_accrightslen=%u}",
402 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
403 #endif /* !HAVE_MSG_CONTROL */
406 #endif /* HAVE_SENDMSG */
413 printxval(domains, tcp->u_arg[0], "PF_???");
415 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
417 switch (tcp->u_arg[0]) {
419 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
423 /* BTW: I don't believe this.. */
425 printxval(domains, tcp->u_arg[2], "PF_???");
430 tprintf("%lu", tcp->u_arg[2]);
442 tprintf("%ld, ", tcp->u_arg[0]);
443 printsock(tcp, tcp->u_arg[1]);
444 tprintf(", %lu", tcp->u_arg[2]);
453 return sys_bind(tcp);
461 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
471 tprintf("%ld, ", tcp->u_arg[0]);
472 } else if (!tcp->u_arg[2])
473 tprintf("%#lx, NULL", tcp->u_arg[1]);
475 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
476 tprintf("%#lx", tcp->u_arg[1]);
478 printsock(tcp, tcp->u_arg[1]);
481 printnum(tcp, tcp->u_arg[2], "%lu");
491 tprintf("%ld, ", tcp->u_arg[0]);
492 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
493 tprintf(", %lu, ", tcp->u_arg[2]);
495 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
506 tprintf("%ld, ", tcp->u_arg[0]);
507 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
508 tprintf(", %lu, ", tcp->u_arg[2]);
510 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
514 printsock(tcp, tcp->u_arg[4]);
516 tprintf(", %lu", tcp->u_arg[5]);
528 tprintf("%ld, ", tcp->u_arg[0]);
529 printmsghdr(tcp, tcp->u_arg[1]);
532 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
538 #endif /* HAVE_SENDMSG */
545 tprintf("%ld, ", tcp->u_arg[0]);
548 tprintf("%#lx", tcp->u_arg[1]);
550 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
552 tprintf(", %lu, ", tcp->u_arg[2]);
553 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
566 tprintf("%ld, ", tcp->u_arg[0]);
569 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
570 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
571 tcp->u_arg[4], tcp->u_arg[5]);
575 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
577 tprintf(", %lu, ", tcp->u_arg[2]);
579 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
581 /* from address, len */
582 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
583 if (tcp->u_arg[4] == 0)
586 tprintf(", %#lx", tcp->u_arg[4]);
587 if (tcp->u_arg[5] == 0)
590 tprintf(", %#lx", tcp->u_arg[5]);
593 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
594 tprintf(", {...}, [?]");
598 printsock(tcp, tcp->u_arg[4]);
600 tprintf(", [%u]", fromlen);
612 tprintf("%ld, ", tcp->u_arg[0]);
614 if (syserror(tcp) || !verbose(tcp))
615 tprintf("%#lx", tcp->u_arg[1]);
617 printmsghdr(tcp, tcp->u_arg[1]);
620 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
626 #endif /* HAVE_SENDMSG */
633 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
634 switch (tcp->u_arg[1]) {
636 tprintf("%s", " /* receive */");
639 tprintf("%s", " /* send */");
642 tprintf("%s", " /* send and receive */");
653 return sys_accept(tcp);
660 return sys_accept(tcp);
668 #if defined(LINUX) && !defined(SPARC)
673 tprintf("%#lx", tcp->u_arg[0]);
676 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
679 tprintf("[%u, %u]", fds[0], fds[1]);
681 #elif defined(SPARC) || defined(SVR4)
683 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
697 printxval(domains, tcp->u_arg[0], "PF_???");
699 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
701 switch (tcp->u_arg[0]) {
703 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
707 /* BTW: I don't believe this.. */
709 printxval(domains, tcp->u_arg[2], "PF_???");
714 tprintf("%lu", tcp->u_arg[2]);
719 tprintf(", %#lx", tcp->u_arg[3]);
723 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
726 tprintf(", [%u, %u]", fds[0], fds[1]);
729 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
732 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
743 tprintf("%ld, ", tcp->u_arg[0]);
744 switch (tcp->u_arg[1]) {
746 tprintf("SOL_SOCKET, ");
747 printxval(sockoptions, tcp->u_arg[2], "SO_???");
753 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
759 tprintf("SOL_IPX, ");
760 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
766 tprintf("SOL_TCP, ");
767 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
772 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
773 * etc. still need work */
775 /* XXX - should know socket family here */
776 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
777 tprintf("%lu, ", tcp->u_arg[2]);
782 tprintf("%#lx, %#lx",
783 tcp->u_arg[3], tcp->u_arg[4]);
786 printnum(tcp, tcp->u_arg[3], "%ld");
788 printnum(tcp, tcp->u_arg[4], "%ld");
798 tprintf("%ld, ", tcp->u_arg[0]);
799 switch (tcp->u_arg[1]) {
801 tprintf("SOL_SOCKET, ");
802 printxval(sockoptions, tcp->u_arg[2], "SO_???");
808 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
814 tprintf("SOL_IPX, ");
815 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
821 tprintf("SOL_TCP, ");
822 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
827 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
828 * etc. still need work */
830 /* XXX - should know socket family here */
831 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
832 tprintf("%lu, ", tcp->u_arg[2]);
835 printnum(tcp, tcp->u_arg[3], "%ld");
836 tprintf(", %lu", tcp->u_arg[4]);