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> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * $Id$ |
| 30 | */ |
| 31 | |
| 32 | #include "defs.h" |
| 33 | |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/socket.h> |
| 36 | #include <sys/un.h> |
| 37 | #include <netinet/in.h> |
| 38 | #include <arpa/inet.h> |
| 39 | #if defined(LINUX) |
| 40 | #include <asm/types.h> |
| 41 | #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3) |
| 42 | # include <netipx/ipx.h> |
| 43 | #else |
| 44 | # include <linux/ipx.h> |
| 45 | #endif |
| 46 | #endif /* LINUX */ |
| 47 | |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 48 | #if defined(LINUX) && defined(MIPS) |
Wichert Akkerman | 505e176 | 1999-11-01 19:39:08 +0000 | [diff] [blame] | 49 | #if defined( HAVE_LINUX_IN6_H) |
| 50 | #include <linux/in6.h> |
| 51 | #endif |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 52 | #endif |
Wichert Akkerman | 505e176 | 1999-11-01 19:39:08 +0000 | [diff] [blame] | 53 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 54 | #ifndef PF_UNSPEC |
| 55 | #define PF_UNSPEC AF_UNSPEC |
| 56 | #endif |
| 57 | |
| 58 | #ifdef LINUX |
| 59 | /* Under Linux these are enums so we can't test for them with ifdef. */ |
| 60 | #define IPPROTO_EGP IPPROTO_EGP |
| 61 | #define IPPROTO_PUP IPPROTO_PUP |
| 62 | #define IPPROTO_IDP IPPROTO_IDP |
| 63 | #define IPPROTO_IGMP IPPROTO_IGMP |
| 64 | #define IPPROTO_RAW IPPROTO_RAW |
| 65 | #define IPPROTO_MAX IPPROTO_MAX |
| 66 | #endif |
| 67 | |
| 68 | static struct xlat domains[] = { |
| 69 | { PF_UNSPEC, "PF_UNSPEC" }, |
| 70 | { PF_UNIX, "PF_UNIX" }, |
| 71 | { PF_INET, "PF_INET" }, |
| 72 | #ifdef PF_LOCAL |
| 73 | { PF_LOCAL, "PS_LOCAL" }, |
| 74 | #endif |
| 75 | #ifdef PF_ISO |
| 76 | { PF_ISO, "PF_ISO" }, |
| 77 | #endif |
| 78 | #ifdef PF_AX25 |
| 79 | { PF_AX25, "PF_AX25" }, |
| 80 | #endif |
| 81 | #ifdef PF_IPX |
| 82 | { PF_IPX, "PF_IPX" }, |
| 83 | #endif |
| 84 | #ifdef PF_APPLETALK |
| 85 | { PF_APPLETALK, "PF_APPLETALK" }, |
| 86 | #endif |
| 87 | #ifdef PF_NETROM |
| 88 | { PF_NETROM, "PF_NETROM" }, |
| 89 | #endif |
| 90 | #ifdef PF_BRIDGE |
| 91 | { PF_BRIDGE, "PF_BRIDGE" }, |
| 92 | #endif |
| 93 | #ifdef PF_AAL5 |
| 94 | { PF_AAL5, "PF_AAL5" }, |
| 95 | #endif |
| 96 | #ifdef PF_X25 |
| 97 | { PF_X25, "PF_X25" }, |
| 98 | #endif |
| 99 | #ifdef PF_INET6 |
| 100 | { PF_INET6, "PF_INET6" }, |
| 101 | #endif |
| 102 | #ifdef PF_ROSE |
| 103 | { PF_ROSE, "PF_ROSE" }, |
| 104 | #endif |
| 105 | #ifdef PF_DECNET |
| 106 | { PF_DECNET, "PF_DECNET" }, |
| 107 | #endif |
| 108 | #ifdef PF_NETBEUI |
| 109 | { PF_NETBEUI, "PF_NETBEUI" }, |
| 110 | #endif |
| 111 | #ifdef PF_IMPLINK |
| 112 | { PF_IMPLINK, "PF_IMPLINK" }, |
| 113 | #endif |
| 114 | { 0, NULL }, |
| 115 | }; |
| 116 | static struct xlat socktypes[] = { |
| 117 | { SOCK_STREAM, "SOCK_STREAM" }, |
| 118 | { SOCK_DGRAM, "SOCK_DGRAM" }, |
| 119 | #ifdef SOCK_RAW |
| 120 | { SOCK_RAW, "SOCK_RAW" }, |
| 121 | #endif |
| 122 | #ifdef SOCK_SEQPACKET |
| 123 | { SOCK_SEQPACKET,"SOCK_SEQPACKET"}, |
| 124 | #endif |
| 125 | #ifdef SOCK_RDM |
| 126 | { SOCK_RDM, "SOCK_RDM" }, |
| 127 | #endif |
| 128 | #ifdef SOCK_PACKET |
| 129 | { SOCK_PACKET, "SOCK_PACKET" }, |
| 130 | #endif |
| 131 | { 0, NULL }, |
| 132 | }; |
| 133 | static struct xlat protocols[] = { |
| 134 | { IPPROTO_IP, "IPPROTO_IP" }, |
| 135 | { IPPROTO_ICMP, "IPPROTO_ICMP" }, |
| 136 | { IPPROTO_TCP, "IPPROTO_TCP" }, |
| 137 | { IPPROTO_UDP, "IPPROTO_UDP" }, |
| 138 | #ifdef IPPROTO_GGP |
| 139 | { IPPROTO_GGP, "IPPROTO_GGP" }, |
| 140 | #endif |
| 141 | #ifdef IPPROTO_EGP |
| 142 | { IPPROTO_EGP, "IPPROTO_EGP" }, |
| 143 | #endif |
| 144 | #ifdef IPPROTO_PUP |
| 145 | { IPPROTO_PUP, "IPPROTO_PUP" }, |
| 146 | #endif |
| 147 | #ifdef IPPROTO_IDP |
| 148 | { IPPROTO_IDP, "IPPROTO_IDP" }, |
| 149 | #endif |
| 150 | #ifdef IPPROTO_IPV6 |
| 151 | { IPPROTO_IPV6, "IPPROTO_IPV6" }, |
| 152 | #endif |
| 153 | #ifdef IPPROTO_ICMPV6 |
| 154 | { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"}, |
| 155 | #endif |
| 156 | #ifdef IPPROTO_IGMP |
| 157 | { IPPROTO_IGMP, "IPPROTO_IGMP" }, |
| 158 | #endif |
| 159 | #ifdef IPPROTO_HELLO |
| 160 | { IPPROTO_HELLO,"IPPROTO_HELLO" }, |
| 161 | #endif |
| 162 | #ifdef IPPROTO_ND |
| 163 | { IPPROTO_ND, "IPPROTO_ND" }, |
| 164 | #endif |
| 165 | #ifdef IPPROTO_RAW |
| 166 | { IPPROTO_RAW, "IPPROTO_RAW" }, |
| 167 | #endif |
| 168 | #ifdef IPPROTO_MAX |
| 169 | { IPPROTO_MAX, "IPPROTO_MAX" }, |
| 170 | #endif |
| 171 | #ifdef IPPROTO_IPIP |
| 172 | { IPPROTO_IPIP, "IPPROTO_IPIP" }, |
| 173 | #endif |
| 174 | { 0, NULL }, |
| 175 | }; |
| 176 | static struct xlat msg_flags[] = { |
| 177 | { MSG_OOB, "MSG_OOB" }, |
| 178 | #ifdef MSG_DONTROUTE |
| 179 | { MSG_DONTROUTE,"MSG_DONTROUTE" }, |
| 180 | #endif |
| 181 | #ifdef MSG_PEEK |
| 182 | { MSG_PEEK, "MSG_PEEK" }, |
| 183 | #endif |
| 184 | #ifdef MSG_CTRUNC |
| 185 | { MSG_CTRUNC, "MSG_CTRUNC" }, |
| 186 | #endif |
| 187 | #ifdef MSG_PROXY |
| 188 | { MSG_PROXY, "MSG_PROXY" }, |
| 189 | #endif |
| 190 | #ifdef MSG_EOR |
| 191 | { MSG_EOR, "MSG_EOR" }, |
| 192 | #endif |
| 193 | #ifdef MSG_WAITALL |
| 194 | { MSG_WAITALL, "MSG_WAITALL" }, |
| 195 | #endif |
| 196 | { 0, NULL }, |
| 197 | }; |
| 198 | |
| 199 | static struct xlat sockoptions[] = { |
| 200 | #ifdef SO_DEBUG |
| 201 | { SO_DEBUG, "SO_DEBUG" }, |
| 202 | #endif |
| 203 | #ifdef SO_REUSEADDR |
| 204 | { SO_REUSEADDR, "SO_REUSEADDR" }, |
| 205 | #endif |
| 206 | #ifdef SO_KEEPALIVE |
| 207 | { SO_KEEPALIVE, "SO_KEEPALIVE" }, |
| 208 | #endif |
| 209 | #ifdef SO_DONTROUTE |
| 210 | { SO_DONTROUTE, "SO_DONTROUTE" }, |
| 211 | #endif |
| 212 | #ifdef SO_BROADCAST |
| 213 | { SO_BROADCAST, "SO_BROADCAST" }, |
| 214 | #endif |
| 215 | #ifdef SO_LINGER |
| 216 | { SO_LINGER, "SO_LINGER" }, |
| 217 | #endif |
| 218 | #ifdef SO_OOBINLINE |
| 219 | { SO_OOBINLINE, "SO_OOBINLINE" }, |
| 220 | #endif |
| 221 | #ifdef SO_TYPE |
| 222 | { SO_TYPE, "SO_TYPE" }, |
| 223 | #endif |
| 224 | #ifdef SO_ERROR |
| 225 | { SO_ERROR, "SO_ERROR" }, |
| 226 | #endif |
| 227 | #ifdef SO_SNDBUF |
| 228 | { SO_SNDBUF, "SO_SNDBUF" }, |
| 229 | #endif |
| 230 | #ifdef SO_RCVBUF |
| 231 | { SO_RCVBUF, "SO_RCVBUF" }, |
| 232 | #endif |
| 233 | #ifdef SO_NO_CHECK |
| 234 | { SO_NO_CHECK, "SO_NO_CHECK" }, |
| 235 | #endif |
| 236 | #ifdef SO_PRIORITY |
| 237 | { SO_PRIORITY, "SO_PRIORITY" }, |
| 238 | #endif |
| 239 | #ifdef SO_ACCEPTCONN |
| 240 | { SO_ACCEPTCONN,"SO_ACCEPTCONN" }, |
| 241 | #endif |
| 242 | #ifdef SO_USELOOPBACK |
| 243 | { SO_USELOOPBACK,"SO_USELOOPBACK"}, |
| 244 | #endif |
| 245 | #ifdef SO_SNDLOWAT |
| 246 | { SO_SNDLOWAT, "SO_SNDLOWAT" }, |
| 247 | #endif |
| 248 | #ifdef SO_RCVLOWAT |
| 249 | { SO_RCVLOWAT, "SO_RCVLOWAT" }, |
| 250 | #endif |
| 251 | #ifdef SO_SNDTIMEO |
| 252 | { SO_SNDTIMEO, "SO_SNDTIMEO" }, |
| 253 | #endif |
| 254 | #ifdef SO_RCVTIMEO |
| 255 | { SO_RCVTIMEO, "SO_RCVTIMEO" }, |
| 256 | #endif |
| 257 | #ifdef SO_BSDCOMPAT |
| 258 | { SO_BSDCOMPAT, "SO_BSDCOMPAT" }, |
| 259 | #endif |
| 260 | #ifdef SO_REUSEPORT |
| 261 | { SO_REUSEPORT, "SO_REUSEPORT" }, |
| 262 | #endif |
| 263 | #ifdef SO_RCVLOWAT |
| 264 | { SO_RCVLOWAT, "SO_RCVLOWAT" }, |
| 265 | #endif |
| 266 | #ifdef SO_SNDLOWAT |
| 267 | { SO_SNDLOWAT, "SO_SNDLOWAT" }, |
| 268 | #endif |
| 269 | #ifdef SO_RCVTIMEO |
| 270 | { SO_RCVTIMEO, "SO_RCVTIMEO" }, |
| 271 | #endif |
| 272 | #ifdef SO_SNDTIMEO |
| 273 | { SO_SNDTIMEO, "SO_SNDTIMEO" }, |
| 274 | #endif |
| 275 | { 0, NULL }, |
| 276 | }; |
| 277 | |
| 278 | #ifdef SOL_IP |
| 279 | static struct xlat sockipoptions[] = { |
| 280 | { IP_TOS, "IP_TOS" }, |
| 281 | { IP_TTL, "IP_TTL" }, |
| 282 | #if defined(IP_HDRINCL) |
| 283 | { IP_HDRINCL, "IP_HDRINCL" }, |
| 284 | #endif |
| 285 | #if defined(IP_OPTIONS) |
| 286 | { IP_OPTIONS, "IP_OPTIONS" }, |
| 287 | #endif |
| 288 | { IP_MULTICAST_IF, "IP_MULTICAST_IF" }, |
| 289 | { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" }, |
| 290 | { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" }, |
| 291 | { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" }, |
| 292 | { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" }, |
| 293 | { 0, NULL }, |
| 294 | }; |
| 295 | #endif /* SOL_IP */ |
| 296 | |
| 297 | #ifdef SOL_IPX |
| 298 | static struct xlat sockipxoptions[] = { |
| 299 | { IPX_TYPE, "IPX_TYPE" }, |
| 300 | { 0, NULL }, |
| 301 | }; |
| 302 | #endif /* SOL_IPX */ |
| 303 | |
| 304 | #ifdef SOL_TCP |
| 305 | static struct xlat socktcpoptions[] = { |
| 306 | { TCP_NODELAY, "TCP_NODELAY" }, |
| 307 | { TCP_MAXSEG, "TCP_MAXSEG" }, |
| 308 | { 0, NULL }, |
| 309 | }; |
| 310 | #endif /* SOL_TCP */ |
| 311 | |
| 312 | void |
| 313 | printsock(tcp, addr) |
| 314 | struct tcb *tcp; |
| 315 | long addr; |
| 316 | { |
| 317 | struct sockaddr sa; |
| 318 | struct sockaddr_in *sin = (struct sockaddr_in *) &sa; |
| 319 | struct sockaddr_un sau; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 320 | #ifdef HAVE_INET_NTOP |
| 321 | struct sockaddr_in6 sa6; |
| 322 | char string_addr[100]; |
| 323 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 324 | #ifdef LINUX |
| 325 | struct sockaddr_ipx sipx; |
| 326 | #endif |
| 327 | |
| 328 | if (addr == 0) { |
| 329 | tprintf("NULL"); |
| 330 | return; |
| 331 | } |
| 332 | if (!verbose(tcp)) { |
| 333 | tprintf("%#lx", addr); |
| 334 | return; |
| 335 | } |
| 336 | if (umove(tcp, addr, &sa) < 0) { |
| 337 | tprintf("{...}"); |
| 338 | return; |
| 339 | } |
| 340 | switch (sa.sa_family) { |
| 341 | case AF_UNIX: |
| 342 | if (umove(tcp, addr, &sau) < 0) |
| 343 | tprintf("{sun_family=AF_UNIX, ...}"); |
| 344 | else |
| 345 | tprintf("{sun_family=AF_UNIX, sun_path=\"%s\"}", |
| 346 | sau.sun_path); |
| 347 | break; |
| 348 | case AF_INET: |
| 349 | tprintf("{sin_family=AF_INET, "); |
| 350 | tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}", |
| 351 | ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)); |
| 352 | break; |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 353 | #ifdef HAVE_INET_NTOP |
| 354 | case AF_INET6: |
| 355 | if (umove(tcp, addr, &sa6) < 0) |
| 356 | tprintf("{sin6_family=AF_INET6, ...}"); |
| 357 | else |
| 358 | { |
| 359 | tprintf("{sin6_family=AF_INET6, "); |
| 360 | inet_ntop(AF_INET6, &sa6.sin6_addr, string_addr, sizeof(string_addr)); |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 361 | tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)}", |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 362 | ntohs(sa6.sin6_port), string_addr, ntohl(sa6.sin6_flowinfo)); |
| 363 | } |
| 364 | break; |
| 365 | #endif |
Wichert Akkerman | dbb440e | 1999-05-11 15:06:44 +0000 | [diff] [blame] | 366 | #if defined(AF_IPX) && defined(linux) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 367 | case AF_IPX: |
| 368 | if (umove(tcp, addr, &sipx)<0) |
| 369 | tprintf("{sipx_family=AF_IPX, ...}"); |
| 370 | else { |
| 371 | int i; |
| 372 | tprintf("{sipx_family=AF_IPX, "); |
| 373 | tprintf("{sipx_port=htons(%u), ", |
| 374 | ntohs(sipx.sipx_port)); |
| 375 | /* Yes, I know, this does not look too |
| 376 | * strace-ish, but otherwise the IPX |
| 377 | * addresses just look monstrous... |
| 378 | * Anyways, feel free if you don't like |
| 379 | * this way.. :) |
| 380 | */ |
Nate Sammons | 6bfcd32 | 1999-04-06 01:39:04 +0000 | [diff] [blame] | 381 | tprintf("%08lx:", (unsigned long)ntohl(sipx.sipx_network)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 382 | for (i = 0; i<IPX_NODE_LEN; i++) |
| 383 | tprintf("%02x", sipx.sipx_node[i]); |
| 384 | tprintf("/[%02x]", sipx.sipx_type); |
| 385 | tprintf("}"); |
| 386 | } |
| 387 | break; |
Wichert Akkerman | dbb440e | 1999-05-11 15:06:44 +0000 | [diff] [blame] | 388 | #endif /* AF_IPX && linux */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 389 | /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5 |
| 390 | AF_X25 AF_INET6 AF_ROSE still need to be done */ |
| 391 | |
| 392 | default: |
| 393 | tprintf("{sa_family=%u, sa_data=", sa.sa_family); |
| 394 | printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data, |
| 395 | sizeof sa.sa_data); |
| 396 | tprintf("}"); |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | #if HAVE_SENDMSG |
| 402 | |
| 403 | static void |
| 404 | printmsghdr(tcp, addr) |
| 405 | struct tcb *tcp; |
| 406 | long addr; |
| 407 | { |
| 408 | struct msghdr msg; |
| 409 | |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 410 | if (umove(tcp, addr, &msg) < 0) { |
| 411 | tprintf("%#lx", addr); |
| 412 | return; |
| 413 | } |
| 414 | tprintf("{msg_name="); |
| 415 | printstr(tcp, (long) msg.msg_name, msg.msg_namelen); |
| 416 | tprintf(", msg_namelen=%u, msg_iov=%#lx, msg_iovlen=%u, ", |
| 417 | msg.msg_namelen, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 418 | (unsigned long) msg.msg_iov, msg.msg_iovlen); |
| 419 | #ifdef HAVE_MSG_CONTROL |
| 420 | tprintf("msg_control=%#lx, msg_controllen=%u, msg_flags=%#x}", |
| 421 | (unsigned long) msg.msg_control, msg.msg_controllen, |
| 422 | msg.msg_flags); |
| 423 | #else /* !HAVE_MSG_CONTROL */ |
| 424 | tprintf("msg_accrights=%#lx, msg_accrightslen=%u}", |
| 425 | (unsigned long) msg.msg_accrights, msg.msg_accrightslen); |
| 426 | #endif /* !HAVE_MSG_CONTROL */ |
| 427 | } |
| 428 | |
| 429 | #endif /* HAVE_SENDMSG */ |
| 430 | |
| 431 | int |
| 432 | sys_socket(tcp) |
| 433 | struct tcb *tcp; |
| 434 | { |
| 435 | if (entering(tcp)) { |
| 436 | printxval(domains, tcp->u_arg[0], "PF_???"); |
| 437 | tprintf(", "); |
| 438 | printxval(socktypes, tcp->u_arg[1], "SOCK_???"); |
| 439 | tprintf(", "); |
| 440 | switch (tcp->u_arg[0]) { |
| 441 | case PF_INET: |
| 442 | printxval(protocols, tcp->u_arg[2], "IPPROTO_???"); |
| 443 | break; |
| 444 | #ifdef PF_IPX |
| 445 | case PF_IPX: |
| 446 | /* BTW: I don't believe this.. */ |
| 447 | tprintf("["); |
| 448 | printxval(domains, tcp->u_arg[2], "PF_???"); |
| 449 | tprintf("]"); |
| 450 | break; |
| 451 | #endif /* PF_IPX */ |
| 452 | default: |
| 453 | tprintf("%lu", tcp->u_arg[2]); |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | int |
| 461 | sys_bind(tcp) |
| 462 | struct tcb *tcp; |
| 463 | { |
| 464 | if (entering(tcp)) { |
| 465 | tprintf("%ld, ", tcp->u_arg[0]); |
| 466 | printsock(tcp, tcp->u_arg[1]); |
| 467 | tprintf(", %lu", tcp->u_arg[2]); |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | int |
| 473 | sys_connect(tcp) |
| 474 | struct tcb *tcp; |
| 475 | { |
| 476 | return sys_bind(tcp); |
| 477 | } |
| 478 | |
| 479 | int |
| 480 | sys_listen(tcp) |
| 481 | struct tcb *tcp; |
| 482 | { |
| 483 | if (entering(tcp)) { |
| 484 | tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]); |
| 485 | } |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | int |
| 490 | sys_accept(tcp) |
| 491 | struct tcb *tcp; |
| 492 | { |
| 493 | if (entering(tcp)) { |
| 494 | tprintf("%ld, ", tcp->u_arg[0]); |
| 495 | } else if (!tcp->u_arg[2]) |
| 496 | tprintf("%#lx, NULL", tcp->u_arg[1]); |
| 497 | else { |
| 498 | if (tcp->u_arg[1] == 0 || syserror(tcp)) { |
| 499 | tprintf("%#lx", tcp->u_arg[1]); |
| 500 | } else { |
| 501 | printsock(tcp, tcp->u_arg[1]); |
| 502 | } |
| 503 | tprintf(", "); |
| 504 | printnum(tcp, tcp->u_arg[2], "%lu"); |
| 505 | } |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | int |
| 510 | sys_send(tcp) |
| 511 | struct tcb *tcp; |
| 512 | { |
| 513 | if (entering(tcp)) { |
| 514 | tprintf("%ld, ", tcp->u_arg[0]); |
| 515 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 516 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 517 | /* flags */ |
| 518 | if (printflags(msg_flags, tcp->u_arg[3]) == 0) |
| 519 | tprintf("0"); |
| 520 | } |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | int |
| 525 | sys_sendto(tcp) |
| 526 | struct tcb *tcp; |
| 527 | { |
| 528 | if (entering(tcp)) { |
| 529 | tprintf("%ld, ", tcp->u_arg[0]); |
| 530 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 531 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 532 | /* flags */ |
| 533 | if (printflags(msg_flags, tcp->u_arg[3]) == 0) |
| 534 | tprintf("0"); |
| 535 | /* to address */ |
| 536 | tprintf(", "); |
| 537 | printsock(tcp, tcp->u_arg[4]); |
| 538 | /* to length */ |
| 539 | tprintf(", %lu", tcp->u_arg[5]); |
| 540 | } |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | #ifdef HAVE_SENDMSG |
| 545 | |
| 546 | int |
| 547 | sys_sendmsg(tcp) |
| 548 | struct tcb *tcp; |
| 549 | { |
| 550 | if (entering(tcp)) { |
| 551 | tprintf("%ld, ", tcp->u_arg[0]); |
| 552 | printmsghdr(tcp, tcp->u_arg[1]); |
| 553 | /* flags */ |
| 554 | tprintf(", "); |
| 555 | if (printflags(msg_flags, tcp->u_arg[2]) == 0) |
| 556 | tprintf("0"); |
| 557 | } |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | #endif /* HAVE_SENDMSG */ |
| 562 | |
| 563 | int |
| 564 | sys_recv(tcp) |
| 565 | struct tcb *tcp; |
| 566 | { |
| 567 | if (entering(tcp)) { |
| 568 | tprintf("%ld, ", tcp->u_arg[0]); |
| 569 | } else { |
| 570 | if (syserror(tcp)) |
| 571 | tprintf("%#lx", tcp->u_arg[1]); |
| 572 | else |
| 573 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 574 | |
| 575 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 576 | if (printflags(msg_flags, tcp->u_arg[3]) == 0) |
| 577 | tprintf("0"); |
| 578 | } |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | int |
| 583 | sys_recvfrom(tcp) |
| 584 | struct tcb *tcp; |
| 585 | { |
| 586 | int fromlen; |
| 587 | |
| 588 | if (entering(tcp)) { |
| 589 | tprintf("%ld, ", tcp->u_arg[0]); |
| 590 | } else { |
| 591 | if (syserror(tcp)) { |
| 592 | tprintf("%#lx, %lu, %lu, %#lx, %#lx", |
| 593 | tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3], |
| 594 | tcp->u_arg[4], tcp->u_arg[5]); |
| 595 | return 0; |
| 596 | } |
| 597 | /* buf */ |
| 598 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 599 | /* len */ |
| 600 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 601 | /* flags */ |
| 602 | if (printflags(msg_flags, tcp->u_arg[3]) == 0) |
| 603 | tprintf("0"); |
| 604 | /* from address, len */ |
| 605 | if (!tcp->u_arg[4] || !tcp->u_arg[5]) { |
| 606 | if (tcp->u_arg[4] == 0) |
| 607 | tprintf(", NULL"); |
| 608 | else |
| 609 | tprintf(", %#lx", tcp->u_arg[4]); |
| 610 | if (tcp->u_arg[5] == 0) |
| 611 | tprintf(", NULL"); |
| 612 | else |
| 613 | tprintf(", %#lx", tcp->u_arg[5]); |
| 614 | return 0; |
| 615 | } |
| 616 | if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) { |
| 617 | tprintf(", {...}, [?]"); |
| 618 | return 0; |
| 619 | } |
| 620 | tprintf(", "); |
| 621 | printsock(tcp, tcp->u_arg[4]); |
| 622 | /* from length */ |
| 623 | tprintf(", [%u]", fromlen); |
| 624 | } |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | #ifdef HAVE_SENDMSG |
| 629 | |
| 630 | int |
| 631 | sys_recvmsg(tcp) |
| 632 | struct tcb *tcp; |
| 633 | { |
| 634 | if (entering(tcp)) { |
| 635 | tprintf("%ld, ", tcp->u_arg[0]); |
| 636 | } else { |
| 637 | if (syserror(tcp) || !verbose(tcp)) |
| 638 | tprintf("%#lx", tcp->u_arg[1]); |
| 639 | else |
| 640 | printmsghdr(tcp, tcp->u_arg[1]); |
| 641 | /* flags */ |
| 642 | tprintf(", "); |
| 643 | if (printflags(msg_flags, tcp->u_arg[2]) == 0) |
| 644 | tprintf("0"); |
| 645 | } |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | #endif /* HAVE_SENDMSG */ |
| 650 | |
| 651 | int |
| 652 | sys_shutdown(tcp) |
| 653 | struct tcb *tcp; |
| 654 | { |
| 655 | if (entering(tcp)) { |
| 656 | tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]); |
| 657 | switch (tcp->u_arg[1]) { |
| 658 | case 0: |
| 659 | tprintf("%s", " /* receive */"); |
| 660 | break; |
| 661 | case 1: |
| 662 | tprintf("%s", " /* send */"); |
| 663 | break; |
| 664 | case 2: |
| 665 | tprintf("%s", " /* send and receive */"); |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | int |
| 673 | sys_getsockname(tcp) |
| 674 | struct tcb *tcp; |
| 675 | { |
| 676 | return sys_accept(tcp); |
| 677 | } |
| 678 | |
| 679 | int |
| 680 | sys_getpeername(tcp) |
| 681 | struct tcb *tcp; |
| 682 | { |
| 683 | return sys_accept(tcp); |
| 684 | } |
| 685 | |
| 686 | int |
| 687 | sys_pipe(tcp) |
| 688 | struct tcb *tcp; |
| 689 | { |
| 690 | |
| 691 | #if defined(LINUX) && !defined(SPARC) |
| 692 | int fds[2]; |
| 693 | |
| 694 | if (exiting(tcp)) { |
| 695 | if (syserror(tcp)) { |
| 696 | tprintf("%#lx", tcp->u_arg[0]); |
| 697 | return 0; |
| 698 | } |
| 699 | if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0) |
| 700 | tprintf("[...]"); |
| 701 | else |
| 702 | tprintf("[%u, %u]", fds[0], fds[1]); |
| 703 | } |
Wichert Akkerman | 5daa028 | 1999-03-15 19:49:42 +0000 | [diff] [blame] | 704 | #elif defined(SPARC) || defined(SVR4) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 705 | if (exiting(tcp)) |
| 706 | tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 707 | #endif |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | int |
| 712 | sys_socketpair(tcp) |
| 713 | struct tcb *tcp; |
| 714 | { |
| 715 | #ifdef LINUX |
| 716 | int fds[2]; |
| 717 | #endif |
| 718 | |
| 719 | if (entering(tcp)) { |
| 720 | printxval(domains, tcp->u_arg[0], "PF_???"); |
| 721 | tprintf(", "); |
| 722 | printxval(socktypes, tcp->u_arg[1], "SOCK_???"); |
| 723 | tprintf(", "); |
| 724 | switch (tcp->u_arg[0]) { |
| 725 | case PF_INET: |
| 726 | printxval(protocols, tcp->u_arg[2], "IPPROTO_???"); |
| 727 | break; |
| 728 | #ifdef PF_IPX |
| 729 | case PF_IPX: |
| 730 | /* BTW: I don't believe this.. */ |
| 731 | tprintf("["); |
| 732 | printxval(domains, tcp->u_arg[2], "PF_???"); |
| 733 | tprintf("]"); |
| 734 | break; |
| 735 | #endif /* PF_IPX */ |
| 736 | default: |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 737 | tprintf("%lu", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 738 | break; |
| 739 | } |
| 740 | } else { |
| 741 | if (syserror(tcp)) { |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 742 | tprintf(", %#lx", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 743 | return 0; |
| 744 | } |
| 745 | #ifdef LINUX |
| 746 | if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0) |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 747 | tprintf(", [...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 748 | else |
| 749 | tprintf(", [%u, %u]", fds[0], fds[1]); |
| 750 | #endif /* LINUX */ |
| 751 | #ifdef SUNOS4 |
| 752 | tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp)); |
| 753 | #endif /* SUNOS4 */ |
| 754 | #ifdef SVR4 |
| 755 | tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp)); |
| 756 | #endif /* SVR4 */ |
| 757 | } |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | int |
| 762 | sys_getsockopt(tcp) |
| 763 | struct tcb *tcp; |
| 764 | { |
| 765 | if (entering(tcp)) { |
| 766 | tprintf("%ld, ", tcp->u_arg[0]); |
| 767 | switch (tcp->u_arg[1]) { |
| 768 | case SOL_SOCKET: |
| 769 | tprintf("SOL_SOCKET, "); |
| 770 | printxval(sockoptions, tcp->u_arg[2], "SO_???"); |
| 771 | tprintf(", "); |
| 772 | break; |
| 773 | #ifdef SOL_IP |
| 774 | case SOL_IP: |
| 775 | tprintf("SOL_IP, "); |
| 776 | printxval(sockipoptions, tcp->u_arg[2], "IP_???"); |
| 777 | tprintf(", "); |
| 778 | break; |
| 779 | #endif |
| 780 | #ifdef SOL_IPX |
| 781 | case SOL_IPX: |
| 782 | tprintf("SOL_IPX, "); |
| 783 | printxval(sockipxoptions, tcp->u_arg[2], "IPX_???"); |
| 784 | tprintf(", "); |
| 785 | break; |
| 786 | #endif |
| 787 | #ifdef SOL_TCP |
| 788 | case SOL_TCP: |
| 789 | tprintf("SOL_TCP, "); |
| 790 | printxval(socktcpoptions, tcp->u_arg[2], "TCP_???"); |
| 791 | tprintf(", "); |
| 792 | break; |
| 793 | #endif |
| 794 | |
| 795 | /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25 |
| 796 | * etc. still need work */ |
| 797 | default: |
| 798 | /* XXX - should know socket family here */ |
| 799 | printxval(protocols, tcp->u_arg[1], "IPPROTO_???"); |
| 800 | tprintf("%lu, ", tcp->u_arg[2]); |
| 801 | break; |
| 802 | } |
| 803 | } else { |
| 804 | if (syserror(tcp)) { |
| 805 | tprintf("%#lx, %#lx", |
| 806 | tcp->u_arg[3], tcp->u_arg[4]); |
| 807 | return 0; |
| 808 | } |
| 809 | printnum(tcp, tcp->u_arg[3], "%ld"); |
| 810 | tprintf(", "); |
| 811 | printnum(tcp, tcp->u_arg[4], "%ld"); |
| 812 | } |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | int |
| 817 | sys_setsockopt(tcp) |
| 818 | struct tcb *tcp; |
| 819 | { |
| 820 | if (entering(tcp)) { |
| 821 | tprintf("%ld, ", tcp->u_arg[0]); |
| 822 | switch (tcp->u_arg[1]) { |
| 823 | case SOL_SOCKET: |
| 824 | tprintf("SOL_SOCKET, "); |
| 825 | printxval(sockoptions, tcp->u_arg[2], "SO_???"); |
| 826 | tprintf(", "); |
| 827 | break; |
| 828 | #ifdef SOL_IP |
| 829 | case SOL_IP: |
| 830 | tprintf("SOL_IP, "); |
| 831 | printxval(sockipoptions, tcp->u_arg[2], "IP_???"); |
| 832 | tprintf(", "); |
| 833 | break; |
| 834 | #endif |
| 835 | #ifdef SOL_IPX |
| 836 | case SOL_IPX: |
| 837 | tprintf("SOL_IPX, "); |
| 838 | printxval(sockipxoptions, tcp->u_arg[2], "IPX_???"); |
| 839 | tprintf(", "); |
| 840 | break; |
| 841 | #endif |
| 842 | #ifdef SOL_TCP |
| 843 | case SOL_TCP: |
| 844 | tprintf("SOL_TCP, "); |
| 845 | printxval(socktcpoptions, tcp->u_arg[2], "TCP_???"); |
| 846 | tprintf(", "); |
| 847 | break; |
| 848 | #endif |
| 849 | |
| 850 | /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25 |
| 851 | * etc. still need work */ |
| 852 | default: |
| 853 | /* XXX - should know socket family here */ |
| 854 | printxval(protocols, tcp->u_arg[1], "IPPROTO_???"); |
| 855 | tprintf("%lu, ", tcp->u_arg[2]); |
| 856 | break; |
| 857 | } |
| 858 | printnum(tcp, tcp->u_arg[3], "%ld"); |
| 859 | tprintf(", %lu", tcp->u_arg[4]); |
| 860 | } |
| 861 | return 0; |
| 862 | } |