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