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 #ifdef HAVE_NETINET_SCTP_H
53 #include <netinet/sctp.h>
55 #include <arpa/inet.h>
57 #include <asm/types.h>
58 #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
59 # include <netipx/ipx.h>
61 # include <linux/ipx.h>
64 #if defined(__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
65 #if defined(HAVE_LINUX_IN6_H)
66 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
70 #define in6_addr in6_addr_kernel
71 #define ipv6_mreq ipv6_mreq_kernel
72 #define sockaddr_in6 sockaddr_in6_kernel
74 #include <linux/in6.h>
75 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
79 #define in6_addr in6_addr_libc
80 #define ipv6_mreq ipv6_mreq_libc
81 #define sockaddr_in6 sockaddr_in6_kernel
86 #if defined(HAVE_SYS_UIO_H)
90 #if defined(HAVE_LINUX_NETLINK_H)
91 #include <linux/netlink.h>
94 #if defined(HAVE_LINUX_IF_PACKET_H)
95 #include <linux/if_packet.h>
98 #if defined(HAVE_LINUX_ICMP_H)
99 #include <linux/icmp.h>
103 #define PF_UNSPEC AF_UNSPEC
106 /* Under Linux these are enums so we can't test for them with ifdef. */
107 #define IPPROTO_EGP IPPROTO_EGP
108 #define IPPROTO_PUP IPPROTO_PUP
109 #define IPPROTO_IDP IPPROTO_IDP
110 #define IPPROTO_IGMP IPPROTO_IGMP
111 #define IPPROTO_RAW IPPROTO_RAW
112 #define IPPROTO_MAX IPPROTO_MAX
114 static const struct xlat domains[] = {
116 { PF_AAL5, "PF_AAL5" },
119 { PF_APPLETALK, "PF_APPLETALK" },
122 { PF_ASH, "PF_ASH" },
125 { PF_ATMPVC, "PF_ATMPVC" },
128 { PF_ATMSVC, "PF_ATMSVC" },
131 { PF_AX25, "PF_AX25" },
134 { PF_BLUETOOTH, "PF_BLUETOOTH" },
137 { PF_BRIDGE, "PF_BRIDGE" },
140 { PF_DECnet, "PF_DECnet" },
143 { PF_DECNET, "PF_DECNET" },
146 { PF_ECONET, "PF_ECONET" },
149 { PF_FILE, "PF_FILE" },
152 { PF_IMPLINK, "PF_IMPLINK" },
155 { PF_INET, "PF_INET" },
158 { PF_INET6, "PF_INET6" },
161 { PF_IPX, "PF_IPX" },
164 { PF_IRDA, "PF_IRDA" },
167 { PF_ISO, "PF_ISO" },
170 { PF_KEY, "PF_KEY" },
173 { PF_UNIX, "PF_UNIX" },
176 { PF_LOCAL, "PF_LOCAL" },
179 { PF_NETBEUI, "PF_NETBEUI" },
182 { PF_NETLINK, "PF_NETLINK" },
185 { PF_NETROM, "PF_NETROM" },
188 { PF_PACKET, "PF_PACKET" },
191 { PF_PPPOX, "PF_PPPOX" },
194 { PF_ROSE, "PF_ROSE" },
197 { PF_ROUTE, "PF_ROUTE" },
200 { PF_SECURITY, "PF_SECURITY" },
203 { PF_SNA, "PF_SNA" },
206 { PF_UNSPEC, "PF_UNSPEC" },
209 { PF_WANPIPE, "PF_WANPIPE" },
212 { PF_X25, "PF_X25" },
216 const struct xlat addrfams[] = {
218 { AF_APPLETALK, "AF_APPLETALK" },
221 { AF_ASH, "AF_ASH" },
224 { AF_ATMPVC, "AF_ATMPVC" },
227 { AF_ATMSVC, "AF_ATMSVC" },
230 { AF_AX25, "AF_AX25" },
233 { AF_BLUETOOTH, "AF_BLUETOOTH" },
236 { AF_BRIDGE, "AF_BRIDGE" },
239 { AF_DECnet, "AF_DECnet" },
242 { AF_ECONET, "AF_ECONET" },
245 { AF_FILE, "AF_FILE" },
248 { AF_IMPLINK, "AF_IMPLINK" },
251 { AF_INET, "AF_INET" },
254 { AF_INET6, "AF_INET6" },
257 { AF_IPX, "AF_IPX" },
260 { AF_IRDA, "AF_IRDA" },
263 { AF_ISO, "AF_ISO" },
266 { AF_KEY, "AF_KEY" },
269 { AF_UNIX, "AF_UNIX" },
272 { AF_LOCAL, "AF_LOCAL" },
275 { AF_NETBEUI, "AF_NETBEUI" },
278 { AF_NETLINK, "AF_NETLINK" },
281 { AF_NETROM, "AF_NETROM" },
284 { AF_PACKET, "AF_PACKET" },
287 { AF_PPPOX, "AF_PPPOX" },
290 { AF_ROSE, "AF_ROSE" },
293 { AF_ROUTE, "AF_ROUTE" },
296 { AF_SECURITY, "AF_SECURITY" },
299 { AF_SNA, "AF_SNA" },
302 { AF_UNSPEC, "AF_UNSPEC" },
305 { AF_WANPIPE, "AF_WANPIPE" },
308 { AF_X25, "AF_X25" },
312 static const struct xlat socktypes[] = {
313 { SOCK_STREAM, "SOCK_STREAM" },
314 { SOCK_DGRAM, "SOCK_DGRAM" },
316 { SOCK_RAW, "SOCK_RAW" },
319 { SOCK_RDM, "SOCK_RDM" },
321 #ifdef SOCK_SEQPACKET
322 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
325 { SOCK_DCCP, "SOCK_DCCP" },
328 { SOCK_PACKET, "SOCK_PACKET" },
332 static const struct xlat sock_type_flags[] = {
334 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
337 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
341 #ifndef SOCK_TYPE_MASK
342 # define SOCK_TYPE_MASK 0xf
344 static const struct xlat socketlayers[] = {
346 { SOL_IP, "SOL_IP" },
348 #if defined(SOL_ICMP)
349 { SOL_ICMP, "SOL_ICMP" },
352 { SOL_TCP, "SOL_TCP" },
355 { SOL_UDP, "SOL_UDP" },
357 #if defined(SOL_IPV6)
358 { SOL_IPV6, "SOL_IPV6" },
360 #if defined(SOL_ICMPV6)
361 { SOL_ICMPV6, "SOL_ICMPV6" },
363 #if defined(SOL_SCTP)
364 { SOL_SCTP, "SOL_SCTP" },
366 #if defined(SOL_UDPLITE)
367 { SOL_UDPLITE, "SOL_UDPLITE" },
370 { SOL_RAW, "SOL_RAW" },
373 { SOL_IPX, "SOL_IPX" },
375 #if defined(SOL_AX25)
376 { SOL_AX25, "SOL_AX25" },
378 #if defined(SOL_ATALK)
379 { SOL_ATALK, "SOL_ATALK" },
381 #if defined(SOL_NETROM)
382 { SOL_NETROM, "SOL_NETROM" },
384 #if defined(SOL_ROSE)
385 { SOL_ROSE, "SOL_ROSE" },
387 #if defined(SOL_DECNET)
388 { SOL_DECNET, "SOL_DECNET" },
391 { SOL_X25, "SOL_X25" },
393 #if defined(SOL_PACKET)
394 { SOL_PACKET, "SOL_PACKET" },
397 { SOL_ATM, "SOL_ATM" },
400 { SOL_AAL, "SOL_AAL" },
402 #if defined(SOL_IRDA)
403 { SOL_IRDA, "SOL_IRDA" },
405 #if defined(SOL_NETBEUI)
406 { SOL_NETBEUI, "SOL_NETBEUI" },
409 { SOL_LLC, "SOL_LLC" },
411 #if defined(SOL_DCCP)
412 { SOL_DCCP, "SOL_DCCP" },
414 #if defined(SOL_NETLINK)
415 { SOL_NETLINK, "SOL_NETLINK" },
417 #if defined(SOL_TIPC)
418 { SOL_TIPC, "SOL_TIPC" },
420 #if defined(SOL_RXRPC)
421 { SOL_RXRPC, "SOL_RXRPC" },
423 #if defined(SOL_PPPOL2TP)
424 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
426 #if defined(SOL_BLUETOOTH)
427 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
429 #if defined(SOL_PNPIPE)
430 { SOL_PNPIPE, "SOL_PNPIPE" },
433 { SOL_RDS, "SOL_RDS" },
435 #if defined(SOL_IUVC)
436 { SOL_IUCV, "SOL_IUCV" },
438 #if defined(SOL_CAIF)
439 { SOL_CAIF, "SOL_CAIF" },
441 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
442 /* The SOL_* array should remain not NULL-terminated. */
444 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
445 falls into "protocols" array below!!!! This is intended!!! ***/
446 static const struct xlat protocols[] = {
447 { IPPROTO_IP, "IPPROTO_IP" },
448 { IPPROTO_ICMP, "IPPROTO_ICMP" },
449 { IPPROTO_TCP, "IPPROTO_TCP" },
450 { IPPROTO_UDP, "IPPROTO_UDP" },
452 { IPPROTO_IGMP, "IPPROTO_IGMP" },
455 { IPPROTO_GGP, "IPPROTO_GGP" },
458 { IPPROTO_IPIP, "IPPROTO_IPIP" },
461 { IPPROTO_EGP, "IPPROTO_EGP" },
464 { IPPROTO_PUP, "IPPROTO_PUP" },
467 { IPPROTO_IDP, "IPPROTO_IDP" },
470 { IPPROTO_TP, "IPPROTO_TP" },
473 { IPPROTO_DCCP, "IPPROTO_DCCP" },
476 { IPPROTO_IPV6, "IPPROTO_IPV6" },
478 #ifdef IPPROTO_ROUTING
479 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
481 #ifdef IPPROTO_FRAGMENT
482 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
485 { IPPROTO_RSVP, "IPPROTO_RSVP" },
488 { IPPROTO_GRE, "IPPROTO_GRE" },
491 { IPPROTO_ESP, "IPPROTO_ESP" },
494 { IPPROTO_AH, "IPPROTO_AH" },
496 #ifdef IPPROTO_ICMPV6
497 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
500 { IPPROTO_NONE, "IPPROTO_NONE" },
502 #ifdef IPPROTO_DSTOPTS
503 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
506 { IPPROTO_HELLO, "IPPROTO_HELLO" },
509 { IPPROTO_ND, "IPPROTO_ND" },
512 { IPPROTO_MTP, "IPPROTO_MTP" },
515 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
518 { IPPROTO_PIM, "IPPROTO_PIM" },
521 { IPPROTO_COMP, "IPPROTO_COMP" },
524 { IPPROTO_SCTP, "IPPROTO_SCTP" },
526 #ifdef IPPROTO_UDPLITE
527 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
530 { IPPROTO_RAW, "IPPROTO_RAW" },
533 { IPPROTO_MAX, "IPPROTO_MAX" },
537 static const struct xlat msg_flags[] = {
538 { MSG_OOB, "MSG_OOB" },
540 { MSG_DONTROUTE, "MSG_DONTROUTE" },
543 { MSG_PEEK, "MSG_PEEK" },
546 { MSG_CTRUNC, "MSG_CTRUNC" },
549 { MSG_PROXY, "MSG_PROXY" },
552 { MSG_EOR, "MSG_EOR" },
555 { MSG_WAITALL, "MSG_WAITALL" },
558 { MSG_TRUNC, "MSG_TRUNC" },
561 { MSG_CTRUNC, "MSG_CTRUNC" },
564 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
567 { MSG_DONTWAIT, "MSG_DONTWAIT" },
570 { MSG_CONFIRM, "MSG_CONFIRM" },
573 { MSG_PROBE, "MSG_PROBE" },
576 { MSG_FIN, "MSG_FIN" },
579 { MSG_SYN, "MSG_SYN" },
582 { MSG_RST, "MSG_RST" },
585 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
588 { MSG_MORE, "MSG_MORE" },
590 #ifdef MSG_CMSG_CLOEXEC
591 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
596 static const struct xlat sockoptions[] = {
598 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
601 { SO_ALLRAW, "SO_ALLRAW" },
603 #ifdef SO_ATTACH_FILTER
604 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
606 #ifdef SO_BINDTODEVICE
607 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
610 { SO_BROADCAST, "SO_BROADCAST" },
613 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
616 { SO_DEBUG, "SO_DEBUG" },
618 #ifdef SO_DETACH_FILTER
619 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
622 { SO_DONTROUTE, "SO_DONTROUTE" },
625 { SO_ERROR, "SO_ERROR" },
628 { SO_ICS, "SO_ICS" },
631 { SO_IMASOCKET, "SO_IMASOCKET" },
634 { SO_KEEPALIVE, "SO_KEEPALIVE" },
637 { SO_LINGER, "SO_LINGER" },
640 { SO_LISTENING, "SO_LISTENING" },
643 { SO_MGMT, "SO_MGMT" },
646 { SO_NO_CHECK, "SO_NO_CHECK" },
649 { SO_OOBINLINE, "SO_OOBINLINE" },
652 { SO_ORDREL, "SO_ORDREL" },
654 #ifdef SO_PARALLELSVR
655 { SO_PARALLELSVR, "SO_PARALLELSVR" },
658 { SO_PASSCRED, "SO_PASSCRED" },
661 { SO_PEERCRED, "SO_PEERCRED" },
664 { SO_PEERNAME, "SO_PEERNAME" },
667 { SO_PEERSEC, "SO_PEERSEC" },
670 { SO_PRIORITY, "SO_PRIORITY" },
673 { SO_PROTOTYPE, "SO_PROTOTYPE" },
676 { SO_RCVBUF, "SO_RCVBUF" },
679 { SO_RCVLOWAT, "SO_RCVLOWAT" },
682 { SO_RCVTIMEO, "SO_RCVTIMEO" },
685 { SO_RDWR, "SO_RDWR" },
688 { SO_REUSEADDR, "SO_REUSEADDR" },
691 { SO_REUSEPORT, "SO_REUSEPORT" },
693 #ifdef SO_SECURITY_AUTHENTICATION
694 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
696 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
697 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
699 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
700 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
703 { SO_SEMA, "SO_SEMA" },
706 { SO_SNDBUF, "SO_SNDBUF" },
709 { SO_SNDLOWAT, "SO_SNDLOWAT" },
712 { SO_SNDTIMEO, "SO_SNDTIMEO" },
715 { SO_TIMESTAMP, "SO_TIMESTAMP" },
718 { SO_TYPE, "SO_TYPE" },
720 #ifdef SO_USELOOPBACK
721 { SO_USELOOPBACK, "SO_USELOOPBACK" },
726 #if !defined(SOL_IP) && defined(IPPROTO_IP)
727 #define SOL_IP IPPROTO_IP
731 static const struct xlat sockipoptions[] = {
733 { IP_TOS, "IP_TOS" },
736 { IP_TTL, "IP_TTL" },
739 { IP_HDRINCL, "IP_HDRINCL" },
742 { IP_OPTIONS, "IP_OPTIONS" },
744 #ifdef IP_ROUTER_ALERT
745 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
747 #ifdef IP_RECVOPTIONS
748 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
751 { IP_RECVOPTS, "IP_RECVOPTS" },
753 #ifdef IP_RECVRETOPTS
754 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
756 #ifdef IP_RECVDSTADDR
757 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
760 { IP_RETOPTS, "IP_RETOPTS" },
763 { IP_PKTINFO, "IP_PKTINFO" },
766 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
768 #ifdef IP_MTU_DISCOVER
769 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
772 { IP_RECVERR, "IP_RECVERR" },
775 { IP_RECVTTL, "IP_RECVTTL" },
778 { IP_RECVTOS, "IP_RECVTOS" },
781 { IP_MTU, "IP_MTU" },
783 #ifdef IP_MULTICAST_IF
784 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
786 #ifdef IP_MULTICAST_TTL
787 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
789 #ifdef IP_MULTICAST_LOOP
790 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
792 #ifdef IP_ADD_MEMBERSHIP
793 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
795 #ifdef IP_DROP_MEMBERSHIP
796 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
798 #ifdef IP_BROADCAST_IF
799 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
801 #ifdef IP_RECVIFINDEX
802 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
805 { IP_MSFILTER, "IP_MSFILTER" },
807 #ifdef MCAST_MSFILTER
808 { MCAST_MSFILTER, "MCAST_MSFILTER" },
811 { IP_FREEBIND, "IP_FREEBIND" },
818 static const struct xlat sockipv6options[] = {
820 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
823 { MCAST_FILTER, "MCAST_FILTER" },
825 #ifdef IPV6_PKTOPTIONS
826 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
829 { IPV6_MTU, "IPV6_MTU" },
832 { IPV6_V6ONLY, "IPV6_V6ONLY" },
835 { IPV6_PKTINFO, "IPV6_PKTINFO" },
838 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
841 { IPV6_RTHDR, "IPV6_RTHDR" },
844 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
847 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
850 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
852 #ifdef IPV6_UNICAST_HOPS
853 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
855 #ifdef IPV6_MULTICAST_HOPS
856 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
858 #ifdef IPV6_MULTICAST_LOOP
859 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
861 #ifdef IPV6_MULTICAST_IF
862 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
864 #ifdef IPV6_MTU_DISCOVER
865 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
868 { IPV6_RECVERR, "IPV6_RECVERR" },
870 #ifdef IPV6_FLOWINFO_SEND
871 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
873 #ifdef IPV6_ADD_MEMBERSHIP
874 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
876 #ifdef IPV6_DROP_MEMBERSHIP
877 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
879 #ifdef IPV6_ROUTER_ALERT
880 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
884 #endif /* SOL_IPV6 */
887 static const struct xlat sockipxoptions[] = {
888 { IPX_TYPE, "IPX_TYPE" },
894 static const struct xlat sockrawoptions[] = {
895 #if defined(ICMP_FILTER)
896 { ICMP_FILTER, "ICMP_FILTER" },
903 static const struct xlat sockpacketoptions[] = {
904 #ifdef PACKET_ADD_MEMBERSHIP
905 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
907 #ifdef PACKET_DROP_MEMBERSHIP
908 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
910 #if defined(PACKET_RECV_OUTPUT)
911 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
913 #if defined(PACKET_RX_RING)
914 { PACKET_RX_RING, "PACKET_RX_RING" },
916 #if defined(PACKET_STATISTICS)
917 { PACKET_STATISTICS, "PACKET_STATISTICS" },
919 #if defined(PACKET_COPY_THRESH)
920 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
922 #if defined(PACKET_AUXDATA)
923 { PACKET_AUXDATA, "PACKET_AUXDATA" },
925 #if defined(PACKET_ORIGDEV)
926 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
928 #if defined(PACKET_VERSION)
929 { PACKET_VERSION, "PACKET_VERSION" },
931 #if defined(PACKET_HDRLEN)
932 { PACKET_HDRLEN, "PACKET_HDRLEN" },
934 #if defined(PACKET_RESERVE)
935 { PACKET_RESERVE, "PACKET_RESERVE" },
937 #if defined(PACKET_TX_RING)
938 { PACKET_TX_RING, "PACKET_TX_RING" },
940 #if defined(PACKET_LOSS)
941 { PACKET_LOSS, "PACKET_LOSS" },
945 #endif /* SOL_PACKET */
948 static const struct xlat socksctpoptions[] = {
949 #if defined(SCTP_RTOINFO)
950 { SCTP_RTOINFO, "SCTP_RTOINFO" },
952 #if defined(SCTP_ASSOCINFO)
953 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
955 #if defined(SCTP_INITMSG)
956 { SCTP_INITMSG, "SCTP_INITMSG" },
958 #if defined(SCTP_NODELAY)
959 { SCTP_NODELAY, "SCTP_NODELAY" },
961 #if defined(SCTP_AUTOCLOSE)
962 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
964 #if defined(SCTP_SET_PEER_PRIMARY_ADDR)
965 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
967 #if defined(SCTP_PRIMARY_ADDR)
968 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
970 #if defined(SCTP_ADAPTATION_LAYER)
971 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
973 #if defined(SCTP_DISABLE_FRAGMENTS)
974 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
976 #if defined(SCTP_PEER_ADDR_PARAMS)
977 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
979 #if defined(SCTP_DEFAULT_SEND_PARAM)
980 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
982 #if defined(SCTP_EVENTS)
983 { SCTP_EVENTS, "SCTP_EVENTS" },
985 #if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
986 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
988 #if defined(SCTP_MAXSEG)
989 { SCTP_MAXSEG, "SCTP_MAXSEG" },
991 #if defined(SCTP_STATUS)
992 { SCTP_STATUS, "SCTP_STATUS" },
994 #if defined(SCTP_GET_PEER_ADDR_INFO)
995 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
997 #if defined(SCTP_DELAYED_ACK)
998 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1000 #if defined(SCTP_CONTEXT)
1001 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1003 #if defined(SCTP_FRAGMENT_INTERLEAVE)
1004 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1006 #if defined(SCTP_PARTIAL_DELIVERY_POINT)
1007 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1009 #if defined(SCTP_MAX_BURST)
1010 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1012 #if defined(SCTP_AUTH_CHUNK)
1013 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1015 #if defined(SCTP_HMAC_IDENT)
1016 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1018 #if defined(SCTP_AUTH_KEY)
1019 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1021 #if defined(SCTP_AUTH_ACTIVE_KEY)
1022 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1024 #if defined(SCTP_AUTH_DELETE_KEY)
1025 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1027 #if defined(SCTP_PEER_AUTH_CHUNKS)
1028 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1030 #if defined(SCTP_LOCAL_AUTH_CHUNKS)
1031 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1033 #if defined(SCTP_GET_ASSOC_NUMBER)
1034 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1037 /* linux specific things */
1038 #if defined(SCTP_SOCKOPT_BINDX_ADD)
1039 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1041 #if defined(SCTP_SOCKOPT_BINDX_REM)
1042 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1044 #if defined(SCTP_SOCKOPT_PEELOFF)
1045 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1047 #if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1048 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1050 #if defined(SCTP_GET_PEER_ADDRS_OLD)
1051 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1053 #if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1054 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1056 #if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1057 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1059 #if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1060 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1062 #if defined(SCTP_GET_PEER_ADDRS)
1063 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1065 #if defined(SCTP_GET_LOCAL_ADDRS)
1066 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1073 #if !defined(SOL_TCP) && defined(IPPROTO_TCP)
1074 #define SOL_TCP IPPROTO_TCP
1078 static const struct xlat socktcpoptions[] = {
1079 { TCP_NODELAY, "TCP_NODELAY" },
1080 { TCP_MAXSEG, "TCP_MAXSEG" },
1081 #if defined(TCP_CORK)
1082 { TCP_CORK, "TCP_CORK" },
1084 #if defined(TCP_KEEPIDLE)
1085 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1087 #if defined(TCP_KEEPINTVL)
1088 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1090 #if defined(TCP_KEEPCNT)
1091 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1093 #if defined(TCP_NKEEP)
1094 { TCP_NKEEP, "TCP_NKEEP" },
1096 #if defined(TCP_SYNCNT)
1097 { TCP_SYNCNT, "TCP_SYNCNT" },
1099 #if defined(TCP_LINGER2)
1100 { TCP_LINGER2, "TCP_LINGER2" },
1102 #if defined(TCP_DEFER_ACCEPT)
1103 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1105 #if defined(TCP_WINDOW_CLAMP)
1106 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1108 #if defined(TCP_INFO)
1109 { TCP_INFO, "TCP_INFO" },
1111 #if defined(TCP_QUICKACK)
1112 { TCP_QUICKACK, "TCP_QUICKACK" },
1114 #if defined(TCP_CONGESTION)
1115 { TCP_CONGESTION, "TCP_CONGESTION" },
1117 #if defined(TCP_MD5SIG)
1118 { TCP_MD5SIG, "TCP_MD5SIG" },
1120 #if defined(TCP_COOKIE_TRANSACTIONS)
1121 { TCP_COOKIE_TRANSACTIONS, "TCP_COOKIE_TRANSACTIONS" },
1123 #if defined(TCP_THIN_LINEAR_TIMEOUTS)
1124 { TCP_THIN_LINEAR_TIMEOUTS, "TCP_THIN_LINEAR_TIMEOUTS" },
1126 #if defined(TCP_THIN_DUPACK)
1127 { TCP_THIN_DUPACK, "TCP_THIN_DUPACK" },
1129 #if defined(TCP_USER_TIMEOUT)
1130 { TCP_USER_TIMEOUT, "TCP_USER_TIMEOUT" },
1134 #endif /* SOL_TCP */
1137 static const struct xlat icmpfilterflags[] = {
1138 #if defined(ICMP_ECHOREPLY)
1139 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1141 #if defined(ICMP_DEST_UNREACH)
1142 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1144 #if defined(ICMP_SOURCE_QUENCH)
1145 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1147 #if defined(ICMP_REDIRECT)
1148 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1150 #if defined(ICMP_ECHO)
1151 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1153 #if defined(ICMP_TIME_EXCEEDED)
1154 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1156 #if defined(ICMP_PARAMETERPROB)
1157 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1159 #if defined(ICMP_TIMESTAMP)
1160 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1162 #if defined(ICMP_TIMESTAMPREPLY)
1163 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1165 #if defined(ICMP_INFO_REQUEST)
1166 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1168 #if defined(ICMP_INFO_REPLY)
1169 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1171 #if defined(ICMP_ADDRESS)
1172 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1174 #if defined(ICMP_ADDRESSREPLY)
1175 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1179 #endif /* SOL_RAW */
1181 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
1182 static const struct xlat af_packet_types[] = {
1183 #if defined(PACKET_HOST)
1184 { PACKET_HOST, "PACKET_HOST" },
1186 #if defined(PACKET_BROADCAST)
1187 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1189 #if defined(PACKET_MULTICAST)
1190 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1192 #if defined(PACKET_OTHERHOST)
1193 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1195 #if defined(PACKET_OUTGOING)
1196 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1198 #if defined(PACKET_LOOPBACK)
1199 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1201 #if defined(PACKET_FASTROUTE)
1202 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1206 #endif /* defined(AF_PACKET) */
1209 printsock(struct tcb *tcp, long addr, int addrlen)
1214 struct sockaddr_in sin;
1215 struct sockaddr_un sau;
1216 #ifdef HAVE_INET_NTOP
1217 struct sockaddr_in6 sa6;
1220 struct sockaddr_ipx sipx;
1223 struct sockaddr_ll ll;
1226 struct sockaddr_nl nl;
1229 char string_addr[100];
1235 if (!verbose(tcp)) {
1236 tprintf("%#lx", addr);
1240 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1241 addrlen = sizeof(addrbuf);
1243 memset(&addrbuf, 0, sizeof(addrbuf));
1244 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
1248 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
1250 tprints("{sa_family=");
1251 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1254 switch (addrbuf.sa.sa_family) {
1258 } else if (addrbuf.sau.sun_path[0]) {
1259 tprints("sun_path=");
1260 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
1262 tprints("sun_path=@");
1263 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
1267 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
1268 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
1270 #ifdef HAVE_INET_NTOP
1272 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
1273 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1274 ntohs(addrbuf.sa6.sin6_port), string_addr,
1275 addrbuf.sa6.sin6_flowinfo);
1276 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1278 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1279 int numericscope = 0;
1280 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1281 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1282 char scopebuf[IFNAMSIZ + 1];
1284 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1287 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1293 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1302 tprintf("sipx_port=htons(%u), ",
1303 ntohs(addrbuf.sipx.sipx_port));
1304 /* Yes, I know, this does not look too
1305 * strace-ish, but otherwise the IPX
1306 * addresses just look monstrous...
1307 * Anyways, feel free if you don't like
1310 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1311 for (i = 0; i < IPX_NODE_LEN; i++)
1312 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1313 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1321 tprintf("proto=%#04x, if%d, pkttype=",
1322 ntohs(addrbuf.ll.sll_protocol),
1323 addrbuf.ll.sll_ifindex);
1324 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1325 tprintf(", addr(%d)={%d, ",
1326 addrbuf.ll.sll_halen,
1327 addrbuf.ll.sll_hatype);
1328 for (i = 0; i < addrbuf.ll.sll_halen; i++)
1329 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1333 #endif /* AF_PACKET */
1336 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1338 #endif /* AF_NETLINK */
1339 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1340 AF_X25 AF_ROSE etc. still need to be done */
1343 tprints("sa_data=");
1344 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1345 sizeof addrbuf.sa.sa_data);
1352 static const struct xlat scmvals[] = {
1354 { SCM_RIGHTS, "SCM_RIGHTS" },
1356 #ifdef SCM_CREDENTIALS
1357 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1363 printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
1365 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1367 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1368 tprintf(", msg_control=%#lx", addr);
1373 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
1374 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1375 tprints(", cmsg_type=");
1377 if (cmsg->cmsg_level == SOL_SOCKET) {
1378 unsigned long cmsg_len;
1380 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1381 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1383 if (cmsg->cmsg_type == SCM_RIGHTS
1384 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1385 int *fds = (int *) CMSG_DATA(cmsg);
1389 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1392 tprintf("%d", *fds++);
1399 if (cmsg->cmsg_type == SCM_CREDENTIALS
1400 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1401 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
1403 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1404 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1414 do_msghdr(struct tcb *tcp, struct msghdr *msg)
1416 tprintf("{msg_name(%d)=", msg->msg_namelen);
1417 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1419 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1420 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
1421 (unsigned long)msg->msg_iov, 1);
1423 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1424 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1425 if (msg->msg_controllen)
1426 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1427 msg->msg_controllen);
1428 tprints(", msg_flags=");
1429 printflags(msg_flags, msg->msg_flags, "MSG_???");
1430 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1431 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1432 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1433 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1438 printmsghdr(struct tcb *tcp, long addr)
1442 if (umove(tcp, addr, &msg) < 0) {
1443 tprintf("%#lx", addr);
1446 do_msghdr(tcp, &msg);
1450 printmmsghdr(struct tcb *tcp, long addr)
1453 struct msghdr msg_hdr;
1457 if (umove(tcp, addr, &mmsg) < 0) {
1458 tprintf("%#lx", addr);
1462 do_msghdr(tcp, &mmsg.msg_hdr);
1463 tprintf(", %u}", mmsg.msg_len);
1466 #endif /* HAVE_SENDMSG */
1469 * low bits of the socket type define real socket type,
1470 * other bits are socket type flags.
1473 tprint_sock_type(struct tcb *tcp, int flags)
1475 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1479 flags &= ~SOCK_TYPE_MASK;
1484 printflags(sock_type_flags, flags, "SOCK_???");
1488 sys_socket(struct tcb *tcp)
1490 if (entering(tcp)) {
1491 printxval(domains, tcp->u_arg[0], "PF_???");
1493 tprint_sock_type(tcp, tcp->u_arg[1]);
1495 switch (tcp->u_arg[0]) {
1500 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1504 /* BTW: I don't believe this.. */
1506 printxval(domains, tcp->u_arg[2], "PF_???");
1511 tprintf("%lu", tcp->u_arg[2]);
1519 sys_bind(struct tcb *tcp)
1521 if (entering(tcp)) {
1522 tprintf("%ld, ", tcp->u_arg[0]);
1523 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1524 tprintf(", %lu", tcp->u_arg[2]);
1530 sys_connect(struct tcb *tcp)
1532 return sys_bind(tcp);
1536 sys_listen(struct tcb *tcp)
1538 if (entering(tcp)) {
1539 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1545 do_accept(struct tcb *tcp, int flags_arg)
1547 if (entering(tcp)) {
1548 tprintf("%ld, ", tcp->u_arg[0]);
1552 tprintf("%#lx, NULL", tcp->u_arg[1]);
1555 if (tcp->u_arg[1] == 0 || syserror(tcp)
1556 || umove(tcp, tcp->u_arg[2], &len) < 0) {
1557 tprintf("%#lx", tcp->u_arg[1]);
1559 printsock(tcp, tcp->u_arg[1], len);
1562 printnum_int(tcp, tcp->u_arg[2], "%u");
1564 if (flags_arg >= 0) {
1566 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1573 sys_accept(struct tcb *tcp)
1575 return do_accept(tcp, -1);
1579 sys_accept4(struct tcb *tcp)
1581 return do_accept(tcp, 3);
1585 sys_send(struct tcb *tcp)
1587 if (entering(tcp)) {
1588 tprintf("%ld, ", tcp->u_arg[0]);
1589 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1590 tprintf(", %lu, ", tcp->u_arg[2]);
1592 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1598 sys_sendto(struct tcb *tcp)
1600 if (entering(tcp)) {
1601 tprintf("%ld, ", tcp->u_arg[0]);
1602 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1603 tprintf(", %lu, ", tcp->u_arg[2]);
1605 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1608 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1610 tprintf(", %lu", tcp->u_arg[5]);
1618 sys_sendmsg(struct tcb *tcp)
1620 if (entering(tcp)) {
1621 tprintf("%ld, ", tcp->u_arg[0]);
1622 printmsghdr(tcp, tcp->u_arg[1]);
1625 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1630 #endif /* HAVE_SENDMSG */
1633 sys_recv(struct tcb *tcp)
1635 if (entering(tcp)) {
1636 tprintf("%ld, ", tcp->u_arg[0]);
1639 tprintf("%#lx", tcp->u_arg[1]);
1641 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1643 tprintf(", %lu, ", tcp->u_arg[2]);
1644 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1650 sys_recvfrom(struct tcb *tcp)
1654 if (entering(tcp)) {
1655 tprintf("%ld, ", tcp->u_arg[0]);
1657 if (syserror(tcp)) {
1658 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1659 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1660 tcp->u_arg[4], tcp->u_arg[5]);
1664 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1666 tprintf(", %lu, ", tcp->u_arg[2]);
1668 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1669 /* from address, len */
1670 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1671 if (tcp->u_arg[4] == 0)
1674 tprintf(", %#lx", tcp->u_arg[4]);
1675 if (tcp->u_arg[5] == 0)
1678 tprintf(", %#lx", tcp->u_arg[5]);
1681 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1682 tprints(", {...}, [?]");
1686 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1688 tprintf(", [%u]", fromlen);
1696 sys_recvmsg(struct tcb *tcp)
1698 if (entering(tcp)) {
1699 tprintf("%ld, ", tcp->u_arg[0]);
1701 if (syserror(tcp) || !verbose(tcp))
1702 tprintf("%#lx", tcp->u_arg[1]);
1704 printmsghdr(tcp, tcp->u_arg[1]);
1707 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1713 sys_recvmmsg(struct tcb *tcp)
1715 /* +5 chars are for "left " prefix */
1716 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
1718 if (entering(tcp)) {
1719 tprintf("%ld, ", tcp->u_arg[0]);
1721 sprint_timespec(str, tcp, tcp->u_arg[4]);
1722 /* Abusing tcp->auxstr as temp storage.
1723 * Will be used and freed on syscall exit.
1725 tcp->auxstr = strdup(str);
1727 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1728 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1730 print_timespec(tcp, tcp->u_arg[4]);
1736 tprintf("%#lx", tcp->u_arg[1]);
1738 printmmsghdr(tcp, tcp->u_arg[1]);
1739 tprintf(", %ld, ", tcp->u_arg[2]);
1741 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1742 /* timeout on entrance */
1743 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1744 free((void *) tcp->auxstr);
1749 if (tcp->u_rval == 0) {
1750 tcp->auxstr = "Timeout";
1755 /* timeout on exit */
1756 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
1762 #endif /* HAVE_SENDMSG */
1764 static const struct xlat shutdown_modes[] = {
1772 sys_shutdown(struct tcb *tcp)
1774 if (entering(tcp)) {
1775 tprintf("%ld, ", tcp->u_arg[0]);
1776 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1782 sys_getsockname(struct tcb *tcp)
1784 return sys_accept(tcp);
1788 sys_getpeername(struct tcb *tcp)
1790 return sys_accept(tcp);
1794 do_pipe(struct tcb *tcp, int flags_arg)
1797 if (syserror(tcp)) {
1798 tprintf("%#lx", tcp->u_arg[0]);
1800 #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1803 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1806 tprintf("[%u, %u]", fds[0], fds[1]);
1807 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
1808 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1810 tprintf("%#lx", tcp->u_arg[0]);
1813 if (flags_arg >= 0) {
1815 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1822 sys_pipe(struct tcb *tcp)
1824 return do_pipe(tcp, -1);
1828 sys_pipe2(struct tcb *tcp)
1830 return do_pipe(tcp, 1);
1834 sys_socketpair(struct tcb *tcp)
1838 if (entering(tcp)) {
1839 printxval(domains, tcp->u_arg[0], "PF_???");
1841 tprint_sock_type(tcp, tcp->u_arg[1]);
1843 switch (tcp->u_arg[0]) {
1845 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1849 /* BTW: I don't believe this.. */
1851 printxval(domains, tcp->u_arg[2], "PF_???");
1856 tprintf("%lu", tcp->u_arg[2]);
1860 if (syserror(tcp)) {
1861 tprintf(", %#lx", tcp->u_arg[3]);
1864 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1867 tprintf(", [%u, %u]", fds[0], fds[1]);
1873 sys_getsockopt(struct tcb *tcp)
1875 if (entering(tcp)) {
1876 tprintf("%ld, ", tcp->u_arg[0]);
1877 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1879 switch (tcp->u_arg[1]) {
1881 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1885 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1890 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1895 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1900 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1905 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1910 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1914 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1915 * etc. still need work */
1917 tprintf("%lu", tcp->u_arg[2]);
1923 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1924 tprintf("%#lx, %#lx",
1925 tcp->u_arg[3], tcp->u_arg[4]);
1929 switch (tcp->u_arg[1]) {
1931 switch (tcp->u_arg[2]) {
1934 if (len == sizeof(struct linger)) {
1935 struct linger linger;
1940 tprintf("{onoff=%d, linger=%d}, "
1951 if (len == sizeof(struct ucred)) {
1957 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1970 switch (tcp->u_arg[2]) {
1971 #ifdef PACKET_STATISTICS
1972 case PACKET_STATISTICS:
1973 if (len == sizeof(struct tpacket_stats)) {
1974 struct tpacket_stats stats;
1979 tprintf("{packets=%u, drops=%u}, "
1992 if (len == sizeof(int)) {
1993 printnum_int(tcp, tcp->u_arg[3], "%d");
1996 printstr(tcp, tcp->u_arg[3], len);
1998 tprintf(", [%d]", len);
2003 #if defined(ICMP_FILTER)
2004 static void printicmpfilter(struct tcb *tcp, long addr)
2006 struct icmp_filter filter;
2012 if (syserror(tcp) || !verbose(tcp)) {
2013 tprintf("%#lx", addr);
2016 if (umove(tcp, addr, &filter) < 0) {
2022 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
2025 #endif /* ICMP_FILTER */
2028 printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
2030 printxval(socketlayers, level, "SOL_??");
2034 printxval(sockoptions, name, "SO_???");
2036 #if defined(SO_LINGER)
2038 if (len == sizeof(struct linger)) {
2039 struct linger linger;
2040 if (umove(tcp, addr, &linger) < 0)
2042 tprintf(", {onoff=%d, linger=%d}",
2053 printxval(sockipoptions, name, "IP_???");
2058 printxval(sockipv6options, name, "IPV6_???");
2063 printxval(sockipxoptions, name, "IPX_???");
2068 printxval(sockpacketoptions, name, "PACKET_???");
2069 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
2071 #ifdef PACKET_RX_RING
2072 case PACKET_RX_RING:
2074 #ifdef PACKET_TX_RING
2075 case PACKET_TX_RING:
2077 #if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2078 if (len == sizeof(struct tpacket_req)) {
2079 struct tpacket_req req;
2080 if (umove(tcp, addr, &req) < 0)
2082 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2090 #endif /* PACKET_RX_RING || PACKET_TX_RING */
2096 printxval(socktcpoptions, name, "TCP_???");
2101 printxval(socksctpoptions, name, "SCTP_???");
2106 printxval(sockrawoptions, name, "RAW_???");
2108 #if defined(ICMP_FILTER)
2111 printicmpfilter(tcp, addr);
2118 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2119 * etc. still need work */
2122 tprintf("%u", name);
2125 /* default arg printing */
2129 if (len == sizeof(int)) {
2130 printnum_int(tcp, addr, "%d");
2133 printstr(tcp, addr, len);
2138 #ifdef HAVE_STRUCT_OPTHDR
2141 print_sock_optmgmt(struct tcb *tcp, long addr, int len)
2146 while (len >= (int) sizeof hdr) {
2147 if (umove(tcp, addr, &hdr) < 0) break;
2151 else if (len > hdr.len + sizeof hdr) {
2157 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
2165 if (c++) tprints(", ");
2166 printstr(tcp, addr, len);
2168 if (c > 1) tprints("]");
2174 sys_setsockopt(struct tcb *tcp)
2176 if (entering(tcp)) {
2177 tprintf("%ld, ", tcp->u_arg[0]);
2178 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
2179 tcp->u_arg[3], tcp->u_arg[4]);
2180 tprintf(", %lu", tcp->u_arg[4]);