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" },
279 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
281 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
282 falls into "protocols" array below!!!! This is intended!!! ***/
283 static struct xlat protocols[] = {
284 { IPPROTO_IP, "IPPROTO_IP" },
285 { IPPROTO_ICMP, "IPPROTO_ICMP" },
286 { IPPROTO_TCP, "IPPROTO_TCP" },
287 { IPPROTO_UDP, "IPPROTO_UDP" },
289 { IPPROTO_GGP, "IPPROTO_GGP" },
292 { IPPROTO_EGP, "IPPROTO_EGP" },
295 { IPPROTO_PUP, "IPPROTO_PUP" },
298 { IPPROTO_IDP, "IPPROTO_IDP" },
301 { IPPROTO_IPV6, "IPPROTO_IPV6" },
303 #ifdef IPPROTO_ICMPV6
304 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
307 { IPPROTO_IGMP, "IPPROTO_IGMP" },
310 { IPPROTO_HELLO,"IPPROTO_HELLO" },
313 { IPPROTO_ND, "IPPROTO_ND" },
316 { IPPROTO_RAW, "IPPROTO_RAW" },
319 { IPPROTO_MAX, "IPPROTO_MAX" },
322 { IPPROTO_IPIP, "IPPROTO_IPIP" },
326 static struct xlat msg_flags[] = {
327 { MSG_OOB, "MSG_OOB" },
329 { MSG_DONTROUTE,"MSG_DONTROUTE" },
332 { MSG_PEEK, "MSG_PEEK" },
335 { MSG_CTRUNC, "MSG_CTRUNC" },
338 { MSG_PROXY, "MSG_PROXY" },
341 { MSG_EOR, "MSG_EOR" },
344 { MSG_WAITALL, "MSG_WAITALL" },
347 { MSG_TRUNC, "MSG_TRUNC" },
350 { MSG_CTRUNC, "MSG_CTRUNC" },
353 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
356 { MSG_DONTWAIT, "MSG_DONTWAIT" },
359 { MSG_CONFIRM, "MSG_CONFIRM" },
362 { MSG_PROBE, "MSG_PROBE" },
367 static struct xlat sockoptions[] = {
369 { SO_PEERCRED, "SO_PEERCRED" },
372 { SO_PASSCRED, "SO_PASSCRED" },
375 { SO_DEBUG, "SO_DEBUG" },
378 { SO_REUSEADDR, "SO_REUSEADDR" },
381 { SO_KEEPALIVE, "SO_KEEPALIVE" },
384 { SO_DONTROUTE, "SO_DONTROUTE" },
387 { SO_BROADCAST, "SO_BROADCAST" },
390 { SO_LINGER, "SO_LINGER" },
393 { SO_OOBINLINE, "SO_OOBINLINE" },
396 { SO_TYPE, "SO_TYPE" },
399 { SO_ERROR, "SO_ERROR" },
402 { SO_SNDBUF, "SO_SNDBUF" },
405 { SO_RCVBUF, "SO_RCVBUF" },
408 { SO_NO_CHECK, "SO_NO_CHECK" },
411 { SO_PRIORITY, "SO_PRIORITY" },
414 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
416 #ifdef SO_USELOOPBACK
417 { SO_USELOOPBACK,"SO_USELOOPBACK"},
420 { SO_SNDLOWAT, "SO_SNDLOWAT" },
423 { SO_RCVLOWAT, "SO_RCVLOWAT" },
426 { SO_SNDTIMEO, "SO_SNDTIMEO" },
429 { SO_RCVTIMEO, "SO_RCVTIMEO" },
432 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
435 { SO_REUSEPORT, "SO_REUSEPORT" },
438 { SO_ORDREL, "SO_ORDREL" },
441 { SO_IMASOCKET, "SO_IMASOCKET" },
444 { SO_MGMT, "SO_MGMT" },
447 { SO_LISTENING, "SO_LISTENING" },
450 { SO_RDWR, "SO_RDWR" },
453 { SO_SEMA, "SO_SEMA" },
455 #ifdef SO_PARALLELSVR
456 { SO_PARALLELSVR,"SO_PARALLELSVR"},
459 { SO_PROTOTYPE, "SO_PROTOTYPE" },
462 { SO_ALLRAW, "SO_ALLRAW" },
465 { SO_ICS, "SO_ICS" },
470 #if !defined (SOL_IP) && defined (IPPROTO_IP)
471 #define SOL_IP IPPROTO_IP
475 static struct xlat sockipoptions[] = {
477 { IP_TOS, "IP_TOS" },
480 { IP_TTL, "IP_TTL" },
483 { IP_HDRINCL, "IP_HDRINCL" },
486 { IP_OPTIONS, "IP_OPTIONS" },
488 #ifdef IP_ROUTER_ALERT
489 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
491 #ifdef IP_RECVOPTIONS
492 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
495 { IP_RECVOPTS, "IP_RECVOPTS" },
497 #ifdef IP_RECVRETOPTS
498 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
500 #ifdef IP_RECVDSTADDR
501 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
504 { IP_RETOPTS, "IP_RETOPTS" },
507 { IP_PKTINFO, "IP_PKTINFO" },
510 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
512 #ifdef IP_MTU_DISCOVER
513 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
516 { IP_RECVERR, "IP_RECVERR" },
519 { IP_RECVTTL, "IP_RECRECVTTL" },
522 { IP_RECVTOS, "IP_RECRECVTOS" },
525 { IP_MTU, "IP_MTU" },
527 #ifdef IP_MULTICAST_IF
528 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
530 #ifdef IP_MULTICAST_TTL
531 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
533 #ifdef IP_MULTICAST_LOOP
534 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
536 #ifdef IP_ADD_MEMBERSHIP
537 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
539 #ifdef IP_DROP_MEMBERSHIP
540 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
542 #ifdef IP_BROADCAST_IF
543 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
545 #ifdef IP_RECVIFINDEX
546 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
553 static struct xlat sockipxoptions[] = {
554 { IPX_TYPE, "IPX_TYPE" },
560 static struct xlat sockrawoptions[] = {
561 #if defined(ICMP_FILTER)
562 { ICMP_FILTER, "ICMP_FILTER" },
569 static struct xlat sockpacketoptions[] = {
570 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
571 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
572 #if defined(PACKET_RECV_OUTPUT)
573 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
575 #if defined(PACKET_RX_RING)
576 { PACKET_RX_RING, "PACKET_RX_RING" },
578 #if defined(PACKET_STATISTICS)
579 { PACKET_STATISTICS, "PACKET_STATISTICS" },
583 #endif /* SOL_PACKET */
585 #if !defined (SOL_TCP) && defined (IPPROTO_TCP)
586 #define SOL_TCP IPPROTO_TCP
590 static struct xlat socktcpoptions[] = {
591 { TCP_NODELAY, "TCP_NODELAY" },
592 { TCP_MAXSEG, "TCP_MAXSEG" },
593 #if defined(TCP_CORK)
594 { TCP_CORK, "TCP_CORK" },
596 #if defined(TCP_KEEPIDLE)
597 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
599 #if defined(TCP_KEEPINTVL)
600 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
602 #if defined(TCP_KEEPCNT)
603 { TCP_KEEPCNT, "TCP_KEEPCNT" },
605 #if defined(TCP_NKEEP)
606 { TCP_NKEEP, "TCP_NKEEP" },
608 #if defined(TCP_SYNCNT)
609 { TCP_SYNCNT, "TCP_SYNCNT" },
611 #if defined(TCP_LINGER2)
612 { TCP_LINGER2, "TCP_LINGER2" },
614 #if defined(TCP_DEFER_ACCEPT)
615 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
617 #if defined(TCP_WINDOW_CLAMP)
618 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
620 #if defined(TCP_INFO)
621 { TCP_INFO, "TCP_INFO" },
623 #if defined(TCP_QUICKACK)
624 { TCP_QUICKACK, "TCP_QUICKACK" },
631 static struct xlat icmpfilterflags[] = {
632 #if defined(ICMP_ECHOREPLY)
633 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
635 #if defined(ICMP_DEST_UNREACH)
636 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
638 #if defined(ICMP_SOURCE_QUENCH)
639 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
641 #if defined(ICMP_REDIRECT)
642 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
644 #if defined(ICMP_ECHO)
645 { (1<<ICMP_ECHO), "ICMP_ECHO" },
647 #if defined(ICMP_TIME_EXCEEDED)
648 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
650 #if defined(ICMP_PARAMETERPROB)
651 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
653 #if defined(ICMP_TIMESTAMP)
654 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
656 #if defined(ICMP_TIMESTAMPREPLY)
657 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
659 #if defined(ICMP_INFO_REQUEST)
660 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
662 #if defined(ICMP_INFO_REPLY)
663 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
665 #if defined(ICMP_ADDRESS)
666 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
668 #if defined(ICMP_ADDRESSREPLY)
669 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
675 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
676 static struct xlat af_packet_types[] = {
677 #if defined(PACKET_HOST)
678 { PACKET_HOST, "PACKET_HOST" },
680 #if defined(PACKET_BROADCAST)
681 { PACKET_BROADCAST, "PACKET_BROADCAST" },
683 #if defined(PACKET_MULTICAST)
684 { PACKET_MULTICAST, "PACKET_MULTICAST" },
686 #if defined(PACKET_OTHERHOST)
687 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
689 #if defined(PACKET_OUTGOING)
690 { PACKET_OUTGOING, "PACKET_OUTGOING" },
692 #if defined(PACKET_LOOPBACK)
693 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
695 #if defined(PACKET_FASTROUTE)
696 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
700 #endif /* defined(AF_PACKET) */
704 printsock(tcp, addr, addrlen)
712 struct sockaddr_in sin;
713 struct sockaddr_un sau;
714 #ifdef HAVE_INET_NTOP
715 struct sockaddr_in6 sa6;
717 #if defined(LINUX) && defined(AF_IPX)
718 struct sockaddr_ipx sipx;
721 struct sockaddr_ll ll;
724 struct sockaddr_nl nl;
727 char string_addr[100];
734 tprintf("%#lx", addr);
737 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
738 addrlen=sizeof(addrbuf);
740 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
745 tprintf("{sa_family=");
746 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
749 switch (addrbuf.sa.sa_family) {
753 } else if (addrbuf.sau.sun_path[0]) {
754 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
756 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
760 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
761 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
763 #ifdef HAVE_INET_NTOP
765 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
766 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
767 ntohs(addrbuf.sa6.sin6_port), string_addr,
768 addrbuf.sa6.sin6_flowinfo);
769 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
771 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
772 int numericscope = 0;
773 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
774 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
775 char scopebuf[IFNAMSIZ + 1];
777 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
780 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
786 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
791 #if defined(AF_IPX) && defined(linux)
795 tprintf("sipx_port=htons(%u), ",
796 ntohs(addrbuf.sipx.sipx_port));
797 /* Yes, I know, this does not look too
798 * strace-ish, but otherwise the IPX
799 * addresses just look monstrous...
800 * Anyways, feel free if you don't like
803 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
804 for (i = 0; i<IPX_NODE_LEN; i++)
805 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
806 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
809 #endif /* AF_IPX && linux */
814 tprintf("proto=%#04x, if%d, pkttype=",
815 ntohs(addrbuf.ll.sll_protocol),
816 addrbuf.ll.sll_ifindex);
817 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
818 tprintf(", addr(%d)={%d, ",
819 addrbuf.ll.sll_halen,
820 addrbuf.ll.sll_hatype);
821 for (i=0; i<addrbuf.ll.sll_halen; i++)
822 tprintf("%02x", addrbuf.ll.sll_addr[i]);
826 #endif /* AF_APACKET */
829 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
831 #endif /* AF_NETLINK */
832 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
833 AF_X25 AF_ROSE etc. still need to be done */
837 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
838 sizeof addrbuf.sa.sa_data);
847 printmsghdr(tcp, addr)
853 if (umove(tcp, addr, &msg) < 0) {
854 tprintf("%#lx", addr);
857 tprintf("{msg_name(%d)=", msg.msg_namelen);
858 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
860 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
861 tprint_iov(tcp, msg.msg_iovlen, (long) msg.msg_iov);
863 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
864 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
865 if (msg.msg_controllen)
866 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
867 tprintf(", msg_flags=");
868 if (printflags(msg_flags, msg.msg_flags)==0)
870 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
871 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
872 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
873 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
877 #endif /* HAVE_SENDMSG */
884 printxval(domains, tcp->u_arg[0], "PF_???");
886 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
888 switch (tcp->u_arg[0]) {
890 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
894 /* BTW: I don't believe this.. */
896 printxval(domains, tcp->u_arg[2], "PF_???");
901 tprintf("%lu", tcp->u_arg[2]);
913 /* not sure really what these args are... but this
914 * is how truss prints it
916 tprintf("%ld, %ld, %ld, ",
917 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
918 printpath(tcp, tcp->u_arg[3]);
919 tprintf(", %ld", tcp->u_arg[4]);
925 sys_so_socketpair(tcp)
929 /* not sure what this arg is */
930 tprintf("0x%lx", tcp->u_arg[0]);
940 tprintf("%ld, ", tcp->u_arg[0]);
941 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
942 tprintf(", %lu", tcp->u_arg[2]);
951 return sys_bind(tcp);
959 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
969 tprintf("%ld, ", tcp->u_arg[0]);
970 } else if (!tcp->u_arg[2])
971 tprintf("%#lx, NULL", tcp->u_arg[1]);
973 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
974 tprintf("%#lx", tcp->u_arg[1]);
976 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
979 printnum(tcp, tcp->u_arg[2], "%lu");
989 tprintf("%ld, ", tcp->u_arg[0]);
990 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
991 tprintf(", %lu, ", tcp->u_arg[2]);
993 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1003 if (entering(tcp)) {
1004 tprintf("%ld, ", tcp->u_arg[0]);
1005 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1006 tprintf(", %lu, ", tcp->u_arg[2]);
1008 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1012 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1014 tprintf(", %lu", tcp->u_arg[5]);
1025 if (entering(tcp)) {
1026 tprintf("%ld, ", tcp->u_arg[0]);
1027 printmsghdr(tcp, tcp->u_arg[1]);
1030 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1036 #endif /* HAVE_SENDMSG */
1042 if (entering(tcp)) {
1043 tprintf("%ld, ", tcp->u_arg[0]);
1046 tprintf("%#lx", tcp->u_arg[1]);
1048 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1050 tprintf(", %lu, ", tcp->u_arg[2]);
1051 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1063 if (entering(tcp)) {
1064 tprintf("%ld, ", tcp->u_arg[0]);
1066 if (syserror(tcp)) {
1067 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1068 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1069 tcp->u_arg[4], tcp->u_arg[5]);
1073 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1075 tprintf(", %lu, ", tcp->u_arg[2]);
1077 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1079 /* from address, len */
1080 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1081 if (tcp->u_arg[4] == 0)
1084 tprintf(", %#lx", tcp->u_arg[4]);
1085 if (tcp->u_arg[5] == 0)
1088 tprintf(", %#lx", tcp->u_arg[5]);
1091 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1092 tprintf(", {...}, [?]");
1096 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1098 tprintf(", [%u]", fromlen);
1109 if (entering(tcp)) {
1110 tprintf("%ld, ", tcp->u_arg[0]);
1112 if (syserror(tcp) || !verbose(tcp))
1113 tprintf("%#lx", tcp->u_arg[1]);
1115 printmsghdr(tcp, tcp->u_arg[1]);
1118 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1124 #endif /* HAVE_SENDMSG */
1130 if (entering(tcp)) {
1131 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1132 switch (tcp->u_arg[1]) {
1134 tprintf("%s", " /* receive */");
1137 tprintf("%s", " /* send */");
1140 tprintf("%s", " /* send and receive */");
1148 sys_getsockname(tcp)
1151 return sys_accept(tcp);
1155 sys_getpeername(tcp)
1158 return sys_accept(tcp);
1166 #if defined(LINUX) && !defined(SPARC) && !defined(SH)
1170 if (syserror(tcp)) {
1171 tprintf("%#lx", tcp->u_arg[0]);
1174 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1177 tprintf("[%u, %u]", fds[0], fds[1]);
1179 #elif defined(SPARC) || defined(SH) || defined(SVR4) || defined(FREEBSD)
1181 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1194 if (entering(tcp)) {
1195 printxval(domains, tcp->u_arg[0], "PF_???");
1197 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1199 switch (tcp->u_arg[0]) {
1201 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1205 /* BTW: I don't believe this.. */
1207 printxval(domains, tcp->u_arg[2], "PF_???");
1212 tprintf("%lu", tcp->u_arg[2]);
1216 if (syserror(tcp)) {
1217 tprintf(", %#lx", tcp->u_arg[3]);
1221 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1224 tprintf(", [%u, %u]", fds[0], fds[1]);
1226 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1227 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1228 #endif /* SUNOS4 || SVR4 || FREEBSD */
1237 if (entering(tcp)) {
1238 tprintf("%ld, ", tcp->u_arg[0]);
1239 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1241 switch (tcp->u_arg[1]) {
1243 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1247 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1252 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1257 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1262 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1266 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1267 * etc. still need work */
1269 tprintf("%lu", tcp->u_arg[2]);
1274 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1275 tprintf(", %#lx, %#lx",
1276 tcp->u_arg[3], tcp->u_arg[4]);
1280 switch (tcp->u_arg[1]) {
1282 switch (tcp->u_arg[2]) {
1285 if (len == sizeof (struct linger)) {
1286 struct linger linger;
1291 tprintf(", {onoff=%d, linger=%d}, "
1305 if (len == sizeof (int)) {
1306 printnum(tcp, tcp->u_arg[3], "%ld");
1309 printstr (tcp, tcp->u_arg[3], len);
1311 tprintf(", [%ld]", len);
1316 #if defined(ICMP_FILTER)
1317 static void printicmpfilter(tcp, addr)
1321 struct icmp_filter filter;
1327 if (syserror(tcp) || !verbose(tcp)) {
1328 tprintf("%#lx", addr);
1331 if (umove(tcp, addr, &filter) < 0) {
1337 if (printflags(icmpfilterflags, ~filter.data) == 0)
1341 #endif /* ICMP_FILTER */
1344 printsockopt (tcp, level, name, addr, len)
1351 printxval(socketlayers, level, "SOL_??");
1355 printxval(sockoptions, name, "SO_???");
1357 #if defined(SO_LINGER)
1359 if (len == sizeof (struct linger)) {
1360 struct linger linger;
1361 if (umove (tcp, addr, &linger) < 0)
1363 tprintf(", {onoff=%d, linger=%d}",
1374 printxval(sockipoptions, name, "IP_???");
1379 printxval(sockipxoptions, name, "IPX_???");
1384 printxval(sockpacketoptions, name, "PACKET_???");
1385 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1390 printxval(socktcpoptions, name, "TCP_???");
1395 printxval(sockrawoptions, name, "RAW_???");
1397 #if defined(ICMP_FILTER)
1400 printicmpfilter(tcp, addr);
1407 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1408 * etc. still need work */
1411 tprintf("%u", name);
1414 /* default arg printing */
1418 if (len == sizeof (int)) {
1419 printnum(tcp, addr, "%ld");
1422 printstr (tcp, addr, len);
1428 #ifdef HAVE_STRUCT_OPTHDR
1431 print_sock_optmgmt (tcp, addr, len)
1439 while (len >= (int) sizeof hdr) {
1440 if (umove(tcp, addr, &hdr) < 0) break;
1444 else if (len > hdr.len + sizeof hdr) {
1450 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
1458 if (c++) tprintf (", ");
1459 printstr (tcp, addr, len);
1461 if (c > 1) tprintf ("]");
1470 if (entering(tcp)) {
1471 tprintf("%ld, ", tcp->u_arg[0]);
1472 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1473 tcp->u_arg[3], tcp->u_arg[4]);
1474 tprintf(", %lu", tcp->u_arg[4]);
1481 static struct xlat sock_version[] = {
1482 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1483 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1484 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1485 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1486 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1487 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1493 netlib_call(tcp, func)
1497 if (entering(tcp)) {
1499 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1502 for (i = 0; i < tcp->u_nargs; i++)
1503 tcp->u_arg[i] = tcp->u_arg[i + 1];
1515 return netlib_call (tcp, sys_socket);
1519 sys_xsocketpair(tcp)
1522 return netlib_call (tcp, sys_socketpair);
1529 return netlib_call (tcp, sys_bind);
1536 return netlib_call (tcp, sys_connect);
1543 return netlib_call (tcp, sys_listen);
1550 return netlib_call (tcp, sys_accept);
1557 return netlib_call (tcp, sys_sendmsg);
1564 return netlib_call (tcp, sys_recvmsg);
1568 sys_xgetsockaddr(tcp)
1571 if (entering(tcp)) {
1572 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1574 if (tcp->u_arg[1] == 0) {
1575 tprintf ("LOCALNAME, ");
1577 else if (tcp->u_arg[1] == 1) {
1578 tprintf ("REMOTENAME, ");
1581 tprintf ("%ld, ", tcp->u_arg [1]);
1583 tprintf ("%ld, ", tcp->u_arg [2]);
1586 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1587 tprintf("%#lx", tcp->u_arg[3]);
1589 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1592 printnum(tcp, tcp->u_arg[4], "%lu");
1602 sys_xsetsockaddr(tcp)
1605 return netlib_call (tcp, sys_setsockaddr);
1611 sys_xgetsockopt(tcp)
1614 return netlib_call (tcp, sys_getsockopt);
1618 sys_xsetsockopt(tcp)
1621 return netlib_call (tcp, sys_setsockopt);
1628 return netlib_call (tcp, sys_shutdown);