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 tprintf("{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 tprintf("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 tprintf(", 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);
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 tprintf(", 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(tcp, addr)
1435 if (umove(tcp, addr, &msg) < 0) {
1436 tprintf("%#lx", addr);
1439 do_msghdr(tcp, &msg);
1444 printmmsghdr(struct tcb *tcp, long addr)
1447 struct msghdr msg_hdr;
1451 if (umove(tcp, addr, &mmsg) < 0) {
1452 tprintf("%#lx", addr);
1456 do_msghdr(tcp, &mmsg.msg_hdr);
1457 tprintf(", %u}", mmsg.msg_len);
1461 #endif /* HAVE_SENDMSG */
1464 * low bits of the socket type define real socket type,
1465 * other bits are socket type flags.
1468 tprint_sock_type(struct tcb *tcp, int flags)
1470 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
1475 flags &= ~SOCK_TYPE_MASK;
1480 printflags(sock_type_flags, flags, "SOCK_???");
1484 sys_socket(struct tcb *tcp)
1486 if (entering(tcp)) {
1487 printxval(domains, tcp->u_arg[0], "PF_???");
1489 tprint_sock_type(tcp, tcp->u_arg[1]);
1491 switch (tcp->u_arg[0]) {
1496 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1500 /* BTW: I don't believe this.. */
1502 printxval(domains, tcp->u_arg[2], "PF_???");
1507 tprintf("%lu", tcp->u_arg[2]);
1519 if (entering(tcp)) {
1520 /* not sure really what these args are... but this
1521 * is how truss prints it
1523 tprintf("%ld, %ld, %ld, ",
1524 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1525 printpath(tcp, tcp->u_arg[3]);
1526 tprintf(", %ld", tcp->u_arg[4]);
1532 sys_so_socketpair(tcp)
1535 if (entering(tcp)) {
1536 /* not sure what this arg is */
1537 tprintf("0x%lx", tcp->u_arg[0]);
1547 if (entering(tcp)) {
1548 tprintf("%ld, ", tcp->u_arg[0]);
1549 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1550 tprintf(", %lu", tcp->u_arg[2]);
1559 return sys_bind(tcp);
1566 if (entering(tcp)) {
1567 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1573 do_accept(struct tcb *tcp, int flags_arg)
1575 if (entering(tcp)) {
1576 tprintf("%ld, ", tcp->u_arg[0]);
1580 tprintf("%#lx, NULL", tcp->u_arg[1]);
1583 if (tcp->u_arg[1] == 0 || syserror(tcp)
1584 || umove (tcp, tcp->u_arg[2], &len) < 0) {
1585 tprintf("%#lx", tcp->u_arg[1]);
1587 printsock(tcp, tcp->u_arg[1], len);
1590 printnum_int(tcp, tcp->u_arg[2], "%u");
1592 if (flags_arg >= 0) {
1594 printflags(sock_type_flags, tcp->u_arg[flags_arg],
1601 sys_accept(struct tcb *tcp)
1603 return do_accept(tcp, -1);
1608 sys_accept4(struct tcb *tcp)
1610 return do_accept(tcp, 3);
1618 if (entering(tcp)) {
1619 tprintf("%ld, ", tcp->u_arg[0]);
1620 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1621 tprintf(", %lu, ", tcp->u_arg[2]);
1623 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1632 if (entering(tcp)) {
1633 tprintf("%ld, ", tcp->u_arg[0]);
1634 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1635 tprintf(", %lu, ", tcp->u_arg[2]);
1637 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1640 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1642 tprintf(", %lu", tcp->u_arg[5]);
1653 if (entering(tcp)) {
1654 tprintf("%ld, ", tcp->u_arg[0]);
1655 printmsghdr(tcp, tcp->u_arg[1]);
1658 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1663 #endif /* HAVE_SENDMSG */
1669 if (entering(tcp)) {
1670 tprintf("%ld, ", tcp->u_arg[0]);
1673 tprintf("%#lx", tcp->u_arg[1]);
1675 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1677 tprintf(", %lu, ", tcp->u_arg[2]);
1678 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1689 if (entering(tcp)) {
1690 tprintf("%ld, ", tcp->u_arg[0]);
1692 if (syserror(tcp)) {
1693 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1694 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1695 tcp->u_arg[4], tcp->u_arg[5]);
1699 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1701 tprintf(", %lu, ", tcp->u_arg[2]);
1703 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1704 /* from address, len */
1705 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1706 if (tcp->u_arg[4] == 0)
1709 tprintf(", %#lx", tcp->u_arg[4]);
1710 if (tcp->u_arg[5] == 0)
1713 tprintf(", %#lx", tcp->u_arg[5]);
1716 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1717 tprintf(", {...}, [?]");
1721 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1723 tprintf(", [%u]", fromlen);
1734 if (entering(tcp)) {
1735 tprintf("%ld, ", tcp->u_arg[0]);
1737 if (syserror(tcp) || !verbose(tcp))
1738 tprintf("%#lx", tcp->u_arg[1]);
1740 printmsghdr(tcp, tcp->u_arg[1]);
1743 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1750 sys_recvmmsg(struct tcb *tcp)
1752 static char str[128];
1753 if (entering(tcp)) {
1755 tprintf("%ld, ", tcp->u_arg[0]);
1757 sprint_timespec(str, tcp, tcp->u_arg[4]);
1758 tcp->auxstr = strdup(str);
1760 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1761 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1763 print_timespec(tcp, tcp->u_arg[4]);
1769 tprintf("%#lx", tcp->u_arg[1]);
1771 printmmsghdr(tcp, tcp->u_arg[1]);
1772 tprintf(", %ld, ", tcp->u_arg[2]);
1774 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1775 /* timeout on entrance */
1776 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1777 free((void *) tcp->auxstr);
1782 if (tcp->u_rval == 0) {
1783 tcp->auxstr = "Timeout";
1788 /* timeout on exit */
1789 strcpy(str, "left ");
1790 sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
1797 #endif /* HAVE_SENDMSG */
1803 if (entering(tcp)) {
1804 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1805 switch (tcp->u_arg[1]) {
1807 tprintf("%s", " /* receive */");
1810 tprintf("%s", " /* send */");
1813 tprintf("%s", " /* send and receive */");
1821 sys_getsockname(tcp)
1824 return sys_accept(tcp);
1828 sys_getpeername(tcp)
1831 return sys_accept(tcp);
1835 do_pipe(struct tcb *tcp, int flags_arg)
1838 if (syserror(tcp)) {
1839 tprintf("%#lx", tcp->u_arg[0]);
1841 #if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1844 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1847 tprintf("[%u, %u]", fds[0], fds[1]);
1848 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
1849 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1851 tprintf("%#lx", tcp->u_arg[0]);
1854 if (flags_arg >= 0) {
1856 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1863 sys_pipe(struct tcb *tcp)
1865 return do_pipe(tcp, -1);
1870 sys_pipe2(struct tcb *tcp)
1872 return do_pipe(tcp, 1);
1877 sys_socketpair(struct tcb *tcp)
1883 if (entering(tcp)) {
1884 printxval(domains, tcp->u_arg[0], "PF_???");
1886 tprint_sock_type(tcp, tcp->u_arg[1]);
1888 switch (tcp->u_arg[0]) {
1890 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1894 /* BTW: I don't believe this.. */
1896 printxval(domains, tcp->u_arg[2], "PF_???");
1901 tprintf("%lu", tcp->u_arg[2]);
1905 if (syserror(tcp)) {
1906 tprintf(", %#lx", tcp->u_arg[3]);
1910 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1913 tprintf(", [%u, %u]", fds[0], fds[1]);
1915 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1916 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1917 #endif /* SUNOS4 || SVR4 || FREEBSD */
1923 sys_getsockopt(struct tcb *tcp)
1925 if (entering(tcp)) {
1926 tprintf("%ld, ", tcp->u_arg[0]);
1927 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1929 switch (tcp->u_arg[1]) {
1931 printxval(sockoptions, tcp->u_arg[2], "SO_???");
1935 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1940 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1945 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1950 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1955 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1960 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1964 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1965 * etc. still need work */
1967 tprintf("%lu", tcp->u_arg[2]);
1973 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1974 tprintf("%#lx, %#lx",
1975 tcp->u_arg[3], tcp->u_arg[4]);
1979 switch (tcp->u_arg[1]) {
1981 switch (tcp->u_arg[2]) {
1984 if (len == sizeof (struct linger)) {
1985 struct linger linger;
1990 tprintf("{onoff=%d, linger=%d}, "
2001 if (len == sizeof (struct ucred)) {
2007 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
2020 switch (tcp->u_arg[2]) {
2021 #ifdef PACKET_STATISTICS
2022 case PACKET_STATISTICS:
2023 if (len == sizeof(struct tpacket_stats)) {
2024 struct tpacket_stats stats;
2029 tprintf("{packets=%u, drops=%u}, "
2042 if (len == sizeof (int)) {
2043 printnum_int(tcp, tcp->u_arg[3], "%d");
2046 printstr (tcp, tcp->u_arg[3], len);
2048 tprintf(", [%d]", len);
2053 #if defined(ICMP_FILTER)
2054 static void printicmpfilter(tcp, addr)
2058 struct icmp_filter filter;
2064 if (syserror(tcp) || !verbose(tcp)) {
2065 tprintf("%#lx", addr);
2068 if (umove(tcp, addr, &filter) < 0) {
2074 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
2077 #endif /* ICMP_FILTER */
2080 printsockopt (tcp, level, name, addr, len)
2087 printxval(socketlayers, level, "SOL_??");
2091 printxval(sockoptions, name, "SO_???");
2093 #if defined(SO_LINGER)
2095 if (len == sizeof (struct linger)) {
2096 struct linger linger;
2097 if (umove (tcp, addr, &linger) < 0)
2099 tprintf(", {onoff=%d, linger=%d}",
2110 printxval(sockipoptions, name, "IP_???");
2115 printxval(sockipv6options, name, "IPV6_???");
2120 printxval(sockipxoptions, name, "IPX_???");
2125 printxval(sockpacketoptions, name, "PACKET_???");
2126 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
2128 #ifdef PACKET_RX_RING
2129 case PACKET_RX_RING:
2131 #ifdef PACKET_TX_RING
2132 case PACKET_TX_RING:
2134 #if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
2135 if (len == sizeof(struct tpacket_req)) {
2136 struct tpacket_req req;
2137 if (umove(tcp, addr, &req) < 0)
2139 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
2147 #endif /* PACKET_RX_RING || PACKET_TX_RING */
2153 printxval(socktcpoptions, name, "TCP_???");
2158 printxval(socksctpoptions, name, "SCTP_???");
2163 printxval(sockrawoptions, name, "RAW_???");
2165 #if defined(ICMP_FILTER)
2168 printicmpfilter(tcp, addr);
2175 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
2176 * etc. still need work */
2179 tprintf("%u", name);
2182 /* default arg printing */
2186 if (len == sizeof (int)) {
2187 printnum_int (tcp, addr, "%d");
2190 printstr (tcp, addr, len);
2196 #ifdef HAVE_STRUCT_OPTHDR
2199 print_sock_optmgmt (tcp, addr, len)
2207 while (len >= (int) sizeof hdr) {
2208 if (umove(tcp, addr, &hdr) < 0) break;
2212 else if (len > hdr.len + sizeof hdr) {
2218 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
2226 if (c++) tprintf (", ");
2227 printstr (tcp, addr, len);
2229 if (c > 1) tprintf ("]");
2238 if (entering(tcp)) {
2239 tprintf("%ld, ", tcp->u_arg[0]);
2240 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
2241 tcp->u_arg[3], tcp->u_arg[4]);
2242 tprintf(", %lu", tcp->u_arg[4]);
2249 static const struct xlat sock_version[] = {
2250 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
2251 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
2252 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
2253 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
2254 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
2255 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
2261 netlib_call(tcp, func)
2265 if (entering(tcp)) {
2267 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2270 for (i = 0; i < tcp->u_nargs; i++)
2271 tcp->u_arg[i] = tcp->u_arg[i + 1];
2283 return netlib_call (tcp, sys_socket);
2287 sys_xsocketpair(tcp)
2290 return netlib_call (tcp, sys_socketpair);
2297 return netlib_call (tcp, sys_bind);
2304 return netlib_call (tcp, sys_connect);
2311 return netlib_call (tcp, sys_listen);
2318 return netlib_call (tcp, sys_accept);
2325 return netlib_call (tcp, sys_sendmsg);
2332 return netlib_call (tcp, sys_recvmsg);
2336 sys_xgetsockaddr(tcp)
2339 if (entering(tcp)) {
2340 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
2342 if (tcp->u_arg[1] == 0) {
2343 tprintf ("LOCALNAME, ");
2345 else if (tcp->u_arg[1] == 1) {
2346 tprintf ("REMOTENAME, ");
2349 tprintf ("%ld, ", tcp->u_arg [1]);
2351 tprintf ("%ld, ", tcp->u_arg [2]);
2354 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
2355 tprintf("%#lx", tcp->u_arg[3]);
2357 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
2360 printnum(tcp, tcp->u_arg[4], "%lu");
2368 sys_xgetsockopt(tcp)
2371 return netlib_call (tcp, sys_getsockopt);
2375 sys_xsetsockopt(tcp)
2378 return netlib_call (tcp, sys_setsockopt);
2385 return netlib_call (tcp, sys_shutdown);
2388 #endif /* UNIXWARE */