]> granicus.if.org Git - strace/blob - net.c
.
[strace] / net.c
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  * 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.
29  *
30  *      $Id$
31  */
32
33 #include "defs.h"
34
35 #include <sys/stat.h>
36 #include <sys/socket.h>
37 #include <sys/un.h>
38
39 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
40 #define in6_addr in6_addr_libc
41 #define ipv6_mreq ipv6_mreq_libc
42 #define sockaddr_in6 sockaddr_in6_libc
43 #endif
44
45 #include <netinet/in.h>
46 #ifdef HAVE_NETINET_TCP_H
47 #include <netinet/tcp.h>
48 #endif
49 #ifdef HAVE_NETINET_UDP_H
50 #include <netinet/udp.h>
51 #endif
52 #include <arpa/inet.h>
53 #include <net/if.h>
54 #if defined(LINUX)
55 #include <asm/types.h>
56 #if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
57 #  include <netipx/ipx.h>
58 #else
59 #  include <linux/ipx.h>
60 #endif
61 #endif /* LINUX */
62
63 #if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
64 #if defined(HAVE_LINUX_IN6_H)
65 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
66 #undef in6_addr
67 #undef ipv6_mreq
68 #undef sockaddr_in6
69 #define in6_addr in6_addr_kernel
70 #define ipv6_mreq ipv6_mreq_kernel
71 #define sockaddr_in6 sockaddr_in6_kernel
72 #endif
73 #include <linux/in6.h>
74 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
75 #undef in6_addr
76 #undef ipv6_mreq
77 #undef sockaddr_in6
78 #define in6_addr in6_addr_libc
79 #define ipv6_mreq ipv6_mreq_libc
80 #define sockaddr_in6 sockaddr_in6_kernel
81 #endif
82 #endif
83 #endif
84
85 #if defined(HAVE_SYS_UIO_H)
86 #include <sys/uio.h>
87 #endif
88
89 #if defined(HAVE_LINUX_NETLINK_H)
90 #include <linux/netlink.h>
91 #endif
92
93 #if defined(HAVE_LINUX_IF_PACKET_H)
94 #include <linux/if_packet.h>
95 #endif
96
97 #if defined(HAVE_LINUX_ICMP_H)
98 #include <linux/icmp.h>
99 #endif
100
101 #ifndef PF_UNSPEC
102 #define PF_UNSPEC AF_UNSPEC
103 #endif
104
105 #if UNIXWARE >= 7
106 #define HAVE_SENDMSG            1               /* HACK - *FIXME* */
107 #endif
108
109 #ifdef LINUX
110 /* Under Linux these are enums so we can't test for them with ifdef. */
111 #define IPPROTO_EGP IPPROTO_EGP
112 #define IPPROTO_PUP IPPROTO_PUP
113 #define IPPROTO_IDP IPPROTO_IDP
114 #define IPPROTO_IGMP IPPROTO_IGMP
115 #define IPPROTO_RAW IPPROTO_RAW
116 #define IPPROTO_MAX IPPROTO_MAX
117 #endif
118
119 static const struct xlat domains[] = {
120 #ifdef PF_AAL5
121         { PF_AAL5,      "PF_AAL5"       },
122 #endif
123 #ifdef PF_APPLETALK
124         { PF_APPLETALK, "PF_APPLETALK"  },
125 #endif
126 #ifdef PF_ASH
127         { PF_ASH,       "PF_ASH"        },
128 #endif
129 #ifdef PF_ATMPVC
130         { PF_ATMPVC,    "PF_ATMPVC"     },
131 #endif
132 #ifdef PF_ATMSVC
133         { PF_ATMSVC,    "PF_ATMSVC"     },
134 #endif
135 #ifdef PF_AX25
136         { PF_AX25,      "PF_AX25"       },
137 #endif
138 #ifdef PF_BLUETOOTH
139         { PF_BLUETOOTH, "PF_BLUETOOTH"  },
140 #endif
141 #ifdef PF_BRIDGE
142         { PF_BRIDGE,    "PF_BRIDGE"     },
143 #endif
144 #ifdef PF_DECnet
145         { PF_DECnet,    "PF_DECnet"     },
146 #endif
147 #ifdef PF_DECNET
148         { PF_DECNET,    "PF_DECNET"     },
149 #endif
150 #ifdef PF_ECONET
151         { PF_ECONET,    "PF_ECONET"     },
152 #endif
153 #ifdef PF_FILE
154         { PF_FILE,      "PF_FILE"       },
155 #endif
156 #ifdef PF_IMPLINK
157         { PF_IMPLINK,   "PF_IMPLINK"    },
158 #endif
159 #ifdef PF_INET
160         { PF_INET,      "PF_INET"       },
161 #endif
162 #ifdef PF_INET6
163         { PF_INET6,     "PF_INET6"      },
164 #endif
165 #ifdef PF_IPX
166         { PF_IPX,       "PF_IPX"        },
167 #endif
168 #ifdef PF_IRDA
169         { PF_IRDA,      "PF_IRDA"       },
170 #endif
171 #ifdef PF_ISO
172         { PF_ISO,       "PF_ISO"        },
173 #endif
174 #ifdef PF_KEY
175         { PF_KEY,       "PF_KEY"        },
176 #endif
177 #ifdef PF_UNIX
178         { PF_UNIX,      "PF_UNIX"       },
179 #endif
180 #ifdef PF_LOCAL
181         { PF_LOCAL,     "PF_LOCAL"      },
182 #endif
183 #ifdef PF_NETBEUI
184         { PF_NETBEUI,   "PF_NETBEUI"    },
185 #endif
186 #ifdef PF_NETLINK
187         { PF_NETLINK,   "PF_NETLINK"    },
188 #endif
189 #ifdef PF_NETROM
190         { PF_NETROM,    "PF_NETROM"     },
191 #endif
192 #ifdef PF_PACKET
193         { PF_PACKET,    "PF_PACKET"     },
194 #endif
195 #ifdef PF_PPPOX
196         { PF_PPPOX,     "PF_PPPOX"      },
197 #endif
198 #ifdef PF_ROSE
199         { PF_ROSE,      "PF_ROSE"       },
200 #endif
201 #ifdef PF_ROUTE
202         { PF_ROUTE,     "PF_ROUTE"      },
203 #endif
204 #ifdef PF_SECURITY
205         { PF_SECURITY,  "PF_SECURITY"   },
206 #endif
207 #ifdef PF_SNA
208         { PF_SNA,       "PF_SNA"        },
209 #endif
210 #ifdef PF_UNSPEC
211         { PF_UNSPEC,    "PF_UNSPEC"     },
212 #endif
213 #ifdef PF_WANPIPE
214         { PF_WANPIPE,   "PF_WANPIPE"    },
215 #endif
216 #ifdef PF_X25
217         { PF_X25,       "PF_X25"        },
218 #endif
219         { 0,            NULL            },
220 };
221 const struct xlat addrfams[] = {
222 #ifdef AF_APPLETALK
223         { AF_APPLETALK, "AF_APPLETALK"  },
224 #endif
225 #ifdef AF_ASH
226         { AF_ASH,       "AF_ASH"        },
227 #endif
228 #ifdef AF_ATMPVC
229         { AF_ATMPVC,    "AF_ATMPVC"     },
230 #endif
231 #ifdef AF_ATMSVC
232         { AF_ATMSVC,    "AF_ATMSVC"     },
233 #endif
234 #ifdef AF_AX25
235         { AF_AX25,      "AF_AX25"       },
236 #endif
237 #ifdef AF_BLUETOOTH
238         { AF_BLUETOOTH, "AF_BLUETOOTH"  },
239 #endif
240 #ifdef AF_BRIDGE
241         { AF_BRIDGE,    "AF_BRIDGE"     },
242 #endif
243 #ifdef AF_DECnet
244         { AF_DECnet,    "AF_DECnet"     },
245 #endif
246 #ifdef AF_ECONET
247         { AF_ECONET,    "AF_ECONET"     },
248 #endif
249 #ifdef AF_FILE
250         { AF_FILE,      "AF_FILE"       },
251 #endif
252 #ifdef AF_IMPLINK
253         { AF_IMPLINK,   "AF_IMPLINK"    },
254 #endif
255 #ifdef AF_INET
256         { AF_INET,      "AF_INET"       },
257 #endif
258 #ifdef AF_INET6
259         { AF_INET6,     "AF_INET6"      },
260 #endif
261 #ifdef AF_IPX
262         { AF_IPX,       "AF_IPX"        },
263 #endif
264 #ifdef AF_IRDA
265         { AF_IRDA,      "AF_IRDA"       },
266 #endif
267 #ifdef AF_ISO
268         { AF_ISO,       "AF_ISO"        },
269 #endif
270 #ifdef AF_KEY
271         { AF_KEY,       "AF_KEY"        },
272 #endif
273 #ifdef AF_UNIX
274         { AF_UNIX,      "AF_UNIX"       },
275 #endif
276 #ifdef AF_LOCAL
277         { AF_LOCAL,     "AF_LOCAL"      },
278 #endif
279 #ifdef AF_NETBEUI
280         { AF_NETBEUI,   "AF_NETBEUI"    },
281 #endif
282 #ifdef AF_NETLINK
283         { AF_NETLINK,   "AF_NETLINK"    },
284 #endif
285 #ifdef AF_NETROM
286         { AF_NETROM,    "AF_NETROM"     },
287 #endif
288 #ifdef AF_PACKET
289         { AF_PACKET,    "AF_PACKET"     },
290 #endif
291 #ifdef AF_PPPOX
292         { AF_PPPOX,     "AF_PPPOX"      },
293 #endif
294 #ifdef AF_ROSE
295         { AF_ROSE,      "AF_ROSE"       },
296 #endif
297 #ifdef AF_ROUTE
298         { AF_ROUTE,     "AF_ROUTE"      },
299 #endif
300 #ifdef AF_SECURITY
301         { AF_SECURITY,  "AF_SECURITY"   },
302 #endif
303 #ifdef AF_SNA
304         { AF_SNA,       "AF_SNA"        },
305 #endif
306 #ifdef AF_UNSPEC
307         { AF_UNSPEC,    "AF_UNSPEC"     },
308 #endif
309 #ifdef AF_WANPIPE
310         { AF_WANPIPE,   "AF_WANPIPE"    },
311 #endif
312 #ifdef AF_X25
313         { AF_X25,       "AF_X25"        },
314 #endif
315         { 0,            NULL            },
316 };
317 static const struct xlat socktypes[] = {
318         { SOCK_STREAM,  "SOCK_STREAM"   },
319         { SOCK_DGRAM,   "SOCK_DGRAM"    },
320 #ifdef SOCK_RAW
321         { SOCK_RAW,     "SOCK_RAW"      },
322 #endif
323 #ifdef SOCK_SEQPACKET
324         { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
325 #endif
326 #ifdef SOCK_RDM
327         { SOCK_RDM,     "SOCK_RDM"      },
328 #endif
329 #ifdef SOCK_PACKET
330         { SOCK_PACKET,  "SOCK_PACKET"   },
331 #endif
332         { 0,            NULL            },
333 };
334 static const struct xlat socketlayers[] = {
335 #if defined(SOL_IP)
336         { SOL_IP,       "SOL_IP"        },
337 #endif
338 #if defined(SOL_ICMP)
339         { SOL_ICMP,     "SOL_ICMP"      },
340 #endif
341 #if defined(SOL_TCP)
342         { SOL_TCP,      "SOL_TCP"       },
343 #endif
344 #if defined(SOL_UDP)
345         { SOL_UDP,      "SOL_UDP"       },
346 #endif
347 #if defined(SOL_IPV6)
348         { SOL_IPV6,     "SOL_IPV6"      },
349 #endif
350 #if defined(SOL_ICMPV6)
351         { SOL_ICMPV6,   "SOL_ICMPV6"    },
352 #endif
353 #if defined(SOL_RAW)
354         { SOL_RAW,      "SOL_RAW"       },
355 #endif
356 #if defined(SOL_IPX)
357         { SOL_IPX,      "SOL_IPX"       },
358 #endif
359 #if defined(SOL_IPX)
360         { SOL_IPX,      "SOL_IPX"       },
361 #endif
362 #if defined(SOL_AX25)
363         { SOL_AX25,     "SOL_AX25"      },
364 #endif
365 #if defined(SOL_ATALK)
366         { SOL_ATALK,    "SOL_ATALK"     },
367 #endif
368 #if defined(SOL_NETROM)
369         { SOL_NETROM,   "SOL_NETROM"    },
370 #endif
371 #if defined(SOL_ROSE)
372         { SOL_ROSE,     "SOL_ROSE"      },
373 #endif
374 #if defined(SOL_DECNET)
375         { SOL_DECNET,   "SOL_DECNET"    },
376 #endif
377 #if defined(SOL_X25)
378         { SOL_X25,      "SOL_X25"       },
379 #endif
380 #if defined(SOL_PACKET)
381         { SOL_PACKET,   "SOL_PACKET"    },
382 #endif
383 #if defined(SOL_ATM)
384         { SOL_ATM,      "SOL_ATM"       },
385 #endif
386 #if defined(SOL_AAL)
387         { SOL_AAL,      "SOL_AAL"       },
388 #endif
389 #if defined(SOL_IRDA)
390         { SOL_IRDA,     "SOL_IRDA"      },
391 #endif
392         { SOL_SOCKET,   "SOL_SOCKET"    },      /* Never used! */
393 };
394 /*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
395      falls into "protocols" array below!!!!   This is intended!!! ***/
396 static const struct xlat protocols[] = {
397         { IPPROTO_IP,   "IPPROTO_IP"    },
398         { IPPROTO_ICMP, "IPPROTO_ICMP"  },
399         { IPPROTO_TCP,  "IPPROTO_TCP"   },
400         { IPPROTO_UDP,  "IPPROTO_UDP"   },
401 #ifdef IPPROTO_GGP
402         { IPPROTO_GGP,  "IPPROTO_GGP"   },
403 #endif
404 #ifdef IPPROTO_EGP
405         { IPPROTO_EGP,  "IPPROTO_EGP"   },
406 #endif
407 #ifdef IPPROTO_PUP
408         { IPPROTO_PUP,  "IPPROTO_PUP"   },
409 #endif
410 #ifdef IPPROTO_IDP
411         { IPPROTO_IDP,  "IPPROTO_IDP"   },
412 #endif
413 #ifdef IPPROTO_IPV6
414         { IPPROTO_IPV6, "IPPROTO_IPV6"  },
415 #endif
416 #ifdef IPPROTO_ICMPV6
417         { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
418 #endif
419 #ifdef IPPROTO_IGMP
420         { IPPROTO_IGMP, "IPPROTO_IGMP"  },
421 #endif
422 #ifdef IPPROTO_HELLO
423         { IPPROTO_HELLO,"IPPROTO_HELLO" },
424 #endif
425 #ifdef IPPROTO_ND
426         { IPPROTO_ND,   "IPPROTO_ND"    },
427 #endif
428 #ifdef IPPROTO_RAW
429         { IPPROTO_RAW,  "IPPROTO_RAW"   },
430 #endif
431 #ifdef IPPROTO_MAX
432         { IPPROTO_MAX,  "IPPROTO_MAX"   },
433 #endif
434 #ifdef IPPROTO_IPIP
435         { IPPROTO_IPIP, "IPPROTO_IPIP"  },
436 #endif
437         { 0,            NULL            },
438 };
439 static const struct xlat msg_flags[] = {
440         { MSG_OOB,      "MSG_OOB"       },
441 #ifdef MSG_DONTROUTE
442         { MSG_DONTROUTE,"MSG_DONTROUTE" },
443 #endif
444 #ifdef MSG_PEEK
445         { MSG_PEEK,     "MSG_PEEK"      },
446 #endif
447 #ifdef MSG_CTRUNC
448         { MSG_CTRUNC,   "MSG_CTRUNC"    },
449 #endif
450 #ifdef MSG_PROXY
451         { MSG_PROXY,    "MSG_PROXY"     },
452 #endif
453 #ifdef MSG_EOR
454         { MSG_EOR,      "MSG_EOR"       },
455 #endif
456 #ifdef MSG_WAITALL
457         { MSG_WAITALL,  "MSG_WAITALL"   },
458 #endif
459 #ifdef MSG_TRUNC
460         { MSG_TRUNC,    "MSG_TRUNC"     },
461 #endif
462 #ifdef MSG_CTRUNC
463         { MSG_CTRUNC,   "MSG_CTRUNC"    },
464 #endif
465 #ifdef MSG_ERRQUEUE
466         { MSG_ERRQUEUE, "MSG_ERRQUEUE"  },
467 #endif
468 #ifdef MSG_DONTWAIT
469         { MSG_DONTWAIT, "MSG_DONTWAIT"  },
470 #endif
471 #ifdef MSG_CONFIRM
472         { MSG_CONFIRM,  "MSG_CONFIRM"   },
473 #endif
474 #ifdef MSG_PROBE
475         { MSG_PROBE,    "MSG_PROBE"     },
476 #endif
477 #ifdef MSG_FIN
478         { MSG_FIN,      "MSG_FIN"       },
479 #endif
480 #ifdef MSG_SYN
481         { MSG_SYN,      "MSG_SYN"       },
482 #endif
483 #ifdef MSG_RST
484         { MSG_RST,      "MSG_RST"       },
485 #endif
486 #ifdef MSG_NOSIGNAL
487         { MSG_NOSIGNAL, "MSG_NOSIGNAL"  },
488 #endif
489 #ifdef MSG_MORE
490         { MSG_MORE,     "MSG_MORE"      },
491 #endif
492         { 0,            NULL            },
493 };
494
495 static const struct xlat sockoptions[] = {
496 #ifdef SO_ACCEPTCONN
497         { SO_ACCEPTCONN,        "SO_ACCEPTCONN" },
498 #endif
499 #ifdef SO_ALLRAW
500         { SO_ALLRAW,    "SO_ALLRAW"     },
501 #endif
502 #ifdef SO_ATTACH_FILTER
503         { SO_ATTACH_FILTER,     "SO_ATTACH_FILTER"      },
504 #endif
505 #ifdef SO_BINDTODEVICE
506         { SO_BINDTODEVICE,      "SO_BINDTODEVICE"       },
507 #endif
508 #ifdef SO_BROADCAST
509         { SO_BROADCAST, "SO_BROADCAST"  },
510 #endif
511 #ifdef SO_BSDCOMPAT
512         { SO_BSDCOMPAT, "SO_BSDCOMPAT"  },
513 #endif
514 #ifdef SO_DEBUG
515         { SO_DEBUG,     "SO_DEBUG"      },
516 #endif
517 #ifdef SO_DETACH_FILTER
518         { SO_DETACH_FILTER,     "SO_DETACH_FILTER"      },
519 #endif
520 #ifdef SO_DONTROUTE
521         { SO_DONTROUTE, "SO_DONTROUTE"  },
522 #endif
523 #ifdef SO_ERROR
524         { SO_ERROR,     "SO_ERROR"      },
525 #endif
526 #ifdef SO_ICS
527         { SO_ICS,       "SO_ICS"        },
528 #endif
529 #ifdef SO_IMASOCKET
530         { SO_IMASOCKET, "SO_IMASOCKET"  },
531 #endif
532 #ifdef SO_KEEPALIVE
533         { SO_KEEPALIVE, "SO_KEEPALIVE"  },
534 #endif
535 #ifdef SO_LINGER
536         { SO_LINGER,    "SO_LINGER"     },
537 #endif
538 #ifdef SO_LISTENING
539         { SO_LISTENING, "SO_LISTENING"  },
540 #endif
541 #ifdef SO_MGMT
542         { SO_MGMT,      "SO_MGMT"       },
543 #endif
544 #ifdef SO_NO_CHECK
545         { SO_NO_CHECK,  "SO_NO_CHECK"   },
546 #endif
547 #ifdef SO_OOBINLINE
548         { SO_OOBINLINE, "SO_OOBINLINE"  },
549 #endif
550 #ifdef SO_ORDREL
551         { SO_ORDREL,    "SO_ORDREL"     },
552 #endif
553 #ifdef SO_PARALLELSVR
554         { SO_PARALLELSVR,       "SO_PARALLELSVR"        },
555 #endif
556 #ifdef SO_PASSCRED
557         { SO_PASSCRED,  "SO_PASSCRED"   },
558 #endif
559 #ifdef SO_PEERCRED
560         { SO_PEERCRED,  "SO_PEERCRED"   },
561 #endif
562 #ifdef SO_PEERNAME
563         { SO_PEERNAME,  "SO_PEERNAME"   },
564 #endif
565 #ifdef SO_PEERSEC
566         { SO_PEERSEC,   "SO_PEERSEC"    },
567 #endif
568 #ifdef SO_PRIORITY
569         { SO_PRIORITY,  "SO_PRIORITY"   },
570 #endif
571 #ifdef SO_PROTOTYPE
572         { SO_PROTOTYPE, "SO_PROTOTYPE"  },
573 #endif
574 #ifdef SO_RCVBUF
575         { SO_RCVBUF,    "SO_RCVBUF"     },
576 #endif
577 #ifdef SO_RCVLOWAT
578         { SO_RCVLOWAT,  "SO_RCVLOWAT"   },
579 #endif
580 #ifdef SO_RCVTIMEO
581         { SO_RCVTIMEO,  "SO_RCVTIMEO"   },
582 #endif
583 #ifdef SO_RDWR
584         { SO_RDWR,      "SO_RDWR"       },
585 #endif
586 #ifdef SO_REUSEADDR
587         { SO_REUSEADDR, "SO_REUSEADDR"  },
588 #endif
589 #ifdef SO_REUSEPORT
590         { SO_REUSEPORT, "SO_REUSEPORT"  },
591 #endif
592 #ifdef SO_SECURITY_AUTHENTICATION
593         { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
594 #endif
595 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
596         { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
597 #endif
598 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
599         { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
600 #endif
601 #ifdef SO_SEMA
602         { SO_SEMA,      "SO_SEMA"       },
603 #endif
604 #ifdef SO_SNDBUF
605         { SO_SNDBUF,    "SO_SNDBUF"     },
606 #endif
607 #ifdef SO_SNDLOWAT
608         { SO_SNDLOWAT,  "SO_SNDLOWAT"   },
609 #endif
610 #ifdef SO_SNDTIMEO
611         { SO_SNDTIMEO,  "SO_SNDTIMEO"   },
612 #endif
613 #ifdef SO_TIMESTAMP
614         { SO_TIMESTAMP, "SO_TIMESTAMP"  },
615 #endif
616 #ifdef SO_TYPE
617         { SO_TYPE,      "SO_TYPE"       },
618 #endif
619 #ifdef SO_USELOOPBACK
620         { SO_USELOOPBACK,       "SO_USELOOPBACK"        },
621 #endif
622         { 0,            NULL            },
623 };
624
625 #if !defined (SOL_IP) && defined (IPPROTO_IP)
626 #define SOL_IP IPPROTO_IP
627 #endif
628
629 #ifdef SOL_IP
630 static const struct xlat sockipoptions[] = {
631 #ifdef IP_TOS
632         { IP_TOS,               "IP_TOS"                },
633 #endif
634 #ifdef IP_TTL
635         { IP_TTL,               "IP_TTL"                },
636 #endif
637 #ifdef IP_HDRINCL
638         { IP_HDRINCL,           "IP_HDRINCL"            },
639 #endif
640 #ifdef IP_OPTIONS
641         { IP_OPTIONS,           "IP_OPTIONS"            },
642 #endif
643 #ifdef IP_ROUTER_ALERT
644         { IP_ROUTER_ALERT,      "IP_ROUTER_ALERT"       },
645 #endif
646 #ifdef IP_RECVOPTIONS
647         { IP_RECVOPTIONS,       "IP_RECVOPTIONS"        },
648 #endif
649 #ifdef IP_RECVOPTS
650         { IP_RECVOPTS,          "IP_RECVOPTS"           },
651 #endif
652 #ifdef IP_RECVRETOPTS
653         { IP_RECVRETOPTS,       "IP_RECVRETOPTS"        },
654 #endif
655 #ifdef IP_RECVDSTADDR
656         { IP_RECVDSTADDR,       "IP_RECVDSTADDR"        },
657 #endif
658 #ifdef IP_RETOPTS
659         { IP_RETOPTS,           "IP_RETOPTS"            },
660 #endif
661 #ifdef IP_PKTINFO
662         { IP_PKTINFO,           "IP_PKTINFO"            },
663 #endif
664 #ifdef IP_PKTOPTIONS
665         { IP_PKTOPTIONS,        "IP_PKTOPTIONS"         },
666 #endif
667 #ifdef IP_MTU_DISCOVER
668         { IP_MTU_DISCOVER,      "IP_MTU_DISCOVER"       },
669 #endif
670 #ifdef IP_RECVERR
671         { IP_RECVERR,           "IP_RECVERR"            },
672 #endif
673 #ifdef IP_RECVTTL
674         { IP_RECVTTL,           "IP_RECVTTL"            },
675 #endif
676 #ifdef IP_RECVTOS
677         { IP_RECVTOS,           "IP_RECVTOS"            },
678 #endif
679 #ifdef IP_MTU
680         { IP_MTU,               "IP_MTU"                },
681 #endif
682 #ifdef IP_MULTICAST_IF
683         { IP_MULTICAST_IF,      "IP_MULTICAST_IF"       },
684 #endif
685 #ifdef IP_MULTICAST_TTL
686         { IP_MULTICAST_TTL,     "IP_MULTICAST_TTL"      },
687 #endif
688 #ifdef IP_MULTICAST_LOOP
689         { IP_MULTICAST_LOOP,    "IP_MULTICAST_LOOP"     },
690 #endif
691 #ifdef IP_ADD_MEMBERSHIP
692         { IP_ADD_MEMBERSHIP,    "IP_ADD_MEMBERSHIP"     },
693 #endif
694 #ifdef IP_DROP_MEMBERSHIP
695         { IP_DROP_MEMBERSHIP,   "IP_DROP_MEMBERSHIP"    },
696 #endif
697 #ifdef IP_BROADCAST_IF
698         { IP_BROADCAST_IF,      "IP_BROADCAST_IF"       },
699 #endif
700 #ifdef IP_RECVIFINDEX
701         { IP_RECVIFINDEX,       "IP_RECVIFINDEX"        },
702 #endif
703 #ifdef IP_MSFILTER
704         { IP_MSFILTER,          "IP_MSFILTER"           },
705 #endif
706 #ifdef MCAST_MSFILTER
707         { MCAST_MSFILTER,       "MCAST_MSFILTER"        },
708 #endif
709 #ifdef IP_FREEBIND
710         { IP_FREEBIND,          "IP_FREEBIND"           },
711 #endif
712         { 0,                    NULL                    },
713 };
714 #endif /* SOL_IP */
715
716 #ifdef SOL_IPV6
717 static const struct xlat sockipv6options[] = {
718 #ifdef IPV6_ADDRFORM
719         { IPV6_ADDRFORM,        "IPV6_ADDRFORM"         },
720 #endif
721 #ifdef MCAST_FILTER
722         { MCAST_FILTER,         "MCAST_FILTER"          },
723 #endif
724 #ifdef IPV6_PKTOPTIONS
725         { IPV6_PKTOPTIONS,      "IPV6_PKTOPTIONS"       },
726 #endif
727 #ifdef IPV6_MTU
728         { IPV6_MTU,             "IPV6_MTU"              },
729 #endif
730 #ifdef IPV6_V6ONLY
731         { IPV6_V6ONLY,          "IPV6_V6ONLY"           },
732 #endif
733 #ifdef IPV6_PKTINFO
734         { IPV6_PKTINFO,         "IPV6_PKTINFO"          },
735 #endif
736 #ifdef IPV6_HOPLIMIT
737         { IPV6_HOPLIMIT,        "IPV6_HOPLIMIT"         },
738 #endif
739 #ifdef IPV6_RTHDR
740         { IPV6_RTHDR,           "IPV6_RTHDR"            },
741 #endif
742 #ifdef IPV6_HOPOPTS
743         { IPV6_HOPOPTS,         "IPV6_HOPOPTS"          },
744 #endif
745 #ifdef IPV6_DSTOPTS
746         { IPV6_DSTOPTS,         "IPV6_DSTOPTS"          },
747 #endif
748 #ifdef IPV6_FLOWINFO
749         { IPV6_FLOWINFO,        "IPV6_FLOWINFO"         },
750 #endif
751 #ifdef IPV6_UNICAST_HOPS
752         { IPV6_UNICAST_HOPS,    "IPV6_UNICAST_HOPS"     },
753 #endif
754 #ifdef IPV6_MULTICAST_HOPS
755         { IPV6_MULTICAST_HOPS,  "IPV6_MULTICAST_HOPS"   },
756 #endif
757 #ifdef IPV6_MULTICAST_LOOP
758         { IPV6_MULTICAST_LOOP,  "IPV6_MULTICAST_LOOP"   },
759 #endif
760 #ifdef IPV6_MULTICAST_IF
761         { IPV6_MULTICAST_IF,    "IPV6_MULTICAST_IF"     },
762 #endif
763 #ifdef IPV6_MTU_DISCOVER
764         { IPV6_MTU_DISCOVER,    "IPV6_MTU_DISCOVER"     },
765 #endif
766 #ifdef IPV6_RECVERR
767         { IPV6_RECVERR,         "IPV6_RECVERR"          },
768 #endif
769 #ifdef IPV6_FLOWINFO_SEND
770         { IPV6_FLOWINFO_SEND,   "IPV6_FLOWINFO_SEND"    },
771 #endif
772 #ifdef IPV6_ADD_MEMBERSHIP
773         { IPV6_ADD_MEMBERSHIP,  "IPV6_ADD_MEMBERSHIP"   },
774 #endif
775 #ifdef IPV6_DROP_MEMBERSHIP
776         { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP"  },
777 #endif
778 #ifdef IPV6_ROUTER_ALERT
779         { IPV6_ROUTER_ALERT,    "IPV6_ROUTER_ALERT"     },
780 #endif
781         { 0,                    NULL                    },
782 };
783 #endif /* SOL_IPV6 */
784
785 #ifdef SOL_IPX
786 static const struct xlat sockipxoptions[] = {
787         { IPX_TYPE,     "IPX_TYPE"      },
788         { 0,            NULL            },
789 };
790 #endif /* SOL_IPX */
791
792 #ifdef SOL_RAW
793 static const struct xlat sockrawoptions[] = {
794 #if defined(ICMP_FILTER)
795         { ICMP_FILTER,          "ICMP_FILTER"   },
796 #endif
797         { 0,                    NULL            },
798 };
799 #endif /* SOL_RAW */
800
801 #ifdef SOL_PACKET
802 static const struct xlat sockpacketoptions[] = {
803         { PACKET_ADD_MEMBERSHIP,        "PACKET_ADD_MEMBERSHIP" },
804         { PACKET_DROP_MEMBERSHIP,       "PACKET_DROP_MEMBERSHIP"},
805 #if defined(PACKET_RECV_OUTPUT)
806         { PACKET_RECV_OUTPUT,           "PACKET_RECV_OUTPUT"    },
807 #endif
808 #if defined(PACKET_RX_RING)
809         { PACKET_RX_RING,               "PACKET_RX_RING"        },
810 #endif
811 #if defined(PACKET_STATISTICS)
812         { PACKET_STATISTICS,            "PACKET_STATISTICS"     },
813 #endif
814         { 0,                            NULL                    },
815 };
816 #endif /* SOL_PACKET */
817
818 #if  !defined (SOL_TCP) && defined (IPPROTO_TCP)
819 #define SOL_TCP IPPROTO_TCP
820 #endif
821
822 #ifdef SOL_TCP
823 static const struct xlat socktcpoptions[] = {
824         { TCP_NODELAY,          "TCP_NODELAY"   },
825         { TCP_MAXSEG,           "TCP_MAXSEG"    },
826 #if defined(TCP_CORK)
827         { TCP_CORK,             "TCP_CORK"      },
828 #endif
829 #if defined(TCP_KEEPIDLE)
830         { TCP_KEEPIDLE,         "TCP_KEEPIDLE" },
831 #endif
832 #if defined(TCP_KEEPINTVL)
833         { TCP_KEEPINTVL,        "TCP_KEEPINTVL" },
834 #endif
835 #if defined(TCP_KEEPCNT)
836         { TCP_KEEPCNT,          "TCP_KEEPCNT" },
837 #endif
838 #if defined(TCP_NKEEP)
839         { TCP_NKEEP,            "TCP_NKEEP"     },
840 #endif
841 #if defined(TCP_SYNCNT)
842         { TCP_SYNCNT,           "TCP_SYNCNT" },
843 #endif
844 #if defined(TCP_LINGER2)
845         { TCP_LINGER2,          "TCP_LINGER2" },
846 #endif
847 #if defined(TCP_DEFER_ACCEPT)
848         { TCP_DEFER_ACCEPT,     "TCP_DEFER_ACCEPT" },
849 #endif
850 #if defined(TCP_WINDOW_CLAMP)
851         { TCP_WINDOW_CLAMP,     "TCP_WINDOW_CLAMP" },
852 #endif
853 #if defined(TCP_INFO)
854         { TCP_INFO,             "TCP_INFO" },
855 #endif
856 #if defined(TCP_QUICKACK)
857         { TCP_QUICKACK,         "TCP_QUICKACK" },
858 #endif
859         { 0,                    NULL            },
860 };
861 #endif /* SOL_TCP */
862
863 #ifdef SOL_RAW
864 static const struct xlat icmpfilterflags[] = {
865 #if defined(ICMP_ECHOREPLY)
866         { (1<<ICMP_ECHOREPLY),          "ICMP_ECHOREPLY"        },
867 #endif
868 #if defined(ICMP_DEST_UNREACH)
869         { (1<<ICMP_DEST_UNREACH),       "ICMP_DEST_UNREACH"     },
870 #endif
871 #if defined(ICMP_SOURCE_QUENCH)
872         { (1<<ICMP_SOURCE_QUENCH),      "ICMP_SOURCE_QUENCH"    },
873 #endif
874 #if defined(ICMP_REDIRECT)
875         { (1<<ICMP_REDIRECT),           "ICMP_REDIRECT"         },
876 #endif
877 #if defined(ICMP_ECHO)
878         { (1<<ICMP_ECHO),               "ICMP_ECHO"             },
879 #endif
880 #if defined(ICMP_TIME_EXCEEDED)
881         { (1<<ICMP_TIME_EXCEEDED),      "ICMP_TIME_EXCEEDED"    },
882 #endif
883 #if defined(ICMP_PARAMETERPROB)
884         { (1<<ICMP_PARAMETERPROB),      "ICMP_PARAMETERPROB"    },
885 #endif
886 #if defined(ICMP_TIMESTAMP)
887         { (1<<ICMP_TIMESTAMP),          "ICMP_TIMESTAMP"        },
888 #endif
889 #if defined(ICMP_TIMESTAMPREPLY)
890         { (1<<ICMP_TIMESTAMPREPLY),     "ICMP_TIMESTAMPREPLY"   },
891 #endif
892 #if defined(ICMP_INFO_REQUEST)
893         { (1<<ICMP_INFO_REQUEST),       "ICMP_INFO_REQUEST"     },
894 #endif
895 #if defined(ICMP_INFO_REPLY)
896         { (1<<ICMP_INFO_REPLY),         "ICMP_INFO_REPLY"       },
897 #endif
898 #if defined(ICMP_ADDRESS)
899         { (1<<ICMP_ADDRESS),            "ICMP_ADDRESS"          },
900 #endif
901 #if defined(ICMP_ADDRESSREPLY)
902         { (1<<ICMP_ADDRESSREPLY),       "ICMP_ADDRESSREPLY"     },
903 #endif
904         { 0,                            NULL                    },
905 };
906 #endif /* SOL_RAW */
907
908 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
909 static const struct xlat af_packet_types[] = {
910 #if defined(PACKET_HOST)
911         { PACKET_HOST,                  "PACKET_HOST"           },
912 #endif
913 #if defined(PACKET_BROADCAST)
914         { PACKET_BROADCAST,             "PACKET_BROADCAST"      },
915 #endif
916 #if defined(PACKET_MULTICAST)
917         { PACKET_MULTICAST,             "PACKET_MULTICAST"      },
918 #endif
919 #if defined(PACKET_OTHERHOST)
920         { PACKET_OTHERHOST,             "PACKET_OTHERHOST"      },
921 #endif
922 #if defined(PACKET_OUTGOING)
923         { PACKET_OUTGOING,              "PACKET_OUTGOING"       },
924 #endif
925 #if defined(PACKET_LOOPBACK)
926         { PACKET_LOOPBACK,              "PACKET_LOOPBACK"       },
927 #endif
928 #if defined(PACKET_FASTROUTE)
929         { PACKET_FASTROUTE,             "PACKET_FASTROUTE"      },
930 #endif
931         { 0,                            NULL                    },
932 };
933 #endif /* defined(AF_PACKET) */
934
935
936 void
937 printsock(tcp, addr, addrlen)
938 struct tcb *tcp;
939 long addr;
940 int addrlen;
941 {
942         union {
943                 char pad[128];
944                 struct sockaddr sa;
945                 struct sockaddr_in sin;
946                 struct sockaddr_un sau;
947 #ifdef HAVE_INET_NTOP
948                 struct sockaddr_in6 sa6;
949 #endif
950 #if defined(LINUX) && defined(AF_IPX)
951                 struct sockaddr_ipx sipx;
952 #endif
953 #ifdef AF_PACKET
954                 struct sockaddr_ll ll;
955 #endif
956 #ifdef AF_NETLINK
957                 struct sockaddr_nl nl;
958 #endif
959         } addrbuf;
960         char string_addr[100];
961
962         if (addr == 0) {
963                 tprintf("NULL");
964                 return;
965         }
966         if (!verbose(tcp)) {
967                 tprintf("%#lx", addr);
968                 return;
969         }
970         if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
971                 addrlen=sizeof(addrbuf);
972
973         if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
974                 tprintf("{...}");
975                 return;
976         }
977
978         tprintf("{sa_family=");
979         printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
980         tprintf(", ");
981
982         switch (addrbuf.sa.sa_family) {
983         case AF_UNIX:
984                 if (addrlen==2) {
985                         tprintf("<nil>");
986                 } else if (addrbuf.sau.sun_path[0]) {
987                         tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
988                 } else {
989                         tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
990                 }
991                 break;
992         case AF_INET:
993                 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
994                         ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
995                 break;
996 #ifdef HAVE_INET_NTOP
997         case AF_INET6:
998                 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
999                 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1000                                 ntohs(addrbuf.sa6.sin6_port), string_addr,
1001                                 addrbuf.sa6.sin6_flowinfo);
1002 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1003                 {
1004 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1005                     int numericscope = 0;
1006                     if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1007                             || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1008                         char scopebuf[IFNAMSIZ + 1];
1009
1010                         if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1011                             numericscope++;
1012                         else
1013                             tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1014                     } else
1015                         numericscope++;
1016
1017                     if (numericscope)
1018 #endif
1019                         tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1020                 }
1021 #endif
1022                     break;
1023 #endif
1024 #if defined(AF_IPX) && defined(linux)
1025         case AF_IPX:
1026                 {
1027                         int i;
1028                         tprintf("sipx_port=htons(%u), ",
1029                                         ntohs(addrbuf.sipx.sipx_port));
1030                         /* Yes, I know, this does not look too
1031                          * strace-ish, but otherwise the IPX
1032                          * addresses just look monstrous...
1033                          * Anyways, feel free if you don't like
1034                          * this way.. :)
1035                          */
1036                         tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1037                         for (i = 0; i<IPX_NODE_LEN; i++)
1038                                 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1039                         tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1040                 }
1041                 break;
1042 #endif /* AF_IPX && linux */
1043 #ifdef AF_PACKET
1044         case AF_PACKET:
1045                 {
1046                         int i;
1047                         tprintf("proto=%#04x, if%d, pkttype=",
1048                                         ntohs(addrbuf.ll.sll_protocol),
1049                                         addrbuf.ll.sll_ifindex);
1050                         printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1051                         tprintf(", addr(%d)={%d, ",
1052                                         addrbuf.ll.sll_halen,
1053                                         addrbuf.ll.sll_hatype);
1054                         for (i=0; i<addrbuf.ll.sll_halen; i++)
1055                                 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1056                 }
1057                 break;
1058
1059 #endif /* AF_APACKET */
1060 #ifdef AF_NETLINK
1061         case AF_NETLINK:
1062                 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1063                 break;
1064 #endif /* AF_NETLINK */
1065         /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1066         AF_X25 AF_ROSE etc. still need to be done */
1067
1068         default:
1069                 tprintf("sa_data=");
1070                 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1071                         sizeof addrbuf.sa.sa_data);
1072                 break;
1073         }
1074         tprintf("}");
1075 }
1076
1077 #if HAVE_SENDMSG
1078 static const struct xlat scmvals[] = {
1079 #ifdef SCM_RIGHTS
1080         { SCM_RIGHTS,           "SCM_RIGHTS"            },
1081 #endif
1082 #ifdef SCM_CREDENTIALS
1083         { SCM_CREDENTIALS,      "SCM_CREDENTIALS"       },
1084 #endif
1085         { 0,                    NULL                    }
1086 };
1087
1088 static void
1089 printcmsghdr(tcp, addr, len)
1090 struct tcb *tcp;
1091 unsigned long addr;
1092 unsigned long len;
1093 {
1094         struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1095                                NULL : malloc(len);
1096         if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1097                 tprintf(", msg_control=%#lx", addr);
1098                 free(cmsg);
1099                 return;
1100         }
1101
1102         tprintf(", {cmsg_len=%zu, cmsg_level=", cmsg->cmsg_len);
1103         printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1104         tprintf(", cmsg_type=");
1105
1106         if (cmsg->cmsg_level == SOL_SOCKET) {
1107                 unsigned long cmsg_len;
1108
1109                 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1110                 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1111
1112                 if (cmsg->cmsg_type == SCM_RIGHTS
1113                     && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1114                         int *fds = (int *) CMSG_DATA (cmsg);
1115                         int first = 1;
1116
1117                         tprintf(", {");
1118                         while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1119                                 if (!first)
1120                                         tprintf(", ");
1121                                 tprintf("%d", *fds++);
1122                                 first = 0;
1123                         }
1124                         tprintf("}}");
1125                         free(cmsg);
1126                         return;
1127                 }
1128                 if (cmsg->cmsg_type == SCM_CREDENTIALS
1129                     && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1130                         struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1131
1132                         tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1133                                 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1134                         free(cmsg);
1135                         return;
1136                 }
1137         }
1138         free(cmsg);
1139         tprintf(", ...}");
1140 }
1141
1142 static void
1143 printmsghdr(tcp, addr)
1144 struct tcb *tcp;
1145 long addr;
1146 {
1147         struct msghdr msg;
1148
1149         if (umove(tcp, addr, &msg) < 0) {
1150                 tprintf("%#lx", addr);
1151                 return;
1152         }
1153         tprintf("{msg_name(%d)=", msg.msg_namelen);
1154         printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
1155
1156         tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
1157         tprint_iov(tcp, (unsigned long)msg.msg_iovlen,
1158                    (unsigned long)msg.msg_iov);
1159
1160 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1161         tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
1162         if (msg.msg_controllen)
1163                 printcmsghdr(tcp, (unsigned long) msg.msg_control,
1164                              msg.msg_controllen);
1165         tprintf(", msg_flags=");
1166         printflags(msg_flags, msg.msg_flags, "MSG_???");
1167 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1168         tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1169                 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
1170 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1171         tprintf("}");
1172 }
1173
1174 #endif /* HAVE_SENDMSG */
1175
1176 int
1177 sys_socket(tcp)
1178 struct tcb *tcp;
1179 {
1180         if (entering(tcp)) {
1181                 printxval(domains, tcp->u_arg[0], "PF_???");
1182                 tprintf(", ");
1183                 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1184                 tprintf(", ");
1185                 switch (tcp->u_arg[0]) {
1186                 case PF_INET:
1187 #ifdef PF_INET6
1188                 case PF_INET6:
1189 #endif
1190                         printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1191                         break;
1192 #ifdef PF_IPX
1193                 case PF_IPX:
1194                         /* BTW: I don't believe this.. */
1195                         tprintf("[");
1196                         printxval(domains, tcp->u_arg[2], "PF_???");
1197                         tprintf("]");
1198                         break;
1199 #endif /* PF_IPX */
1200                 default:
1201                         tprintf("%lu", tcp->u_arg[2]);
1202                         break;
1203                 }
1204         }
1205         return 0;
1206 }
1207
1208 int
1209 sys_so_socket(tcp)
1210 struct tcb *tcp;
1211 {
1212         if (entering(tcp)) {
1213                 /* not sure really what these args are... but this
1214                  * is how truss prints it
1215                  */
1216                 tprintf("%ld, %ld, %ld, ",
1217                   tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1218                 printpath(tcp, tcp->u_arg[3]);
1219                 tprintf(", %ld", tcp->u_arg[4]);
1220         }
1221         return 0;
1222 }
1223
1224 int
1225 sys_so_socketpair(tcp)
1226 struct tcb *tcp;
1227 {
1228         if (entering(tcp)) {
1229                 /* not sure what this arg is */
1230                 tprintf("0x%lx", tcp->u_arg[0]);
1231         }
1232         return 0;
1233 }
1234
1235 int
1236 sys_bind(tcp)
1237 struct tcb *tcp;
1238 {
1239         if (entering(tcp)) {
1240                 tprintf("%ld, ", tcp->u_arg[0]);
1241                 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1242                 tprintf(", %lu", tcp->u_arg[2]);
1243         }
1244         return 0;
1245 }
1246
1247 int
1248 sys_connect(tcp)
1249 struct tcb *tcp;
1250 {
1251         return sys_bind(tcp);
1252 }
1253
1254 int
1255 sys_listen(tcp)
1256 struct tcb *tcp;
1257 {
1258         if (entering(tcp)) {
1259                 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1260         }
1261         return 0;
1262 }
1263
1264 int
1265 sys_accept(tcp)
1266 struct tcb *tcp;
1267 {
1268         if (entering(tcp)) {
1269                 tprintf("%ld, ", tcp->u_arg[0]);
1270         } else if (!tcp->u_arg[2])
1271                 tprintf("%#lx, NULL", tcp->u_arg[1]);
1272         else {
1273                 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
1274                         tprintf("%#lx", tcp->u_arg[1]);
1275                 } else {
1276                         printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1277                 }
1278                 tprintf(", ");
1279                 printnum(tcp, tcp->u_arg[2], "%lu");
1280         }
1281         return 0;
1282 }
1283
1284 int
1285 sys_send(tcp)
1286 struct tcb *tcp;
1287 {
1288         if (entering(tcp)) {
1289                 tprintf("%ld, ", tcp->u_arg[0]);
1290                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1291                 tprintf(", %lu, ", tcp->u_arg[2]);
1292                 /* flags */
1293                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1294         }
1295         return 0;
1296 }
1297
1298 int
1299 sys_sendto(tcp)
1300 struct tcb *tcp;
1301 {
1302         if (entering(tcp)) {
1303                 tprintf("%ld, ", tcp->u_arg[0]);
1304                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1305                 tprintf(", %lu, ", tcp->u_arg[2]);
1306                 /* flags */
1307                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1308                 /* to address */
1309                 tprintf(", ");
1310                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1311                 /* to length */
1312                 tprintf(", %lu", tcp->u_arg[5]);
1313         }
1314         return 0;
1315 }
1316
1317 #ifdef HAVE_SENDMSG
1318
1319 int
1320 sys_sendmsg(tcp)
1321 struct tcb *tcp;
1322 {
1323         if (entering(tcp)) {
1324                 tprintf("%ld, ", tcp->u_arg[0]);
1325                 printmsghdr(tcp, tcp->u_arg[1]);
1326                 /* flags */
1327                 tprintf(", ");
1328                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1329         }
1330         return 0;
1331 }
1332
1333 #endif /* HAVE_SENDMSG */
1334
1335 int
1336 sys_recv(tcp)
1337 struct tcb *tcp;
1338 {
1339         if (entering(tcp)) {
1340                 tprintf("%ld, ", tcp->u_arg[0]);
1341         } else {
1342                 if (syserror(tcp))
1343                         tprintf("%#lx", tcp->u_arg[1]);
1344                 else
1345                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1346
1347                 tprintf(", %lu, ", tcp->u_arg[2]);
1348                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1349         }
1350         return 0;
1351 }
1352
1353 int
1354 sys_recvfrom(tcp)
1355 struct tcb *tcp;
1356 {
1357         int fromlen;
1358
1359         if (entering(tcp)) {
1360                 tprintf("%ld, ", tcp->u_arg[0]);
1361         } else {
1362                 if (syserror(tcp)) {
1363                         tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1364                                 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1365                                 tcp->u_arg[4], tcp->u_arg[5]);
1366                         return 0;
1367                 }
1368                 /* buf */
1369                 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1370                 /* len */
1371                 tprintf(", %lu, ", tcp->u_arg[2]);
1372                 /* flags */
1373                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1374                 /* from address, len */
1375                 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1376                         if (tcp->u_arg[4] == 0)
1377                                 tprintf(", NULL");
1378                         else
1379                                 tprintf(", %#lx", tcp->u_arg[4]);
1380                         if (tcp->u_arg[5] == 0)
1381                                 tprintf(", NULL");
1382                         else
1383                                 tprintf(", %#lx", tcp->u_arg[5]);
1384                         return 0;
1385                 }
1386                 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1387                         tprintf(", {...}, [?]");
1388                         return 0;
1389                 }
1390                 tprintf(", ");
1391                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1392                 /* from length */
1393                 tprintf(", [%u]", fromlen);
1394         }
1395         return 0;
1396 }
1397
1398 #ifdef HAVE_SENDMSG
1399
1400 int
1401 sys_recvmsg(tcp)
1402 struct tcb *tcp;
1403 {
1404         if (entering(tcp)) {
1405                 tprintf("%ld, ", tcp->u_arg[0]);
1406         } else {
1407                 if (syserror(tcp) || !verbose(tcp))
1408                         tprintf("%#lx", tcp->u_arg[1]);
1409                 else
1410                         printmsghdr(tcp, tcp->u_arg[1]);
1411                 /* flags */
1412                 tprintf(", ");
1413                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1414         }
1415         return 0;
1416 }
1417
1418 #endif /* HAVE_SENDMSG */
1419
1420 int
1421 sys_shutdown(tcp)
1422 struct tcb *tcp;
1423 {
1424         if (entering(tcp)) {
1425                 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1426                 switch (tcp->u_arg[1]) {
1427                 case 0:
1428                         tprintf("%s", " /* receive */");
1429                         break;
1430                 case 1:
1431                         tprintf("%s", " /* send */");
1432                         break;
1433                 case 2:
1434                         tprintf("%s", " /* send and receive */");
1435                         break;
1436                 }
1437         }
1438         return 0;
1439 }
1440
1441 int
1442 sys_getsockname(tcp)
1443 struct tcb *tcp;
1444 {
1445         return sys_accept(tcp);
1446 }
1447
1448 int
1449 sys_getpeername(tcp)
1450 struct tcb *tcp;
1451 {
1452         return sys_accept(tcp);
1453 }
1454
1455 int
1456 sys_pipe(tcp)
1457 struct tcb *tcp;
1458 {
1459
1460 #if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1461         int fds[2];
1462
1463         if (exiting(tcp)) {
1464                 if (syserror(tcp)) {
1465                         tprintf("%#lx", tcp->u_arg[0]);
1466                         return 0;
1467                 }
1468                 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1469                         tprintf("[...]");
1470                 else
1471                         tprintf("[%u, %u]", fds[0], fds[1]);
1472         }
1473 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
1474         if (exiting(tcp))
1475                 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1476 #endif
1477         return 0;
1478 }
1479
1480 int
1481 sys_socketpair(tcp)
1482 struct tcb *tcp;
1483 {
1484 #ifdef LINUX
1485         int fds[2];
1486 #endif
1487
1488         if (entering(tcp)) {
1489                 printxval(domains, tcp->u_arg[0], "PF_???");
1490                 tprintf(", ");
1491                 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1492                 tprintf(", ");
1493                 switch (tcp->u_arg[0]) {
1494                 case PF_INET:
1495                         printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1496                         break;
1497 #ifdef PF_IPX
1498                 case PF_IPX:
1499                         /* BTW: I don't believe this.. */
1500                         tprintf("[");
1501                         printxval(domains, tcp->u_arg[2], "PF_???");
1502                         tprintf("]");
1503                         break;
1504 #endif /* PF_IPX */
1505                 default:
1506                         tprintf("%lu", tcp->u_arg[2]);
1507                         break;
1508                 }
1509         } else {
1510                 if (syserror(tcp)) {
1511                         tprintf(", %#lx", tcp->u_arg[3]);
1512                         return 0;
1513                 }
1514 #ifdef LINUX
1515                 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1516                         tprintf(", [...]");
1517                 else
1518                         tprintf(", [%u, %u]", fds[0], fds[1]);
1519 #endif /* LINUX */
1520 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1521                 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1522 #endif /* SUNOS4 || SVR4 || FREEBSD */
1523         }
1524         return 0;
1525 }
1526
1527 int
1528 sys_getsockopt(tcp)
1529 struct tcb *tcp;
1530 {
1531         if (entering(tcp)) {
1532                 tprintf("%ld, ", tcp->u_arg[0]);
1533                 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1534                 tprintf (", ");
1535                 switch (tcp->u_arg[1]) {
1536                 case SOL_SOCKET:
1537                         printxval(sockoptions, tcp->u_arg[2], "SO_???");
1538                         break;
1539 #ifdef SOL_IP
1540                 case SOL_IP:
1541                         printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1542                         break;
1543 #endif
1544 #ifdef SOL_IPV6
1545                 case SOL_IPV6:
1546                         printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1547                         break;
1548 #endif
1549 #ifdef SOL_IPX
1550                 case SOL_IPX:
1551                         printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1552                         break;
1553 #endif
1554 #ifdef SOL_PACKET
1555                 case SOL_PACKET:
1556                         printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1557                         break;
1558 #endif
1559 #ifdef SOL_TCP
1560                 case SOL_TCP:
1561                         printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1562                         break;
1563 #endif
1564
1565                 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1566                  * etc. still need work */
1567                 default:
1568                         tprintf("%lu", tcp->u_arg[2]);
1569                         break;
1570                 }
1571         } else {
1572                 int len;
1573                 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1574                         tprintf(", %#lx, %#lx",
1575                                 tcp->u_arg[3], tcp->u_arg[4]);
1576                         return 0;
1577                 }
1578
1579                 switch (tcp->u_arg[1]) {
1580                 case SOL_SOCKET:
1581                         switch (tcp->u_arg[2]) {
1582 #ifdef SO_LINGER
1583                         case SO_LINGER:
1584                                 if (len == sizeof (struct linger)) {
1585                                         struct linger linger;
1586                                         if (umove (tcp,
1587                                                    tcp->u_arg[3],
1588                                                    &linger) < 0)
1589                                                 break;
1590                                         tprintf(", {onoff=%d, linger=%d}, "
1591                                                 "[%d]",
1592                                                 linger.l_onoff,
1593                                                 linger.l_linger,
1594                                                 len);
1595                                         return 0;
1596                                 }
1597                                 break;
1598 #endif
1599                         }
1600                         break;
1601                 }
1602
1603                 tprintf (", ");
1604                 if (len == sizeof (int)) {
1605                         printnum(tcp, tcp->u_arg[3], "%ld");
1606                 }
1607                 else {
1608                         printstr (tcp, tcp->u_arg[3], len);
1609                 }
1610                 tprintf(", [%d]", len);
1611         }
1612         return 0;
1613 }
1614
1615 #if defined(ICMP_FILTER)
1616 static void printicmpfilter(tcp, addr)
1617 struct tcb *tcp;
1618 long addr;
1619 {
1620         struct icmp_filter      filter;
1621
1622         if (!addr) {
1623                 tprintf("NULL");
1624                 return;
1625         }
1626         if (syserror(tcp) || !verbose(tcp)) {
1627                 tprintf("%#lx", addr);
1628                 return;
1629         }
1630         if (umove(tcp, addr, &filter) < 0) {
1631                 tprintf("{...}");
1632                 return;
1633         }
1634
1635         tprintf("~(");
1636         printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1637         tprintf(")");
1638 }
1639 #endif /* ICMP_FILTER */
1640
1641 static int
1642 printsockopt (tcp, level, name, addr, len)
1643 struct tcb *tcp;
1644 int level;
1645 int name;
1646 long addr;
1647 int len;
1648 {
1649         printxval(socketlayers, level, "SOL_??");
1650         tprintf (", ");
1651         switch (level) {
1652             case SOL_SOCKET:
1653                 printxval(sockoptions, name, "SO_???");
1654                 switch (name) {
1655 #if defined(SO_LINGER)
1656                     case SO_LINGER:
1657                         if (len == sizeof (struct linger)) {
1658                                 struct linger linger;
1659                                 if (umove (tcp, addr, &linger) < 0)
1660                                         break;
1661                                 tprintf(", {onoff=%d, linger=%d}",
1662                                         linger.l_onoff,
1663                                         linger.l_linger);
1664                                 return 0;
1665                         }
1666                         break;
1667 #endif
1668                 }
1669                 break;
1670 #ifdef SOL_IP
1671             case SOL_IP:
1672                 printxval(sockipoptions, name, "IP_???");
1673                 break;
1674 #endif
1675 #ifdef SOL_IPV6
1676             case SOL_IPV6:
1677                 printxval(sockipv6options, name, "IPV6_???");
1678                 break;
1679 #endif
1680 #ifdef SOL_IPX
1681             case SOL_IPX:
1682                 printxval(sockipxoptions, name, "IPX_???");
1683                 break;
1684 #endif
1685 #ifdef SOL_PACKET
1686             case SOL_PACKET:
1687                 printxval(sockpacketoptions, name, "PACKET_???");
1688                 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1689                 break;
1690 #endif
1691 #ifdef SOL_TCP
1692             case SOL_TCP:
1693                 printxval(socktcpoptions, name, "TCP_???");
1694                 break;
1695 #endif
1696 #ifdef SOL_RAW
1697             case SOL_RAW:
1698                 printxval(sockrawoptions, name, "RAW_???");
1699                 switch (name) {
1700 #if defined(ICMP_FILTER)
1701                     case ICMP_FILTER:
1702                         tprintf(", ");
1703                         printicmpfilter(tcp, addr);
1704                         return 0;
1705 #endif
1706                 }
1707                 break;
1708 #endif
1709
1710                 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1711                  * etc. still need work  */
1712
1713             default:
1714                 tprintf("%u", name);
1715         }
1716
1717         /* default arg printing */
1718
1719         tprintf (", ");
1720
1721         if (len == sizeof (int)) {
1722                 printnum_int (tcp, addr, "%d");
1723         }
1724         else {
1725                 printstr (tcp, addr, len);
1726         }
1727         return 0;
1728 }
1729
1730
1731 #ifdef HAVE_STRUCT_OPTHDR
1732
1733 void
1734 print_sock_optmgmt (tcp, addr, len)
1735 struct tcb *tcp;
1736 long addr;
1737 int len;
1738 {
1739         int c = 0;
1740         struct opthdr hdr;
1741
1742         while (len >= (int) sizeof hdr) {
1743                 if (umove(tcp, addr, &hdr) < 0) break;
1744                 if (c++) {
1745                         tprintf (", ");
1746                 }
1747                 else if (len > hdr.len + sizeof hdr) {
1748                         tprintf ("[");
1749                 }
1750                 tprintf ("{");
1751                 addr += sizeof hdr;
1752                 len -= sizeof hdr;
1753                 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
1754                 if (hdr.len > 0) {
1755                         addr += hdr.len;
1756                         len -= hdr.len;
1757                 }
1758                 tprintf ("}");
1759         }
1760         if (len > 0) {
1761                 if (c++) tprintf (", ");
1762                 printstr (tcp, addr, len);
1763         }
1764         if (c > 1) tprintf ("]");
1765 }
1766
1767 #endif
1768
1769 int
1770 sys_setsockopt(tcp)
1771 struct tcb *tcp;
1772 {
1773         if (entering(tcp)) {
1774                 tprintf("%ld, ", tcp->u_arg[0]);
1775                 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1776                               tcp->u_arg[3], tcp->u_arg[4]);
1777                 tprintf(", %lu", tcp->u_arg[4]);
1778         }
1779         return 0;
1780 }
1781
1782 #if UNIXWARE >= 7
1783
1784 static const struct xlat sock_version[] = {
1785         { __NETLIB_UW211_SVR4,  "UW211_SVR4" },
1786         { __NETLIB_UW211_XPG4,  "UW211_XPG4" },
1787         { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1788         { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1789         { __NETLIB_FP1_SVR4,    "FP1_SVR4" },
1790         { __NETLIB_FP1_XPG4,    "FP1_XPG4" },
1791         { 0,            NULL            },
1792 };
1793
1794
1795 int
1796 netlib_call(tcp, func)
1797 struct tcb *tcp;
1798 int (*func) ();
1799 {
1800         if (entering(tcp)) {
1801                 int i;
1802                 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1803                 tprintf(", ");
1804                 --tcp->u_nargs;
1805                 for (i = 0; i < tcp->u_nargs; i++)
1806                         tcp->u_arg[i] = tcp->u_arg[i + 1];
1807                 return func (tcp);
1808
1809         }
1810
1811         return func (tcp);
1812 }
1813
1814 int
1815 sys_xsocket(tcp)
1816 struct tcb *tcp;
1817 {
1818         return netlib_call (tcp, sys_socket);
1819 }
1820
1821 int
1822 sys_xsocketpair(tcp)
1823 struct tcb *tcp;
1824 {
1825         return netlib_call (tcp, sys_socketpair);
1826 }
1827
1828 int
1829 sys_xbind(tcp)
1830 struct tcb *tcp;
1831 {
1832         return netlib_call (tcp, sys_bind);
1833 }
1834
1835 int
1836 sys_xconnect(tcp)
1837 struct tcb *tcp;
1838 {
1839         return netlib_call (tcp, sys_connect);
1840 }
1841
1842 int
1843 sys_xlisten(tcp)
1844 struct tcb *tcp;
1845 {
1846         return netlib_call (tcp, sys_listen);
1847 }
1848
1849 int
1850 sys_xaccept(tcp)
1851 struct tcb *tcp;
1852 {
1853         return netlib_call (tcp, sys_accept);
1854 }
1855
1856 int
1857 sys_xsendmsg(tcp)
1858 struct tcb *tcp;
1859 {
1860         return netlib_call (tcp, sys_sendmsg);
1861 }
1862
1863 int
1864 sys_xrecvmsg(tcp)
1865 struct tcb *tcp;
1866 {
1867         return netlib_call (tcp, sys_recvmsg);
1868 }
1869
1870 int
1871 sys_xgetsockaddr(tcp)
1872 struct tcb *tcp;
1873 {
1874         if (entering(tcp)) {
1875                 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1876                 tprintf(", ");
1877                 if (tcp->u_arg[1] == 0) {
1878                         tprintf ("LOCALNAME, ");
1879                 }
1880                 else if (tcp->u_arg[1] == 1) {
1881                         tprintf ("REMOTENAME, ");
1882                 }
1883                 else {
1884                         tprintf ("%ld, ", tcp->u_arg [1]);
1885                 }
1886                 tprintf ("%ld, ", tcp->u_arg [2]);
1887         }
1888         else {
1889                 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1890                         tprintf("%#lx", tcp->u_arg[3]);
1891                 } else {
1892                         printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1893                 }
1894                 tprintf(", ");
1895                 printnum(tcp, tcp->u_arg[4], "%lu");
1896         }
1897
1898         return 0;
1899
1900 }
1901
1902 #if 0
1903
1904 int
1905 sys_xsetsockaddr(tcp)
1906 struct tcb *tcp;
1907 {
1908         return netlib_call (tcp, sys_setsockaddr);
1909 }
1910
1911 #endif
1912
1913 int
1914 sys_xgetsockopt(tcp)
1915 struct tcb *tcp;
1916 {
1917         return netlib_call (tcp, sys_getsockopt);
1918 }
1919
1920 int
1921 sys_xsetsockopt(tcp)
1922 struct tcb *tcp;
1923 {
1924         return netlib_call (tcp, sys_setsockopt);
1925 }
1926
1927 int
1928 sys_xshutdown(tcp)
1929 struct tcb *tcp;
1930 {
1931         return netlib_call (tcp, sys_shutdown);
1932 }
1933
1934 #endif