Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +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> |
| 5 | * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include "defs.h" |
| 33 | #include "msghdr.h" |
| 34 | #include <arpa/inet.h> |
| 35 | #include <netinet/in.h> |
| 36 | |
| 37 | #include "xlat/msg_flags.h" |
| 38 | #include "xlat/scmvals.h" |
| 39 | #include "xlat/ip_cmsg_types.h" |
| 40 | |
| 41 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 42 | struct cmsghdr32 { |
| 43 | uint32_t cmsg_len; |
| 44 | int cmsg_level; |
| 45 | int cmsg_type; |
| 46 | }; |
| 47 | #endif |
| 48 | |
| 49 | typedef union { |
| 50 | char *ptr; |
| 51 | struct cmsghdr *cmsg; |
| 52 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 53 | struct cmsghdr32 *cmsg32; |
| 54 | #endif |
| 55 | } union_cmsghdr; |
| 56 | |
| 57 | static void |
Dmitry V. Levin | b7937bd | 2016-06-30 22:39:02 +0000 | [diff] [blame] | 58 | print_scm_rights(struct tcb *tcp, const void *cmsg_data, const size_t data_len) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 59 | { |
| 60 | const int *fds = cmsg_data; |
Dmitry V. Levin | 029d979 | 2016-06-30 22:20:56 +0000 | [diff] [blame] | 61 | const size_t nfds = data_len / sizeof(*fds); |
| 62 | size_t i; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 63 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 64 | tprints("["); |
Dmitry V. Levin | 029d979 | 2016-06-30 22:20:56 +0000 | [diff] [blame] | 65 | |
| 66 | for (i = 0; i < nfds; ++i) { |
| 67 | if (i) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 68 | tprints(", "); |
Dmitry V. Levin | d35d5ec | 2016-07-02 21:14:26 +0000 | [diff] [blame^] | 69 | if (abbrev(tcp) && i >= max_strlen) { |
| 70 | tprints("..."); |
| 71 | break; |
| 72 | } |
Dmitry V. Levin | 029d979 | 2016-06-30 22:20:56 +0000 | [diff] [blame] | 73 | printfd(tcp, fds[i]); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 74 | } |
Dmitry V. Levin | 029d979 | 2016-06-30 22:20:56 +0000 | [diff] [blame] | 75 | |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 76 | tprints("]"); |
| 77 | } |
| 78 | |
| 79 | static void |
Dmitry V. Levin | b7937bd | 2016-06-30 22:39:02 +0000 | [diff] [blame] | 80 | print_scm_creds(struct tcb *tcp, const void *cmsg_data, const size_t data_len) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 81 | { |
| 82 | const struct ucred *uc = cmsg_data; |
| 83 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 84 | tprintf("{pid=%u, uid=%u, gid=%u}", |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 85 | (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid); |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | print_scm_security(struct tcb *tcp, const void *cmsg_data, |
| 90 | const size_t data_len) |
| 91 | { |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 92 | print_quoted_string(cmsg_data, data_len, 0); |
| 93 | } |
| 94 | |
| 95 | static void |
| 96 | print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data, |
| 97 | const size_t data_len) |
| 98 | { |
| 99 | const struct in_pktinfo *info = cmsg_data; |
| 100 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 101 | tprints("{ipi_ifindex="); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 102 | print_ifindex(info->ipi_ifindex); |
Dmitry V. Levin | db0e6e1 | 2016-06-29 22:07:20 +0000 | [diff] [blame] | 103 | tprintf(", ipi_spec_dst=inet_addr(\"%s\")", |
| 104 | inet_ntoa(info->ipi_spec_dst)); |
| 105 | tprintf(", ipi_addr=inet_addr(\"%s\")}", |
| 106 | inet_ntoa(info->ipi_addr)); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void |
Dmitry V. Levin | b7937bd | 2016-06-30 22:39:02 +0000 | [diff] [blame] | 110 | print_cmsg_uint(struct tcb *tcp, const void *cmsg_data, const size_t data_len) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 111 | { |
Dmitry V. Levin | b7937bd | 2016-06-30 22:39:02 +0000 | [diff] [blame] | 112 | const unsigned int *p = cmsg_data; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 113 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 114 | tprintf("[%u]", *p); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 118 | print_cmsg_uint8_t(struct tcb *tcp, const void *cmsg_data, |
| 119 | const size_t data_len) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 120 | { |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 121 | const uint8_t *p = cmsg_data; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 122 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 123 | tprintf("[%#x]", *p); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 127 | print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data, |
| 128 | const size_t data_len) |
| 129 | { |
| 130 | const unsigned char *opts = cmsg_data; |
| 131 | size_t i; |
| 132 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 133 | tprints("["); |
Dmitry V. Levin | 2a89737 | 2016-06-28 22:25:10 +0000 | [diff] [blame] | 134 | for (i = 0; i < data_len; ++i) { |
| 135 | if (i) |
| 136 | tprints(", "); |
| 137 | tprintf("0x%02x", opts[i]); |
| 138 | } |
| 139 | tprints("]"); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 142 | struct sock_ee { |
| 143 | uint32_t ee_errno; |
| 144 | uint8_t ee_origin; |
| 145 | uint8_t ee_type; |
| 146 | uint8_t ee_code; |
| 147 | uint8_t ee_pad; |
| 148 | uint32_t ee_info; |
| 149 | uint32_t ee_data; |
| 150 | struct sockaddr_in offender; |
| 151 | }; |
| 152 | |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 153 | static void |
| 154 | print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data, |
| 155 | const size_t data_len) |
| 156 | { |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 157 | const struct sock_ee *const err = cmsg_data; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 158 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 159 | tprintf("{ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u" |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 160 | ", ee_info=%u, ee_data=%u, offender=", |
| 161 | err->ee_errno, err->ee_origin, err->ee_type, |
| 162 | err->ee_code, err->ee_info, err->ee_data); |
| 163 | print_sockaddr(tcp, &err->offender, sizeof(err->offender)); |
| 164 | tprints("}"); |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data, |
| 169 | const size_t data_len) |
| 170 | { |
Dmitry V. Levin | dfeea69 | 2016-06-30 22:26:35 +0000 | [diff] [blame] | 171 | const int addr_len = |
| 172 | data_len > sizeof(struct sockaddr_storage) |
| 173 | ? sizeof(struct sockaddr_storage) : data_len; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 174 | |
Dmitry V. Levin | dfeea69 | 2016-06-30 22:26:35 +0000 | [diff] [blame] | 175 | print_sockaddr(tcp, cmsg_data, addr_len); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 178 | typedef void (* const cmsg_printer)(struct tcb *, const void *, size_t); |
| 179 | |
| 180 | static const struct { |
| 181 | const cmsg_printer printer; |
| 182 | const size_t min_len; |
| 183 | } cmsg_socket_printers[] = { |
| 184 | [SCM_RIGHTS] = { print_scm_rights, sizeof(int) }, |
| 185 | [SCM_CREDENTIALS] = { print_scm_creds, sizeof(struct ucred) }, |
| 186 | [SCM_SECURITY] = { print_scm_security, 1 } |
| 187 | }, cmsg_ip_printers[] = { |
| 188 | [IP_PKTINFO] = { print_cmsg_ip_pktinfo, sizeof(struct in_pktinfo) }, |
| 189 | [IP_TTL] = { print_cmsg_uint, sizeof(unsigned int) }, |
| 190 | [IP_TOS] = { print_cmsg_uint8_t, 1 }, |
| 191 | [IP_RECVOPTS] = { print_cmsg_ip_opts, 1 }, |
| 192 | [IP_RETOPTS] = { print_cmsg_ip_opts, 1 }, |
| 193 | [IP_RECVERR] = { print_cmsg_ip_recverr, sizeof(struct sock_ee) }, |
| 194 | [IP_ORIGDSTADDR] = { print_cmsg_ip_origdstaddr, sizeof(struct sockaddr_in) }, |
| 195 | [IP_CHECKSUM] = { print_cmsg_uint, sizeof(unsigned int) }, |
| 196 | [SCM_SECURITY] = { print_scm_security, 1 } |
| 197 | }; |
| 198 | |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 199 | static void |
| 200 | print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type, |
| 201 | const void *cmsg_data, const size_t data_len) |
| 202 | { |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 203 | const unsigned int utype = cmsg_type; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 204 | switch (cmsg_level) { |
| 205 | case SOL_SOCKET: |
| 206 | printxval(scmvals, cmsg_type, "SCM_???"); |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 207 | if (utype < ARRAY_SIZE(cmsg_socket_printers) |
| 208 | && cmsg_socket_printers[utype].printer |
| 209 | && data_len >= cmsg_socket_printers[utype].min_len) { |
| 210 | tprints(", cmsg_data="); |
| 211 | cmsg_socket_printers[utype].printer(tcp, cmsg_data, data_len); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 212 | } |
| 213 | break; |
| 214 | case SOL_IP: |
| 215 | printxval(ip_cmsg_types, cmsg_type, "IP_???"); |
Dmitry V. Levin | df57a9b | 2016-06-30 22:49:36 +0000 | [diff] [blame] | 216 | if (utype < ARRAY_SIZE(cmsg_ip_printers) |
| 217 | && cmsg_ip_printers[utype].printer |
| 218 | && data_len >= cmsg_ip_printers[utype].min_len) { |
| 219 | tprints(", cmsg_data="); |
| 220 | cmsg_ip_printers[utype].printer(tcp, cmsg_data, data_len); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 221 | } |
| 222 | break; |
| 223 | default: |
Dmitry V. Levin | 6c30aec | 2016-06-30 22:14:51 +0000 | [diff] [blame] | 224 | tprintf("%#x", cmsg_type); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | static void |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 229 | decode_msg_control(struct tcb *tcp, unsigned long addr, const size_t control_len) |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 230 | { |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 231 | if (!control_len) |
| 232 | return; |
| 233 | tprints(", msg_control="); |
| 234 | |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 235 | const size_t cmsg_size = |
| 236 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 237 | (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) : |
| 238 | #endif |
| 239 | sizeof(struct cmsghdr); |
| 240 | |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 241 | size_t buf_len = control_len; |
| 242 | char *buf = buf_len < cmsg_size ? NULL : malloc(buf_len); |
| 243 | if (!buf || umoven(tcp, addr, buf_len, buf) < 0) { |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 244 | printaddr(addr); |
| 245 | free(buf); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | union_cmsghdr u = { .ptr = buf }; |
| 250 | |
| 251 | tprints("["); |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 252 | while (buf_len >= cmsg_size) { |
| 253 | const size_t cmsg_len = |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 254 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 255 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len : |
| 256 | #endif |
| 257 | u.cmsg->cmsg_len; |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 258 | const int cmsg_level = |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 259 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 260 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level : |
| 261 | #endif |
| 262 | u.cmsg->cmsg_level; |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 263 | const int cmsg_type = |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 264 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 265 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type : |
| 266 | #endif |
| 267 | u.cmsg->cmsg_type; |
| 268 | |
| 269 | if (u.ptr != buf) |
| 270 | tprints(", "); |
| 271 | tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len); |
| 272 | printxval(socketlayers, cmsg_level, "SOL_???"); |
| 273 | tprints(", cmsg_type="); |
| 274 | |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 275 | size_t len = cmsg_len > buf_len ? buf_len : cmsg_len; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 276 | |
| 277 | print_cmsg_type_data(tcp, cmsg_level, cmsg_type, |
| 278 | (const void *) (u.ptr + cmsg_size), |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 279 | len > cmsg_size ? len - cmsg_size: 0); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 280 | tprints("}"); |
| 281 | |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 282 | if (len < cmsg_size) { |
| 283 | buf_len -= cmsg_size; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 284 | break; |
| 285 | } |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 286 | len = (cmsg_len + current_wordsize - 1) & |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 287 | (size_t) ~(current_wordsize - 1); |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 288 | if (len >= buf_len) { |
| 289 | buf_len = 0; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 290 | break; |
| 291 | } |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 292 | u.ptr += len; |
| 293 | buf_len -= len; |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 294 | } |
Dmitry V. Levin | 1d53210 | 2016-06-30 22:34:27 +0000 | [diff] [blame] | 295 | if (buf_len) { |
| 296 | tprints(", "); |
| 297 | printaddr(addr + (control_len - buf_len)); |
| 298 | } |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 299 | tprints("]"); |
| 300 | free(buf); |
| 301 | } |
| 302 | |
| 303 | static void |
| 304 | print_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size) |
| 305 | { |
| 306 | tprints("{msg_name="); |
| 307 | decode_sockaddr(tcp, (long)msg->msg_name, msg->msg_namelen); |
| 308 | tprintf(", msg_namelen=%d", msg->msg_namelen); |
| 309 | |
| 310 | tprints(", msg_iov="); |
| 311 | tprint_iov_upto(tcp, (unsigned long) msg->msg_iovlen, |
| 312 | (unsigned long) msg->msg_iov, IOV_DECODE_STR, data_size); |
| 313 | tprintf(", msg_iovlen=%lu", (unsigned long) msg->msg_iovlen); |
| 314 | |
| 315 | decode_msg_control(tcp, (unsigned long) msg->msg_control, |
| 316 | msg->msg_controllen); |
| 317 | tprintf(", msg_controllen=%lu", (unsigned long) msg->msg_controllen); |
| 318 | |
| 319 | tprints(", msg_flags="); |
| 320 | printflags(msg_flags, msg->msg_flags, "MSG_???"); |
| 321 | tprints("}"); |
| 322 | } |
| 323 | |
| 324 | void |
| 325 | decode_msghdr(struct tcb *tcp, long addr, unsigned long data_size) |
| 326 | { |
| 327 | struct msghdr msg; |
| 328 | |
| 329 | if (addr && verbose(tcp) && fetch_struct_msghdr(tcp, addr, &msg)) |
| 330 | print_msghdr(tcp, &msg, data_size); |
| 331 | else |
| 332 | printaddr(addr); |
| 333 | } |
| 334 | |
| 335 | void |
| 336 | dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size) |
| 337 | { |
| 338 | struct msghdr msg; |
| 339 | |
| 340 | if (fetch_struct_msghdr(tcp, addr, &msg)) |
| 341 | dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size); |
| 342 | } |
| 343 | |
| 344 | static int |
| 345 | decode_mmsghdr(struct tcb *tcp, long addr, bool use_msg_len) |
| 346 | { |
| 347 | struct mmsghdr mmsg; |
| 348 | int fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg); |
| 349 | |
| 350 | if (fetched) { |
Dmitry V. Levin | a50ec34 | 2016-06-27 00:14:34 +0000 | [diff] [blame] | 351 | tprints("{msg_hdr="); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 352 | print_msghdr(tcp, &mmsg.msg_hdr, use_msg_len ? mmsg.msg_len : -1UL); |
Dmitry V. Levin | a50ec34 | 2016-06-27 00:14:34 +0000 | [diff] [blame] | 353 | tprintf(", msg_len=%u}", mmsg.msg_len); |
Dmitry V. Levin | 95cce4f | 2016-06-27 00:02:55 +0000 | [diff] [blame] | 354 | } else { |
| 355 | printaddr(addr); |
| 356 | } |
| 357 | |
| 358 | return fetched; |
| 359 | } |
| 360 | |
| 361 | void |
| 362 | decode_mmsgvec(struct tcb *tcp, unsigned long addr, unsigned int len, |
| 363 | bool use_msg_len) |
| 364 | { |
| 365 | if (syserror(tcp)) { |
| 366 | printaddr(addr); |
| 367 | } else { |
| 368 | unsigned int i, fetched; |
| 369 | |
| 370 | tprints("["); |
| 371 | for (i = 0; i < len; ++i, addr += fetched) { |
| 372 | if (i) |
| 373 | tprints(", "); |
| 374 | fetched = decode_mmsghdr(tcp, addr, use_msg_len); |
| 375 | if (!fetched) |
| 376 | break; |
| 377 | } |
| 378 | tprints("]"); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void |
| 383 | dumpiov_in_mmsghdr(struct tcb *tcp, long addr) |
| 384 | { |
| 385 | unsigned int len = tcp->u_rval; |
| 386 | unsigned int i, fetched; |
| 387 | struct mmsghdr mmsg; |
| 388 | |
| 389 | for (i = 0; i < len; ++i, addr += fetched) { |
| 390 | fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg); |
| 391 | if (!fetched) |
| 392 | break; |
| 393 | tprintf(" = %lu buffers in vector %u\n", |
| 394 | (unsigned long)mmsg.msg_hdr.msg_iovlen, i); |
| 395 | dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen, |
| 396 | (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len); |
| 397 | } |
| 398 | } |