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>
5 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
36 #include <sys/socket.h>
39 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40 #define in6_addr in6_addr_libc
41 #define ipv6_mreq ipv6_mreq_libc
42 #define sockaddr_in6 sockaddr_in6_libc
45 #include <netinet/in.h>
46 #ifdef HAVE_NETINET_TCP_H
47 #include <netinet/tcp.h>
49 #ifdef HAVE_NETINET_UDP_H
50 #include <netinet/udp.h>
52 #include <arpa/inet.h>
55 #include <asm/types.h>
56 #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
57 # include <netipx/ipx.h>
59 # include <linux/ipx.h>
63 #if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
64 #if defined(HAVE_LINUX_IN6_H)
65 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
69 #define in6_addr in6_addr_kernel
70 #define ipv6_mreq ipv6_mreq_kernel
71 #define sockaddr_in6 sockaddr_in6_kernel
73 #include <linux/in6.h>
74 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
78 #define in6_addr in6_addr_libc
79 #define ipv6_mreq ipv6_mreq_libc
80 #define sockaddr_in6 sockaddr_in6_kernel
85 #if defined(HAVE_SYS_UIO_H)
89 #if defined(HAVE_LINUX_NETLINK_H)
90 #include <linux/netlink.h>
93 #if defined(HAVE_LINUX_IF_PACKET_H)
94 #include <linux/if_packet.h>
97 #if defined(HAVE_LINUX_ICMP_H)
98 #include <linux/icmp.h>
102 #define PF_UNSPEC AF_UNSPEC
106 #define HAVE_SENDMSG 1 /* HACK - *FIXME* */
110 /* Under Linux these are enums so we can't test for them with ifdef. */
111 #define IPPROTO_EGP IPPROTO_EGP
112 #define IPPROTO_PUP IPPROTO_PUP
113 #define IPPROTO_IDP IPPROTO_IDP
114 #define IPPROTO_IGMP IPPROTO_IGMP
115 #define IPPROTO_RAW IPPROTO_RAW
116 #define IPPROTO_MAX IPPROTO_MAX
119 static struct xlat domains[] = {
120 { PF_UNSPEC, "PF_UNSPEC" },
121 { PF_UNIX, "PF_UNIX" },
122 { PF_INET, "PF_INET" },
124 { PF_NETLINK, "PF_NETLINK" },
127 { PF_PACKET, "PF_PACKET" },
130 { PF_INET6, "PF_INET6" },
133 { PF_ATMSVC, "PF_INET6" },
136 { PF_INET6, "PF_INET6" },
139 { PF_LOCAL, "PS_LOCAL" },
142 { PF_ISO, "PF_ISO" },
145 { PF_AX25, "PF_AX25" },
148 { PF_IPX, "PF_IPX" },
151 { PF_APPLETALK, "PF_APPLETALK" },
154 { PF_NETROM, "PF_NETROM" },
157 { PF_BRIDGE, "PF_BRIDGE" },
160 { PF_AAL5, "PF_AAL5" },
163 { PF_X25, "PF_X25" },
166 { PF_ROSE, "PF_ROSE" },
169 { PF_DECNET, "PF_DECNET" },
172 { PF_NETBEUI, "PF_NETBEUI" },
175 { PF_IMPLINK, "PF_IMPLINK" },
179 static struct xlat addrfams[] = {
180 { AF_UNSPEC, "AF_UNSPEC" },
181 { AF_UNIX, "AF_UNIX" },
182 { AF_INET, "AF_INET" },
184 { AF_INET6, "AF_INET6" },
186 { AF_DECnet, "AF_DECnet" },
188 { AF_ATMSVC, "AF_ATMSVC" },
191 { AF_PACKET, "AF_PACKET" },
194 { AF_NETLINK, "AF_NETLINK" },
197 { AF_ISO, "AF_ISO" },
200 { AF_IMPLINK, "AF_IMPLINK" },
204 static struct xlat socktypes[] = {
205 { SOCK_STREAM, "SOCK_STREAM" },
206 { SOCK_DGRAM, "SOCK_DGRAM" },
208 { SOCK_RAW, "SOCK_RAW" },
210 #ifdef SOCK_SEQPACKET
211 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
214 { SOCK_RDM, "SOCK_RDM" },
217 { SOCK_PACKET, "SOCK_PACKET" },
221 static struct xlat socketlayers[] = {
223 { SOL_IP, "SOL_IP" },
225 #if defined(SOL_ICMP)
226 { SOL_ICMP, "SOL_ICMP" },
229 { SOL_TCP, "SOL_TCP" },
232 { SOL_UDP, "SOL_UDP" },
234 #if defined(SOL_IPV6)
235 { SOL_IPV6, "SOL_IPV6" },
237 #if defined(SOL_ICMPV6)
238 { SOL_ICMPV6, "SOL_ICMPV6" },
241 { SOL_RAW, "SOL_RAW" },
244 { SOL_IPX, "SOL_IPX" },
247 { SOL_IPX, "SOL_IPX" },
249 #if defined(SOL_AX25)
250 { SOL_AX25, "SOL_AX25" },
252 #if defined(SOL_ATALK)
253 { SOL_ATALK, "SOL_ATALK" },
255 #if defined(SOL_NETROM)
256 { SOL_NETROM, "SOL_NETROM" },
258 #if defined(SOL_ROSE)
259 { SOL_ROSE, "SOL_ROSE" },
261 #if defined(SOL_DECNET)
262 { SOL_DECNET, "SOL_DECNET" },
265 { SOL_X25, "SOL_X25" },
267 #if defined(SOL_PACKET)
268 { SOL_PACKET, "SOL_PACKET" },
271 { SOL_ATM, "SOL_ATM" },
274 { SOL_AAL, "SOL_AAL" },
276 #if defined(SOL_IRDA)
277 { SOL_IRDA, "SOL_IRDA" },
280 static struct xlat protocols[] = {
281 { IPPROTO_IP, "IPPROTO_IP" },
282 { IPPROTO_ICMP, "IPPROTO_ICMP" },
283 { IPPROTO_TCP, "IPPROTO_TCP" },
284 { IPPROTO_UDP, "IPPROTO_UDP" },
286 { IPPROTO_GGP, "IPPROTO_GGP" },
289 { IPPROTO_EGP, "IPPROTO_EGP" },
292 { IPPROTO_PUP, "IPPROTO_PUP" },
295 { IPPROTO_IDP, "IPPROTO_IDP" },
298 { IPPROTO_IPV6, "IPPROTO_IPV6" },
300 #ifdef IPPROTO_ICMPV6
301 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
304 { IPPROTO_IGMP, "IPPROTO_IGMP" },
307 { IPPROTO_HELLO,"IPPROTO_HELLO" },
310 { IPPROTO_ND, "IPPROTO_ND" },
313 { IPPROTO_RAW, "IPPROTO_RAW" },
316 { IPPROTO_MAX, "IPPROTO_MAX" },
319 { IPPROTO_IPIP, "IPPROTO_IPIP" },
323 static struct xlat msg_flags[] = {
324 { MSG_OOB, "MSG_OOB" },
326 { MSG_DONTROUTE,"MSG_DONTROUTE" },
329 { MSG_PEEK, "MSG_PEEK" },
332 { MSG_CTRUNC, "MSG_CTRUNC" },
335 { MSG_PROXY, "MSG_PROXY" },
338 { MSG_EOR, "MSG_EOR" },
341 { MSG_WAITALL, "MSG_WAITALL" },
344 { MSG_TRUNC, "MSG_TRUNC" },
347 { MSG_CTRUNC, "MSG_CTRUNC" },
350 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
353 { MSG_DONTWAIT, "MSG_DONTWAIT" },
356 { MSG_CONFIRM, "MSG_CONFIRM" },
359 { MSG_PROBE, "MSG_PROBE" },
364 static struct xlat sockoptions[] = {
366 { SO_PEERCRED, "SO_PEERCRED" },
369 { SO_PASSCRED, "SO_PASSCRED" },
372 { SO_DEBUG, "SO_DEBUG" },
375 { SO_REUSEADDR, "SO_REUSEADDR" },
378 { SO_KEEPALIVE, "SO_KEEPALIVE" },
381 { SO_DONTROUTE, "SO_DONTROUTE" },
384 { SO_BROADCAST, "SO_BROADCAST" },
387 { SO_LINGER, "SO_LINGER" },
390 { SO_OOBINLINE, "SO_OOBINLINE" },
393 { SO_TYPE, "SO_TYPE" },
396 { SO_ERROR, "SO_ERROR" },
399 { SO_SNDBUF, "SO_SNDBUF" },
402 { SO_RCVBUF, "SO_RCVBUF" },
405 { SO_NO_CHECK, "SO_NO_CHECK" },
408 { SO_PRIORITY, "SO_PRIORITY" },
411 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
413 #ifdef SO_USELOOPBACK
414 { SO_USELOOPBACK,"SO_USELOOPBACK"},
417 { SO_SNDLOWAT, "SO_SNDLOWAT" },
420 { SO_RCVLOWAT, "SO_RCVLOWAT" },
423 { SO_SNDTIMEO, "SO_SNDTIMEO" },
426 { SO_RCVTIMEO, "SO_RCVTIMEO" },
429 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
432 { SO_REUSEPORT, "SO_REUSEPORT" },
435 { SO_RCVLOWAT, "SO_RCVLOWAT" },
438 { SO_SNDLOWAT, "SO_SNDLOWAT" },
441 { SO_RCVTIMEO, "SO_RCVTIMEO" },
444 { SO_SNDTIMEO, "SO_SNDTIMEO" },
450 static struct xlat sockipoptions[] = {
451 { IP_TOS, "IP_TOS" },
452 { IP_TTL, "IP_TTL" },
453 #if defined(IP_HDRINCL)
454 { IP_HDRINCL, "IP_HDRINCL" },
456 #if defined(IP_OPTIONS)
457 { IP_OPTIONS, "IP_OPTIONS" },
459 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
460 #if defined(IP_RECVOPTIONS)
461 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
463 { IP_RETOPTS, "IP_RETOPTS" },
464 { IP_PKTINFO, "IP_PKTINFO" },
465 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
466 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
467 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
468 { IP_RECVERR, "IP_RECVERR" },
469 { IP_RECVTTL, "IP_RECRECVTTL" },
470 { IP_RECVTOS, "IP_RECRECVTOS" },
472 { IP_MTU, "IP_MTU" },
474 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
475 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
476 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
477 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
478 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
484 static struct xlat sockipxoptions[] = {
485 { IPX_TYPE, "IPX_TYPE" },
491 static struct xlat sockrawoptions[] = {
492 #if defined(ICMP_FILTER)
493 { ICMP_FILTER, "ICMP_FILTER" },
500 static struct xlat sockpacketoptions[] = {
501 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
502 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
503 #if defined(PACKET_RECV_OUTPUT)
504 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
506 #if defined(PACKET_RX_RING)
507 { PACKET_RX_RING, "PACKET_RX_RING" },
509 #if defined(PACKET_STATISTICS)
510 { PACKET_STATISTICS, "PACKET_STATISTICS" },
514 #endif /* SOL_PACKET */
517 static struct xlat socktcpoptions[] = {
518 { TCP_NODELAY, "TCP_NODELAY" },
519 { TCP_MAXSEG, "TCP_MAXSEG" },
520 #if defined(TCP_CORK)
521 { TCP_CORK, "TCP_CORK" },
528 static struct xlat icmpfilterflags[] = {
529 #if defined(ICMP_ECHOREPLY)
530 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
532 #if defined(ICMP_DEST_UNREACH)
533 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
535 #if defined(ICMP_SOURCE_QUENCH)
536 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
538 #if defined(ICMP_REDIRECT)
539 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
541 #if defined(ICMP_ECHO)
542 { (1<<ICMP_ECHO), "ICMP_ECHO" },
544 #if defined(ICMP_TIME_EXCEEDED)
545 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
547 #if defined(ICMP_PARAMETERPROB)
548 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
550 #if defined(ICMP_TIMESTAMP)
551 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
553 #if defined(ICMP_TIMESTAMPREPLY)
554 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
556 #if defined(ICMP_INFO_REQUEST)
557 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
559 #if defined(ICMP_INFO_REPLY)
560 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
562 #if defined(ICMP_ADDRESS)
563 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
565 #if defined(ICMP_ADDRESSREPLY)
566 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
574 printsock(tcp, addr, addrlen)
582 struct sockaddr_in sin;
583 struct sockaddr_un sau;
584 #ifdef HAVE_INET_NTOP
585 struct sockaddr_in6 sa6;
587 #if defined(LINUX) && defined(AF_IPX)
588 struct sockaddr_ipx sipx;
591 struct sockaddr_ll ll;
594 struct sockaddr_nl nl;
597 char string_addr[100];
604 tprintf("%#lx", addr);
607 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
608 addrlen=sizeof(addrbuf);
610 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
615 tprintf("{sin_family=");
616 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
619 switch (addrbuf.sa.sa_family) {
623 } else if (addrbuf.sau.sun_path[0]) {
624 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
626 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
630 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
631 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
633 #ifdef HAVE_INET_NTOP
635 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
636 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
637 ntohs(addrbuf.sa6.sin6_port), string_addr,
638 addrbuf.sa6.sin6_flowinfo);
639 #ifdef HAVE_SIN6_SCOPE_ID
641 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
642 int numericscope = 0;
643 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
644 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
645 char scopebuf[IFNAMSIZ + 1];
647 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
650 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
656 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
661 #if defined(AF_IPX) && defined(linux)
665 tprintf("{sipx_port=htons(%u), ",
666 ntohs(addrbuf.sipx.sipx_port));
667 /* Yes, I know, this does not look too
668 * strace-ish, but otherwise the IPX
669 * addresses just look monstrous...
670 * Anyways, feel free if you don't like
673 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
674 for (i = 0; i<IPX_NODE_LEN; i++)
675 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
676 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
679 #endif /* AF_IPX && linux */
684 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
685 ntohs(addrbuf.ll.sll_protocol),
686 addrbuf.ll.sll_ifindex,
687 addrbuf.ll.sll_pkttype,
688 addrbuf.ll.sll_halen,
689 addrbuf.ll.sll_hatype);
690 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
691 tprintf("%02x", addrbuf.ll.sll_addr[i]);
695 #endif /* AF_APACKET */
698 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
700 #endif /* AF_NETLINK */
701 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
702 AF_X25 AF_ROSE etc. still need to be done */
705 tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);
706 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
707 sizeof addrbuf.sa.sa_data);
716 printiovec(tcp, iovec, len)
724 iov = (struct iovec *) malloc(len * sizeof *iov);
726 fprintf(stderr, "No memory");
729 if (umoven(tcp, (long)iovec,
730 len * sizeof *iov, (char *) iov) < 0) {
731 tprintf("%#lx", (unsigned long)iovec);
734 for (i = 0; i < len; i++) {
738 printstr(tcp, (long) iov[i].iov_base,
740 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
748 printmsghdr(tcp, addr)
754 if (umove(tcp, addr, &msg) < 0) {
755 tprintf("%#lx", addr);
758 tprintf("{msg_name(%d)=", msg.msg_namelen);
759 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
761 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
762 printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
764 #ifdef HAVE_MSG_CONTROL
765 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
766 if (msg.msg_controllen)
767 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
768 tprintf(", msg_flags=");
769 if (printflags(msg_flags, msg.msg_flags)==0)
771 #else /* !HAVE_MSG_CONTROL */
772 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
773 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
774 #endif /* !HAVE_MSG_CONTROL */
778 #endif /* HAVE_SENDMSG */
785 printxval(domains, tcp->u_arg[0], "PF_???");
787 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
789 switch (tcp->u_arg[0]) {
791 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
795 /* BTW: I don't believe this.. */
797 printxval(domains, tcp->u_arg[2], "PF_???");
802 tprintf("%lu", tcp->u_arg[2]);
814 /* not sure really what these args are... but this
815 * is how truss prints it
817 tprintf("%ld, %ld, %ld, ",
818 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
819 printpath(tcp, tcp->u_arg[3]);
820 tprintf(", %ld", tcp->u_arg[4]);
826 sys_so_socketpair(tcp)
830 /* not sure what this arg is */
831 tprintf("0x%lx", tcp->u_arg[0]);
841 tprintf("%ld, ", tcp->u_arg[0]);
842 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
843 tprintf(", %lu", tcp->u_arg[2]);
852 return sys_bind(tcp);
860 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
870 tprintf("%ld, ", tcp->u_arg[0]);
871 } else if (!tcp->u_arg[2])
872 tprintf("%#lx, NULL", tcp->u_arg[1]);
874 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
875 tprintf("%#lx", tcp->u_arg[1]);
877 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
880 printnum(tcp, tcp->u_arg[2], "%lu");
890 tprintf("%ld, ", tcp->u_arg[0]);
891 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
892 tprintf(", %lu, ", tcp->u_arg[2]);
894 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
905 tprintf("%ld, ", tcp->u_arg[0]);
906 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
907 tprintf(", %lu, ", tcp->u_arg[2]);
909 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
913 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
915 tprintf(", %lu", tcp->u_arg[5]);
927 tprintf("%ld, ", tcp->u_arg[0]);
928 printmsghdr(tcp, tcp->u_arg[1]);
931 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
937 #endif /* HAVE_SENDMSG */
944 tprintf("%ld, ", tcp->u_arg[0]);
947 tprintf("%#lx", tcp->u_arg[1]);
949 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
951 tprintf(", %lu, ", tcp->u_arg[2]);
952 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
965 tprintf("%ld, ", tcp->u_arg[0]);
968 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
969 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
970 tcp->u_arg[4], tcp->u_arg[5]);
974 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
976 tprintf(", %lu, ", tcp->u_arg[2]);
978 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
980 /* from address, len */
981 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
982 if (tcp->u_arg[4] == 0)
985 tprintf(", %#lx", tcp->u_arg[4]);
986 if (tcp->u_arg[5] == 0)
989 tprintf(", %#lx", tcp->u_arg[5]);
992 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
993 tprintf(", {...}, [?]");
997 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
999 tprintf(", [%u]", fromlen);
1010 if (entering(tcp)) {
1011 tprintf("%ld, ", tcp->u_arg[0]);
1013 if (syserror(tcp) || !verbose(tcp))
1014 tprintf("%#lx", tcp->u_arg[1]);
1016 printmsghdr(tcp, tcp->u_arg[1]);
1019 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1025 #endif /* HAVE_SENDMSG */
1031 if (entering(tcp)) {
1032 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1033 switch (tcp->u_arg[1]) {
1035 tprintf("%s", " /* receive */");
1038 tprintf("%s", " /* send */");
1041 tprintf("%s", " /* send and receive */");
1049 sys_getsockname(tcp)
1052 return sys_accept(tcp);
1056 sys_getpeername(tcp)
1059 return sys_accept(tcp);
1067 #if defined(LINUX) && !defined(SPARC)
1071 if (syserror(tcp)) {
1072 tprintf("%#lx", tcp->u_arg[0]);
1075 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1078 tprintf("[%u, %u]", fds[0], fds[1]);
1080 #elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
1082 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1095 if (entering(tcp)) {
1096 printxval(domains, tcp->u_arg[0], "PF_???");
1098 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1100 switch (tcp->u_arg[0]) {
1102 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1106 /* BTW: I don't believe this.. */
1108 printxval(domains, tcp->u_arg[2], "PF_???");
1113 tprintf("%lu", tcp->u_arg[2]);
1117 if (syserror(tcp)) {
1118 tprintf(", %#lx", tcp->u_arg[3]);
1122 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1125 tprintf(", [%u, %u]", fds[0], fds[1]);
1127 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1128 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1129 #endif /* SUNOS4 || SVR4 || FREEBSD */
1138 if (entering(tcp)) {
1139 tprintf("%ld, ", tcp->u_arg[0]);
1140 switch (tcp->u_arg[1]) {
1142 tprintf("SOL_SOCKET, ");
1143 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1148 tprintf("SOL_IP, ");
1149 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1155 tprintf("SOL_IPX, ");
1156 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1162 tprintf("SOL_PACKET, ");
1163 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1169 tprintf("SOL_TCP, ");
1170 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1175 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1176 * etc. still need work */
1178 /* XXX - should know socket family here */
1179 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1180 tprintf(", %lu, ", tcp->u_arg[2]);
1184 if (syserror(tcp)) {
1185 tprintf("%#lx, %#lx",
1186 tcp->u_arg[3], tcp->u_arg[4]);
1189 printnum(tcp, tcp->u_arg[3], "%ld");
1191 printnum(tcp, tcp->u_arg[4], "%ld");
1196 #if defined(ICMP_FILTER)
1197 static void printicmpfilter(tcp, addr)
1201 struct icmp_filter filter;
1207 if (syserror(tcp) || !verbose(tcp)) {
1208 tprintf("%#lx", addr);
1211 if (umove(tcp, addr, &filter) < 0) {
1217 if (printflags(icmpfilterflags, ~filter.data) == 0)
1221 #endif /* ICMP_FILTER */
1227 if (entering(tcp)) {
1228 tprintf("%ld, ", tcp->u_arg[0]);
1229 switch (tcp->u_arg[1]) {
1231 tprintf("SOL_SOCKET, ");
1232 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1234 printnum(tcp, tcp->u_arg[3], "%ld");
1235 tprintf(", %lu", tcp->u_arg[4]);
1239 tprintf("SOL_IP, ");
1240 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1242 printnum(tcp, tcp->u_arg[3], "%ld");
1243 tprintf(", %lu", tcp->u_arg[4]);
1248 tprintf("SOL_IPX, ");
1249 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1251 printnum(tcp, tcp->u_arg[3], "%ld");
1252 tprintf(", %lu", tcp->u_arg[4]);
1257 tprintf("SOL_PACKET, ");
1258 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1260 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1261 printnum(tcp, tcp->u_arg[3], "%ld");
1262 tprintf(", %lu", tcp->u_arg[4]);
1267 tprintf("SOL_TCP, ");
1268 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1270 printnum(tcp, tcp->u_arg[3], "%ld");
1271 tprintf(", %lu", tcp->u_arg[4]);
1276 tprintf("SOL_RAW, ");
1277 printxval(sockrawoptions, tcp->u_arg[2], "RAW_???");
1279 switch (tcp->u_arg[2]) {
1280 #if defined(ICMP_FILTER)
1282 printicmpfilter(tcp, tcp->u_arg[3]);
1286 printnum(tcp, tcp->u_arg[3], "%ld");
1289 tprintf(", %lu", tcp->u_arg[4]);
1293 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1294 * etc. still need work */
1296 /* XXX - should know socket family here */
1297 printxval(socketlayers, tcp->u_arg[1], "IPPROTO_???");
1298 tprintf(", %lu, ", tcp->u_arg[2]);
1299 printnum(tcp, tcp->u_arg[3], "%ld");
1300 tprintf(", %lu", tcp->u_arg[4]);
1309 static struct xlat sock_version[] = {
1310 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1311 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1312 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1313 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1314 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1315 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1321 netlib_call(tcp, func)
1325 if (entering(tcp)) {
1327 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1330 for (i = 0; i < tcp->u_nargs; i++)
1331 tcp->u_arg[i] = tcp->u_arg[i + 1];
1343 return netlib_call (tcp, sys_socket);
1347 sys_xsocketpair(tcp)
1350 return netlib_call (tcp, sys_socketpair);
1357 return netlib_call (tcp, sys_bind);
1364 return netlib_call (tcp, sys_connect);
1371 return netlib_call (tcp, sys_listen);
1378 return netlib_call (tcp, sys_accept);
1385 return netlib_call (tcp, sys_sendmsg);
1392 return netlib_call (tcp, sys_recvmsg);
1396 sys_xgetsockaddr(tcp)
1399 if (entering(tcp)) {
1400 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1402 if (tcp->u_arg[1] == 0) {
1403 tprintf ("LOCALNAME, ");
1405 else if (tcp->u_arg[1] == 1) {
1406 tprintf ("REMOTENAME, ");
1409 tprintf ("%ld, ", tcp->u_arg [1]);
1411 tprintf ("%ld, ", tcp->u_arg [2]);
1414 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1415 tprintf("%#lx", tcp->u_arg[3]);
1417 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1420 printnum(tcp, tcp->u_arg[4], "%lu");
1430 sys_xsetsockaddr(tcp)
1433 return netlib_call (tcp, sys_setsockaddr);
1439 sys_xgetsockopt(tcp)
1442 return netlib_call (tcp, sys_getsockopt);
1446 sys_xsetsockopt(tcp)
1449 return netlib_call (tcp, sys_setsockopt);
1456 return netlib_call (tcp, sys_shutdown);