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.
33 #include <sys/socket.h>
35 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
36 # define in6_addr in6_addr_libc
37 # define ipv6_mreq ipv6_mreq_libc
38 # define sockaddr_in6 sockaddr_in6_libc
40 #include <netinet/in.h>
41 #ifdef HAVE_NETINET_TCP_H
42 # include <netinet/tcp.h>
44 #ifdef HAVE_NETINET_UDP_H
45 # include <netinet/udp.h>
47 #ifdef HAVE_NETINET_SCTP_H
48 # include <netinet/sctp.h>
50 #include <arpa/inet.h>
52 #include <asm/types.h>
53 #if defined(__GLIBC__)
54 # include <netipx/ipx.h>
56 # include <linux/ipx.h>
59 #if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
60 # if defined(HAVE_LINUX_IN6_H)
61 # if defined(HAVE_SIN6_SCOPE_ID_LINUX)
65 # define in6_addr in6_addr_kernel
66 # define ipv6_mreq ipv6_mreq_kernel
67 # define sockaddr_in6 sockaddr_in6_kernel
69 # include <linux/in6.h>
70 # if defined(HAVE_SIN6_SCOPE_ID_LINUX)
74 # define in6_addr in6_addr_libc
75 # define ipv6_mreq ipv6_mreq_libc
76 # define sockaddr_in6 sockaddr_in6_kernel
81 #if defined(HAVE_SYS_UIO_H)
84 #if defined(HAVE_LINUX_NETLINK_H)
85 # include <linux/netlink.h>
87 #if defined(HAVE_LINUX_IF_PACKET_H)
88 # include <linux/if_packet.h>
90 #if defined(HAVE_LINUX_ICMP_H)
91 # include <linux/icmp.h>
94 # define PF_UNSPEC AF_UNSPEC
97 /* Under Linux these are enums so we can't test for them with ifdef. */
98 #define IPPROTO_EGP IPPROTO_EGP
99 #define IPPROTO_PUP IPPROTO_PUP
100 #define IPPROTO_IDP IPPROTO_IDP
101 #define IPPROTO_IGMP IPPROTO_IGMP
102 #define IPPROTO_RAW IPPROTO_RAW
103 #define IPPROTO_MAX IPPROTO_MAX
105 static const struct xlat domains[] = {
107 { PF_AAL5, "PF_AAL5" },
110 { PF_APPLETALK, "PF_APPLETALK" },
113 { PF_ASH, "PF_ASH" },
116 { PF_ATMPVC, "PF_ATMPVC" },
119 { PF_ATMSVC, "PF_ATMSVC" },
122 { PF_AX25, "PF_AX25" },
125 { PF_BLUETOOTH, "PF_BLUETOOTH" },
128 { PF_BRIDGE, "PF_BRIDGE" },
131 { PF_DECnet, "PF_DECnet" },
134 { PF_DECNET, "PF_DECNET" },
137 { PF_ECONET, "PF_ECONET" },
140 { PF_FILE, "PF_FILE" },
143 { PF_IMPLINK, "PF_IMPLINK" },
146 { PF_INET, "PF_INET" },
149 { PF_INET6, "PF_INET6" },
152 { PF_IPX, "PF_IPX" },
155 { PF_IRDA, "PF_IRDA" },
158 { PF_ISO, "PF_ISO" },
161 { PF_KEY, "PF_KEY" },
164 { PF_UNIX, "PF_UNIX" },
167 { PF_LOCAL, "PF_LOCAL" },
170 { PF_NETBEUI, "PF_NETBEUI" },
173 { PF_NETLINK, "PF_NETLINK" },
176 { PF_NETROM, "PF_NETROM" },
179 { PF_PACKET, "PF_PACKET" },
182 { PF_PPPOX, "PF_PPPOX" },
185 { PF_ROSE, "PF_ROSE" },
188 { PF_ROUTE, "PF_ROUTE" },
191 { PF_SECURITY, "PF_SECURITY" },
194 { PF_SNA, "PF_SNA" },
197 { PF_UNSPEC, "PF_UNSPEC" },
200 { PF_WANPIPE, "PF_WANPIPE" },
203 { PF_X25, "PF_X25" },
207 const struct xlat addrfams[] = {
209 { AF_APPLETALK, "AF_APPLETALK" },
212 { AF_ASH, "AF_ASH" },
215 { AF_ATMPVC, "AF_ATMPVC" },
218 { AF_ATMSVC, "AF_ATMSVC" },
221 { AF_AX25, "AF_AX25" },
224 { AF_BLUETOOTH, "AF_BLUETOOTH" },
227 { AF_BRIDGE, "AF_BRIDGE" },
230 { AF_DECnet, "AF_DECnet" },
233 { AF_ECONET, "AF_ECONET" },
236 { AF_FILE, "AF_FILE" },
239 { AF_IMPLINK, "AF_IMPLINK" },
242 { AF_INET, "AF_INET" },
245 { AF_INET6, "AF_INET6" },
248 { AF_IPX, "AF_IPX" },
251 { AF_IRDA, "AF_IRDA" },
254 { AF_ISO, "AF_ISO" },
257 { AF_KEY, "AF_KEY" },
260 { AF_UNIX, "AF_UNIX" },
263 { AF_LOCAL, "AF_LOCAL" },
266 { AF_NETBEUI, "AF_NETBEUI" },
269 { AF_NETLINK, "AF_NETLINK" },
272 { AF_NETROM, "AF_NETROM" },
275 { AF_PACKET, "AF_PACKET" },
278 { AF_PPPOX, "AF_PPPOX" },
281 { AF_ROSE, "AF_ROSE" },
284 { AF_ROUTE, "AF_ROUTE" },
287 { AF_SECURITY, "AF_SECURITY" },
290 { AF_SNA, "AF_SNA" },
293 { AF_UNSPEC, "AF_UNSPEC" },
296 { AF_WANPIPE, "AF_WANPIPE" },
299 { AF_X25, "AF_X25" },
303 static const struct xlat socktypes[] = {
304 { SOCK_STREAM, "SOCK_STREAM" },
305 { SOCK_DGRAM, "SOCK_DGRAM" },
307 { SOCK_RAW, "SOCK_RAW" },
310 { SOCK_RDM, "SOCK_RDM" },
312 #ifdef SOCK_SEQPACKET
313 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
316 { SOCK_DCCP, "SOCK_DCCP" },
319 { SOCK_PACKET, "SOCK_PACKET" },
323 static const struct xlat sock_type_flags[] = {
325 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
328 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
332 #ifndef SOCK_TYPE_MASK
333 # define SOCK_TYPE_MASK 0xf
335 static const struct xlat socketlayers[] = {
337 { SOL_IP, "SOL_IP" },
339 #if defined(SOL_ICMP)
340 { SOL_ICMP, "SOL_ICMP" },
343 { SOL_TCP, "SOL_TCP" },
346 { SOL_UDP, "SOL_UDP" },
348 #if defined(SOL_IPV6)
349 { SOL_IPV6, "SOL_IPV6" },
351 #if defined(SOL_ICMPV6)
352 { SOL_ICMPV6, "SOL_ICMPV6" },
354 #if defined(SOL_SCTP)
355 { SOL_SCTP, "SOL_SCTP" },
357 #if defined(SOL_UDPLITE)
358 { SOL_UDPLITE, "SOL_UDPLITE" },
361 { SOL_RAW, "SOL_RAW" },
364 { SOL_IPX, "SOL_IPX" },
366 #if defined(SOL_AX25)
367 { SOL_AX25, "SOL_AX25" },
369 #if defined(SOL_ATALK)
370 { SOL_ATALK, "SOL_ATALK" },
372 #if defined(SOL_NETROM)
373 { SOL_NETROM, "SOL_NETROM" },
375 #if defined(SOL_ROSE)
376 { SOL_ROSE, "SOL_ROSE" },
378 #if defined(SOL_DECNET)
379 { SOL_DECNET, "SOL_DECNET" },
382 { SOL_X25, "SOL_X25" },
384 #if defined(SOL_PACKET)
385 { SOL_PACKET, "SOL_PACKET" },
388 { SOL_ATM, "SOL_ATM" },
391 { SOL_AAL, "SOL_AAL" },
393 #if defined(SOL_IRDA)
394 { SOL_IRDA, "SOL_IRDA" },
396 #if defined(SOL_NETBEUI)
397 { SOL_NETBEUI, "SOL_NETBEUI" },
400 { SOL_LLC, "SOL_LLC" },
402 #if defined(SOL_DCCP)
403 { SOL_DCCP, "SOL_DCCP" },
405 #if defined(SOL_NETLINK)
406 { SOL_NETLINK, "SOL_NETLINK" },
408 #if defined(SOL_TIPC)
409 { SOL_TIPC, "SOL_TIPC" },
411 #if defined(SOL_RXRPC)
412 { SOL_RXRPC, "SOL_RXRPC" },
414 #if defined(SOL_PPPOL2TP)
415 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
417 #if defined(SOL_BLUETOOTH)
418 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
420 #if defined(SOL_PNPIPE)
421 { SOL_PNPIPE, "SOL_PNPIPE" },
424 { SOL_RDS, "SOL_RDS" },
426 #if defined(SOL_IUVC)
427 { SOL_IUCV, "SOL_IUCV" },
429 #if defined(SOL_CAIF)
430 { SOL_CAIF, "SOL_CAIF" },
432 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
433 /* The SOL_* array should remain not NULL-terminated. */
435 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
436 falls into "protocols" array below!!!! This is intended!!! ***/
437 static const struct xlat protocols[] = {
438 { IPPROTO_IP, "IPPROTO_IP" },
439 { IPPROTO_ICMP, "IPPROTO_ICMP" },
440 { IPPROTO_TCP, "IPPROTO_TCP" },
441 { IPPROTO_UDP, "IPPROTO_UDP" },
443 { IPPROTO_IGMP, "IPPROTO_IGMP" },
446 { IPPROTO_GGP, "IPPROTO_GGP" },
449 { IPPROTO_IPIP, "IPPROTO_IPIP" },
452 { IPPROTO_EGP, "IPPROTO_EGP" },
455 { IPPROTO_PUP, "IPPROTO_PUP" },
458 { IPPROTO_IDP, "IPPROTO_IDP" },
461 { IPPROTO_TP, "IPPROTO_TP" },
464 { IPPROTO_DCCP, "IPPROTO_DCCP" },
467 { IPPROTO_IPV6, "IPPROTO_IPV6" },
469 #ifdef IPPROTO_ROUTING
470 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
472 #ifdef IPPROTO_FRAGMENT
473 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
476 { IPPROTO_RSVP, "IPPROTO_RSVP" },
479 { IPPROTO_GRE, "IPPROTO_GRE" },
482 { IPPROTO_ESP, "IPPROTO_ESP" },
485 { IPPROTO_AH, "IPPROTO_AH" },
487 #ifdef IPPROTO_ICMPV6
488 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
491 { IPPROTO_NONE, "IPPROTO_NONE" },
493 #ifdef IPPROTO_DSTOPTS
494 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
497 { IPPROTO_HELLO, "IPPROTO_HELLO" },
500 { IPPROTO_ND, "IPPROTO_ND" },
503 { IPPROTO_MTP, "IPPROTO_MTP" },
506 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
509 { IPPROTO_PIM, "IPPROTO_PIM" },
512 { IPPROTO_COMP, "IPPROTO_COMP" },
515 { IPPROTO_SCTP, "IPPROTO_SCTP" },
517 #ifdef IPPROTO_UDPLITE
518 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
521 { IPPROTO_RAW, "IPPROTO_RAW" },
524 { IPPROTO_MAX, "IPPROTO_MAX" },
528 static const struct xlat msg_flags[] = {
529 { MSG_OOB, "MSG_OOB" },
531 { MSG_DONTROUTE, "MSG_DONTROUTE" },
534 { MSG_PEEK, "MSG_PEEK" },
537 { MSG_CTRUNC, "MSG_CTRUNC" },
540 { MSG_PROXY, "MSG_PROXY" },
543 { MSG_EOR, "MSG_EOR" },
546 { MSG_WAITALL, "MSG_WAITALL" },
549 { MSG_TRUNC, "MSG_TRUNC" },
552 { MSG_CTRUNC, "MSG_CTRUNC" },
555 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
558 { MSG_DONTWAIT, "MSG_DONTWAIT" },
561 { MSG_CONFIRM, "MSG_CONFIRM" },
564 { MSG_PROBE, "MSG_PROBE" },
567 { MSG_FIN, "MSG_FIN" },
570 { MSG_SYN, "MSG_SYN" },
573 { MSG_RST, "MSG_RST" },
576 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
579 { MSG_MORE, "MSG_MORE" },
581 #ifdef MSG_WAITFORONE
582 { MSG_WAITFORONE, "MSG_WAITFORONE" },
584 #ifdef MSG_CMSG_CLOEXEC
585 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
590 static const struct xlat sockoptions[] = {
592 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
595 { SO_ALLRAW, "SO_ALLRAW" },
597 #ifdef SO_ATTACH_FILTER
598 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
600 #ifdef SO_BINDTODEVICE
601 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
604 { SO_BROADCAST, "SO_BROADCAST" },
607 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
610 { SO_DEBUG, "SO_DEBUG" },
612 #ifdef SO_DETACH_FILTER
613 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
616 { SO_DONTROUTE, "SO_DONTROUTE" },
619 { SO_ERROR, "SO_ERROR" },
622 { SO_ICS, "SO_ICS" },
625 { SO_IMASOCKET, "SO_IMASOCKET" },
628 { SO_KEEPALIVE, "SO_KEEPALIVE" },
631 { SO_LINGER, "SO_LINGER" },
634 { SO_LISTENING, "SO_LISTENING" },
637 { SO_MGMT, "SO_MGMT" },
640 { SO_NO_CHECK, "SO_NO_CHECK" },
643 { SO_OOBINLINE, "SO_OOBINLINE" },
646 { SO_ORDREL, "SO_ORDREL" },
648 #ifdef SO_PARALLELSVR
649 { SO_PARALLELSVR, "SO_PARALLELSVR" },
652 { SO_PASSCRED, "SO_PASSCRED" },
655 { SO_PEERCRED, "SO_PEERCRED" },
658 { SO_PEERNAME, "SO_PEERNAME" },
661 { SO_PEERSEC, "SO_PEERSEC" },
664 { SO_PRIORITY, "SO_PRIORITY" },
667 { SO_PROTOTYPE, "SO_PROTOTYPE" },
670 { SO_RCVBUF, "SO_RCVBUF" },
673 { SO_RCVLOWAT, "SO_RCVLOWAT" },
676 { SO_RCVTIMEO, "SO_RCVTIMEO" },
679 { SO_RDWR, "SO_RDWR" },
682 { SO_REUSEADDR, "SO_REUSEADDR" },
685 { SO_REUSEPORT, "SO_REUSEPORT" },
687 #ifdef SO_SECURITY_AUTHENTICATION
688 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
690 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
691 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
693 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
694 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
697 { SO_SEMA, "SO_SEMA" },
700 { SO_SNDBUF, "SO_SNDBUF" },
703 { SO_SNDLOWAT, "SO_SNDLOWAT" },
706 { SO_SNDTIMEO, "SO_SNDTIMEO" },
709 { SO_TIMESTAMP, "SO_TIMESTAMP" },
712 { SO_TYPE, "SO_TYPE" },
714 #ifdef SO_USELOOPBACK
715 { SO_USELOOPBACK, "SO_USELOOPBACK" },
720 #if !defined(SOL_IP) && defined(IPPROTO_IP)
721 #define SOL_IP IPPROTO_IP
725 static const struct xlat sockipoptions[] = {
727 { IP_TOS, "IP_TOS" },
730 { IP_TTL, "IP_TTL" },
733 { IP_HDRINCL, "IP_HDRINCL" },
736 { IP_OPTIONS, "IP_OPTIONS" },
738 #ifdef IP_ROUTER_ALERT
739 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
741 #ifdef IP_RECVOPTIONS
742 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
745 { IP_RECVOPTS, "IP_RECVOPTS" },
747 #ifdef IP_RECVRETOPTS
748 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
750 #ifdef IP_RECVDSTADDR
751 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
754 { IP_RETOPTS, "IP_RETOPTS" },
757 { IP_PKTINFO, "IP_PKTINFO" },
760 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
762 #ifdef IP_MTU_DISCOVER
763 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
766 { IP_RECVERR, "IP_RECVERR" },
769 { IP_RECVTTL, "IP_RECVTTL" },
772 { IP_RECVTOS, "IP_RECVTOS" },
775 { IP_MTU, "IP_MTU" },
777 #ifdef IP_MULTICAST_IF
778 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
780 #ifdef IP_MULTICAST_TTL
781 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
783 #ifdef IP_MULTICAST_LOOP
784 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
786 #ifdef IP_ADD_MEMBERSHIP
787 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
789 #ifdef IP_DROP_MEMBERSHIP
790 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
792 #ifdef IP_BROADCAST_IF
793 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
795 #ifdef IP_RECVIFINDEX
796 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
799 { IP_MSFILTER, "IP_MSFILTER" },
801 #ifdef MCAST_MSFILTER
802 { MCAST_MSFILTER, "MCAST_MSFILTER" },
805 { IP_FREEBIND, "IP_FREEBIND" },
812 static const struct xlat sockipv6options[] = {
814 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
817 { MCAST_FILTER, "MCAST_FILTER" },
819 #ifdef IPV6_PKTOPTIONS
820 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
823 { IPV6_MTU, "IPV6_MTU" },
826 { IPV6_V6ONLY, "IPV6_V6ONLY" },
829 { IPV6_PKTINFO, "IPV6_PKTINFO" },
832 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
835 { IPV6_RTHDR, "IPV6_RTHDR" },
838 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
841 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
844 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
846 #ifdef IPV6_UNICAST_HOPS
847 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
849 #ifdef IPV6_MULTICAST_HOPS
850 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
852 #ifdef IPV6_MULTICAST_LOOP
853 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
855 #ifdef IPV6_MULTICAST_IF
856 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
858 #ifdef IPV6_MTU_DISCOVER
859 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
862 { IPV6_RECVERR, "IPV6_RECVERR" },
864 #ifdef IPV6_FLOWINFO_SEND
865 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
867 #ifdef IPV6_ADD_MEMBERSHIP
868 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
870 #ifdef IPV6_DROP_MEMBERSHIP
871 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
873 #ifdef IPV6_ROUTER_ALERT
874 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
878 #endif /* SOL_IPV6 */
881 static const struct xlat sockipxoptions[] = {
882 { IPX_TYPE, "IPX_TYPE" },
888 static const struct xlat sockrawoptions[] = {
889 #if defined(ICMP_FILTER)
890 { ICMP_FILTER, "ICMP_FILTER" },
897 static const struct xlat sockpacketoptions[] = {
898 #ifdef PACKET_ADD_MEMBERSHIP
899 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
901 #ifdef PACKET_DROP_MEMBERSHIP
902 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
904 #if defined(PACKET_RECV_OUTPUT)
905 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
907 #if defined(PACKET_RX_RING)
908 { PACKET_RX_RING, "PACKET_RX_RING" },
910 #if defined(PACKET_STATISTICS)
911 { PACKET_STATISTICS, "PACKET_STATISTICS" },
913 #if defined(PACKET_COPY_THRESH)
914 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
916 #if defined(PACKET_AUXDATA)
917 { PACKET_AUXDATA, "PACKET_AUXDATA" },
919 #if defined(PACKET_ORIGDEV)
920 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
922 #if defined(PACKET_VERSION)
923 { PACKET_VERSION, "PACKET_VERSION" },
925 #if defined(PACKET_HDRLEN)
926 { PACKET_HDRLEN, "PACKET_HDRLEN" },
928 #if defined(PACKET_RESERVE)
929 { PACKET_RESERVE, "PACKET_RESERVE" },
931 #if defined(PACKET_TX_RING)
932 { PACKET_TX_RING, "PACKET_TX_RING" },
934 #if defined(PACKET_LOSS)
935 { PACKET_LOSS, "PACKET_LOSS" },
939 #endif /* SOL_PACKET */
942 static const struct xlat socksctpoptions[] = {
943 #if defined(SCTP_RTOINFO)
944 { SCTP_RTOINFO, "SCTP_RTOINFO" },
946 #if defined(SCTP_ASSOCINFO)
947 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
949 #if defined(SCTP_INITMSG)
950 { SCTP_INITMSG, "SCTP_INITMSG" },
952 #if defined(SCTP_NODELAY)
953 { SCTP_NODELAY, "SCTP_NODELAY" },
955 #if defined(SCTP_AUTOCLOSE)
956 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
958 #if defined(SCTP_SET_PEER_PRIMARY_ADDR)
959 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
961 #if defined(SCTP_PRIMARY_ADDR)
962 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
964 #if defined(SCTP_ADAPTATION_LAYER)
965 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
967 #if defined(SCTP_DISABLE_FRAGMENTS)
968 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
970 #if defined(SCTP_PEER_ADDR_PARAMS)
971 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
973 #if defined(SCTP_DEFAULT_SEND_PARAM)
974 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
976 #if defined(SCTP_EVENTS)
977 { SCTP_EVENTS, "SCTP_EVENTS" },
979 #if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
980 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
982 #if defined(SCTP_MAXSEG)
983 { SCTP_MAXSEG, "SCTP_MAXSEG" },
985 #if defined(SCTP_STATUS)
986 { SCTP_STATUS, "SCTP_STATUS" },
988 #if defined(SCTP_GET_PEER_ADDR_INFO)
989 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
991 #if defined(SCTP_DELAYED_ACK)
992 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
994 #if defined(SCTP_CONTEXT)
995 { SCTP_CONTEXT, "SCTP_CONTEXT" },
997 #if defined(SCTP_FRAGMENT_INTERLEAVE)
998 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1000 #if defined(SCTP_PARTIAL_DELIVERY_POINT)
1001 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1003 #if defined(SCTP_MAX_BURST)
1004 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1006 #if defined(SCTP_AUTH_CHUNK)
1007 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1009 #if defined(SCTP_HMAC_IDENT)
1010 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1012 #if defined(SCTP_AUTH_KEY)
1013 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1015 #if defined(SCTP_AUTH_ACTIVE_KEY)
1016 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1018 #if defined(SCTP_AUTH_DELETE_KEY)
1019 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1021 #if defined(SCTP_PEER_AUTH_CHUNKS)
1022 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1024 #if defined(SCTP_LOCAL_AUTH_CHUNKS)
1025 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1027 #if defined(SCTP_GET_ASSOC_NUMBER)
1028 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1031 /* linux specific things */
1032 #if defined(SCTP_SOCKOPT_BINDX_ADD)
1033 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1035 #if defined(SCTP_SOCKOPT_BINDX_REM)
1036 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1038 #if defined(SCTP_SOCKOPT_PEELOFF)
1039 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1041 #if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1042 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1044 #if defined(SCTP_GET_PEER_ADDRS_OLD)
1045 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1047 #if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1048 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1050 #if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1051 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1053 #if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1054 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1056 #if defined(SCTP_GET_PEER_ADDRS)
1057 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1059 #if defined(SCTP_GET_LOCAL_ADDRS)
1060 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1067 #if !defined(SOL_TCP) && defined(IPPROTO_TCP)
1068 #define SOL_TCP IPPROTO_TCP
1072 static const struct xlat socktcpoptions[] = {
1073 { TCP_NODELAY, "TCP_NODELAY" },
1074 { TCP_MAXSEG, "TCP_MAXSEG" },
1075 #if defined(TCP_CORK)
1076 { TCP_CORK, "TCP_CORK" },
1078 #if defined(TCP_KEEPIDLE)
1079 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1081 #if defined(TCP_KEEPINTVL)
1082 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1084 #if defined(TCP_KEEPCNT)
1085 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1087 #if defined(TCP_NKEEP)
1088 { TCP_NKEEP, "TCP_NKEEP" },
1090 #if defined(TCP_SYNCNT)
1091 { TCP_SYNCNT, "TCP_SYNCNT" },
1093 #if defined(TCP_LINGER2)
1094 { TCP_LINGER2, "TCP_LINGER2" },
1096 #if defined(TCP_DEFER_ACCEPT)
1097 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1099 #if defined(TCP_WINDOW_CLAMP)
1100 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1102 #if defined(TCP_INFO)
1103 { TCP_INFO, "TCP_INFO" },
1105 #if defined(TCP_QUICKACK)
1106 { TCP_QUICKACK, "TCP_QUICKACK" },
1108 #if defined(TCP_CONGESTION)
1109 { TCP_CONGESTION, "TCP_CONGESTION" },
1111 #if defined(TCP_MD5SIG)
1112 { TCP_MD5SIG, "TCP_MD5SIG" },
1114 #if defined(TCP_COOKIE_TRANSACTIONS)
1115 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1117 #if defined(TCP_THIN_LINEAR_TIMEOUTS)
1118 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1120 #if defined(TCP_THIN_DUPACK)
1121 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1123 #if defined(TCP_USER_TIMEOUT)
1124 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1128 #endif /* SOL_TCP */
1131 static const struct xlat icmpfilterflags[] = {
1132 #if defined(ICMP_ECHOREPLY)
1133 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1135 #if defined(ICMP_DEST_UNREACH)
1136 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1138 #if defined(ICMP_SOURCE_QUENCH)
1139 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1141 #if defined(ICMP_REDIRECT)
1142 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1144 #if defined(ICMP_ECHO)
1145 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1147 #if defined(ICMP_TIME_EXCEEDED)
1148 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1150 #if defined(ICMP_PARAMETERPROB)
1151 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1153 #if defined(ICMP_TIMESTAMP)
1154 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1156 #if defined(ICMP_TIMESTAMPREPLY)
1157 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1159 #if defined(ICMP_INFO_REQUEST)
1160 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1162 #if defined(ICMP_INFO_REPLY)
1163 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1165 #if defined(ICMP_ADDRESS)
1166 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1168 #if defined(ICMP_ADDRESSREPLY)
1169 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1173 #endif /* SOL_RAW */
1175 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
1176 static const struct xlat af_packet_types[] = {
1177 #if defined(PACKET_HOST)
1178 { PACKET_HOST, "PACKET_HOST" },
1180 #if defined(PACKET_BROADCAST)
1181 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1183 #if defined(PACKET_MULTICAST)
1184 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1186 #if defined(PACKET_OTHERHOST)
1187 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1189 #if defined(PACKET_OUTGOING)
1190 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1192 #if defined(PACKET_LOOPBACK)
1193 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1195 #if defined(PACKET_FASTROUTE)
1196 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1200 #endif /* defined(AF_PACKET) */
1203 printsock(struct tcb *tcp, long addr, int addrlen)
1208 struct sockaddr_in sin;
1209 struct sockaddr_un sau;
1210 #ifdef HAVE_INET_NTOP
1211 struct sockaddr_in6 sa6;
1214 struct sockaddr_ipx sipx;
1217 struct sockaddr_ll ll;
1220 struct sockaddr_nl nl;
1223 char string_addr[100];
1229 if (!verbose(tcp)) {
1230 tprintf("%#lx", addr);
1234 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1235 addrlen = sizeof(addrbuf);
1237 memset(&addrbuf, 0, sizeof(addrbuf));
1238 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
1242 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
1244 tprints("{sa_family=");
1245 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1248 switch (addrbuf.sa.sa_family) {
1252 } else if (addrbuf.sau.sun_path[0]) {
1253 tprints("sun_path=");
1254 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
1256 tprints("sun_path=@");
1257 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
1261 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
1262 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
1264 #ifdef HAVE_INET_NTOP
1266 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
1267 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1268 ntohs(addrbuf.sa6.sin6_port), string_addr,
1269 addrbuf.sa6.sin6_flowinfo);
1270 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1272 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1273 int numericscope = 0;
1274 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1275 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1276 char scopebuf[IFNAMSIZ + 1];
1278 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1281 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1287 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1296 tprintf("sipx_port=htons(%u), ",
1297 ntohs(addrbuf.sipx.sipx_port));
1298 /* Yes, I know, this does not look too
1299 * strace-ish, but otherwise the IPX
1300 * addresses just look monstrous...
1301 * Anyways, feel free if you don't like
1304 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1305 for (i = 0; i < IPX_NODE_LEN; i++)
1306 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1307 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1315 tprintf("proto=%#04x, if%d, pkttype=",
1316 ntohs(addrbuf.ll.sll_protocol),
1317 addrbuf.ll.sll_ifindex);
1318 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1319 tprintf(", addr(%d)={%d, ",
1320 addrbuf.ll.sll_halen,
1321 addrbuf.ll.sll_hatype);
1322 for (i = 0; i < addrbuf.ll.sll_halen; i++)
1323 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1327 #endif /* AF_PACKET */
1330 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1332 #endif /* AF_NETLINK */
1333 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1334 AF_X25 AF_ROSE etc. still need to be done */
1337 tprints("sa_data=");
1338 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1339 sizeof addrbuf.sa.sa_data);
1346 static const struct xlat scmvals[] = {
1348 { SCM_RIGHTS, "SCM_RIGHTS" },
1350 #ifdef SCM_CREDENTIALS
1351 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1357 printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
1359 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1361 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1362 tprintf(", msg_control=%#lx", addr);
1367 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
1368 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1369 tprints(", cmsg_type=");
1371 if (cmsg->cmsg_level == SOL_SOCKET) {
1372 unsigned long cmsg_len;
1374 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1375 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1377 if (cmsg->cmsg_type == SCM_RIGHTS
1378 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1379 int *fds = (int *) CMSG_DATA(cmsg);
1383 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1386 tprintf("%d", *fds++);
1393 if (cmsg->cmsg_type == SCM_CREDENTIALS
1394 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1395 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
1397 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1398 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1408 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
1410 tprintf("{msg_name(%d)=", msg->msg_namelen);
1411 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1413 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1414 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
1415 (unsigned long)msg->msg_iov, 1, data_size);
1417 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1418 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1419 if (msg->msg_controllen)
1420 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1421 msg->msg_controllen);
1422 tprints(", msg_flags=");
1423 printflags(msg_flags, msg->msg_flags, "MSG_???");
1424 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1425 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1426 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1427 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1432 uint32_t /* void* */ msg_name;
1433 uint32_t /* socklen_t */msg_namelen;
1434 uint32_t /* iovec* */ msg_iov;
1435 uint32_t /* size_t */ msg_iovlen;
1436 uint32_t /* void* */ msg_control;
1437 uint32_t /* size_t */ msg_controllen;
1438 uint32_t /* int */ msg_flags;
1441 struct msghdr32 msg_hdr;
1442 uint32_t /* unsigned */ msg_len;
1446 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
1450 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1451 if (current_wordsize == 4) {
1452 struct msghdr32 msg32;
1454 if (umove(tcp, addr, &msg32) < 0) {
1455 tprintf("%#lx", addr);
1458 msg.msg_name = (void*)(long)msg32.msg_name;
1459 msg.msg_namelen = msg32.msg_namelen;
1460 msg.msg_iov = (void*)(long)msg32.msg_iov;
1461 msg.msg_iovlen = msg32.msg_iovlen;
1462 msg.msg_control = (void*)(long)msg32.msg_control;
1463 msg.msg_controllen = msg32.msg_controllen;
1464 msg.msg_flags = msg32.msg_flags;
1467 if (umove(tcp, addr, &msg) < 0) {
1468 tprintf("%#lx", addr);
1471 do_msghdr(tcp, &msg, data_size);
1475 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
1478 struct msghdr msg_hdr;
1482 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1483 if (current_wordsize == 4) {
1484 struct mmsghdr32 mmsg32;
1486 addr += sizeof(mmsg32) * idx;
1487 if (umove(tcp, addr, &mmsg32) < 0) {
1488 tprintf("%#lx", addr);
1491 mmsg.msg_hdr.msg_name = (void*)(long)mmsg32.msg_hdr.msg_name;
1492 mmsg.msg_hdr.msg_namelen = mmsg32.msg_hdr.msg_namelen;
1493 mmsg.msg_hdr.msg_iov = (void*)(long)mmsg32.msg_hdr.msg_iov;
1494 mmsg.msg_hdr.msg_iovlen = mmsg32.msg_hdr.msg_iovlen;
1495 mmsg.msg_hdr.msg_control = (void*)(long)mmsg32.msg_hdr.msg_control;
1496 mmsg.msg_hdr.msg_controllen = mmsg32.msg_hdr.msg_controllen;
1497 mmsg.msg_hdr.msg_flags = mmsg32.msg_hdr.msg_flags;
1498 mmsg.msg_len = mmsg32.msg_len;
1502 addr += sizeof(mmsg) * idx;
1503 if (umove(tcp, addr, &mmsg) < 0) {
1504 tprintf("%#lx", addr);
1509 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
1510 tprintf(", %u}", mmsg.msg_len);
1514 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
1517 if (syserror(tcp)) {
1518 tprintf("%#lx", tcp->u_arg[1]);
1520 unsigned int len = tcp->u_rval;
1524 for (i = 0; i < len; ++i) {
1527 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
1532 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1534 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1537 #endif /* HAVE_SENDMSG */
1540 * low bits of the socket type define real socket type,
1541 * other bits are socket type flags.
1544 tprint_sock_type(struct tcb *tcp, int flags)
1546 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1550 flags &= ~SOCK_TYPE_MASK;
1555 printflags(sock_type_flags, flags, "SOCK_???");
1559 sys_socket(struct tcb *tcp)
1561 if (entering(tcp)) {
1562 printxval(domains, tcp->u_arg[0], "PF_???");
1564 tprint_sock_type(tcp, tcp->u_arg[1]);
1566 switch (tcp->u_arg[0]) {
1571 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1575 /* BTW: I don't believe this.. */
1577 printxval(domains, tcp->u_arg[2], "PF_???");
1582 tprintf("%lu", tcp->u_arg[2]);
1590 sys_bind(struct tcb *tcp)
1592 if (entering(tcp)) {
1593 tprintf("%ld, ", tcp->u_arg[0]);
1594 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1595 tprintf(", %lu", tcp->u_arg[2]);
1601 sys_connect(struct tcb *tcp)
1603 return sys_bind(tcp);
1607 sys_listen(struct tcb *tcp)
1609 if (entering(tcp)) {
1610 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1616 do_accept(struct tcb *tcp, int flags_arg)
1618 if (entering(tcp)) {
1619 tprintf("%ld, ", tcp->u_arg[0]);
1623 tprintf("%#lx, NULL", tcp->u_arg[1]);
1626 if (tcp->u_arg[1] == 0 || syserror(tcp)
1627 || umove(tcp, tcp->u_arg[2], &len) < 0) {
1628 tprintf("%#lx", tcp->u_arg[1]);
1630 printsock(tcp, tcp->u_arg[1], len);
1633 printnum_int(tcp, tcp->u_arg[2], "%u");
1635 if (flags_arg >= 0) {
1637 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1644 sys_accept(struct tcb *tcp)
1646 return do_accept(tcp, -1);
1650 sys_accept4(struct tcb *tcp)
1652 return do_accept(tcp, 3);
1656 sys_send(struct tcb *tcp)
1658 if (entering(tcp)) {
1659 tprintf("%ld, ", tcp->u_arg[0]);
1660 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1661 tprintf(", %lu, ", tcp->u_arg[2]);
1663 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1669 sys_sendto(struct tcb *tcp)
1671 if (entering(tcp)) {
1672 tprintf("%ld, ", tcp->u_arg[0]);
1673 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1674 tprintf(", %lu, ", tcp->u_arg[2]);
1676 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1679 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1681 tprintf(", %lu", tcp->u_arg[5]);
1689 sys_sendmsg(struct tcb *tcp)
1691 if (entering(tcp)) {
1692 tprintf("%ld, ", tcp->u_arg[0]);
1693 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
1696 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1702 sys_sendmmsg(struct tcb *tcp)
1704 if (entering(tcp)) {
1706 tprintf("%d, ", (int) tcp->u_arg[0]);
1707 if (!verbose(tcp)) {
1708 tprintf("%#lx, %u, ",
1709 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
1710 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1714 decode_mmsg(tcp, (unsigned long) -1L);
1719 #endif /* HAVE_SENDMSG */
1722 sys_recv(struct tcb *tcp)
1724 if (entering(tcp)) {
1725 tprintf("%ld, ", tcp->u_arg[0]);
1728 tprintf("%#lx", tcp->u_arg[1]);
1730 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1732 tprintf(", %lu, ", tcp->u_arg[2]);
1733 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1739 sys_recvfrom(struct tcb *tcp)
1743 if (entering(tcp)) {
1744 tprintf("%ld, ", tcp->u_arg[0]);
1746 if (syserror(tcp)) {
1747 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1748 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1749 tcp->u_arg[4], tcp->u_arg[5]);
1753 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1755 tprintf(", %lu, ", tcp->u_arg[2]);
1757 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1758 /* from address, len */
1759 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1760 if (tcp->u_arg[4] == 0)
1763 tprintf(", %#lx", tcp->u_arg[4]);
1764 if (tcp->u_arg[5] == 0)
1767 tprintf(", %#lx", tcp->u_arg[5]);
1770 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1771 tprints(", {...}, [?]");
1775 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1777 tprintf(", [%u]", fromlen);
1785 sys_recvmsg(struct tcb *tcp)
1787 if (entering(tcp)) {
1788 tprintf("%ld, ", tcp->u_arg[0]);
1790 if (syserror(tcp) || !verbose(tcp))
1791 tprintf("%#lx", tcp->u_arg[1]);
1793 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
1796 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1802 sys_recvmmsg(struct tcb *tcp)
1804 /* +5 chars are for "left " prefix */
1805 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
1807 if (entering(tcp)) {
1808 tprintf("%ld, ", tcp->u_arg[0]);
1810 sprint_timespec(str, tcp, tcp->u_arg[4]);
1811 /* Abusing tcp->auxstr as temp storage.
1812 * Will be used and freed on syscall exit.
1814 tcp->auxstr = strdup(str);
1816 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1817 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1819 print_timespec(tcp, tcp->u_arg[4]);
1824 decode_mmsg(tcp, 0);
1825 /* timeout on entrance */
1826 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1827 free((void *) tcp->auxstr);
1832 if (tcp->u_rval == 0) {
1833 tcp->auxstr = "Timeout";
1838 /* timeout on exit */
1839 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
1845 #endif /* HAVE_SENDMSG */
1847 static const struct xlat shutdown_modes[] = {
1855 sys_shutdown(struct tcb *tcp)
1857 if (entering(tcp)) {
1858 tprintf("%ld, ", tcp->u_arg[0]);
1859 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1865 sys_getsockname(struct tcb *tcp)
1867 return sys_accept(tcp);
1871 sys_getpeername(struct tcb *tcp)
1873 return sys_accept(tcp);
1877 do_pipe(struct tcb *tcp, int flags_arg)
1880 if (syserror(tcp)) {
1881 tprintf("%#lx", tcp->u_arg[0]);
1883 #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1886 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1889 tprintf("[%u, %u]", fds[0], fds[1]);
1890 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
1891 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1893 tprintf("%#lx", tcp->u_arg[0]);
1896 if (flags_arg >= 0) {
1898 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1905 sys_pipe(struct tcb *tcp)
1907 return do_pipe(tcp, -1);
1911 sys_pipe2(struct tcb *tcp)
1913 return do_pipe(tcp, 1);
1917 sys_socketpair(struct tcb *tcp)
1921 if (entering(tcp)) {
1922 printxval(domains, tcp->u_arg[0], "PF_???");
1924 tprint_sock_type(tcp, tcp->u_arg[1]);
1926 switch (tcp->u_arg[0]) {
1928 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1932 /* BTW: I don't believe this.. */
1934 printxval(domains, tcp->u_arg[2], "PF_???");
1939 tprintf("%lu", tcp->u_arg[2]);
1943 if (syserror(tcp)) {
1944 tprintf(", %#lx", tcp->u_arg[3]);
1947 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1950 tprintf(", [%u, %u]", fds[0], fds[1]);
1956 sys_getsockopt(struct tcb *tcp)
1958 if (entering(tcp)) {
1959 tprintf("%ld, ", tcp->u_arg[0]);
1960 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1962 switch (tcp->u_arg[1]) {
1964 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1968 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1973 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1978 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1983 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1988 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1993 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1997 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1998 * etc. still need work */
2000 tprintf("%lu", tcp->u_arg[2]);
2006 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
2007 tprintf("%#lx, %#lx",
2008 tcp->u_arg[3], tcp->u_arg[4]);
2012 switch (tcp->u_arg[1]) {
2014 switch (tcp->u_arg[2]) {
2017 if (len == sizeof(struct linger)) {
2018 struct linger linger;
2023 tprintf("{onoff=%d, linger=%d}, "
2034 if (len == sizeof(struct ucred)) {
2040 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2053 switch (tcp->u_arg[2]) {
2054 #ifdef PACKET_STATISTICS
2055 case PACKET_STATISTICS:
2056 if (len == sizeof(struct tpacket_stats)) {
2057 struct tpacket_stats stats;
2062 tprintf("{packets=%u, drops=%u}, "
2075 if (len == sizeof(int)) {
2076 printnum_int(tcp, tcp->u_arg[3], "%d");
2079 printstr(tcp, tcp->u_arg[3], len);
2081 tprintf(", [%d]", len);
2086 #if defined(ICMP_FILTER)
2087 static void printicmpfilter(struct tcb *tcp, long addr)
2089 struct icmp_filter filter;
2095 if (syserror(tcp) || !verbose(tcp)) {
2096 tprintf("%#lx", addr);
2099 if (umove(tcp, addr, &filter) < 0) {
2105 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
2108 #endif /* ICMP_FILTER */
2111 printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
2113 printxval(socketlayers, level, "SOL_??");
2117 printxval(sockoptions, name, "SO_???");
2119 #if defined(SO_LINGER)
2121 if (len == sizeof(struct linger)) {
2122 struct linger linger;
2123 if (umove(tcp, addr, &linger) < 0)
2125 tprintf(", {onoff=%d, linger=%d}",
2136 printxval(sockipoptions, name, "IP_???");
2141 printxval(sockipv6options, name, "IPV6_???");
2146 printxval(sockipxoptions, name, "IPX_???");
2151 printxval(sockpacketoptions, name, "PACKET_???");
2152 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
2154 #ifdef PACKET_RX_RING
2155 case PACKET_RX_RING:
2157 #ifdef PACKET_TX_RING
2158 case PACKET_TX_RING:
2160 #if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2161 if (len == sizeof(struct tpacket_req)) {
2162 struct tpacket_req req;
2163 if (umove(tcp, addr, &req) < 0)
2165 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2173 #endif /* PACKET_RX_RING || PACKET_TX_RING */
2179 printxval(socktcpoptions, name, "TCP_???");
2184 printxval(socksctpoptions, name, "SCTP_???");
2189 printxval(sockrawoptions, name, "RAW_???");
2191 #if defined(ICMP_FILTER)
2194 printicmpfilter(tcp, addr);
2201 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2202 * etc. still need work */
2205 tprintf("%u", name);
2208 /* default arg printing */
2212 if (len == sizeof(int)) {
2213 printnum_int(tcp, addr, "%d");
2216 printstr(tcp, addr, len);
2221 #ifdef HAVE_STRUCT_OPTHDR
2224 print_sock_optmgmt(struct tcb *tcp, long addr, int len)
2229 while (len >= (int) sizeof hdr) {
2230 if (umove(tcp, addr, &hdr) < 0) break;
2234 else if (len > hdr.len + sizeof hdr) {
2240 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
2248 if (c++) tprints(", ");
2249 printstr(tcp, addr, len);
2251 if (c > 1) tprints("]");
2257 sys_setsockopt(struct tcb *tcp)
2259 if (entering(tcp)) {
2260 tprintf("%ld, ", tcp->u_arg[0]);
2261 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
2262 tcp->u_arg[3], tcp->u_arg[4]);
2263 tprintf(", %lu", tcp->u_arg[4]);