Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 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. |
| 18 | * |
| 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. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include <sys/stat.h> |
| 33 | #include <sys/socket.h> |
Dmitry V. Levin | b2fa2be | 2014-11-21 20:46:16 +0000 | [diff] [blame] | 34 | #include <sys/uio.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/un.h> |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 36 | #if defined(HAVE_SIN6_SCOPE_ID_LINUX) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 37 | # define in6_addr in6_addr_libc |
| 38 | # define ipv6_mreq ipv6_mreq_libc |
| 39 | # define sockaddr_in6 sockaddr_in6_libc |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 40 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 41 | #include <netinet/in.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 42 | #ifdef HAVE_NETINET_TCP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 43 | # include <netinet/tcp.h> |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 44 | #endif |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 45 | #ifdef HAVE_NETINET_UDP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 46 | # include <netinet/udp.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 47 | #endif |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 48 | #ifdef HAVE_NETINET_SCTP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 49 | # include <netinet/sctp.h> |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 50 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 51 | #include <arpa/inet.h> |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 52 | #include <net/if.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 53 | #include <asm/types.h> |
Denys Vlasenko | 99aa181 | 2013-02-08 18:49:06 +0100 | [diff] [blame] | 54 | #if defined(__GLIBC__) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 55 | # include <netipx/ipx.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 56 | #else |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 57 | # include <linux/ipx.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 58 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 59 | |
Denys Vlasenko | 99aa181 | 2013-02-08 18:49:06 +0100 | [diff] [blame] | 60 | #if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 61 | # if defined(HAVE_LINUX_IN6_H) |
| 62 | # if defined(HAVE_SIN6_SCOPE_ID_LINUX) |
| 63 | # undef in6_addr |
| 64 | # undef ipv6_mreq |
| 65 | # undef sockaddr_in6 |
| 66 | # define in6_addr in6_addr_kernel |
| 67 | # define ipv6_mreq ipv6_mreq_kernel |
| 68 | # define sockaddr_in6 sockaddr_in6_kernel |
| 69 | # endif |
| 70 | # include <linux/in6.h> |
| 71 | # if defined(HAVE_SIN6_SCOPE_ID_LINUX) |
| 72 | # undef in6_addr |
| 73 | # undef ipv6_mreq |
| 74 | # undef sockaddr_in6 |
| 75 | # define in6_addr in6_addr_libc |
| 76 | # define ipv6_mreq ipv6_mreq_libc |
| 77 | # define sockaddr_in6 sockaddr_in6_kernel |
| 78 | # endif |
| 79 | # endif |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 80 | #endif |
Wichert Akkerman | 505e176 | 1999-11-01 19:39:08 +0000 | [diff] [blame] | 81 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 82 | #if defined(HAVE_LINUX_NETLINK_H) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 83 | # include <linux/netlink.h> |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 84 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 85 | #if defined(HAVE_LINUX_IF_PACKET_H) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 86 | # include <linux/if_packet.h> |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 87 | #endif |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 88 | #if defined(HAVE_LINUX_ICMP_H) |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 89 | # include <linux/icmp.h> |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 90 | #endif |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 91 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 92 | # include <bluetooth/bluetooth.h> |
| 93 | # include <bluetooth/hci.h> |
| 94 | # include <bluetooth/l2cap.h> |
| 95 | # include <bluetooth/rfcomm.h> |
| 96 | # include <bluetooth/sco.h> |
| 97 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 98 | #ifndef PF_UNSPEC |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 99 | # define PF_UNSPEC AF_UNSPEC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 100 | #endif |
| 101 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 102 | #include "xlat/domains.h" |
| 103 | #include "xlat/addrfams.h" |
| 104 | #include "xlat/socktypes.h" |
| 105 | #include "xlat/sock_type_flags.h" |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 106 | #ifndef SOCK_TYPE_MASK |
| 107 | # define SOCK_TYPE_MASK 0xf |
| 108 | #endif |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 109 | #include "xlat/socketlayers.h" |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 110 | /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 111 | falls into "inet_protocols" array below!!!! This is intended!!! ***/ |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 112 | #include "xlat/inet_protocols.h" |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 113 | |
| 114 | #ifdef PF_NETLINK |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 115 | #include "xlat/netlink_protocols.h" |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 116 | #endif |
| 117 | |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 118 | #if defined(HAVE_BLUETOOTH_BLUETOOTH_H) |
| 119 | # include "xlat/bt_protocols.h" |
| 120 | #endif |
| 121 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 122 | #include "xlat/msg_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 123 | #include "xlat/sockoptions.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 124 | |
Denys Vlasenko | c36c352 | 2012-02-25 02:47:15 +0100 | [diff] [blame] | 125 | #if !defined(SOL_IP) && defined(IPPROTO_IP) |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 126 | #define SOL_IP IPPROTO_IP |
| 127 | #endif |
| 128 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 129 | #ifdef SOL_IP |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 130 | #include "xlat/sockipoptions.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 131 | #endif /* SOL_IP */ |
| 132 | |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 133 | #ifdef SOL_IPV6 |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 134 | #include "xlat/sockipv6options.h" |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 135 | #endif /* SOL_IPV6 */ |
| 136 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 137 | #ifdef SOL_IPX |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 138 | #include "xlat/sockipxoptions.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 139 | #endif /* SOL_IPX */ |
| 140 | |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 141 | #ifdef SOL_RAW |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 142 | #include "xlat/sockrawoptions.h" |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 143 | #endif /* SOL_RAW */ |
| 144 | |
| 145 | #ifdef SOL_PACKET |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 146 | #include "xlat/sockpacketoptions.h" |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 147 | #endif /* SOL_PACKET */ |
| 148 | |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 149 | #ifdef SOL_SCTP |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 150 | #include "xlat/socksctpoptions.h" |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 151 | #endif |
| 152 | |
Denys Vlasenko | c36c352 | 2012-02-25 02:47:15 +0100 | [diff] [blame] | 153 | #if !defined(SOL_TCP) && defined(IPPROTO_TCP) |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 154 | #define SOL_TCP IPPROTO_TCP |
| 155 | #endif |
| 156 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 157 | #ifdef SOL_TCP |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 158 | #include "xlat/socktcpoptions.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | #endif /* SOL_TCP */ |
| 160 | |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 161 | #ifdef SOL_RAW |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 162 | #include "xlat/icmpfilterflags.h" |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 163 | #endif /* SOL_RAW */ |
| 164 | |
Wichert Akkerman | b0c598f | 2002-04-01 12:48:06 +0000 | [diff] [blame] | 165 | #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */ |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 166 | #include "xlat/af_packet_types.h" |
Wichert Akkerman | b0c598f | 2002-04-01 12:48:06 +0000 | [diff] [blame] | 167 | #endif /* defined(AF_PACKET) */ |
| 168 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 169 | void |
Dmitry V. Levin | b6c32f4 | 2007-10-08 23:31:19 +0000 | [diff] [blame] | 170 | printsock(struct tcb *tcp, long addr, int addrlen) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 171 | { |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 172 | union { |
| 173 | char pad[128]; |
| 174 | struct sockaddr sa; |
| 175 | struct sockaddr_in sin; |
| 176 | struct sockaddr_un sau; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 177 | #ifdef HAVE_INET_NTOP |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 178 | struct sockaddr_in6 sa6; |
| 179 | #endif |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 180 | #if defined(AF_IPX) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 181 | struct sockaddr_ipx sipx; |
| 182 | #endif |
| 183 | #ifdef AF_PACKET |
| 184 | struct sockaddr_ll ll; |
| 185 | #endif |
| 186 | #ifdef AF_NETLINK |
| 187 | struct sockaddr_nl nl; |
| 188 | #endif |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 189 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 190 | struct sockaddr_hci hci; |
| 191 | struct sockaddr_l2 l2; |
| 192 | struct sockaddr_rc rc; |
| 193 | struct sockaddr_sco sco; |
| 194 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 195 | } addrbuf; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 196 | char string_addr[100]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 197 | |
| 198 | if (addr == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 199 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | if (!verbose(tcp)) { |
| 203 | tprintf("%#lx", addr); |
| 204 | return; |
| 205 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 206 | |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 207 | if (addrlen < 2 || addrlen > (int) sizeof(addrbuf)) |
Dmitry V. Levin | b6c32f4 | 2007-10-08 23:31:19 +0000 | [diff] [blame] | 208 | addrlen = sizeof(addrbuf); |
| 209 | |
| 210 | memset(&addrbuf, 0, sizeof(addrbuf)); |
| 211 | if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 212 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 213 | return; |
| 214 | } |
Dmitry V. Levin | b6c32f4 | 2007-10-08 23:31:19 +0000 | [diff] [blame] | 215 | addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0'; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 216 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 217 | tprints("{sa_family="); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 218 | printxval(addrfams, addrbuf.sa.sa_family, "AF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 219 | tprints(", "); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 220 | |
| 221 | switch (addrbuf.sa.sa_family) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 222 | case AF_UNIX: |
Dmitry V. Levin | b6c32f4 | 2007-10-08 23:31:19 +0000 | [diff] [blame] | 223 | if (addrlen == 2) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 224 | tprints("NULL"); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 225 | } else if (addrbuf.sau.sun_path[0]) { |
Dmitry V. Levin | c86340e | 2012-02-22 00:23:52 +0000 | [diff] [blame] | 226 | tprints("sun_path="); |
Dmitry V. Levin | 16fbe97 | 2007-10-13 21:03:17 +0000 | [diff] [blame] | 227 | printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path)); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 228 | } else { |
Dmitry V. Levin | c86340e | 2012-02-22 00:23:52 +0000 | [diff] [blame] | 229 | tprints("sun_path=@"); |
Dmitry V. Levin | 16fbe97 | 2007-10-13 21:03:17 +0000 | [diff] [blame] | 230 | printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1)); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 231 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 232 | break; |
| 233 | case AF_INET: |
John Hughes | 1fcb1d6 | 2001-09-18 15:56:53 +0000 | [diff] [blame] | 234 | tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")", |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 235 | ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 236 | break; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 237 | #ifdef HAVE_INET_NTOP |
| 238 | case AF_INET6: |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 239 | inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr)); |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 240 | tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u", |
| 241 | ntohs(addrbuf.sa6.sin6_port), string_addr, |
| 242 | addrbuf.sa6.sin6_flowinfo); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 243 | #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 244 | { |
| 245 | #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 246 | int numericscope = 0; |
| 247 | if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr) |
| 248 | || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) { |
| 249 | char scopebuf[IFNAMSIZ + 1]; |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 250 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 251 | if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL) |
| 252 | numericscope++; |
| 253 | else |
| 254 | tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf); |
| 255 | } else |
| 256 | numericscope++; |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 257 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 258 | if (numericscope) |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 259 | #endif |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 260 | tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id); |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 261 | } |
| 262 | #endif |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 263 | break; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 264 | #endif |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 265 | #if defined(AF_IPX) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 266 | case AF_IPX: |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 267 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 268 | int i; |
John Hughes | 1fcb1d6 | 2001-09-18 15:56:53 +0000 | [diff] [blame] | 269 | tprintf("sipx_port=htons(%u), ", |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 270 | ntohs(addrbuf.sipx.sipx_port)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 271 | /* Yes, I know, this does not look too |
| 272 | * strace-ish, but otherwise the IPX |
| 273 | * addresses just look monstrous... |
| 274 | * Anyways, feel free if you don't like |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 275 | * this way.. :) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 276 | */ |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 277 | tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network)); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 278 | for (i = 0; i < IPX_NODE_LEN; i++) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 279 | tprintf("%02x", addrbuf.sipx.sipx_node[i]); |
| 280 | tprintf("/[%02x]", addrbuf.sipx.sipx_type); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 281 | } |
| 282 | break; |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 283 | #endif /* AF_IPX */ |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 284 | #ifdef AF_PACKET |
| 285 | case AF_PACKET: |
| 286 | { |
| 287 | int i; |
Wichert Akkerman | b0c598f | 2002-04-01 12:48:06 +0000 | [diff] [blame] | 288 | tprintf("proto=%#04x, if%d, pkttype=", |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 289 | ntohs(addrbuf.ll.sll_protocol), |
Wichert Akkerman | b0c598f | 2002-04-01 12:48:06 +0000 | [diff] [blame] | 290 | addrbuf.ll.sll_ifindex); |
Dmitry V. Levin | 1306365 | 2014-09-10 00:13:56 +0000 | [diff] [blame] | 291 | printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???"); |
Wichert Akkerman | b0c598f | 2002-04-01 12:48:06 +0000 | [diff] [blame] | 292 | tprintf(", addr(%d)={%d, ", |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 293 | addrbuf.ll.sll_halen, |
| 294 | addrbuf.ll.sll_hatype); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 295 | for (i = 0; i < addrbuf.ll.sll_halen; i++) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 296 | tprintf("%02x", addrbuf.ll.sll_addr[i]); |
| 297 | } |
| 298 | break; |
| 299 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 300 | #endif /* AF_PACKET */ |
Roland McGrath | 36ef1bc | 2003-11-06 23:41:23 +0000 | [diff] [blame] | 301 | #ifdef AF_NETLINK |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 302 | case AF_NETLINK: |
| 303 | tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups); |
| 304 | break; |
| 305 | #endif /* AF_NETLINK */ |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 306 | #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H) |
| 307 | case AF_BLUETOOTH: |
| 308 | tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or " |
| 309 | "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or " |
| 310 | "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or " |
| 311 | "{hci_dev=htobs(%d)}", |
| 312 | addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1], |
| 313 | addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3], |
| 314 | addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5], |
| 315 | addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1], |
| 316 | addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3], |
| 317 | addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5], |
| 318 | addrbuf.rc.rc_channel, |
| 319 | btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0], |
| 320 | addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2], |
| 321 | addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4], |
| 322 | addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid), |
| 323 | btohs(addrbuf.hci.hci_dev)); |
| 324 | break; |
| 325 | #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 326 | /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5 |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 327 | AF_X25 AF_ROSE etc. still need to be done */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 328 | |
| 329 | default: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 330 | tprints("sa_data="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 331 | printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data, |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 332 | sizeof addrbuf.sa.sa_data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | break; |
| 334 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 335 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | #if HAVE_SENDMSG |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 339 | #include "xlat/scmvals.h" |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 340 | |
| 341 | static void |
Denys Vlasenko | 132c52a | 2009-03-23 13:12:46 +0000 | [diff] [blame] | 342 | printcmsghdr(struct tcb *tcp, unsigned long addr, unsigned long len) |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 343 | { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 344 | struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ? |
| 345 | NULL : malloc(len); |
| 346 | if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) { |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 347 | tprintf(", msg_control=%#lx", addr); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 348 | free(cmsg); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 349 | return; |
| 350 | } |
| 351 | |
Denys Vlasenko | 132c52a | 2009-03-23 13:12:46 +0000 | [diff] [blame] | 352 | tprintf(", {cmsg_len=%u, cmsg_level=", (unsigned) cmsg->cmsg_len); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 353 | printxval(socketlayers, cmsg->cmsg_level, "SOL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 354 | tprints(", cmsg_type="); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 355 | |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 356 | if (cmsg->cmsg_level == SOL_SOCKET) { |
| 357 | unsigned long cmsg_len; |
Roland McGrath | 96ad7b8 | 2005-02-02 03:11:32 +0000 | [diff] [blame] | 358 | |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 359 | printxval(scmvals, cmsg->cmsg_type, "SCM_???"); |
| 360 | cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len; |
| 361 | |
| 362 | if (cmsg->cmsg_type == SCM_RIGHTS |
| 363 | && CMSG_LEN(sizeof(int)) <= cmsg_len) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 364 | int *fds = (int *) CMSG_DATA(cmsg); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 365 | int first = 1; |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 366 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 367 | tprints(", {"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 368 | while ((char *) fds < ((char *) cmsg + cmsg_len)) { |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 369 | if (!first) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 370 | tprints(", "); |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 371 | printfd(tcp, *fds++); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 372 | first = 0; |
| 373 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 374 | tprints("}}"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 375 | free(cmsg); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 378 | if (cmsg->cmsg_type == SCM_CREDENTIALS |
| 379 | && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 380 | struct ucred *uc = (struct ucred *) CMSG_DATA(cmsg); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 381 | |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 382 | tprintf("{pid=%ld, uid=%ld, gid=%ld}}", |
| 383 | (long)uc->pid, (long)uc->uid, (long)uc->gid); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 384 | free(cmsg); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 385 | return; |
| 386 | } |
| 387 | } |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 388 | free(cmsg); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 389 | tprints(", ...}"); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 390 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 391 | |
| 392 | static void |
Denys Vlasenko | e0bc222 | 2012-04-28 14:26:18 +0200 | [diff] [blame] | 393 | do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 394 | { |
| 395 | tprintf("{msg_name(%d)=", msg->msg_namelen); |
| 396 | printsock(tcp, (long)msg->msg_name, msg->msg_namelen); |
| 397 | |
| 398 | tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen); |
Denys Vlasenko | e0bc222 | 2012-04-28 14:26:18 +0200 | [diff] [blame] | 399 | tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen, |
| 400 | (unsigned long)msg->msg_iov, 1, data_size); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 401 | |
| 402 | #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL |
| 403 | tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen); |
| 404 | if (msg->msg_controllen) |
| 405 | printcmsghdr(tcp, (unsigned long) msg->msg_control, |
| 406 | msg->msg_controllen); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 407 | tprints(", msg_flags="); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 408 | printflags(msg_flags, msg->msg_flags, "MSG_???"); |
| 409 | #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */ |
| 410 | tprintf("msg_accrights=%#lx, msg_accrightslen=%u", |
| 411 | (unsigned long) msg->msg_accrights, msg->msg_accrightslen); |
| 412 | #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 413 | tprints("}"); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 414 | } |
| 415 | |
Denys Vlasenko | 3e759d4 | 2013-02-12 11:57:48 +0100 | [diff] [blame] | 416 | struct msghdr32 { |
| 417 | uint32_t /* void* */ msg_name; |
| 418 | uint32_t /* socklen_t */msg_namelen; |
| 419 | uint32_t /* iovec* */ msg_iov; |
| 420 | uint32_t /* size_t */ msg_iovlen; |
| 421 | uint32_t /* void* */ msg_control; |
| 422 | uint32_t /* size_t */ msg_controllen; |
| 423 | uint32_t /* int */ msg_flags; |
| 424 | }; |
| 425 | struct mmsghdr32 { |
| 426 | struct msghdr32 msg_hdr; |
| 427 | uint32_t /* unsigned */ msg_len; |
| 428 | }; |
| 429 | |
Masatake YAMATO | caf6a43 | 2014-11-07 01:23:25 +0900 | [diff] [blame] | 430 | #ifndef HAVE_STRUCT_MMSGHDR |
| 431 | struct mmsghdr { |
| 432 | struct msghdr msg_hdr; |
| 433 | unsigned msg_len; |
| 434 | }; |
| 435 | #endif |
| 436 | |
Masatake YAMATO | b248543 | 2014-11-07 01:23:24 +0900 | [diff] [blame] | 437 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 438 | static void |
| 439 | copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32) |
| 440 | { |
| 441 | to_msg->msg_name = (void*)(long)from_msg32->msg_name; |
| 442 | to_msg->msg_namelen = from_msg32->msg_namelen; |
| 443 | to_msg->msg_iov = (void*)(long)from_msg32->msg_iov; |
| 444 | to_msg->msg_iovlen = from_msg32->msg_iovlen; |
| 445 | to_msg->msg_control = (void*)(long)from_msg32->msg_control; |
| 446 | to_msg->msg_controllen = from_msg32->msg_controllen; |
| 447 | to_msg->msg_flags = from_msg32->msg_flags; |
| 448 | } |
| 449 | #endif |
| 450 | |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 451 | static bool |
| 452 | extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg) |
| 453 | { |
| 454 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 455 | if (current_wordsize == 4) { |
| 456 | struct msghdr32 msg32; |
| 457 | |
| 458 | if (umove(tcp, addr, &msg32) < 0) |
| 459 | return false; |
Masatake YAMATO | b248543 | 2014-11-07 01:23:24 +0900 | [diff] [blame] | 460 | copy_from_msghdr32(msg, &msg32); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 461 | } else |
| 462 | #endif |
| 463 | if (umove(tcp, addr, msg) < 0) |
| 464 | return false; |
| 465 | return true; |
| 466 | } |
| 467 | |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 468 | static bool |
| 469 | extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg) |
| 470 | { |
| 471 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 472 | if (current_wordsize == 4) { |
| 473 | struct mmsghdr32 mmsg32; |
| 474 | |
| 475 | addr += sizeof(struct mmsghdr32) * idx; |
| 476 | if (umove(tcp, addr, &mmsg32) < 0) |
| 477 | return false; |
| 478 | |
| 479 | copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr); |
| 480 | mmsg->msg_len = mmsg32.msg_len; |
| 481 | } else |
| 482 | #endif |
| 483 | { |
| 484 | addr += sizeof(*mmsg) * idx; |
| 485 | if (umove(tcp, addr, mmsg) < 0) |
| 486 | return false; |
| 487 | } |
| 488 | return true; |
| 489 | } |
| 490 | |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 491 | static void |
Denys Vlasenko | e0bc222 | 2012-04-28 14:26:18 +0200 | [diff] [blame] | 492 | printmsghdr(struct tcb *tcp, long addr, unsigned long data_size) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 493 | { |
| 494 | struct msghdr msg; |
| 495 | |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 496 | if (extractmsghdr(tcp, addr, &msg)) |
| 497 | do_msghdr(tcp, &msg, data_size); |
| 498 | else |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 499 | tprintf("%#lx", addr); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | void |
| 503 | dumpiov_in_msghdr(struct tcb *tcp, long addr) |
| 504 | { |
| 505 | struct msghdr msg; |
| 506 | |
| 507 | if (extractmsghdr(tcp, addr, &msg)) |
| 508 | dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 511 | static void |
Dmitry V. Levin | 5ea9765 | 2012-05-01 20:41:40 +0000 | [diff] [blame] | 512 | printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 513 | { |
Masatake YAMATO | caf6a43 | 2014-11-07 01:23:25 +0900 | [diff] [blame] | 514 | struct mmsghdr mmsg; |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 515 | |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 516 | if (extractmmsghdr(tcp, addr, idx, &mmsg)) { |
| 517 | tprints("{"); |
| 518 | do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len); |
| 519 | tprintf(", %u}", mmsg.msg_len); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 520 | } |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 521 | else |
| 522 | tprintf("%#lx", addr); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 523 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 524 | |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 525 | static void |
Dmitry V. Levin | 5ea9765 | 2012-05-01 20:41:40 +0000 | [diff] [blame] | 526 | decode_mmsg(struct tcb *tcp, unsigned long msg_len) |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 527 | { |
| 528 | /* mmsgvec */ |
| 529 | if (syserror(tcp)) { |
| 530 | tprintf("%#lx", tcp->u_arg[1]); |
| 531 | } else { |
| 532 | unsigned int len = tcp->u_rval; |
| 533 | unsigned int i; |
| 534 | |
| 535 | tprints("{"); |
| 536 | for (i = 0; i < len; ++i) { |
| 537 | if (i) |
| 538 | tprints(", "); |
Dmitry V. Levin | 5ea9765 | 2012-05-01 20:41:40 +0000 | [diff] [blame] | 539 | printmmsghdr(tcp, tcp->u_arg[1], i, msg_len); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 540 | } |
| 541 | tprints("}"); |
| 542 | } |
| 543 | /* vlen */ |
| 544 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
| 545 | /* flags */ |
| 546 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 547 | } |
| 548 | |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 549 | void |
| 550 | dumpiov_in_mmsghdr(struct tcb *tcp, long addr) |
| 551 | { |
| 552 | unsigned int len = tcp->u_rval; |
| 553 | unsigned int i; |
| 554 | struct mmsghdr mmsg; |
| 555 | |
| 556 | for (i = 0; i < len; ++i) { |
| 557 | if (extractmmsghdr(tcp, addr, i, &mmsg)) { |
| 558 | tprintf(" = %lu buffers in vector %u\n", |
| 559 | (unsigned long)mmsg.msg_hdr.msg_iovlen, i); |
| 560 | dumpiov(tcp, mmsg.msg_hdr.msg_iovlen, |
| 561 | (long)mmsg.msg_hdr.msg_iov); |
| 562 | } |
| 563 | } |
| 564 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 565 | #endif /* HAVE_SENDMSG */ |
| 566 | |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 567 | /* |
| 568 | * low bits of the socket type define real socket type, |
| 569 | * other bits are socket type flags. |
| 570 | */ |
| 571 | static void |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 572 | tprint_sock_type(int flags) |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 573 | { |
| 574 | const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK); |
| 575 | |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 576 | if (str) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 577 | tprints(str); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 578 | flags &= ~SOCK_TYPE_MASK; |
| 579 | if (!flags) |
| 580 | return; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 581 | tprints("|"); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 582 | } |
| 583 | printflags(sock_type_flags, flags, "SOCK_???"); |
| 584 | } |
| 585 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 586 | int |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 587 | sys_socket(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 588 | { |
| 589 | if (entering(tcp)) { |
| 590 | printxval(domains, tcp->u_arg[0], "PF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 591 | tprints(", "); |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 592 | tprint_sock_type(tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 593 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 594 | switch (tcp->u_arg[0]) { |
| 595 | case PF_INET: |
Roland McGrath | 8758e54 | 2003-06-23 23:39:59 +0000 | [diff] [blame] | 596 | #ifdef PF_INET6 |
| 597 | case PF_INET6: |
| 598 | #endif |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 599 | printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 600 | break; |
| 601 | #ifdef PF_IPX |
| 602 | case PF_IPX: |
| 603 | /* BTW: I don't believe this.. */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 604 | tprints("["); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 605 | printxval(domains, tcp->u_arg[2], "PF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 606 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 607 | break; |
| 608 | #endif /* PF_IPX */ |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 609 | #ifdef PF_NETLINK |
| 610 | case PF_NETLINK: |
| 611 | printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???"); |
| 612 | break; |
| 613 | #endif |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 614 | #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H) |
| 615 | case PF_BLUETOOTH: |
| 616 | printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???"); |
| 617 | break; |
| 618 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 619 | default: |
| 620 | tprintf("%lu", tcp->u_arg[2]); |
| 621 | break; |
| 622 | } |
| 623 | } |
| 624 | return 0; |
| 625 | } |
| 626 | |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 627 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 628 | sys_bind(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 629 | { |
| 630 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 631 | printfd(tcp, tcp->u_arg[0]); |
| 632 | tprints(", "); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 633 | printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 634 | tprintf(", %lu", tcp->u_arg[2]); |
| 635 | } |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 640 | sys_connect(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 641 | { |
| 642 | return sys_bind(tcp); |
| 643 | } |
| 644 | |
| 645 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 646 | sys_listen(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 647 | { |
| 648 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 649 | printfd(tcp, tcp->u_arg[0]); |
| 650 | tprints(", "); |
| 651 | tprintf("%lu", tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 656 | static int |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 657 | do_sockname(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 658 | { |
| 659 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 660 | printfd(tcp, tcp->u_arg[0]); |
| 661 | tprints(", "); |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | if (!tcp->u_arg[2]) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 665 | tprintf("%#lx, NULL", tcp->u_arg[1]); |
| 666 | else { |
Dmitry V. Levin | 2fc6615 | 2009-01-01 22:47:51 +0000 | [diff] [blame] | 667 | int len; |
| 668 | if (tcp->u_arg[1] == 0 || syserror(tcp) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 669 | || umove(tcp, tcp->u_arg[2], &len) < 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 670 | tprintf("%#lx", tcp->u_arg[1]); |
| 671 | } else { |
Dmitry V. Levin | 2fc6615 | 2009-01-01 22:47:51 +0000 | [diff] [blame] | 672 | printsock(tcp, tcp->u_arg[1], len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 673 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 674 | tprints(", "); |
Dmitry V. Levin | 2fc6615 | 2009-01-01 22:47:51 +0000 | [diff] [blame] | 675 | printnum_int(tcp, tcp->u_arg[2], "%u"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 676 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 677 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 678 | tprints(", "); |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 679 | printflags(sock_type_flags, tcp->u_arg[flags_arg], |
| 680 | "SOCK_???"); |
| 681 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | int |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 686 | sys_accept(struct tcb *tcp) |
| 687 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 688 | do_sockname(tcp, -1); |
| 689 | return RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 690 | } |
| 691 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 692 | int |
| 693 | sys_accept4(struct tcb *tcp) |
| 694 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 695 | do_sockname(tcp, 3); |
| 696 | return RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 697 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 698 | |
| 699 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 700 | sys_send(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 701 | { |
| 702 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 703 | printfd(tcp, tcp->u_arg[0]); |
| 704 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 705 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 706 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 707 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 708 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 709 | } |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 714 | sys_sendto(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 715 | { |
| 716 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 717 | printfd(tcp, tcp->u_arg[0]); |
| 718 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 719 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 720 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 721 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 722 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 723 | /* to address */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 724 | tprints(", "); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 725 | printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 726 | /* to length */ |
| 727 | tprintf(", %lu", tcp->u_arg[5]); |
| 728 | } |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | #ifdef HAVE_SENDMSG |
| 733 | |
| 734 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 735 | sys_sendmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 736 | { |
| 737 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 738 | printfd(tcp, tcp->u_arg[0]); |
| 739 | tprints(", "); |
Dmitry V. Levin | 043b5f8 | 2012-05-01 20:30:02 +0000 | [diff] [blame] | 740 | printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 741 | /* flags */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 742 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 743 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 744 | } |
| 745 | return 0; |
| 746 | } |
| 747 | |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 748 | int |
| 749 | sys_sendmmsg(struct tcb *tcp) |
| 750 | { |
| 751 | if (entering(tcp)) { |
| 752 | /* sockfd */ |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 753 | printfd(tcp, tcp->u_arg[0]); |
| 754 | tprints(", "); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 755 | if (!verbose(tcp)) { |
| 756 | tprintf("%#lx, %u, ", |
| 757 | tcp->u_arg[1], (unsigned int) tcp->u_arg[2]); |
| 758 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 759 | } |
| 760 | } else { |
| 761 | if (verbose(tcp)) |
Dmitry V. Levin | 5ea9765 | 2012-05-01 20:41:40 +0000 | [diff] [blame] | 762 | decode_mmsg(tcp, (unsigned long) -1L); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 763 | } |
| 764 | return 0; |
| 765 | } |
| 766 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 767 | #endif /* HAVE_SENDMSG */ |
| 768 | |
| 769 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 770 | sys_recv(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 771 | { |
| 772 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 773 | printfd(tcp, tcp->u_arg[0]); |
| 774 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 775 | } else { |
| 776 | if (syserror(tcp)) |
| 777 | tprintf("%#lx", tcp->u_arg[1]); |
| 778 | else |
| 779 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 780 | |
| 781 | tprintf(", %lu, ", tcp->u_arg[2]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 782 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 783 | } |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 788 | sys_recvfrom(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 789 | { |
| 790 | int fromlen; |
| 791 | |
| 792 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 793 | printfd(tcp, tcp->u_arg[0]); |
| 794 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 795 | } else { |
| 796 | if (syserror(tcp)) { |
| 797 | tprintf("%#lx, %lu, %lu, %#lx, %#lx", |
| 798 | tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3], |
| 799 | tcp->u_arg[4], tcp->u_arg[5]); |
| 800 | return 0; |
| 801 | } |
| 802 | /* buf */ |
| 803 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 804 | /* len */ |
| 805 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 806 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 807 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 808 | /* from address, len */ |
| 809 | if (!tcp->u_arg[4] || !tcp->u_arg[5]) { |
| 810 | if (tcp->u_arg[4] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 811 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 812 | else |
| 813 | tprintf(", %#lx", tcp->u_arg[4]); |
| 814 | if (tcp->u_arg[5] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 815 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 816 | else |
| 817 | tprintf(", %#lx", tcp->u_arg[5]); |
| 818 | return 0; |
| 819 | } |
| 820 | if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 821 | tprints(", {...}, [?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 822 | return 0; |
| 823 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 824 | tprints(", "); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 825 | printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 826 | /* from length */ |
| 827 | tprintf(", [%u]", fromlen); |
| 828 | } |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | #ifdef HAVE_SENDMSG |
| 833 | |
| 834 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 835 | sys_recvmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 836 | { |
| 837 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 838 | printfd(tcp, tcp->u_arg[0]); |
| 839 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 840 | } else { |
| 841 | if (syserror(tcp) || !verbose(tcp)) |
| 842 | tprintf("%#lx", tcp->u_arg[1]); |
| 843 | else |
Denys Vlasenko | e0bc222 | 2012-04-28 14:26:18 +0200 | [diff] [blame] | 844 | printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 845 | /* flags */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 846 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 847 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 848 | } |
| 849 | return 0; |
| 850 | } |
| 851 | |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 852 | int |
| 853 | sys_recvmmsg(struct tcb *tcp) |
| 854 | { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 855 | /* +5 chars are for "left " prefix */ |
| 856 | static char str[5 + TIMESPEC_TEXT_BUFSIZE]; |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 857 | |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 858 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 859 | printfd(tcp, tcp->u_arg[0]); |
| 860 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 861 | if (verbose(tcp)) { |
| 862 | sprint_timespec(str, tcp, tcp->u_arg[4]); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 863 | /* Abusing tcp->auxstr as temp storage. |
| 864 | * Will be used and freed on syscall exit. |
| 865 | */ |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 866 | tcp->auxstr = strdup(str); |
| 867 | } else { |
| 868 | tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]); |
| 869 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 870 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 871 | print_timespec(tcp, tcp->u_arg[4]); |
| 872 | } |
| 873 | return 0; |
| 874 | } else { |
| 875 | if (verbose(tcp)) { |
Dmitry V. Levin | 5ea9765 | 2012-05-01 20:41:40 +0000 | [diff] [blame] | 876 | decode_mmsg(tcp, 0); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 877 | /* timeout on entrance */ |
| 878 | tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}"); |
| 879 | free((void *) tcp->auxstr); |
| 880 | tcp->auxstr = NULL; |
| 881 | } |
| 882 | if (syserror(tcp)) |
| 883 | return 0; |
| 884 | if (tcp->u_rval == 0) { |
| 885 | tcp->auxstr = "Timeout"; |
| 886 | return RVAL_STR; |
| 887 | } |
| 888 | if (!verbose(tcp)) |
| 889 | return 0; |
| 890 | /* timeout on exit */ |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 891 | sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 892 | tcp->auxstr = str; |
| 893 | return RVAL_STR; |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 894 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 895 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 896 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 897 | #endif /* HAVE_SENDMSG */ |
| 898 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 899 | #include "xlat/shutdown_modes.h" |
Sebastian Pipping | 9cd3850 | 2011-03-03 01:12:25 +0100 | [diff] [blame] | 900 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 901 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 902 | sys_shutdown(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 903 | { |
| 904 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 905 | printfd(tcp, tcp->u_arg[0]); |
| 906 | tprints(", "); |
Sebastian Pipping | 9cd3850 | 2011-03-03 01:12:25 +0100 | [diff] [blame] | 907 | printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 908 | } |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 913 | sys_getsockname(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 914 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 915 | return do_sockname(tcp, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 918 | static int |
| 919 | do_pipe(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 920 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 921 | if (exiting(tcp)) { |
| 922 | if (syserror(tcp)) { |
| 923 | tprintf("%#lx", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 924 | } else { |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 925 | #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 926 | int fds[2]; |
| 927 | |
| 928 | if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 929 | tprints("[...]"); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 930 | else |
| 931 | tprintf("[%u, %u]", fds[0], fds[1]); |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 932 | #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 933 | tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp)); |
| 934 | #else |
| 935 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 936 | #endif |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 937 | } |
| 938 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 939 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 940 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 941 | } |
| 942 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 947 | sys_pipe(struct tcb *tcp) |
| 948 | { |
| 949 | return do_pipe(tcp, -1); |
| 950 | } |
| 951 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 952 | int |
| 953 | sys_pipe2(struct tcb *tcp) |
| 954 | { |
| 955 | return do_pipe(tcp, 1); |
| 956 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 957 | |
| 958 | int |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 959 | sys_socketpair(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 960 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 961 | int fds[2]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 962 | |
| 963 | if (entering(tcp)) { |
| 964 | printxval(domains, tcp->u_arg[0], "PF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 965 | tprints(", "); |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 966 | tprint_sock_type(tcp->u_arg[1]); |
Dmitry V. Levin | 033fb91 | 2014-03-11 22:50:39 +0000 | [diff] [blame] | 967 | tprintf(", %lu", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 968 | } else { |
| 969 | if (syserror(tcp)) { |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 970 | tprintf(", %#lx", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 971 | return 0; |
| 972 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 973 | if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 974 | tprints(", [...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 975 | else |
| 976 | tprintf(", [%u, %u]", fds[0], fds[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 977 | } |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | int |
Dmitry V. Levin | 3128919 | 2009-11-06 18:05:40 +0000 | [diff] [blame] | 982 | sys_getsockopt(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 983 | { |
| 984 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 985 | printfd(tcp, tcp->u_arg[0]); |
| 986 | tprints(", "); |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 987 | printxval(socketlayers, tcp->u_arg[1], "SOL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 988 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 989 | switch (tcp->u_arg[1]) { |
| 990 | case SOL_SOCKET: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 991 | printxval(sockoptions, tcp->u_arg[2], "SO_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 992 | break; |
| 993 | #ifdef SOL_IP |
| 994 | case SOL_IP: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 995 | printxval(sockipoptions, tcp->u_arg[2], "IP_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 996 | break; |
| 997 | #endif |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 998 | #ifdef SOL_IPV6 |
| 999 | case SOL_IPV6: |
| 1000 | printxval(sockipv6options, tcp->u_arg[2], "IPV6_???"); |
| 1001 | break; |
| 1002 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1003 | #ifdef SOL_IPX |
| 1004 | case SOL_IPX: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1005 | printxval(sockipxoptions, tcp->u_arg[2], "IPX_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | #endif |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1008 | #ifdef SOL_PACKET |
| 1009 | case SOL_PACKET: |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1010 | printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???"); |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1011 | break; |
| 1012 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1013 | #ifdef SOL_TCP |
| 1014 | case SOL_TCP: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1015 | printxval(socktcpoptions, tcp->u_arg[2], "TCP_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1016 | break; |
| 1017 | #endif |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 1018 | #ifdef SOL_SCTP |
| 1019 | case SOL_SCTP: |
| 1020 | printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???"); |
| 1021 | break; |
| 1022 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1023 | |
| 1024 | /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25 |
| 1025 | * etc. still need work */ |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 1026 | default: |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1027 | tprintf("%lu", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1028 | break; |
| 1029 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1030 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1031 | } else { |
Roland McGrath | fc544db | 2005-02-02 02:48:57 +0000 | [diff] [blame] | 1032 | int len; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1033 | if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) { |
Dmitry V. Levin | 3128919 | 2009-11-06 18:05:40 +0000 | [diff] [blame] | 1034 | tprintf("%#lx, %#lx", |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1035 | tcp->u_arg[3], tcp->u_arg[4]); |
| 1036 | return 0; |
| 1037 | } |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1038 | |
| 1039 | switch (tcp->u_arg[1]) { |
| 1040 | case SOL_SOCKET: |
| 1041 | switch (tcp->u_arg[2]) { |
| 1042 | #ifdef SO_LINGER |
| 1043 | case SO_LINGER: |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1044 | if (len == sizeof(struct linger)) { |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1045 | struct linger linger; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1046 | if (umove(tcp, |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1047 | tcp->u_arg[3], |
| 1048 | &linger) < 0) |
| 1049 | break; |
Dmitry V. Levin | 3128919 | 2009-11-06 18:05:40 +0000 | [diff] [blame] | 1050 | tprintf("{onoff=%d, linger=%d}, " |
Roland McGrath | 96ad7b8 | 2005-02-02 03:11:32 +0000 | [diff] [blame] | 1051 | "[%d]", |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1052 | linger.l_onoff, |
| 1053 | linger.l_linger, |
| 1054 | len); |
| 1055 | return 0; |
| 1056 | } |
| 1057 | break; |
| 1058 | #endif |
Dmitry V. Levin | 0ddd8ad | 2010-12-03 16:54:53 +0000 | [diff] [blame] | 1059 | #ifdef SO_PEERCRED |
| 1060 | case SO_PEERCRED: |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1061 | if (len == sizeof(struct ucred)) { |
Dmitry V. Levin | 0ddd8ad | 2010-12-03 16:54:53 +0000 | [diff] [blame] | 1062 | struct ucred uc; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1063 | if (umove(tcp, |
Dmitry V. Levin | 0ddd8ad | 2010-12-03 16:54:53 +0000 | [diff] [blame] | 1064 | tcp->u_arg[3], |
| 1065 | &uc) < 0) |
| 1066 | break; |
| 1067 | tprintf("{pid=%ld, uid=%ld, gid=%ld}, " |
| 1068 | "[%d]", |
| 1069 | (long)uc.pid, |
| 1070 | (long)uc.uid, |
| 1071 | (long)uc.gid, |
| 1072 | len); |
| 1073 | return 0; |
| 1074 | } |
| 1075 | break; |
| 1076 | #endif |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1077 | } |
| 1078 | break; |
Dmitry V. Levin | ca75bd6 | 2009-11-13 12:51:04 +0000 | [diff] [blame] | 1079 | case SOL_PACKET: |
| 1080 | switch (tcp->u_arg[2]) { |
| 1081 | #ifdef PACKET_STATISTICS |
| 1082 | case PACKET_STATISTICS: |
| 1083 | if (len == sizeof(struct tpacket_stats)) { |
| 1084 | struct tpacket_stats stats; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1085 | if (umove(tcp, |
Dmitry V. Levin | ca75bd6 | 2009-11-13 12:51:04 +0000 | [diff] [blame] | 1086 | tcp->u_arg[3], |
| 1087 | &stats) < 0) |
| 1088 | break; |
| 1089 | tprintf("{packets=%u, drops=%u}, " |
| 1090 | "[%d]", |
| 1091 | stats.tp_packets, |
| 1092 | stats.tp_drops, |
| 1093 | len); |
| 1094 | return 0; |
| 1095 | } |
| 1096 | break; |
| 1097 | #endif |
| 1098 | } |
| 1099 | break; |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1102 | if (len == sizeof(int)) { |
Dmitry V. Levin | 3128919 | 2009-11-06 18:05:40 +0000 | [diff] [blame] | 1103 | printnum_int(tcp, tcp->u_arg[3], "%d"); |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1104 | } |
| 1105 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1106 | printstr(tcp, tcp->u_arg[3], len); |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1107 | } |
Roland McGrath | fc544db | 2005-02-02 02:48:57 +0000 | [diff] [blame] | 1108 | tprintf(", [%d]", len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1109 | } |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1113 | #if defined(ICMP_FILTER) |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1114 | static void printicmpfilter(struct tcb *tcp, long addr) |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1115 | { |
| 1116 | struct icmp_filter filter; |
| 1117 | |
| 1118 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1119 | tprints("NULL"); |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1120 | return; |
| 1121 | } |
| 1122 | if (syserror(tcp) || !verbose(tcp)) { |
| 1123 | tprintf("%#lx", addr); |
| 1124 | return; |
| 1125 | } |
| 1126 | if (umove(tcp, addr, &filter) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1127 | tprints("{...}"); |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1128 | return; |
| 1129 | } |
| 1130 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1131 | tprints("~("); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1132 | printflags(icmpfilterflags, ~filter.data, "ICMP_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1133 | tprints(")"); |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 1134 | } |
| 1135 | #endif /* ICMP_FILTER */ |
| 1136 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1137 | static int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1138 | printsockopt(struct tcb *tcp, int level, int name, long addr, int len) |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1139 | { |
| 1140 | printxval(socketlayers, level, "SOL_??"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1141 | tprints(", "); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1142 | switch (level) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1143 | case SOL_SOCKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1144 | printxval(sockoptions, name, "SO_???"); |
| 1145 | switch (name) { |
| 1146 | #if defined(SO_LINGER) |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1147 | case SO_LINGER: |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1148 | if (len == sizeof(struct linger)) { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1149 | struct linger linger; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1150 | if (umove(tcp, addr, &linger) < 0) |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1151 | break; |
| 1152 | tprintf(", {onoff=%d, linger=%d}", |
| 1153 | linger.l_onoff, |
| 1154 | linger.l_linger); |
| 1155 | return 0; |
| 1156 | } |
| 1157 | break; |
| 1158 | #endif |
| 1159 | } |
| 1160 | break; |
| 1161 | #ifdef SOL_IP |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1162 | case SOL_IP: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1163 | printxval(sockipoptions, name, "IP_???"); |
| 1164 | break; |
| 1165 | #endif |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 1166 | #ifdef SOL_IPV6 |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1167 | case SOL_IPV6: |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 1168 | printxval(sockipv6options, name, "IPV6_???"); |
| 1169 | break; |
| 1170 | #endif |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1171 | #ifdef SOL_IPX |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1172 | case SOL_IPX: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1173 | printxval(sockipxoptions, name, "IPX_???"); |
| 1174 | break; |
| 1175 | #endif |
| 1176 | #ifdef SOL_PACKET |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1177 | case SOL_PACKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1178 | printxval(sockpacketoptions, name, "PACKET_???"); |
| 1179 | /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */ |
Dmitry V. Levin | ca75bd6 | 2009-11-13 12:51:04 +0000 | [diff] [blame] | 1180 | switch (name) { |
| 1181 | #ifdef PACKET_RX_RING |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1182 | case PACKET_RX_RING: |
Dmitry V. Levin | ca75bd6 | 2009-11-13 12:51:04 +0000 | [diff] [blame] | 1183 | #endif |
| 1184 | #ifdef PACKET_TX_RING |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1185 | case PACKET_TX_RING: |
Dmitry V. Levin | ca75bd6 | 2009-11-13 12:51:04 +0000 | [diff] [blame] | 1186 | #endif |
| 1187 | #if defined(PACKET_RX_RING) || defined(PACKET_TX_RING) |
| 1188 | if (len == sizeof(struct tpacket_req)) { |
| 1189 | struct tpacket_req req; |
| 1190 | if (umove(tcp, addr, &req) < 0) |
| 1191 | break; |
| 1192 | tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}", |
| 1193 | req.tp_block_size, |
| 1194 | req.tp_block_nr, |
| 1195 | req.tp_frame_size, |
| 1196 | req.tp_frame_nr); |
| 1197 | return 0; |
| 1198 | } |
| 1199 | break; |
| 1200 | #endif /* PACKET_RX_RING || PACKET_TX_RING */ |
| 1201 | } |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | #endif |
| 1204 | #ifdef SOL_TCP |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1205 | case SOL_TCP: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1206 | printxval(socktcpoptions, name, "TCP_???"); |
| 1207 | break; |
| 1208 | #endif |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 1209 | #ifdef SOL_SCTP |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1210 | case SOL_SCTP: |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 1211 | printxval(socksctpoptions, name, "SCTP_???"); |
| 1212 | break; |
| 1213 | #endif |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1214 | #ifdef SOL_RAW |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1215 | case SOL_RAW: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1216 | printxval(sockrawoptions, name, "RAW_???"); |
| 1217 | switch (name) { |
| 1218 | #if defined(ICMP_FILTER) |
Denys Vlasenko | b237b1b | 2012-02-27 13:56:59 +0100 | [diff] [blame] | 1219 | case ICMP_FILTER: |
| 1220 | tprints(", "); |
| 1221 | printicmpfilter(tcp, addr); |
| 1222 | return 0; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1223 | #endif |
| 1224 | } |
| 1225 | break; |
| 1226 | #endif |
| 1227 | |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 1228 | /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25 |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1229 | * etc. still need work */ |
| 1230 | |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 1231 | default: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1232 | tprintf("%u", name); |
| 1233 | } |
| 1234 | |
| 1235 | /* default arg printing */ |
| 1236 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1237 | tprints(", "); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 1238 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1239 | if (len == sizeof(int)) { |
| 1240 | printnum_int(tcp, addr, "%d"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1241 | } |
| 1242 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1243 | printstr(tcp, addr, len); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1244 | } |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1248 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1249 | sys_setsockopt(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1250 | { |
| 1251 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 1252 | printfd(tcp, tcp->u_arg[0]); |
| 1253 | tprints(", "); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1254 | printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1255 | tcp->u_arg[3], tcp->u_arg[4]); |
John Hughes | 93f7fcc | 2002-05-22 15:46:49 +0000 | [diff] [blame] | 1256 | tprintf(", %lu", tcp->u_arg[4]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1257 | } |
| 1258 | return 0; |
| 1259 | } |