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;
314 #ifdef HAVE_INET_NTOP
315 struct sockaddr_in6 sa6;
316 char string_addr[100];
319 struct sockaddr_ipx sipx;
327 tprintf("%#lx", addr);
330 if (umove(tcp, addr, &sa) < 0) {
334 switch (sa.sa_family) {
336 if (umove(tcp, addr, &sau) < 0)
337 tprintf("{sun_family=AF_UNIX, ...}");
339 tprintf("{sun_family=AF_UNIX, sun_path=\"%s\"}",
343 tprintf("{sin_family=AF_INET, ");
344 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
345 ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
347 #ifdef HAVE_INET_NTOP
349 if (umove(tcp, addr, &sa6) < 0)
350 tprintf("{sin6_family=AF_INET6, ...}");
353 tprintf("{sin6_family=AF_INET6, ");
354 inet_ntop(AF_INET6, &sa6.sin6_addr, string_addr, sizeof(string_addr));
355 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)",
356 ntohs(sa6.sin6_port), string_addr, ntohl(sa6.sin6_flowinfo));
360 #if defined(AF_IPX) && defined(linux)
362 if (umove(tcp, addr, &sipx)<0)
363 tprintf("{sipx_family=AF_IPX, ...}");
366 tprintf("{sipx_family=AF_IPX, ");
367 tprintf("{sipx_port=htons(%u), ",
368 ntohs(sipx.sipx_port));
369 /* Yes, I know, this does not look too
370 * strace-ish, but otherwise the IPX
371 * addresses just look monstrous...
372 * Anyways, feel free if you don't like
375 tprintf("%08lx:", (unsigned long)ntohl(sipx.sipx_network));
376 for (i = 0; i<IPX_NODE_LEN; i++)
377 tprintf("%02x", sipx.sipx_node[i]);
378 tprintf("/[%02x]", sipx.sipx_type);
382 #endif /* AF_IPX && linux */
383 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
384 AF_X25 AF_INET6 AF_ROSE still need to be done */
387 tprintf("{sa_family=%u, sa_data=", sa.sa_family);
388 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
398 printmsghdr(tcp, addr)
404 if (umove(tcp, addr, &msg) < 0) {
405 tprintf("%#lx", addr);
408 tprintf("{msg_name=");
409 printstr(tcp, (long) msg.msg_name, msg.msg_namelen);
410 tprintf(", msg_namelen=%u, msg_iov=%#lx, msg_iovlen=%u, ",
412 (unsigned long) msg.msg_iov, msg.msg_iovlen);
413 #ifdef HAVE_MSG_CONTROL
414 tprintf("msg_control=%#lx, msg_controllen=%u, msg_flags=%#x}",
415 (unsigned long) msg.msg_control, msg.msg_controllen,
417 #else /* !HAVE_MSG_CONTROL */
418 tprintf("msg_accrights=%#lx, msg_accrightslen=%u}",
419 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
420 #endif /* !HAVE_MSG_CONTROL */
423 #endif /* HAVE_SENDMSG */
430 printxval(domains, tcp->u_arg[0], "PF_???");
432 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
434 switch (tcp->u_arg[0]) {
436 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
440 /* BTW: I don't believe this.. */
442 printxval(domains, tcp->u_arg[2], "PF_???");
447 tprintf("%lu", tcp->u_arg[2]);
459 tprintf("%ld, ", tcp->u_arg[0]);
460 printsock(tcp, tcp->u_arg[1]);
461 tprintf(", %lu", tcp->u_arg[2]);
470 return sys_bind(tcp);
478 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
488 tprintf("%ld, ", tcp->u_arg[0]);
489 } else if (!tcp->u_arg[2])
490 tprintf("%#lx, NULL", tcp->u_arg[1]);
492 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
493 tprintf("%#lx", tcp->u_arg[1]);
495 printsock(tcp, tcp->u_arg[1]);
498 printnum(tcp, tcp->u_arg[2], "%lu");
508 tprintf("%ld, ", tcp->u_arg[0]);
509 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
510 tprintf(", %lu, ", tcp->u_arg[2]);
512 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
523 tprintf("%ld, ", tcp->u_arg[0]);
524 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
525 tprintf(", %lu, ", tcp->u_arg[2]);
527 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
531 printsock(tcp, tcp->u_arg[4]);
533 tprintf(", %lu", tcp->u_arg[5]);
545 tprintf("%ld, ", tcp->u_arg[0]);
546 printmsghdr(tcp, tcp->u_arg[1]);
549 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
555 #endif /* HAVE_SENDMSG */
562 tprintf("%ld, ", tcp->u_arg[0]);
565 tprintf("%#lx", tcp->u_arg[1]);
567 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
569 tprintf(", %lu, ", tcp->u_arg[2]);
570 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
583 tprintf("%ld, ", tcp->u_arg[0]);
586 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
587 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
588 tcp->u_arg[4], tcp->u_arg[5]);
592 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
594 tprintf(", %lu, ", tcp->u_arg[2]);
596 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
598 /* from address, len */
599 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
600 if (tcp->u_arg[4] == 0)
603 tprintf(", %#lx", tcp->u_arg[4]);
604 if (tcp->u_arg[5] == 0)
607 tprintf(", %#lx", tcp->u_arg[5]);
610 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
611 tprintf(", {...}, [?]");
615 printsock(tcp, tcp->u_arg[4]);
617 tprintf(", [%u]", fromlen);
629 tprintf("%ld, ", tcp->u_arg[0]);
631 if (syserror(tcp) || !verbose(tcp))
632 tprintf("%#lx", tcp->u_arg[1]);
634 printmsghdr(tcp, tcp->u_arg[1]);
637 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
643 #endif /* HAVE_SENDMSG */
650 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
651 switch (tcp->u_arg[1]) {
653 tprintf("%s", " /* receive */");
656 tprintf("%s", " /* send */");
659 tprintf("%s", " /* send and receive */");
670 return sys_accept(tcp);
677 return sys_accept(tcp);
685 #if defined(LINUX) && !defined(SPARC)
690 tprintf("%#lx", tcp->u_arg[0]);
693 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
696 tprintf("[%u, %u]", fds[0], fds[1]);
698 #elif defined(SPARC) || defined(SVR4)
700 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
714 printxval(domains, tcp->u_arg[0], "PF_???");
716 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
718 switch (tcp->u_arg[0]) {
720 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
724 /* BTW: I don't believe this.. */
726 printxval(domains, tcp->u_arg[2], "PF_???");
731 tprintf("%lu", tcp->u_arg[2]);
736 tprintf(", %#lx", tcp->u_arg[3]);
740 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
743 tprintf(", [%u, %u]", fds[0], fds[1]);
746 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
749 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
760 tprintf("%ld, ", tcp->u_arg[0]);
761 switch (tcp->u_arg[1]) {
763 tprintf("SOL_SOCKET, ");
764 printxval(sockoptions, tcp->u_arg[2], "SO_???");
770 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
776 tprintf("SOL_IPX, ");
777 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
783 tprintf("SOL_TCP, ");
784 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
789 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
790 * etc. still need work */
792 /* XXX - should know socket family here */
793 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
794 tprintf("%lu, ", tcp->u_arg[2]);
799 tprintf("%#lx, %#lx",
800 tcp->u_arg[3], tcp->u_arg[4]);
803 printnum(tcp, tcp->u_arg[3], "%ld");
805 printnum(tcp, tcp->u_arg[4], "%ld");
815 tprintf("%ld, ", tcp->u_arg[0]);
816 switch (tcp->u_arg[1]) {
818 tprintf("SOL_SOCKET, ");
819 printxval(sockoptions, tcp->u_arg[2], "SO_???");
825 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
831 tprintf("SOL_IPX, ");
832 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
838 tprintf("SOL_TCP, ");
839 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
844 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
845 * etc. still need work */
847 /* XXX - should know socket family here */
848 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
849 tprintf("%lu, ", tcp->u_arg[2]);
852 printnum(tcp, tcp->u_arg[3], "%ld");
853 tprintf(", %lu", tcp->u_arg[4]);