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>
58 #include <asm/types.h>
59 #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
60 # include <netipx/ipx.h>
62 # include <linux/ipx.h>
66 #if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
67 #if defined(HAVE_LINUX_IN6_H)
68 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
72 #define in6_addr in6_addr_kernel
73 #define ipv6_mreq ipv6_mreq_kernel
74 #define sockaddr_in6 sockaddr_in6_kernel
76 #include <linux/in6.h>
77 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
81 #define in6_addr in6_addr_libc
82 #define ipv6_mreq ipv6_mreq_libc
83 #define sockaddr_in6 sockaddr_in6_kernel
88 #if defined(HAVE_SYS_UIO_H)
92 #if defined(HAVE_LINUX_NETLINK_H)
93 #include <linux/netlink.h>
96 #if defined(HAVE_LINUX_IF_PACKET_H)
97 #include <linux/if_packet.h>
100 #if defined(HAVE_LINUX_ICMP_H)
101 #include <linux/icmp.h>
105 #define PF_UNSPEC AF_UNSPEC
109 #define HAVE_SENDMSG 1 /* HACK - *FIXME* */
113 /* Under Linux these are enums so we can't test for them with ifdef. */
114 #define IPPROTO_EGP IPPROTO_EGP
115 #define IPPROTO_PUP IPPROTO_PUP
116 #define IPPROTO_IDP IPPROTO_IDP
117 #define IPPROTO_IGMP IPPROTO_IGMP
118 #define IPPROTO_RAW IPPROTO_RAW
119 #define IPPROTO_MAX IPPROTO_MAX
122 static const struct xlat domains[] = {
124 { PF_AAL5, "PF_AAL5" },
127 { PF_APPLETALK, "PF_APPLETALK" },
130 { PF_ASH, "PF_ASH" },
133 { PF_ATMPVC, "PF_ATMPVC" },
136 { PF_ATMSVC, "PF_ATMSVC" },
139 { PF_AX25, "PF_AX25" },
142 { PF_BLUETOOTH, "PF_BLUETOOTH" },
145 { PF_BRIDGE, "PF_BRIDGE" },
148 { PF_DECnet, "PF_DECnet" },
151 { PF_DECNET, "PF_DECNET" },
154 { PF_ECONET, "PF_ECONET" },
157 { PF_FILE, "PF_FILE" },
160 { PF_IMPLINK, "PF_IMPLINK" },
163 { PF_INET, "PF_INET" },
166 { PF_INET6, "PF_INET6" },
169 { PF_IPX, "PF_IPX" },
172 { PF_IRDA, "PF_IRDA" },
175 { PF_ISO, "PF_ISO" },
178 { PF_KEY, "PF_KEY" },
181 { PF_UNIX, "PF_UNIX" },
184 { PF_LOCAL, "PF_LOCAL" },
187 { PF_NETBEUI, "PF_NETBEUI" },
190 { PF_NETLINK, "PF_NETLINK" },
193 { PF_NETROM, "PF_NETROM" },
196 { PF_PACKET, "PF_PACKET" },
199 { PF_PPPOX, "PF_PPPOX" },
202 { PF_ROSE, "PF_ROSE" },
205 { PF_ROUTE, "PF_ROUTE" },
208 { PF_SECURITY, "PF_SECURITY" },
211 { PF_SNA, "PF_SNA" },
214 { PF_UNSPEC, "PF_UNSPEC" },
217 { PF_WANPIPE, "PF_WANPIPE" },
220 { PF_X25, "PF_X25" },
224 const struct xlat addrfams[] = {
226 { AF_APPLETALK, "AF_APPLETALK" },
229 { AF_ASH, "AF_ASH" },
232 { AF_ATMPVC, "AF_ATMPVC" },
235 { AF_ATMSVC, "AF_ATMSVC" },
238 { AF_AX25, "AF_AX25" },
241 { AF_BLUETOOTH, "AF_BLUETOOTH" },
244 { AF_BRIDGE, "AF_BRIDGE" },
247 { AF_DECnet, "AF_DECnet" },
250 { AF_ECONET, "AF_ECONET" },
253 { AF_FILE, "AF_FILE" },
256 { AF_IMPLINK, "AF_IMPLINK" },
259 { AF_INET, "AF_INET" },
262 { AF_INET6, "AF_INET6" },
265 { AF_IPX, "AF_IPX" },
268 { AF_IRDA, "AF_IRDA" },
271 { AF_ISO, "AF_ISO" },
274 { AF_KEY, "AF_KEY" },
277 { AF_UNIX, "AF_UNIX" },
280 { AF_LOCAL, "AF_LOCAL" },
283 { AF_NETBEUI, "AF_NETBEUI" },
286 { AF_NETLINK, "AF_NETLINK" },
289 { AF_NETROM, "AF_NETROM" },
292 { AF_PACKET, "AF_PACKET" },
295 { AF_PPPOX, "AF_PPPOX" },
298 { AF_ROSE, "AF_ROSE" },
301 { AF_ROUTE, "AF_ROUTE" },
304 { AF_SECURITY, "AF_SECURITY" },
307 { AF_SNA, "AF_SNA" },
310 { AF_UNSPEC, "AF_UNSPEC" },
313 { AF_WANPIPE, "AF_WANPIPE" },
316 { AF_X25, "AF_X25" },
320 static const struct xlat socktypes[] = {
321 { SOCK_STREAM, "SOCK_STREAM" },
322 { SOCK_DGRAM, "SOCK_DGRAM" },
324 { SOCK_RAW, "SOCK_RAW" },
327 { SOCK_RDM, "SOCK_RDM" },
329 #ifdef SOCK_SEQPACKET
330 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
333 { SOCK_DCCP, "SOCK_DCCP" },
336 { SOCK_PACKET, "SOCK_PACKET" },
340 static const struct xlat sock_type_flags[] = {
342 { SOCK_CLOEXEC, "SOCK_CLOEXEC" },
345 { SOCK_NONBLOCK,"SOCK_NONBLOCK" },
349 #ifndef SOCK_TYPE_MASK
350 # define SOCK_TYPE_MASK 0xf
352 static const struct xlat socketlayers[] = {
354 { SOL_IP, "SOL_IP" },
356 #if defined(SOL_ICMP)
357 { SOL_ICMP, "SOL_ICMP" },
360 { SOL_TCP, "SOL_TCP" },
363 { SOL_UDP, "SOL_UDP" },
365 #if defined(SOL_IPV6)
366 { SOL_IPV6, "SOL_IPV6" },
368 #if defined(SOL_ICMPV6)
369 { SOL_ICMPV6, "SOL_ICMPV6" },
371 #if defined(SOL_SCTP)
372 { SOL_SCTP, "SOL_SCTP" },
374 #if defined(SOL_UDPLITE)
375 { SOL_UDPLITE, "SOL_UDPLITE" },
378 { SOL_RAW, "SOL_RAW" },
381 { SOL_IPX, "SOL_IPX" },
383 #if defined(SOL_AX25)
384 { SOL_AX25, "SOL_AX25" },
386 #if defined(SOL_ATALK)
387 { SOL_ATALK, "SOL_ATALK" },
389 #if defined(SOL_NETROM)
390 { SOL_NETROM, "SOL_NETROM" },
392 #if defined(SOL_ROSE)
393 { SOL_ROSE, "SOL_ROSE" },
395 #if defined(SOL_DECNET)
396 { SOL_DECNET, "SOL_DECNET" },
399 { SOL_X25, "SOL_X25" },
401 #if defined(SOL_PACKET)
402 { SOL_PACKET, "SOL_PACKET" },
405 { SOL_ATM, "SOL_ATM" },
408 { SOL_AAL, "SOL_AAL" },
410 #if defined(SOL_IRDA)
411 { SOL_IRDA, "SOL_IRDA" },
413 #if defined(SOL_NETBEUI)
414 { SOL_NETBEUI, "SOL_NETBEUI" },
417 { SOL_LLC, "SOL_LLC" },
419 #if defined(SOL_DCCP)
420 { SOL_DCCP, "SOL_DCCP" },
422 #if defined(SOL_NETLINK)
423 { SOL_NETLINK, "SOL_NETLINK" },
425 #if defined(SOL_TIPC)
426 { SOL_TIPC, "SOL_TIPC" },
428 #if defined(SOL_RXRPC)
429 { SOL_RXRPC, "SOL_RXRPC" },
431 #if defined(SOL_PPPOL2TP)
432 { SOL_PPPOL2TP, "SOL_PPPOL2TP" },
434 #if defined(SOL_BLUETOOTH)
435 { SOL_BLUETOOTH,"SOL_BLUETOOTH" },
437 #if defined(SOL_PNPIPE)
438 { SOL_PNPIPE, "SOL_PNPIPE" },
441 { SOL_RDS, "SOL_RDS" },
443 #if defined(SOL_IUVC)
444 { SOL_IUCV, "SOL_IUCV" },
446 #if defined(SOL_CAIF)
447 { SOL_CAIF, "SOL_CAIF" },
449 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
450 /* The SOL_* array should remain not NULL-terminated. */
452 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
453 falls into "protocols" array below!!!! This is intended!!! ***/
454 static const struct xlat protocols[] = {
455 { IPPROTO_IP, "IPPROTO_IP" },
456 { IPPROTO_ICMP, "IPPROTO_ICMP" },
457 { IPPROTO_TCP, "IPPROTO_TCP" },
458 { IPPROTO_UDP, "IPPROTO_UDP" },
460 { IPPROTO_IGMP, "IPPROTO_IGMP" },
463 { IPPROTO_GGP, "IPPROTO_GGP" },
466 { IPPROTO_IPIP, "IPPROTO_IPIP" },
469 { IPPROTO_EGP, "IPPROTO_EGP" },
472 { IPPROTO_PUP, "IPPROTO_PUP" },
475 { IPPROTO_IDP, "IPPROTO_IDP" },
478 { IPPROTO_TP, "IPPROTO_TP" },
481 { IPPROTO_DCCP, "IPPROTO_DCCP" },
484 { IPPROTO_IPV6, "IPPROTO_IPV6" },
486 #ifdef IPPROTO_ROUTING
487 { IPPROTO_ROUTING, "IPPROTO_ROUTING" },
489 #ifdef IPPROTO_FRAGMENT
490 { IPPROTO_FRAGMENT, "IPPROTO_FRAGMENT" },
493 { IPPROTO_RSVP, "IPPROTO_RSVP" },
496 { IPPROTO_GRE, "IPPROTO_GRE" },
499 { IPPROTO_ESP, "IPPROTO_ESP" },
502 { IPPROTO_AH, "IPPROTO_AH" },
504 #ifdef IPPROTO_ICMPV6
505 { IPPROTO_ICMPV6, "IPPROTO_ICMPV6" },
508 { IPPROTO_NONE, "IPPROTO_NONE" },
510 #ifdef IPPROTO_DSTOPTS
511 { IPPROTO_DSTOPTS, "IPPROTO_DSTOPTS" },
514 { IPPROTO_HELLO, "IPPROTO_HELLO" },
517 { IPPROTO_ND, "IPPROTO_ND" },
520 { IPPROTO_MTP, "IPPROTO_MTP" },
523 { IPPROTO_ENCAP, "IPPROTO_ENCAP" },
526 { IPPROTO_PIM, "IPPROTO_PIM" },
529 { IPPROTO_COMP, "IPPROTO_COMP" },
532 { IPPROTO_SCTP, "IPPROTO_SCTP" },
534 #ifdef IPPROTO_UDPLITE
535 { IPPROTO_UDPLITE, "IPPROTO_UDPLITE" },
538 { IPPROTO_RAW, "IPPROTO_RAW" },
541 { IPPROTO_MAX, "IPPROTO_MAX" },
545 static const struct xlat msg_flags[] = {
546 { MSG_OOB, "MSG_OOB" },
548 { MSG_DONTROUTE, "MSG_DONTROUTE" },
551 { MSG_PEEK, "MSG_PEEK" },
554 { MSG_CTRUNC, "MSG_CTRUNC" },
557 { MSG_PROXY, "MSG_PROXY" },
560 { MSG_EOR, "MSG_EOR" },
563 { MSG_WAITALL, "MSG_WAITALL" },
566 { MSG_TRUNC, "MSG_TRUNC" },
569 { MSG_CTRUNC, "MSG_CTRUNC" },
572 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
575 { MSG_DONTWAIT, "MSG_DONTWAIT" },
578 { MSG_CONFIRM, "MSG_CONFIRM" },
581 { MSG_PROBE, "MSG_PROBE" },
584 { MSG_FIN, "MSG_FIN" },
587 { MSG_SYN, "MSG_SYN" },
590 { MSG_RST, "MSG_RST" },
593 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
596 { MSG_MORE, "MSG_MORE" },
598 #ifdef MSG_CMSG_CLOEXEC
599 { MSG_CMSG_CLOEXEC, "MSG_CMSG_CLOEXEC" },
604 static const struct xlat sockoptions[] = {
606 { SO_ACCEPTCONN, "SO_ACCEPTCONN" },
609 { SO_ALLRAW, "SO_ALLRAW" },
611 #ifdef SO_ATTACH_FILTER
612 { SO_ATTACH_FILTER, "SO_ATTACH_FILTER" },
614 #ifdef SO_BINDTODEVICE
615 { SO_BINDTODEVICE, "SO_BINDTODEVICE" },
618 { SO_BROADCAST, "SO_BROADCAST" },
621 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
624 { SO_DEBUG, "SO_DEBUG" },
626 #ifdef SO_DETACH_FILTER
627 { SO_DETACH_FILTER, "SO_DETACH_FILTER" },
630 { SO_DONTROUTE, "SO_DONTROUTE" },
633 { SO_ERROR, "SO_ERROR" },
636 { SO_ICS, "SO_ICS" },
639 { SO_IMASOCKET, "SO_IMASOCKET" },
642 { SO_KEEPALIVE, "SO_KEEPALIVE" },
645 { SO_LINGER, "SO_LINGER" },
648 { SO_LISTENING, "SO_LISTENING" },
651 { SO_MGMT, "SO_MGMT" },
654 { SO_NO_CHECK, "SO_NO_CHECK" },
657 { SO_OOBINLINE, "SO_OOBINLINE" },
660 { SO_ORDREL, "SO_ORDREL" },
662 #ifdef SO_PARALLELSVR
663 { SO_PARALLELSVR, "SO_PARALLELSVR" },
666 { SO_PASSCRED, "SO_PASSCRED" },
669 { SO_PEERCRED, "SO_PEERCRED" },
672 { SO_PEERNAME, "SO_PEERNAME" },
675 { SO_PEERSEC, "SO_PEERSEC" },
678 { SO_PRIORITY, "SO_PRIORITY" },
681 { SO_PROTOTYPE, "SO_PROTOTYPE" },
684 { SO_RCVBUF, "SO_RCVBUF" },
687 { SO_RCVLOWAT, "SO_RCVLOWAT" },
690 { SO_RCVTIMEO, "SO_RCVTIMEO" },
693 { SO_RDWR, "SO_RDWR" },
696 { SO_REUSEADDR, "SO_REUSEADDR" },
699 { SO_REUSEPORT, "SO_REUSEPORT" },
701 #ifdef SO_SECURITY_AUTHENTICATION
702 { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
704 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
705 { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
707 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
708 { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
711 { SO_SEMA, "SO_SEMA" },
714 { SO_SNDBUF, "SO_SNDBUF" },
717 { SO_SNDLOWAT, "SO_SNDLOWAT" },
720 { SO_SNDTIMEO, "SO_SNDTIMEO" },
723 { SO_TIMESTAMP, "SO_TIMESTAMP" },
726 { SO_TYPE, "SO_TYPE" },
728 #ifdef SO_USELOOPBACK
729 { SO_USELOOPBACK, "SO_USELOOPBACK" },
734 #if !defined (SOL_IP) && defined (IPPROTO_IP)
735 #define SOL_IP IPPROTO_IP
739 static const struct xlat sockipoptions[] = {
741 { IP_TOS, "IP_TOS" },
744 { IP_TTL, "IP_TTL" },
747 { IP_HDRINCL, "IP_HDRINCL" },
750 { IP_OPTIONS, "IP_OPTIONS" },
752 #ifdef IP_ROUTER_ALERT
753 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
755 #ifdef IP_RECVOPTIONS
756 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
759 { IP_RECVOPTS, "IP_RECVOPTS" },
761 #ifdef IP_RECVRETOPTS
762 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
764 #ifdef IP_RECVDSTADDR
765 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
768 { IP_RETOPTS, "IP_RETOPTS" },
771 { IP_PKTINFO, "IP_PKTINFO" },
774 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
776 #ifdef IP_MTU_DISCOVER
777 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
780 { IP_RECVERR, "IP_RECVERR" },
783 { IP_RECVTTL, "IP_RECVTTL" },
786 { IP_RECVTOS, "IP_RECVTOS" },
789 { IP_MTU, "IP_MTU" },
791 #ifdef IP_MULTICAST_IF
792 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
794 #ifdef IP_MULTICAST_TTL
795 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
797 #ifdef IP_MULTICAST_LOOP
798 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
800 #ifdef IP_ADD_MEMBERSHIP
801 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
803 #ifdef IP_DROP_MEMBERSHIP
804 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
806 #ifdef IP_BROADCAST_IF
807 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
809 #ifdef IP_RECVIFINDEX
810 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
813 { IP_MSFILTER, "IP_MSFILTER" },
815 #ifdef MCAST_MSFILTER
816 { MCAST_MSFILTER, "MCAST_MSFILTER" },
819 { IP_FREEBIND, "IP_FREEBIND" },
826 static const struct xlat sockipv6options[] = {
828 { IPV6_ADDRFORM, "IPV6_ADDRFORM" },
831 { MCAST_FILTER, "MCAST_FILTER" },
833 #ifdef IPV6_PKTOPTIONS
834 { IPV6_PKTOPTIONS, "IPV6_PKTOPTIONS" },
837 { IPV6_MTU, "IPV6_MTU" },
840 { IPV6_V6ONLY, "IPV6_V6ONLY" },
843 { IPV6_PKTINFO, "IPV6_PKTINFO" },
846 { IPV6_HOPLIMIT, "IPV6_HOPLIMIT" },
849 { IPV6_RTHDR, "IPV6_RTHDR" },
852 { IPV6_HOPOPTS, "IPV6_HOPOPTS" },
855 { IPV6_DSTOPTS, "IPV6_DSTOPTS" },
858 { IPV6_FLOWINFO, "IPV6_FLOWINFO" },
860 #ifdef IPV6_UNICAST_HOPS
861 { IPV6_UNICAST_HOPS, "IPV6_UNICAST_HOPS" },
863 #ifdef IPV6_MULTICAST_HOPS
864 { IPV6_MULTICAST_HOPS, "IPV6_MULTICAST_HOPS" },
866 #ifdef IPV6_MULTICAST_LOOP
867 { IPV6_MULTICAST_LOOP, "IPV6_MULTICAST_LOOP" },
869 #ifdef IPV6_MULTICAST_IF
870 { IPV6_MULTICAST_IF, "IPV6_MULTICAST_IF" },
872 #ifdef IPV6_MTU_DISCOVER
873 { IPV6_MTU_DISCOVER, "IPV6_MTU_DISCOVER" },
876 { IPV6_RECVERR, "IPV6_RECVERR" },
878 #ifdef IPV6_FLOWINFO_SEND
879 { IPV6_FLOWINFO_SEND, "IPV6_FLOWINFO_SEND" },
881 #ifdef IPV6_ADD_MEMBERSHIP
882 { IPV6_ADD_MEMBERSHIP, "IPV6_ADD_MEMBERSHIP" },
884 #ifdef IPV6_DROP_MEMBERSHIP
885 { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP" },
887 #ifdef IPV6_ROUTER_ALERT
888 { IPV6_ROUTER_ALERT, "IPV6_ROUTER_ALERT" },
892 #endif /* SOL_IPV6 */
895 static const struct xlat sockipxoptions[] = {
896 { IPX_TYPE, "IPX_TYPE" },
902 static const struct xlat sockrawoptions[] = {
903 #if defined(ICMP_FILTER)
904 { ICMP_FILTER, "ICMP_FILTER" },
911 static const struct xlat sockpacketoptions[] = {
912 #ifdef PACKET_ADD_MEMBERSHIP
913 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
915 #ifdef PACKET_DROP_MEMBERSHIP
916 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
918 #if defined(PACKET_RECV_OUTPUT)
919 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
921 #if defined(PACKET_RX_RING)
922 { PACKET_RX_RING, "PACKET_RX_RING" },
924 #if defined(PACKET_STATISTICS)
925 { PACKET_STATISTICS, "PACKET_STATISTICS" },
927 #if defined(PACKET_COPY_THRESH)
928 { PACKET_COPY_THRESH, "PACKET_COPY_THRESH" },
930 #if defined(PACKET_AUXDATA)
931 { PACKET_AUXDATA, "PACKET_AUXDATA" },
933 #if defined(PACKET_ORIGDEV)
934 { PACKET_ORIGDEV, "PACKET_ORIGDEV" },
936 #if defined(PACKET_VERSION)
937 { PACKET_VERSION, "PACKET_VERSION" },
939 #if defined(PACKET_HDRLEN)
940 { PACKET_HDRLEN, "PACKET_HDRLEN" },
942 #if defined(PACKET_RESERVE)
943 { PACKET_RESERVE, "PACKET_RESERVE" },
945 #if defined(PACKET_TX_RING)
946 { PACKET_TX_RING, "PACKET_TX_RING" },
948 #if defined(PACKET_LOSS)
949 { PACKET_LOSS, "PACKET_LOSS" },
953 #endif /* SOL_PACKET */
956 static const struct xlat socksctpoptions[] = {
957 #if defined(SCTP_RTOINFO)
958 { SCTP_RTOINFO, "SCTP_RTOINFO" },
960 #if defined(SCTP_ASSOCINFO)
961 { SCTP_ASSOCINFO, "SCTP_ASSOCINFO"},
963 #if defined(SCTP_INITMSG)
964 { SCTP_INITMSG, "SCTP_INITMSG" },
966 #if defined(SCTP_NODELAY)
967 { SCTP_NODELAY, "SCTP_NODELAY" },
969 #if defined(SCTP_AUTOCLOSE)
970 { SCTP_AUTOCLOSE, "SCTP_AUTOCLOSE"},
972 #if defined(SCTP_SET_PEER_PRIMARY_ADDR)
973 { SCTP_SET_PEER_PRIMARY_ADDR, "SCTP_SET_PEER_PRIMARY_ADDR"},
975 #if defined(SCTP_PRIMARY_ADDR)
976 { SCTP_PRIMARY_ADDR, "SCTP_PRIMARY_ADDR" },
978 #if defined(SCTP_ADAPTATION_LAYER)
979 { SCTP_ADAPTATION_LAYER, "SCTP_ADAPTATION_LAYER" },
981 #if defined(SCTP_DISABLE_FRAGMENTS)
982 { SCTP_DISABLE_FRAGMENTS, "SCTP_DISABLE_FRAGMENTS"},
984 #if defined(SCTP_PEER_ADDR_PARAMS)
985 { SCTP_PEER_ADDR_PARAMS, "SCTP_PEER_ADDR_PARAMS" },
987 #if defined(SCTP_DEFAULT_SEND_PARAM)
988 { SCTP_DEFAULT_SEND_PARAM, "SCTP_DEFAULT_SEND_PARAM"},
990 #if defined(SCTP_EVENTS)
991 { SCTP_EVENTS, "SCTP_EVENTS" },
993 #if defined(SCTP_I_WANT_MAPPED_V4_ADDR)
994 { SCTP_I_WANT_MAPPED_V4_ADDR, "SCTP_I_WANT_MAPPED_V4_ADDR"},
996 #if defined(SCTP_MAXSEG)
997 { SCTP_MAXSEG, "SCTP_MAXSEG" },
999 #if defined(SCTP_STATUS)
1000 { SCTP_STATUS, "SCTP_STATUS" },
1002 #if defined(SCTP_GET_PEER_ADDR_INFO)
1003 { SCTP_GET_PEER_ADDR_INFO, "SCTP_GET_PEER_ADDR_INFO"},
1005 #if defined(SCTP_DELAYED_ACK)
1006 { SCTP_DELAYED_ACK, "SCTP_DELAYED_ACK" },
1008 #if defined(SCTP_CONTEXT)
1009 { SCTP_CONTEXT, "SCTP_CONTEXT" },
1011 #if defined(SCTP_FRAGMENT_INTERLEAVE)
1012 { SCTP_FRAGMENT_INTERLEAVE, "SCTP_FRAGMENT_INTERLEAVE"},
1014 #if defined(SCTP_PARTIAL_DELIVERY_POINT)
1015 { SCTP_PARTIAL_DELIVERY_POINT, "SCTP_PARTIAL_DELIVERY_POINT"},
1017 #if defined(SCTP_MAX_BURST)
1018 { SCTP_MAX_BURST, "SCTP_MAX_BURST" },
1020 #if defined(SCTP_AUTH_CHUNK)
1021 { SCTP_AUTH_CHUNK, "SCTP_AUTH_CHUNK" },
1023 #if defined(SCTP_HMAC_IDENT)
1024 { SCTP_HMAC_IDENT, "SCTP_HMAC_IDENT" },
1026 #if defined(SCTP_AUTH_KEY)
1027 { SCTP_AUTH_KEY, "SCTP_AUTH_KEY" },
1029 #if defined(SCTP_AUTH_ACTIVE_KEY)
1030 { SCTP_AUTH_ACTIVE_KEY, "SCTP_AUTH_ACTIVE_KEY" },
1032 #if defined(SCTP_AUTH_DELETE_KEY)
1033 { SCTP_AUTH_DELETE_KEY, "SCTP_AUTH_DELETE_KEY" },
1035 #if defined(SCTP_PEER_AUTH_CHUNKS)
1036 { SCTP_PEER_AUTH_CHUNKS, "SCTP_PEER_AUTH_CHUNKS" },
1038 #if defined(SCTP_LOCAL_AUTH_CHUNKS)
1039 { SCTP_LOCAL_AUTH_CHUNKS, "SCTP_LOCAL_AUTH_CHUNKS"},
1041 #if defined(SCTP_GET_ASSOC_NUMBER)
1042 { SCTP_GET_ASSOC_NUMBER, "SCTP_GET_ASSOC_NUMBER" },
1045 /* linux specific things */
1046 #if defined(SCTP_SOCKOPT_BINDX_ADD)
1047 { SCTP_SOCKOPT_BINDX_ADD, "SCTP_SOCKOPT_BINDX_ADD" },
1049 #if defined(SCTP_SOCKOPT_BINDX_REM)
1050 { SCTP_SOCKOPT_BINDX_REM, "SCTP_SOCKOPT_BINDX_REM" },
1052 #if defined(SCTP_SOCKOPT_PEELOFF)
1053 { SCTP_SOCKOPT_PEELOFF, "SCTP_SOCKOPT_PEELOFF" },
1055 #if defined(SCTP_GET_PEER_ADDRS_NUM_OLD)
1056 { SCTP_GET_PEER_ADDRS_NUM_OLD, "SCTP_GET_PEER_ADDRS_NUM_OLD" },
1058 #if defined(SCTP_GET_PEER_ADDRS_OLD)
1059 { SCTP_GET_PEER_ADDRS_OLD, "SCTP_GET_PEER_ADDRS_OLD" },
1061 #if defined(SCTP_GET_LOCAL_ADDRS_NUM_OLD)
1062 { SCTP_GET_LOCAL_ADDRS_NUM_OLD, "SCTP_GET_LOCAL_ADDRS_NUM_OLD" },
1064 #if defined(SCTP_GET_LOCAL_ADDRS_OLD)
1065 { SCTP_GET_LOCAL_ADDRS_OLD, "SCTP_GET_LOCAL_ADDRS_OLD" },
1067 #if defined(SCTP_SOCKOPT_CONNECTX_OLD)
1068 { SCTP_SOCKOPT_CONNECTX_OLD, "SCTP_SOCKOPT_CONNECTX_OLD" },
1070 #if defined(SCTP_GET_PEER_ADDRS)
1071 { SCTP_GET_PEER_ADDRS, "SCTP_GET_PEER_ADDRS" },
1073 #if defined(SCTP_GET_LOCAL_ADDRS)
1074 { SCTP_GET_LOCAL_ADDRS, "SCTP_GET_LOCAL_ADDRS" },
1081 #if !defined (SOL_TCP) && defined (IPPROTO_TCP)
1082 #define SOL_TCP IPPROTO_TCP
1086 static const struct xlat socktcpoptions[] = {
1087 { TCP_NODELAY, "TCP_NODELAY" },
1088 { TCP_MAXSEG, "TCP_MAXSEG" },
1089 #if defined(TCP_CORK)
1090 { TCP_CORK, "TCP_CORK" },
1092 #if defined(TCP_KEEPIDLE)
1093 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
1095 #if defined(TCP_KEEPINTVL)
1096 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
1098 #if defined(TCP_KEEPCNT)
1099 { TCP_KEEPCNT, "TCP_KEEPCNT" },
1101 #if defined(TCP_NKEEP)
1102 { TCP_NKEEP, "TCP_NKEEP" },
1104 #if defined(TCP_SYNCNT)
1105 { TCP_SYNCNT, "TCP_SYNCNT" },
1107 #if defined(TCP_LINGER2)
1108 { TCP_LINGER2, "TCP_LINGER2" },
1110 #if defined(TCP_DEFER_ACCEPT)
1111 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
1113 #if defined(TCP_WINDOW_CLAMP)
1114 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
1116 #if defined(TCP_INFO)
1117 { TCP_INFO, "TCP_INFO" },
1119 #if defined(TCP_QUICKACK)
1120 { TCP_QUICKACK, "TCP_QUICKACK" },
1124 #endif /* SOL_TCP */
1127 static const struct xlat icmpfilterflags[] = {
1128 #if defined(ICMP_ECHOREPLY)
1129 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
1131 #if defined(ICMP_DEST_UNREACH)
1132 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
1134 #if defined(ICMP_SOURCE_QUENCH)
1135 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
1137 #if defined(ICMP_REDIRECT)
1138 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
1140 #if defined(ICMP_ECHO)
1141 { (1<<ICMP_ECHO), "ICMP_ECHO" },
1143 #if defined(ICMP_TIME_EXCEEDED)
1144 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
1146 #if defined(ICMP_PARAMETERPROB)
1147 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
1149 #if defined(ICMP_TIMESTAMP)
1150 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
1152 #if defined(ICMP_TIMESTAMPREPLY)
1153 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
1155 #if defined(ICMP_INFO_REQUEST)
1156 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
1158 #if defined(ICMP_INFO_REPLY)
1159 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
1161 #if defined(ICMP_ADDRESS)
1162 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
1164 #if defined(ICMP_ADDRESSREPLY)
1165 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
1169 #endif /* SOL_RAW */
1171 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
1172 static const struct xlat af_packet_types[] = {
1173 #if defined(PACKET_HOST)
1174 { PACKET_HOST, "PACKET_HOST" },
1176 #if defined(PACKET_BROADCAST)
1177 { PACKET_BROADCAST, "PACKET_BROADCAST" },
1179 #if defined(PACKET_MULTICAST)
1180 { PACKET_MULTICAST, "PACKET_MULTICAST" },
1182 #if defined(PACKET_OTHERHOST)
1183 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
1185 #if defined(PACKET_OUTGOING)
1186 { PACKET_OUTGOING, "PACKET_OUTGOING" },
1188 #if defined(PACKET_LOOPBACK)
1189 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
1191 #if defined(PACKET_FASTROUTE)
1192 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
1196 #endif /* defined(AF_PACKET) */
1200 printsock(struct tcb *tcp, long addr, int addrlen)
1205 struct sockaddr_in sin;
1206 struct sockaddr_un sau;
1207 #ifdef HAVE_INET_NTOP
1208 struct sockaddr_in6 sa6;
1210 #if defined(LINUX) && defined(AF_IPX)
1211 struct sockaddr_ipx sipx;
1214 struct sockaddr_ll ll;
1217 struct sockaddr_nl nl;
1220 char string_addr[100];
1226 if (!verbose(tcp)) {
1227 tprintf("%#lx", addr);
1231 if (addrlen < 2 || addrlen > sizeof(addrbuf))
1232 addrlen = sizeof(addrbuf);
1234 memset(&addrbuf, 0, sizeof(addrbuf));
1235 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
1239 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
1241 tprints("{sa_family=");
1242 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
1245 switch (addrbuf.sa.sa_family) {
1249 } else if (addrbuf.sau.sun_path[0]) {
1251 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
1254 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
1258 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
1259 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
1261 #ifdef HAVE_INET_NTOP
1263 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
1264 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1265 ntohs(addrbuf.sa6.sin6_port), string_addr,
1266 addrbuf.sa6.sin6_flowinfo);
1267 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1269 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1270 int numericscope = 0;
1271 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
1272 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
1273 char scopebuf[IFNAMSIZ + 1];
1275 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1278 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1284 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1289 #if defined(AF_IPX) && defined(linux)
1293 tprintf("sipx_port=htons(%u), ",
1294 ntohs(addrbuf.sipx.sipx_port));
1295 /* Yes, I know, this does not look too
1296 * strace-ish, but otherwise the IPX
1297 * addresses just look monstrous...
1298 * Anyways, feel free if you don't like
1301 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1302 for (i = 0; i < IPX_NODE_LEN; i++)
1303 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1304 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1307 #endif /* AF_IPX && linux */
1312 tprintf("proto=%#04x, if%d, pkttype=",
1313 ntohs(addrbuf.ll.sll_protocol),
1314 addrbuf.ll.sll_ifindex);
1315 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1316 tprintf(", addr(%d)={%d, ",
1317 addrbuf.ll.sll_halen,
1318 addrbuf.ll.sll_hatype);
1319 for (i = 0; i < addrbuf.ll.sll_halen; i++)
1320 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1324 #endif /* AF_APACKET */
1327 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1329 #endif /* AF_NETLINK */
1330 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1331 AF_X25 AF_ROSE etc. still need to be done */
1334 tprints("sa_data=");
1335 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1336 sizeof addrbuf.sa.sa_data);
1343 static const struct xlat scmvals[] = {
1345 { SCM_RIGHTS, "SCM_RIGHTS" },
1347 #ifdef SCM_CREDENTIALS
1348 { SCM_CREDENTIALS, "SCM_CREDENTIALS" },
1354 printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len)
1356 struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1358 if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1359 tprintf(", msg_control=%#lx", addr);
1364 tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len);
1365 printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1366 tprints(", cmsg_type=");
1368 if (cmsg->cmsg_level == SOL_SOCKET) {
1369 unsigned long cmsg_len;
1371 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1372 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1374 if (cmsg->cmsg_type == SCM_RIGHTS
1375 && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1376 int *fds = (int *) CMSG_DATA(cmsg);
1380 while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1383 tprintf("%d", *fds++);
1390 if (cmsg->cmsg_type == SCM_CREDENTIALS
1391 && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1392 struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg);
1394 tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1395 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1405 do_msghdr(struct tcb *tcp, struct msghdr *msg)
1407 tprintf("{msg_name(%d)=", msg->msg_namelen);
1408 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
1410 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
1411 tprint_iov(tcp, (unsigned long)msg->msg_iovlen,
1412 (unsigned long)msg->msg_iov, 1);
1414 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1415 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
1416 if (msg->msg_controllen)
1417 printcmsghdr(tcp, (unsigned long) msg->msg_control,
1418 msg->msg_controllen);
1419 tprints(", msg_flags=");
1420 printflags(msg_flags, msg->msg_flags, "MSG_???");
1421 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1422 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1423 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
1424 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1429 printmsghdr(struct tcb *tcp, long addr)
1433 if (umove(tcp, addr, &msg) < 0) {
1434 tprintf("%#lx", addr);
1437 do_msghdr(tcp, &msg);
1442 printmmsghdr(struct tcb *tcp, long addr)
1445 struct msghdr msg_hdr;
1449 if (umove(tcp, addr, &mmsg) < 0) {
1450 tprintf("%#lx", addr);
1454 do_msghdr(tcp, &mmsg.msg_hdr);
1455 tprintf(", %u}", mmsg.msg_len);
1459 #endif /* HAVE_SENDMSG */
1462 * low bits of the socket type define real socket type,
1463 * other bits are socket type flags.
1466 tprint_sock_type(struct tcb *tcp, int flags)
1468 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1472 flags &= ~SOCK_TYPE_MASK;
1477 printflags(sock_type_flags, flags, "SOCK_???");
1481 sys_socket(struct tcb *tcp)
1483 if (entering(tcp)) {
1484 printxval(domains, tcp->u_arg[0], "PF_???");
1486 tprint_sock_type(tcp, tcp->u_arg[1]);
1488 switch (tcp->u_arg[0]) {
1493 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1497 /* BTW: I don't believe this.. */
1499 printxval(domains, tcp->u_arg[2], "PF_???");
1504 tprintf("%lu", tcp->u_arg[2]);
1513 sys_so_socket(struct tcb *tcp)
1515 if (entering(tcp)) {
1516 /* not sure really what these args are... but this
1517 * is how truss prints it
1519 tprintf("%ld, %ld, %ld, ",
1520 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1521 printpath(tcp, tcp->u_arg[3]);
1522 tprintf(", %ld", tcp->u_arg[4]);
1528 sys_so_socketpair(struct tcb *tcp)
1530 if (entering(tcp)) {
1531 /* not sure what this arg is */
1532 tprintf("0x%lx", tcp->u_arg[0]);
1539 sys_bind(struct tcb *tcp)
1541 if (entering(tcp)) {
1542 tprintf("%ld, ", tcp->u_arg[0]);
1543 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1544 tprintf(", %lu", tcp->u_arg[2]);
1550 sys_connect(struct tcb *tcp)
1552 return sys_bind(tcp);
1556 sys_listen(struct tcb *tcp)
1558 if (entering(tcp)) {
1559 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1565 do_accept(struct tcb *tcp, int flags_arg)
1567 if (entering(tcp)) {
1568 tprintf("%ld, ", tcp->u_arg[0]);
1572 tprintf("%#lx, NULL", tcp->u_arg[1]);
1575 if (tcp->u_arg[1] == 0 || syserror(tcp)
1576 || umove(tcp, tcp->u_arg[2], &len) < 0) {
1577 tprintf("%#lx", tcp->u_arg[1]);
1579 printsock(tcp, tcp->u_arg[1], len);
1582 printnum_int(tcp, tcp->u_arg[2], "%u");
1584 if (flags_arg >= 0) {
1586 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1593 sys_accept(struct tcb *tcp)
1595 return do_accept(tcp, -1);
1600 sys_accept4(struct tcb *tcp)
1602 return do_accept(tcp, 3);
1607 sys_send(struct tcb *tcp)
1609 if (entering(tcp)) {
1610 tprintf("%ld, ", tcp->u_arg[0]);
1611 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1612 tprintf(", %lu, ", tcp->u_arg[2]);
1614 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1620 sys_sendto(struct tcb *tcp)
1622 if (entering(tcp)) {
1623 tprintf("%ld, ", tcp->u_arg[0]);
1624 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1625 tprintf(", %lu, ", tcp->u_arg[2]);
1627 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1630 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1632 tprintf(", %lu", tcp->u_arg[5]);
1640 sys_sendmsg(struct tcb *tcp)
1642 if (entering(tcp)) {
1643 tprintf("%ld, ", tcp->u_arg[0]);
1644 printmsghdr(tcp, tcp->u_arg[1]);
1647 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1652 #endif /* HAVE_SENDMSG */
1655 sys_recv(struct tcb *tcp)
1657 if (entering(tcp)) {
1658 tprintf("%ld, ", tcp->u_arg[0]);
1661 tprintf("%#lx", tcp->u_arg[1]);
1663 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1665 tprintf(", %lu, ", tcp->u_arg[2]);
1666 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1672 sys_recvfrom(struct tcb *tcp)
1676 if (entering(tcp)) {
1677 tprintf("%ld, ", tcp->u_arg[0]);
1679 if (syserror(tcp)) {
1680 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1681 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1682 tcp->u_arg[4], tcp->u_arg[5]);
1686 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1688 tprintf(", %lu, ", tcp->u_arg[2]);
1690 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1691 /* from address, len */
1692 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1693 if (tcp->u_arg[4] == 0)
1696 tprintf(", %#lx", tcp->u_arg[4]);
1697 if (tcp->u_arg[5] == 0)
1700 tprintf(", %#lx", tcp->u_arg[5]);
1703 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1704 tprints(", {...}, [?]");
1708 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1710 tprintf(", [%u]", fromlen);
1718 sys_recvmsg(struct tcb *tcp)
1720 if (entering(tcp)) {
1721 tprintf("%ld, ", tcp->u_arg[0]);
1723 if (syserror(tcp) || !verbose(tcp))
1724 tprintf("%#lx", tcp->u_arg[1]);
1726 printmsghdr(tcp, tcp->u_arg[1]);
1729 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1736 sys_recvmmsg(struct tcb *tcp)
1738 static char str[128];
1739 if (entering(tcp)) {
1741 tprintf("%ld, ", tcp->u_arg[0]);
1743 sprint_timespec(str, tcp, tcp->u_arg[4]);
1744 tcp->auxstr = strdup(str);
1746 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1747 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1749 print_timespec(tcp, tcp->u_arg[4]);
1755 tprintf("%#lx", tcp->u_arg[1]);
1757 printmmsghdr(tcp, tcp->u_arg[1]);
1758 tprintf(", %ld, ", tcp->u_arg[2]);
1760 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1761 /* timeout on entrance */
1762 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1763 free((void *) tcp->auxstr);
1768 if (tcp->u_rval == 0) {
1769 tcp->auxstr = "Timeout";
1774 /* timeout on exit */
1775 strcpy(str, "left ");
1776 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1783 #endif /* HAVE_SENDMSG */
1785 static const struct xlat shutdown_modes[] = {
1793 sys_shutdown(struct tcb *tcp)
1795 if (entering(tcp)) {
1796 tprintf("%ld, ", tcp->u_arg[0]);
1797 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1803 sys_getsockname(struct tcb *tcp)
1805 return sys_accept(tcp);
1809 sys_getpeername(struct tcb *tcp)
1811 return sys_accept(tcp);
1815 do_pipe(struct tcb *tcp, int flags_arg)
1818 if (syserror(tcp)) {
1819 tprintf("%#lx", tcp->u_arg[0]);
1821 #if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1824 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1827 tprintf("[%u, %u]", fds[0], fds[1]);
1828 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
1829 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1831 tprintf("%#lx", tcp->u_arg[0]);
1834 if (flags_arg >= 0) {
1836 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1843 sys_pipe(struct tcb *tcp)
1845 return do_pipe(tcp, -1);
1850 sys_pipe2(struct tcb *tcp)
1852 return do_pipe(tcp, 1);
1857 sys_socketpair(struct tcb *tcp)
1863 if (entering(tcp)) {
1864 printxval(domains, tcp->u_arg[0], "PF_???");
1866 tprint_sock_type(tcp, tcp->u_arg[1]);
1868 switch (tcp->u_arg[0]) {
1870 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1874 /* BTW: I don't believe this.. */
1876 printxval(domains, tcp->u_arg[2], "PF_???");
1881 tprintf("%lu", tcp->u_arg[2]);
1885 if (syserror(tcp)) {
1886 tprintf(", %#lx", tcp->u_arg[3]);
1890 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1893 tprintf(", [%u, %u]", fds[0], fds[1]);
1895 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1896 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1897 #endif /* SUNOS4 || SVR4 || FREEBSD */
1903 sys_getsockopt(struct tcb *tcp)
1905 if (entering(tcp)) {
1906 tprintf("%ld, ", tcp->u_arg[0]);
1907 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1909 switch (tcp->u_arg[1]) {
1911 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1915 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1920 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1925 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1930 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1935 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1940 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1944 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1945 * etc. still need work */
1947 tprintf("%lu", tcp->u_arg[2]);
1953 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1954 tprintf("%#lx, %#lx",
1955 tcp->u_arg[3], tcp->u_arg[4]);
1959 switch (tcp->u_arg[1]) {
1961 switch (tcp->u_arg[2]) {
1964 if (len == sizeof(struct linger)) {
1965 struct linger linger;
1970 tprintf("{onoff=%d, linger=%d}, "
1981 if (len == sizeof(struct ucred)) {
1987 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2000 switch (tcp->u_arg[2]) {
2001 #ifdef PACKET_STATISTICS
2002 case PACKET_STATISTICS:
2003 if (len == sizeof(struct tpacket_stats)) {
2004 struct tpacket_stats stats;
2009 tprintf("{packets=%u, drops=%u}, "
2022 if (len == sizeof(int)) {
2023 printnum_int(tcp, tcp->u_arg[3], "%d");
2026 printstr(tcp, tcp->u_arg[3], len);
2028 tprintf(", [%d]", len);
2033 #if defined(ICMP_FILTER)
2034 static void printicmpfilter(struct tcb *tcp, long addr)
2036 struct icmp_filter filter;
2042 if (syserror(tcp) || !verbose(tcp)) {
2043 tprintf("%#lx", addr);
2046 if (umove(tcp, addr, &filter) < 0) {
2052 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
2055 #endif /* ICMP_FILTER */
2058 printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
2060 printxval(socketlayers, level, "SOL_??");
2064 printxval(sockoptions, name, "SO_???");
2066 #if defined(SO_LINGER)
2068 if (len == sizeof(struct linger)) {
2069 struct linger linger;
2070 if (umove(tcp, addr, &linger) < 0)
2072 tprintf(", {onoff=%d, linger=%d}",
2083 printxval(sockipoptions, name, "IP_???");
2088 printxval(sockipv6options, name, "IPV6_???");
2093 printxval(sockipxoptions, name, "IPX_???");
2098 printxval(sockpacketoptions, name, "PACKET_???");
2099 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
2101 #ifdef PACKET_RX_RING
2102 case PACKET_RX_RING:
2104 #ifdef PACKET_TX_RING
2105 case PACKET_TX_RING:
2107 #if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2108 if (len == sizeof(struct tpacket_req)) {
2109 struct tpacket_req req;
2110 if (umove(tcp, addr, &req) < 0)
2112 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2120 #endif /* PACKET_RX_RING || PACKET_TX_RING */
2126 printxval(socktcpoptions, name, "TCP_???");
2131 printxval(socksctpoptions, name, "SCTP_???");
2136 printxval(sockrawoptions, name, "RAW_???");
2138 #if defined(ICMP_FILTER)
2141 printicmpfilter(tcp, addr);
2148 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2149 * etc. still need work */
2152 tprintf("%u", name);
2155 /* default arg printing */
2159 if (len == sizeof(int)) {
2160 printnum_int(tcp, addr, "%d");
2163 printstr(tcp, addr, len);
2169 #ifdef HAVE_STRUCT_OPTHDR
2172 print_sock_optmgmt(struct tcb *tcp, long addr, int len)
2177 while (len >= (int) sizeof hdr) {
2178 if (umove(tcp, addr, &hdr) < 0) break;
2182 else if (len > hdr.len + sizeof hdr) {
2188 printsockopt(tcp, hdr.level, hdr.name, addr, hdr.len);
2196 if (c++) tprints(", ");
2197 printstr(tcp, addr, len);
2199 if (c > 1) tprints("]");
2205 sys_setsockopt(struct tcb *tcp)
2207 if (entering(tcp)) {
2208 tprintf("%ld, ", tcp->u_arg[0]);
2209 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
2210 tcp->u_arg[3], tcp->u_arg[4]);
2211 tprintf(", %lu", tcp->u_arg[4]);
2218 static const struct xlat sock_version[] = {
2219 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2220 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2221 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2222 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2223 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2224 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
2230 netlib_call(struct tcb *tcp, int (*func)())
2232 if (entering(tcp)) {
2234 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
2237 for (i = 0; i < tcp->u_nargs; i++)
2238 tcp->u_arg[i] = tcp->u_arg[i + 1];
2246 sys_xsocket(struct tcb *tcp)
2248 return netlib_call(tcp, sys_socket);
2252 sys_xsocketpair(struct tcb *tcp)
2254 return netlib_call(tcp, sys_socketpair);
2258 sys_xbind(struct tcb *tcp)
2260 return netlib_call(tcp, sys_bind);
2264 sys_xconnect(struct tcb *tcp)
2266 return netlib_call(tcp, sys_connect);
2270 sys_xlisten(struct tcb *tcp)
2272 return netlib_call(tcp, sys_listen);
2276 sys_xaccept(struct tcb *tcp)
2278 return netlib_call(tcp, sys_accept);
2282 sys_xsendmsg(struct tcb *tcp)
2284 return netlib_call(tcp, sys_sendmsg);
2288 sys_xrecvmsg(struct tcb *tcp)
2290 return netlib_call(tcp, sys_recvmsg);
2294 sys_xgetsockaddr(struct tcb *tcp)
2296 if (entering(tcp)) {
2297 printxval(sock_version, tcp->u_arg[0], "__NETLIB_???");
2299 if (tcp->u_arg[1] == 0) {
2300 tprints("LOCALNAME, ");
2302 else if (tcp->u_arg[1] == 1) {
2303 tprints("REMOTENAME, ");
2306 tprintf("%ld, ", tcp->u_arg[1]);
2308 tprintf("%ld, ", tcp->u_arg[2]);
2311 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2312 tprintf("%#lx", tcp->u_arg[3]);
2314 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2317 printnum(tcp, tcp->u_arg[4], "%lu");
2325 sys_xgetsockopt(struct tcb *tcp)
2327 return netlib_call(tcp, sys_getsockopt);
2331 sys_xsetsockopt(struct tcb *tcp)
2333 return netlib_call(tcp, sys_setsockopt);
2337 sys_xshutdown(struct tcb *tcp)
2339 return netlib_call(tcp, sys_shutdown);
2342 #endif /* UNIXWARE */