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 const struct xlat domains[] = {
121 { PF_AAL5, "PF_AAL5" },
124 { PF_APPLETALK, "PF_APPLETALK" },
127 { PF_ASH, "PF_ASH" },
130 { PF_ATMPVC, "PF_ATMPVC" },
133 { PF_ATMSVC, "PF_ATMSVC" },
136 { PF_AX25, "PF_AX25" },
139 { PF_BLUETOOTH, "PF_BLUETOOTH" },
142 { PF_BRIDGE, "PF_BRIDGE" },
145 { PF_DECnet, "PF_DECnet" },
148 { PF_DECNET, "PF_DECNET" },
151 { PF_ECONET, "PF_ECONET" },
154 { PF_FILE, "PF_FILE" },
157 { PF_IMPLINK, "PF_IMPLINK" },
160 { PF_INET, "PF_INET" },
163 { PF_INET6, "PF_INET6" },
166 { PF_IPX, "PF_IPX" },
169 { PF_IRDA, "PF_IRDA" },
172 { PF_ISO, "PF_ISO" },
175 { PF_KEY, "PF_KEY" },
178 { PF_UNIX, "PF_UNIX" },
181 { PF_LOCAL, "PF_LOCAL" },
184 { PF_NETBEUI, "PF_NETBEUI" },
187 { PF_NETLINK, "PF_NETLINK" },
190 { PF_NETROM, "PF_NETROM" },
193 { PF_PACKET, "PF_PACKET" },
196 { PF_PPPOX, "PF_PPPOX" },
199 { PF_ROSE, "PF_ROSE" },
202 { PF_ROUTE, "PF_ROUTE" },
205 { PF_SECURITY, "PF_SECURITY" },
208 { PF_SNA, "PF_SNA" },
211 { PF_UNSPEC, "PF_UNSPEC" },
214 { PF_WANPIPE, "PF_WANPIPE" },
217 { PF_X25, "PF_X25" },
221 const struct xlat addrfams[] = {
223 { AF_APPLETALK, "AF_APPLETALK" },
226 { AF_ASH, "AF_ASH" },
229 { AF_ATMPVC, "AF_ATMPVC" },
232 { AF_ATMSVC, "AF_ATMSVC" },
235 { AF_AX25, "AF_AX25" },
238 { AF_BLUETOOTH, "AF_BLUETOOTH" },
241 { AF_BRIDGE, "AF_BRIDGE" },
244 { AF_DECnet, "AF_DECnet" },
247 { AF_ECONET, "AF_ECONET" },
250 { AF_FILE, "AF_FILE" },
253 { AF_IMPLINK, "AF_IMPLINK" },
256 { AF_INET, "AF_INET" },
259 { AF_INET6, "AF_INET6" },
262 { AF_IPX, "AF_IPX" },
265 { AF_IRDA, "AF_IRDA" },
268 { AF_ISO, "AF_ISO" },
271 { AF_KEY, "AF_KEY" },
274 { AF_UNIX, "AF_UNIX" },
277 { AF_LOCAL, "AF_LOCAL" },
280 { AF_NETBEUI, "AF_NETBEUI" },
283 { AF_NETLINK, "AF_NETLINK" },
286 { AF_NETROM, "AF_NETROM" },
289 { AF_PACKET, "AF_PACKET" },
292 { AF_PPPOX, "AF_PPPOX" },
295 { AF_ROSE, "AF_ROSE" },
298 { AF_ROUTE, "AF_ROUTE" },
301 { AF_SECURITY, "AF_SECURITY" },
304 { AF_SNA, "AF_SNA" },
307 { AF_UNSPEC, "AF_UNSPEC" },
310 { AF_WANPIPE, "AF_WANPIPE" },
313 { AF_X25, "AF_X25" },
317 static const struct xlat socktypes[] = {
318 { SOCK_STREAM, "SOCK_STREAM" },
319 { SOCK_DGRAM, "SOCK_DGRAM" },
321 { SOCK_RAW, "SOCK_RAW" },
323 #ifdef SOCK_SEQPACKET
324 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
327 { SOCK_RDM, "SOCK_RDM" },
330 { SOCK_PACKET, "SOCK_PACKET" },
334 static const struct xlat socketlayers[] = {
336 { SOL_IP, "SOL_IP" },
338 #if defined(SOL_ICMP)
339 { SOL_ICMP, "SOL_ICMP" },
342 { SOL_TCP, "SOL_TCP" },
345 { SOL_UDP, "SOL_UDP" },
347 #if defined(SOL_IPV6)
348 { SOL_IPV6, "SOL_IPV6" },
350 #if defined(SOL_ICMPV6)
351 { SOL_ICMPV6, "SOL_ICMPV6" },
354 { SOL_RAW, "SOL_RAW" },
357 { SOL_IPX, "SOL_IPX" },
360 { SOL_IPX, "SOL_IPX" },
362 #if defined(SOL_AX25)
363 { SOL_AX25, "SOL_AX25" },
365 #if defined(SOL_ATALK)
366 { SOL_ATALK, "SOL_ATALK" },
368 #if defined(SOL_NETROM)
369 { SOL_NETROM, "SOL_NETROM" },
371 #if defined(SOL_ROSE)
372 { SOL_ROSE, "SOL_ROSE" },
374 #if defined(SOL_DECNET)
375 { SOL_DECNET, "SOL_DECNET" },
378 { SOL_X25, "SOL_X25" },
380 #if defined(SOL_PACKET)
381 { SOL_PACKET, "SOL_PACKET" },
384 { SOL_ATM, "SOL_ATM" },
387 { SOL_AAL, "SOL_AAL" },
389 #if defined(SOL_IRDA)
390 { SOL_IRDA, "SOL_IRDA" },
392 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
394 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
395 falls into "protocols" array below!!!! This is intended!!! ***/
396 static const struct xlat protocols[] = {
397 { IPPROTO_IP, "IPPROTO_IP" },
398 { IPPROTO_ICMP, "IPPROTO_ICMP" },
399 { IPPROTO_TCP, "IPPROTO_TCP" },
400 { IPPROTO_UDP, "IPPROTO_UDP" },
402 { IPPROTO_GGP, "IPPROTO_GGP" },
405 { IPPROTO_EGP, "IPPROTO_EGP" },
408 { IPPROTO_PUP, "IPPROTO_PUP" },
411 { IPPROTO_IDP, "IPPROTO_IDP" },
414 { IPPROTO_IPV6, "IPPROTO_IPV6" },
416 #ifdef IPPROTO_ICMPV6
417 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
420 { IPPROTO_IGMP, "IPPROTO_IGMP" },
423 { IPPROTO_HELLO,"IPPROTO_HELLO" },
426 { IPPROTO_ND, "IPPROTO_ND" },
429 { IPPROTO_RAW, "IPPROTO_RAW" },
432 { IPPROTO_MAX, "IPPROTO_MAX" },
435 { IPPROTO_IPIP, "IPPROTO_IPIP" },
439 static const struct xlat msg_flags[] = {
440 { MSG_OOB, "MSG_OOB" },
442 { MSG_DONTROUTE,"MSG_DONTROUTE" },
445 { MSG_PEEK, "MSG_PEEK" },
448 { MSG_CTRUNC, "MSG_CTRUNC" },
451 { MSG_PROXY, "MSG_PROXY" },
454 { MSG_EOR, "MSG_EOR" },
457 { MSG_WAITALL, "MSG_WAITALL" },
460 { MSG_TRUNC, "MSG_TRUNC" },
463 { MSG_CTRUNC, "MSG_CTRUNC" },
466 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
469 { MSG_DONTWAIT, "MSG_DONTWAIT" },
472 { MSG_CONFIRM, "MSG_CONFIRM" },
475 { MSG_PROBE, "MSG_PROBE" },
478 { MSG_FIN, "MSG_FIN" },
481 { MSG_SYN, "MSG_SYN" },
484 { MSG_RST, "MSG_RST" },
487 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
490 { MSG_MORE, "MSG_MORE" },
495 static const struct xlat sockoptions[] = {
497 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
500 { SO_ALLRAW, "SO_ALLRAW" },
502 #ifdef SO_ATTACH_FILTER
503 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
505 #ifdef SO_BINDTODEVICE
506 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
509 { SO_BROADCAST, "SO_BROADCAST" },
512 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
515 { SO_DEBUG, "SO_DEBUG" },
517 #ifdef SO_DETACH_FILTER
518 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
521 { SO_DONTROUTE, "SO_DONTROUTE" },
524 { SO_ERROR, "SO_ERROR" },
527 { SO_ICS, "SO_ICS" },
530 { SO_IMASOCKET, "SO_IMASOCKET" },
533 { SO_KEEPALIVE, "SO_KEEPALIVE" },
536 { SO_LINGER, "SO_LINGER" },
539 { SO_LISTENING, "SO_LISTENING" },
542 { SO_MGMT, "SO_MGMT" },
545 { SO_NO_CHECK, "SO_NO_CHECK" },
548 { SO_OOBINLINE, "SO_OOBINLINE" },
551 { SO_ORDREL, "SO_ORDREL" },
553 #ifdef SO_PARALLELSVR
554 { SO_PARALLELSVR, "SO_PARALLELSVR" },
557 { SO_PASSCRED, "SO_PASSCRED" },
560 { SO_PEERCRED, "SO_PEERCRED" },
563 { SO_PEERNAME, "SO_PEERNAME" },
566 { SO_PEERSEC, "SO_PEERSEC" },
569 { SO_PRIORITY, "SO_PRIORITY" },
572 { SO_PROTOTYPE, "SO_PROTOTYPE" },
575 { SO_RCVBUF, "SO_RCVBUF" },
578 { SO_RCVLOWAT, "SO_RCVLOWAT" },
581 { SO_RCVTIMEO, "SO_RCVTIMEO" },
584 { SO_RDWR, "SO_RDWR" },
587 { SO_REUSEADDR, "SO_REUSEADDR" },
590 { SO_REUSEPORT, "SO_REUSEPORT" },
592 #ifdef SO_SECURITY_AUTHENTICATION
593 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
595 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
596 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
598 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
599 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
602 { SO_SEMA, "SO_SEMA" },
605 { SO_SNDBUF, "SO_SNDBUF" },
608 { SO_SNDLOWAT, "SO_SNDLOWAT" },
611 { SO_SNDTIMEO, "SO_SNDTIMEO" },
614 { SO_TIMESTAMP, "SO_TIMESTAMP" },
617 { SO_TYPE, "SO_TYPE" },
619 #ifdef SO_USELOOPBACK
620 { SO_USELOOPBACK, "SO_USELOOPBACK" },
625 #if !defined (SOL_IP) && defined (IPPROTO_IP)
626 #define SOL_IP IPPROTO_IP
630 static const struct xlat sockipoptions[] = {
632 { IP_TOS, "IP_TOS" },
635 { IP_TTL, "IP_TTL" },
638 { IP_HDRINCL, "IP_HDRINCL" },
641 { IP_OPTIONS, "IP_OPTIONS" },
643 #ifdef IP_ROUTER_ALERT
644 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
646 #ifdef IP_RECVOPTIONS
647 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
650 { IP_RECVOPTS, "IP_RECVOPTS" },
652 #ifdef IP_RECVRETOPTS
653 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
655 #ifdef IP_RECVDSTADDR
656 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
659 { IP_RETOPTS, "IP_RETOPTS" },
662 { IP_PKTINFO, "IP_PKTINFO" },
665 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
667 #ifdef IP_MTU_DISCOVER
668 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
671 { IP_RECVERR, "IP_RECVERR" },
674 { IP_RECVTTL, "IP_RECVTTL" },
677 { IP_RECVTOS, "IP_RECVTOS" },
680 { IP_MTU, "IP_MTU" },
682 #ifdef IP_MULTICAST_IF
683 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
685 #ifdef IP_MULTICAST_TTL
686 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
688 #ifdef IP_MULTICAST_LOOP
689 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
691 #ifdef IP_ADD_MEMBERSHIP
692 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
694 #ifdef IP_DROP_MEMBERSHIP
695 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
697 #ifdef IP_BROADCAST_IF
698 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
700 #ifdef IP_RECVIFINDEX
701 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
704 { IP_MSFILTER, "IP_MSFILTER" },
706 #ifdef MCAST_MSFILTER
707 { MCAST_MSFILTER, "MCAST_MSFILTER" },
710 { IP_FREEBIND, "IP_FREEBIND" },
717 static const struct xlat sockipv6options[] = {
719 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
722 { MCAST_FILTER, "MCAST_FILTER" },
724 #ifdef IPV6_PKTOPTIONS
725 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
728 { IPV6_MTU, "IPV6_MTU" },
731 { IPV6_V6ONLY, "IPV6_V6ONLY" },
734 { IPV6_PKTINFO, "IPV6_PKTINFO" },
737 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
740 { IPV6_RTHDR, "IPV6_RTHDR" },
743 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
746 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
749 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
751 #ifdef IPV6_UNICAST_HOPS
752 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
754 #ifdef IPV6_MULTICAST_HOPS
755 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
757 #ifdef IPV6_MULTICAST_LOOP
758 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
760 #ifdef IPV6_MULTICAST_IF
761 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
763 #ifdef IPV6_MTU_DISCOVER
764 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
767 { IPV6_RECVERR, "IPV6_RECVERR" },
769 #ifdef IPV6_FLOWINFO_SEND
770 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
772 #ifdef IPV6_ADD_MEMBERSHIP
773 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
775 #ifdef IPV6_DROP_MEMBERSHIP
776 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
778 #ifdef IPV6_ROUTER_ALERT
779 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
783 #endif /* SOL_IPV6 */
786 static const struct xlat sockipxoptions[] = {
787 { IPX_TYPE, "IPX_TYPE" },
793 static const struct xlat sockrawoptions[] = {
794 #if defined(ICMP_FILTER)
795 { ICMP_FILTER, "ICMP_FILTER" },
802 static const struct xlat sockpacketoptions[] = {
803 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
804 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
805 #if defined(PACKET_RECV_OUTPUT)
806 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
808 #if defined(PACKET_RX_RING)
809 { PACKET_RX_RING, "PACKET_RX_RING" },
811 #if defined(PACKET_STATISTICS)
812 { PACKET_STATISTICS, "PACKET_STATISTICS" },
816 #endif /* SOL_PACKET */
818 #if !defined (SOL_TCP) && defined (IPPROTO_TCP)
819 #define SOL_TCP IPPROTO_TCP
823 static const struct xlat socktcpoptions[] = {
824 { TCP_NODELAY, "TCP_NODELAY" },
825 { TCP_MAXSEG, "TCP_MAXSEG" },
826 #if defined(TCP_CORK)
827 { TCP_CORK, "TCP_CORK" },
829 #if defined(TCP_KEEPIDLE)
830 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
832 #if defined(TCP_KEEPINTVL)
833 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
835 #if defined(TCP_KEEPCNT)
836 { TCP_KEEPCNT, "TCP_KEEPCNT" },
838 #if defined(TCP_NKEEP)
839 { TCP_NKEEP, "TCP_NKEEP" },
841 #if defined(TCP_SYNCNT)
842 { TCP_SYNCNT, "TCP_SYNCNT" },
844 #if defined(TCP_LINGER2)
845 { TCP_LINGER2, "TCP_LINGER2" },
847 #if defined(TCP_DEFER_ACCEPT)
848 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
850 #if defined(TCP_WINDOW_CLAMP)
851 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
853 #if defined(TCP_INFO)
854 { TCP_INFO, "TCP_INFO" },
856 #if defined(TCP_QUICKACK)
857 { TCP_QUICKACK, "TCP_QUICKACK" },
864 static const struct xlat icmpfilterflags[] = {
865 #if defined(ICMP_ECHOREPLY)
866 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
868 #if defined(ICMP_DEST_UNREACH)
869 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
871 #if defined(ICMP_SOURCE_QUENCH)
872 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
874 #if defined(ICMP_REDIRECT)
875 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
877 #if defined(ICMP_ECHO)
878 { (1<<ICMP_ECHO), "ICMP_ECHO" },
880 #if defined(ICMP_TIME_EXCEEDED)
881 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
883 #if defined(ICMP_PARAMETERPROB)
884 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
886 #if defined(ICMP_TIMESTAMP)
887 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
889 #if defined(ICMP_TIMESTAMPREPLY)
890 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
892 #if defined(ICMP_INFO_REQUEST)
893 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
895 #if defined(ICMP_INFO_REPLY)
896 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
898 #if defined(ICMP_ADDRESS)
899 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
901 #if defined(ICMP_ADDRESSREPLY)
902 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
908 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
909 static const struct xlat af_packet_types[] = {
910 #if defined(PACKET_HOST)
911 { PACKET_HOST, "PACKET_HOST" },
913 #if defined(PACKET_BROADCAST)
914 { PACKET_BROADCAST, "PACKET_BROADCAST" },
916 #if defined(PACKET_MULTICAST)
917 { PACKET_MULTICAST, "PACKET_MULTICAST" },
919 #if defined(PACKET_OTHERHOST)
920 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
922 #if defined(PACKET_OUTGOING)
923 { PACKET_OUTGOING, "PACKET_OUTGOING" },
925 #if defined(PACKET_LOOPBACK)
926 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
928 #if defined(PACKET_FASTROUTE)
929 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
933 #endif /* defined(AF_PACKET) */
937 printsock(tcp, addr, addrlen)
945 struct sockaddr_in sin;
946 struct sockaddr_un sau;
947 #ifdef HAVE_INET_NTOP
948 struct sockaddr_in6 sa6;
950 #if defined(LINUX) && defined(AF_IPX)
951 struct sockaddr_ipx sipx;
954 struct sockaddr_ll ll;
957 struct sockaddr_nl nl;
960 char string_addr[100];
967 tprintf("%#lx", addr);
970 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
971 addrlen=sizeof(addrbuf);
973 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
978 tprintf("{sa_family=");
979 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
982 switch (addrbuf.sa.sa_family) {
986 } else if (addrbuf.sau.sun_path[0]) {
987 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
989 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
993 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
994 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
996 #ifdef HAVE_INET_NTOP
998 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
999 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1000 ntohs(addrbuf.sa6.sin6_port), string_addr,
1001 addrbuf.sa6.sin6_flowinfo);
1002 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1004 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1005 int numericscope = 0;
1006 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1007 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1008 char scopebuf[IFNAMSIZ + 1];
1010 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1013 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1019 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1024 #if defined(AF_IPX) && defined(linux)
1028 tprintf("sipx_port=htons(%u), ",
1029 ntohs(addrbuf.sipx.sipx_port));
1030 /* Yes, I know, this does not look too
1031 * strace-ish, but otherwise the IPX
1032 * addresses just look monstrous...
1033 * Anyways, feel free if you don't like
1036 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1037 for (i = 0; i<IPX_NODE_LEN; i++)
1038 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1039 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1042 #endif /* AF_IPX && linux */
1047 tprintf("proto=%#04x, if%d, pkttype=",
1048 ntohs(addrbuf.ll.sll_protocol),
1049 addrbuf.ll.sll_ifindex);
1050 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1051 tprintf(", addr(%d)={%d, ",
1052 addrbuf.ll.sll_halen,
1053 addrbuf.ll.sll_hatype);
1054 for (i=0; i<addrbuf.ll.sll_halen; i++)
1055 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1059 #endif /* AF_APACKET */
1062 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1064 #endif /* AF_NETLINK */
1065 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1066 AF_X25 AF_ROSE etc. still need to be done */
1069 tprintf("sa_data=");
1070 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1071 sizeof addrbuf.sa.sa_data);
1078 static const struct xlat scmvals[] = {
1080 { SCM_RIGHTS, "SCM_RIGHTS" },
1082 #ifdef SCM_CREDENTIALS
1083 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1089 printcmsghdr(tcp, addr, len)
1094 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1096 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1097 tprintf(", msg_control=%#lx", addr);
1102 tprintf(", {cmsg_len=%zu, cmsg_level=", cmsg->cmsg_len);
1103 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1104 tprintf(", cmsg_type=");
1106 if (cmsg->cmsg_level == SOL_SOCKET) {
1107 unsigned long cmsg_len;
1109 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1110 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1112 if (cmsg->cmsg_type == SCM_RIGHTS
1113 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1114 int *fds = (int *) CMSG_DATA (cmsg);
1118 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1121 tprintf("%d", *fds++);
1128 if (cmsg->cmsg_type == SCM_CREDENTIALS
1129 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1130 struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1132 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1133 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1143 printmsghdr(tcp, addr)
1149 if (umove(tcp, addr, &msg) < 0) {
1150 tprintf("%#lx", addr);
1153 tprintf("{msg_name(%d)=", msg.msg_namelen);
1154 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
1156 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
1157 tprint_iov(tcp, (unsigned long)msg.msg_iovlen,
1158 (unsigned long)msg.msg_iov);
1160 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1161 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
1162 if (msg.msg_controllen)
1163 printcmsghdr(tcp, (unsigned long) msg.msg_control,
1164 msg.msg_controllen);
1165 tprintf(", msg_flags=");
1166 printflags(msg_flags, msg.msg_flags, "MSG_???");
1167 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1168 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1169 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
1170 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1174 #endif /* HAVE_SENDMSG */
1180 if (entering(tcp)) {
1181 printxval(domains, tcp->u_arg[0], "PF_???");
1183 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1185 switch (tcp->u_arg[0]) {
1190 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1194 /* BTW: I don't believe this.. */
1196 printxval(domains, tcp->u_arg[2], "PF_???");
1201 tprintf("%lu", tcp->u_arg[2]);
1213 if (entering(tcp)) {
1214 /* not sure really what these args are... but this
1215 * is how truss prints it
1217 tprintf("%ld, %ld, %ld, ",
1218 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1219 printpath(tcp, tcp->u_arg[3]);
1220 tprintf(", %ld", tcp->u_arg[4]);
1226 sys_so_socketpair(tcp)
1229 if (entering(tcp)) {
1230 /* not sure what this arg is */
1231 tprintf("0x%lx", tcp->u_arg[0]);
1241 if (entering(tcp)) {
1242 tprintf("%ld, ", tcp->u_arg[0]);
1243 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1244 tprintf(", %lu", tcp->u_arg[2]);
1253 return sys_bind(tcp);
1260 if (entering(tcp)) {
1261 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1270 if (entering(tcp)) {
1271 tprintf("%ld, ", tcp->u_arg[0]);
1272 } else if (!tcp->u_arg[2])
1273 tprintf("%#lx, NULL", tcp->u_arg[1]);
1275 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
1276 tprintf("%#lx", tcp->u_arg[1]);
1278 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1281 printnum(tcp, tcp->u_arg[2], "%lu");
1290 if (entering(tcp)) {
1291 tprintf("%ld, ", tcp->u_arg[0]);
1292 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1293 tprintf(", %lu, ", tcp->u_arg[2]);
1295 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1304 if (entering(tcp)) {
1305 tprintf("%ld, ", tcp->u_arg[0]);
1306 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1307 tprintf(", %lu, ", tcp->u_arg[2]);
1309 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1312 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1314 tprintf(", %lu", tcp->u_arg[5]);
1325 if (entering(tcp)) {
1326 tprintf("%ld, ", tcp->u_arg[0]);
1327 printmsghdr(tcp, tcp->u_arg[1]);
1330 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1335 #endif /* HAVE_SENDMSG */
1341 if (entering(tcp)) {
1342 tprintf("%ld, ", tcp->u_arg[0]);
1345 tprintf("%#lx", tcp->u_arg[1]);
1347 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1349 tprintf(", %lu, ", tcp->u_arg[2]);
1350 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1361 if (entering(tcp)) {
1362 tprintf("%ld, ", tcp->u_arg[0]);
1364 if (syserror(tcp)) {
1365 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1366 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1367 tcp->u_arg[4], tcp->u_arg[5]);
1371 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1373 tprintf(", %lu, ", tcp->u_arg[2]);
1375 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1376 /* from address, len */
1377 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1378 if (tcp->u_arg[4] == 0)
1381 tprintf(", %#lx", tcp->u_arg[4]);
1382 if (tcp->u_arg[5] == 0)
1385 tprintf(", %#lx", tcp->u_arg[5]);
1388 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1389 tprintf(", {...}, [?]");
1393 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1395 tprintf(", [%u]", fromlen);
1406 if (entering(tcp)) {
1407 tprintf("%ld, ", tcp->u_arg[0]);
1409 if (syserror(tcp) || !verbose(tcp))
1410 tprintf("%#lx", tcp->u_arg[1]);
1412 printmsghdr(tcp, tcp->u_arg[1]);
1415 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1420 #endif /* HAVE_SENDMSG */
1426 if (entering(tcp)) {
1427 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1428 switch (tcp->u_arg[1]) {
1430 tprintf("%s", " /* receive */");
1433 tprintf("%s", " /* send */");
1436 tprintf("%s", " /* send and receive */");
1444 sys_getsockname(tcp)
1447 return sys_accept(tcp);
1451 sys_getpeername(tcp)
1454 return sys_accept(tcp);
1462 #if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1466 if (syserror(tcp)) {
1467 tprintf("%#lx", tcp->u_arg[0]);
1470 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1473 tprintf("[%u, %u]", fds[0], fds[1]);
1475 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
1477 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1490 if (entering(tcp)) {
1491 printxval(domains, tcp->u_arg[0], "PF_???");
1493 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1495 switch (tcp->u_arg[0]) {
1497 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1501 /* BTW: I don't believe this.. */
1503 printxval(domains, tcp->u_arg[2], "PF_???");
1508 tprintf("%lu", tcp->u_arg[2]);
1512 if (syserror(tcp)) {
1513 tprintf(", %#lx", tcp->u_arg[3]);
1517 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1520 tprintf(", [%u, %u]", fds[0], fds[1]);
1522 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1523 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1524 #endif /* SUNOS4 || SVR4 || FREEBSD */
1533 if (entering(tcp)) {
1534 tprintf("%ld, ", tcp->u_arg[0]);
1535 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1537 switch (tcp->u_arg[1]) {
1539 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1543 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1548 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1553 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1558 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1563 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1567 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1568 * etc. still need work */
1570 tprintf("%lu", tcp->u_arg[2]);
1575 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1576 tprintf(", %#lx, %#lx",
1577 tcp->u_arg[3], tcp->u_arg[4]);
1581 switch (tcp->u_arg[1]) {
1583 switch (tcp->u_arg[2]) {
1586 if (len == sizeof (struct linger)) {
1587 struct linger linger;
1592 tprintf(", {onoff=%d, linger=%d}, "
1606 if (len == sizeof (int)) {
1607 printnum(tcp, tcp->u_arg[3], "%ld");
1610 printstr (tcp, tcp->u_arg[3], len);
1612 tprintf(", [%d]", len);
1617 #if defined(ICMP_FILTER)
1618 static void printicmpfilter(tcp, addr)
1622 struct icmp_filter filter;
1628 if (syserror(tcp) || !verbose(tcp)) {
1629 tprintf("%#lx", addr);
1632 if (umove(tcp, addr, &filter) < 0) {
1638 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1641 #endif /* ICMP_FILTER */
1644 printsockopt (tcp, level, name, addr, len)
1651 printxval(socketlayers, level, "SOL_??");
1655 printxval(sockoptions, name, "SO_???");
1657 #if defined(SO_LINGER)
1659 if (len == sizeof (struct linger)) {
1660 struct linger linger;
1661 if (umove (tcp, addr, &linger) < 0)
1663 tprintf(", {onoff=%d, linger=%d}",
1674 printxval(sockipoptions, name, "IP_???");
1679 printxval(sockipv6options, name, "IPV6_???");
1684 printxval(sockipxoptions, name, "IPX_???");
1689 printxval(sockpacketoptions, name, "PACKET_???");
1690 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1695 printxval(socktcpoptions, name, "TCP_???");
1700 printxval(sockrawoptions, name, "RAW_???");
1702 #if defined(ICMP_FILTER)
1705 printicmpfilter(tcp, addr);
1712 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1713 * etc. still need work */
1716 tprintf("%u", name);
1719 /* default arg printing */
1723 if (len == sizeof (int)) {
1724 printnum_int (tcp, addr, "%d");
1727 printstr (tcp, addr, len);
1733 #ifdef HAVE_STRUCT_OPTHDR
1736 print_sock_optmgmt (tcp, addr, len)
1744 while (len >= (int) sizeof hdr) {
1745 if (umove(tcp, addr, &hdr) < 0) break;
1749 else if (len > hdr.len + sizeof hdr) {
1755 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
1763 if (c++) tprintf (", ");
1764 printstr (tcp, addr, len);
1766 if (c > 1) tprintf ("]");
1775 if (entering(tcp)) {
1776 tprintf("%ld, ", tcp->u_arg[0]);
1777 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1778 tcp->u_arg[3], tcp->u_arg[4]);
1779 tprintf(", %lu", tcp->u_arg[4]);
1786 static const struct xlat sock_version[] = {
1787 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1788 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1789 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1790 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1791 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1792 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1798 netlib_call(tcp, func)
1802 if (entering(tcp)) {
1804 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1807 for (i = 0; i < tcp->u_nargs; i++)
1808 tcp->u_arg[i] = tcp->u_arg[i + 1];
1820 return netlib_call (tcp, sys_socket);
1824 sys_xsocketpair(tcp)
1827 return netlib_call (tcp, sys_socketpair);
1834 return netlib_call (tcp, sys_bind);
1841 return netlib_call (tcp, sys_connect);
1848 return netlib_call (tcp, sys_listen);
1855 return netlib_call (tcp, sys_accept);
1862 return netlib_call (tcp, sys_sendmsg);
1869 return netlib_call (tcp, sys_recvmsg);
1873 sys_xgetsockaddr(tcp)
1876 if (entering(tcp)) {
1877 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1879 if (tcp->u_arg[1] == 0) {
1880 tprintf ("LOCALNAME, ");
1882 else if (tcp->u_arg[1] == 1) {
1883 tprintf ("REMOTENAME, ");
1886 tprintf ("%ld, ", tcp->u_arg [1]);
1888 tprintf ("%ld, ", tcp->u_arg [2]);
1891 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1892 tprintf("%#lx", tcp->u_arg[3]);
1894 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1897 printnum(tcp, tcp->u_arg[4], "%lu");
1907 sys_xsetsockaddr(tcp)
1910 return netlib_call (tcp, sys_setsockaddr);
1916 sys_xgetsockopt(tcp)
1919 return netlib_call (tcp, sys_getsockopt);
1923 sys_xsetsockopt(tcp)
1926 return netlib_call (tcp, sys_setsockopt);
1933 return netlib_call (tcp, sys_shutdown);