]> granicus.if.org Git - strace/blobdiff - net.c
mips n32: fix preadv/pwritev offset decoding
[strace] / net.c
diff --git a/net.c b/net.c
index 1de3cb33434da2c5eb87f93b2d80bcd0d6c9a681..cb29faad6204de8e5a6f56f8e889b34376a5a9bc 100644 (file)
--- a/net.c
+++ b/net.c
 #include <sys/socket.h>
 #include <sys/uio.h>
 #include <sys/un.h>
-#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
-# define in6_addr in6_addr_libc
-# define ipv6_mreq ipv6_mreq_libc
-# define sockaddr_in6 sockaddr_in6_libc
-#endif
 #include <netinet/in.h>
 #ifdef HAVE_NETINET_TCP_H
 # include <netinet/tcp.h>
 # include <linux/ipx.h>
 #endif
 
-#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
-# if defined(HAVE_LINUX_IN6_H)
-#  if defined(HAVE_SIN6_SCOPE_ID_LINUX)
-#   undef in6_addr
-#   undef ipv6_mreq
-#   undef sockaddr_in6
-#   define in6_addr in6_addr_kernel
-#   define ipv6_mreq ipv6_mreq_kernel
-#   define sockaddr_in6 sockaddr_in6_kernel
-#  endif
-#  include <linux/in6.h>
-#  if defined(HAVE_SIN6_SCOPE_ID_LINUX)
-#   undef in6_addr
-#   undef ipv6_mreq
-#   undef sockaddr_in6
-#   define in6_addr in6_addr_libc
-#   define ipv6_mreq ipv6_mreq_libc
-#   define sockaddr_in6 sockaddr_in6_kernel
-#  endif
-# endif
-#endif
-
 #if defined(HAVE_LINUX_NETLINK_H)
 # include <linux/netlink.h>
 #endif
 #ifndef SOCK_TYPE_MASK
 # define SOCK_TYPE_MASK 0xf
 #endif
+
+#ifndef SOL_IP
+# define SOL_IP 0
+#endif
+#ifndef SOL_TCP
+# define SOL_TCP 6
+#endif
+#ifndef SOL_UDP
+# define SOL_UDP 17
+#endif
+#ifndef SOL_IPV6
+# define SOL_IPV6 41
+#endif
+#ifndef SOL_ICMPV6
+# define SOL_ICMPV6 58
+#endif
+#ifndef SOL_SCTP
+# define SOL_SCTP 132
+#endif
+#ifndef SOL_UDPLITE
+# define SOL_UDPLITE 136
+#endif
+#ifndef SOL_RAW
+# define SOL_RAW 255
+#endif
+#ifndef SOL_IPX
+# define SOL_IPX 256
+#endif
+#ifndef SOL_AX25
+# define SOL_AX25 257
+#endif
+#ifndef SOL_ATALK
+# define SOL_ATALK 258
+#endif
+#ifndef SOL_NETROM
+# define SOL_NETROM 259
+#endif
+#ifndef SOL_ROSE
+# define SOL_ROSE 260
+#endif
+#ifndef SOL_DECNET
+# define SOL_DECNET 261
+#endif
+#ifndef SOL_X25
+# define SOL_X25 262
+#endif
+#ifndef SOL_PACKET
+# define SOL_PACKET 263
+#endif
+#ifndef SOL_ATM
+# define SOL_ATM 264
+#endif
+#ifndef SOL_AAL
+# define SOL_AAL 265
+#endif
+#ifndef SOL_IRDA
+# define SOL_IRDA 266
+#endif
+#ifndef SOL_NETBEUI
+# define SOL_NETBEUI 267
+#endif
+#ifndef SOL_LLC
+# define SOL_LLC 268
+#endif
+#ifndef SOL_DCCP
+# define SOL_DCCP 269
+#endif
+#ifndef SOL_NETLINK
+# define SOL_NETLINK 270
+#endif
+#ifndef SOL_TIPC
+# define SOL_TIPC 271
+#endif
+#ifndef SOL_RXRPC
+# define SOL_RXRPC 272
+#endif
+#ifndef SOL_PPPOL2TP
+# define SOL_PPPOL2TP 273
+#endif
+#ifndef SOL_BLUETOOTH
+# define SOL_BLUETOOTH 274
+#endif
+#ifndef SOL_PNPIPE
+# define SOL_PNPIPE 275
+#endif
+#ifndef SOL_RDS
+# define SOL_RDS 276
+#endif
+#ifndef SOL_IUCV
+# define SOL_IUCV 277
+#endif
+#ifndef SOL_CAIF
+# define SOL_CAIF 278
+#endif
+#ifndef SOL_ALG
+# define SOL_ALG 279
+#endif
+#ifndef SOL_NFC
+# define SOL_NFC 280
+#endif
 #include "xlat/socketlayers.h"
-/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
-     falls into "inet_protocols" array below!!!!   This is intended!!! ***/
+
 #include "xlat/inet_protocols.h"
 
 #ifdef PF_NETLINK
 #endif
 
 #include "xlat/msg_flags.h"
-#include "xlat/sockoptions.h"
-
-#if !defined(SOL_IP) && defined(IPPROTO_IP)
-#define SOL_IP IPPROTO_IP
-#endif
-
-#ifdef SOL_IP
-#include "xlat/sockipoptions.h"
-#endif /* SOL_IP */
-
-#ifdef SOL_IPV6
-#include "xlat/sockipv6options.h"
-#endif /* SOL_IPV6 */
-
-#ifdef SOL_IPX
-#include "xlat/sockipxoptions.h"
-#endif /* SOL_IPX */
-
-#ifdef SOL_RAW
-#include "xlat/sockrawoptions.h"
-#endif /* SOL_RAW */
-
-#ifdef SOL_PACKET
-#include "xlat/sockpacketoptions.h"
-#endif /* SOL_PACKET */
-
-#ifdef SOL_SCTP
-#include "xlat/socksctpoptions.h"
-#endif
-
-#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
-#define SOL_TCP IPPROTO_TCP
-#endif
-
-#ifdef SOL_TCP
-#include "xlat/socktcpoptions.h"
-#endif /* SOL_TCP */
-
-#ifdef SOL_RAW
-#include "xlat/icmpfilterflags.h"
-#endif /* SOL_RAW */
 
 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
-#include "xlat/af_packet_types.h"
-#endif /* defined(AF_PACKET) */
+# include "xlat/af_packet_types.h"
+#endif
 
 void
 printsock(struct tcb *tcp, long addr, int addrlen)
@@ -227,10 +258,14 @@ printsock(struct tcb *tcp, long addr, int addrlen)
                        tprints("NULL");
                } else if (addrbuf.sau.sun_path[0]) {
                        tprints("sun_path=");
-                       printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
+                       print_quoted_string(addrbuf.sau.sun_path,
+                                           sizeof(addrbuf.sau.sun_path) + 1,
+                                           QUOTE_0_TERMINATED);
                } else {
                        tprints("sun_path=@");
-                       printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
+                       print_quoted_string(addrbuf.sau.sun_path + 1,
+                                           sizeof(addrbuf.sau.sun_path),
+                                           QUOTE_0_TERMINATED);
                }
                break;
        case AF_INET:
@@ -336,8 +371,8 @@ printsock(struct tcb *tcp, long addr, int addrlen)
 
        default:
                tprints("sa_data=");
-               printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
-                       sizeof addrbuf.sa.sa_data);
+               print_quoted_string(addrbuf.sa.sa_data,
+                                   sizeof(addrbuf.sa.sa_data), 0);
                break;
        }
        tprints("}");
@@ -1089,6 +1124,15 @@ sys_socketpair(struct tcb *tcp)
        return 0;
 }
 
+#include "xlat/sockoptions.h"
+#include "xlat/sockipoptions.h"
+#include "xlat/sockipv6options.h"
+#include "xlat/sockipxoptions.h"
+#include "xlat/sockrawoptions.h"
+#include "xlat/sockpacketoptions.h"
+#include "xlat/socksctpoptions.h"
+#include "xlat/socktcpoptions.h"
+
 static void
 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
 {
@@ -1101,41 +1145,27 @@ print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
        case SOL_SOCKET:
                printxval(sockoptions, name, "SO_???");
                break;
-#ifdef SOL_IP
        case SOL_IP:
                printxval(sockipoptions, name, "IP_???");
                break;
-#endif
-#ifdef SOL_IPV6
        case SOL_IPV6:
                printxval(sockipv6options, name, "IPV6_???");
                break;
-#endif
-#ifdef SOL_IPX
        case SOL_IPX:
                printxval(sockipxoptions, name, "IPX_???");
                break;
-#endif
-#ifdef SOL_PACKET
        case SOL_PACKET:
                printxval(sockpacketoptions, name, "PACKET_???");
                break;
-#endif
-#ifdef SOL_TCP
        case SOL_TCP:
                printxval(socktcpoptions, name, "TCP_???");
                break;
-#endif
-#ifdef SOL_SCTP
        case SOL_SCTP:
                printxval(socksctpoptions, name, "SCTP_???");
                break;
-#endif
-#ifdef SOL_RAW
        case SOL_RAW:
                printxval(sockrawoptions, name, "RAW_???");
                break;
-#endif
 
                /* Other SOL_* protocol levels still need work. */
 
@@ -1200,6 +1230,8 @@ print_tpacket_stats(struct tcb *tcp, long addr, int len)
 #endif /* PACKET_STATISTICS */
 
 #ifdef ICMP_FILTER
+# include "xlat/icmpfilterflags.h"
+
 static void
 print_icmp_filter(struct tcb *tcp, long addr, int len)
 {
@@ -1237,29 +1269,25 @@ print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
                }
                break;
 
-#ifdef SOL_PACKET
        case SOL_PACKET:
                switch (name) {
-# ifdef PACKET_STATISTICS
+#ifdef PACKET_STATISTICS
                case PACKET_STATISTICS:
                        print_tpacket_stats(tcp, addr, len);
                        goto done;
-# endif
+#endif
                }
                break;
-#endif /* SOL_PACKET */
 
-#ifdef SOL_RAW
        case SOL_RAW:
                switch (name) {
-# ifdef ICMP_FILTER
+#ifdef ICMP_FILTER
                case ICMP_FILTER:
                        print_icmp_filter(tcp, addr, len);
                        goto done;
-# endif
+#endif
                }
                break;
-#endif /* SOL_RAW */
        }
 
        /* default arg printing */
@@ -1297,6 +1325,56 @@ sys_getsockopt(struct tcb *tcp)
        return 0;
 }
 
+#ifdef MCAST_JOIN_GROUP
+static void
+print_group_req(struct tcb *tcp, long addr, int len)
+{
+       struct group_req greq;
+
+       if (len != sizeof(greq) ||
+           umove(tcp, addr, &greq) < 0) {
+               tprintf("%#lx", addr);
+               return;
+       }
+
+       union {
+               struct sockaddr *sa;
+               struct sockaddr_in *sin;
+#ifdef HAVE_INET_NTOP
+               struct sockaddr_in6 *sin6;
+#endif
+       } a = { .sa = (struct sockaddr *) &greq.gr_group };
+#ifdef HAVE_INET_NTOP
+       char str[INET6_ADDRSTRLEN];
+#endif
+
+       tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
+       printxval(addrfams, a.sa->sa_family, "AF_???");
+
+       switch (a.sa->sa_family) {
+       case AF_INET:
+               tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
+                       ntohs(a.sin->sin_port),
+                       inet_ntoa(a.sin->sin_addr));
+               return;
+#ifdef HAVE_INET_NTOP
+       case AF_INET6:
+               if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
+                       break;
+               tprintf(", sin6_port=htons(%u)"
+                       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
+                       ntohs(a.sin6->sin6_port), str);
+               return;
+#endif /* HAVE_INET_NTOP */
+       }
+
+       tprints(", sa_data=");
+       print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
+       tprintf("}}");
+
+}
+#endif /* MCAST_JOIN_GROUP */
+
 #ifdef PACKET_RX_RING
 static void
 print_tpacket_req(struct tcb *tcp, long addr, int len)
@@ -1358,38 +1436,45 @@ print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
                }
                break;
 
-#ifdef SOL_PACKET
+       case SOL_IP:
+               switch (name) {
+#ifdef MCAST_JOIN_GROUP
+               case MCAST_JOIN_GROUP:
+               case MCAST_LEAVE_GROUP:
+                       print_group_req(tcp, addr, len);
+                       goto done;
+#endif /* MCAST_JOIN_GROUP */
+               }
+               break;
+
        case SOL_PACKET:
                switch (name) {
-# ifdef PACKET_RX_RING
+#ifdef PACKET_RX_RING
                case PACKET_RX_RING:
-#  ifdef PACKET_TX_RING
+# ifdef PACKET_TX_RING
                case PACKET_TX_RING:
-#  endif
+# endif
                        print_tpacket_req(tcp, addr, len);
                        goto done;
-# endif /* PACKET_RX_RING */
-# ifdef PACKET_ADD_MEMBERSHIP
+#endif /* PACKET_RX_RING */
+#ifdef PACKET_ADD_MEMBERSHIP
                case PACKET_ADD_MEMBERSHIP:
                case PACKET_DROP_MEMBERSHIP:
                        print_packet_mreq(tcp, addr, len);
                        goto done;
-# endif /* PACKET_ADD_MEMBERSHIP */
+#endif /* PACKET_ADD_MEMBERSHIP */
                }
                break;
-#endif /* SOL_PACKET */
 
-#ifdef SOL_RAW
        case SOL_RAW:
                switch (name) {
-# ifdef ICMP_FILTER
+#ifdef ICMP_FILTER
                case ICMP_FILTER:
                        print_icmp_filter(tcp, addr, len);
                        goto done;
-# endif
+#endif
                }
                break;
-#endif /* SOL_RAW */
        }
 
        /* default arg printing */