]> granicus.if.org Git - strace/blob - net.c
2007-11-01 Roland McGrath <roland@redhat.com>
[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 #ifdef MSG_CMSG_CLOEXEC
493         { MSG_CMSG_CLOEXEC,     "MSG_CMSG_CLOEXEC"      },
494 #endif
495         { 0,                    NULL                    },
496 };
497
498 static const struct xlat sockoptions[] = {
499 #ifdef SO_ACCEPTCONN
500         { SO_ACCEPTCONN,        "SO_ACCEPTCONN" },
501 #endif
502 #ifdef SO_ALLRAW
503         { SO_ALLRAW,    "SO_ALLRAW"     },
504 #endif
505 #ifdef SO_ATTACH_FILTER
506         { SO_ATTACH_FILTER,     "SO_ATTACH_FILTER"      },
507 #endif
508 #ifdef SO_BINDTODEVICE
509         { SO_BINDTODEVICE,      "SO_BINDTODEVICE"       },
510 #endif
511 #ifdef SO_BROADCAST
512         { SO_BROADCAST, "SO_BROADCAST"  },
513 #endif
514 #ifdef SO_BSDCOMPAT
515         { SO_BSDCOMPAT, "SO_BSDCOMPAT"  },
516 #endif
517 #ifdef SO_DEBUG
518         { SO_DEBUG,     "SO_DEBUG"      },
519 #endif
520 #ifdef SO_DETACH_FILTER
521         { SO_DETACH_FILTER,     "SO_DETACH_FILTER"      },
522 #endif
523 #ifdef SO_DONTROUTE
524         { SO_DONTROUTE, "SO_DONTROUTE"  },
525 #endif
526 #ifdef SO_ERROR
527         { SO_ERROR,     "SO_ERROR"      },
528 #endif
529 #ifdef SO_ICS
530         { SO_ICS,       "SO_ICS"        },
531 #endif
532 #ifdef SO_IMASOCKET
533         { SO_IMASOCKET, "SO_IMASOCKET"  },
534 #endif
535 #ifdef SO_KEEPALIVE
536         { SO_KEEPALIVE, "SO_KEEPALIVE"  },
537 #endif
538 #ifdef SO_LINGER
539         { SO_LINGER,    "SO_LINGER"     },
540 #endif
541 #ifdef SO_LISTENING
542         { SO_LISTENING, "SO_LISTENING"  },
543 #endif
544 #ifdef SO_MGMT
545         { SO_MGMT,      "SO_MGMT"       },
546 #endif
547 #ifdef SO_NO_CHECK
548         { SO_NO_CHECK,  "SO_NO_CHECK"   },
549 #endif
550 #ifdef SO_OOBINLINE
551         { SO_OOBINLINE, "SO_OOBINLINE"  },
552 #endif
553 #ifdef SO_ORDREL
554         { SO_ORDREL,    "SO_ORDREL"     },
555 #endif
556 #ifdef SO_PARALLELSVR
557         { SO_PARALLELSVR,       "SO_PARALLELSVR"        },
558 #endif
559 #ifdef SO_PASSCRED
560         { SO_PASSCRED,  "SO_PASSCRED"   },
561 #endif
562 #ifdef SO_PEERCRED
563         { SO_PEERCRED,  "SO_PEERCRED"   },
564 #endif
565 #ifdef SO_PEERNAME
566         { SO_PEERNAME,  "SO_PEERNAME"   },
567 #endif
568 #ifdef SO_PEERSEC
569         { SO_PEERSEC,   "SO_PEERSEC"    },
570 #endif
571 #ifdef SO_PRIORITY
572         { SO_PRIORITY,  "SO_PRIORITY"   },
573 #endif
574 #ifdef SO_PROTOTYPE
575         { SO_PROTOTYPE, "SO_PROTOTYPE"  },
576 #endif
577 #ifdef SO_RCVBUF
578         { SO_RCVBUF,    "SO_RCVBUF"     },
579 #endif
580 #ifdef SO_RCVLOWAT
581         { SO_RCVLOWAT,  "SO_RCVLOWAT"   },
582 #endif
583 #ifdef SO_RCVTIMEO
584         { SO_RCVTIMEO,  "SO_RCVTIMEO"   },
585 #endif
586 #ifdef SO_RDWR
587         { SO_RDWR,      "SO_RDWR"       },
588 #endif
589 #ifdef SO_REUSEADDR
590         { SO_REUSEADDR, "SO_REUSEADDR"  },
591 #endif
592 #ifdef SO_REUSEPORT
593         { SO_REUSEPORT, "SO_REUSEPORT"  },
594 #endif
595 #ifdef SO_SECURITY_AUTHENTICATION
596         { SO_SECURITY_AUTHENTICATION,"SO_SECURITY_AUTHENTICATION"},
597 #endif
598 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
599         { SO_SECURITY_ENCRYPTION_NETWORK,"SO_SECURITY_ENCRYPTION_NETWORK"},
600 #endif
601 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
602         { SO_SECURITY_ENCRYPTION_TRANSPORT,"SO_SECURITY_ENCRYPTION_TRANSPORT"},
603 #endif
604 #ifdef SO_SEMA
605         { SO_SEMA,      "SO_SEMA"       },
606 #endif
607 #ifdef SO_SNDBUF
608         { SO_SNDBUF,    "SO_SNDBUF"     },
609 #endif
610 #ifdef SO_SNDLOWAT
611         { SO_SNDLOWAT,  "SO_SNDLOWAT"   },
612 #endif
613 #ifdef SO_SNDTIMEO
614         { SO_SNDTIMEO,  "SO_SNDTIMEO"   },
615 #endif
616 #ifdef SO_TIMESTAMP
617         { SO_TIMESTAMP, "SO_TIMESTAMP"  },
618 #endif
619 #ifdef SO_TYPE
620         { SO_TYPE,      "SO_TYPE"       },
621 #endif
622 #ifdef SO_USELOOPBACK
623         { SO_USELOOPBACK,       "SO_USELOOPBACK"        },
624 #endif
625         { 0,            NULL            },
626 };
627
628 #if !defined (SOL_IP) && defined (IPPROTO_IP)
629 #define SOL_IP IPPROTO_IP
630 #endif
631
632 #ifdef SOL_IP
633 static const struct xlat sockipoptions[] = {
634 #ifdef IP_TOS
635         { IP_TOS,               "IP_TOS"                },
636 #endif
637 #ifdef IP_TTL
638         { IP_TTL,               "IP_TTL"                },
639 #endif
640 #ifdef IP_HDRINCL
641         { IP_HDRINCL,           "IP_HDRINCL"            },
642 #endif
643 #ifdef IP_OPTIONS
644         { IP_OPTIONS,           "IP_OPTIONS"            },
645 #endif
646 #ifdef IP_ROUTER_ALERT
647         { IP_ROUTER_ALERT,      "IP_ROUTER_ALERT"       },
648 #endif
649 #ifdef IP_RECVOPTIONS
650         { IP_RECVOPTIONS,       "IP_RECVOPTIONS"        },
651 #endif
652 #ifdef IP_RECVOPTS
653         { IP_RECVOPTS,          "IP_RECVOPTS"           },
654 #endif
655 #ifdef IP_RECVRETOPTS
656         { IP_RECVRETOPTS,       "IP_RECVRETOPTS"        },
657 #endif
658 #ifdef IP_RECVDSTADDR
659         { IP_RECVDSTADDR,       "IP_RECVDSTADDR"        },
660 #endif
661 #ifdef IP_RETOPTS
662         { IP_RETOPTS,           "IP_RETOPTS"            },
663 #endif
664 #ifdef IP_PKTINFO
665         { IP_PKTINFO,           "IP_PKTINFO"            },
666 #endif
667 #ifdef IP_PKTOPTIONS
668         { IP_PKTOPTIONS,        "IP_PKTOPTIONS"         },
669 #endif
670 #ifdef IP_MTU_DISCOVER
671         { IP_MTU_DISCOVER,      "IP_MTU_DISCOVER"       },
672 #endif
673 #ifdef IP_RECVERR
674         { IP_RECVERR,           "IP_RECVERR"            },
675 #endif
676 #ifdef IP_RECVTTL
677         { IP_RECVTTL,           "IP_RECVTTL"            },
678 #endif
679 #ifdef IP_RECVTOS
680         { IP_RECVTOS,           "IP_RECVTOS"            },
681 #endif
682 #ifdef IP_MTU
683         { IP_MTU,               "IP_MTU"                },
684 #endif
685 #ifdef IP_MULTICAST_IF
686         { IP_MULTICAST_IF,      "IP_MULTICAST_IF"       },
687 #endif
688 #ifdef IP_MULTICAST_TTL
689         { IP_MULTICAST_TTL,     "IP_MULTICAST_TTL"      },
690 #endif
691 #ifdef IP_MULTICAST_LOOP
692         { IP_MULTICAST_LOOP,    "IP_MULTICAST_LOOP"     },
693 #endif
694 #ifdef IP_ADD_MEMBERSHIP
695         { IP_ADD_MEMBERSHIP,    "IP_ADD_MEMBERSHIP"     },
696 #endif
697 #ifdef IP_DROP_MEMBERSHIP
698         { IP_DROP_MEMBERSHIP,   "IP_DROP_MEMBERSHIP"    },
699 #endif
700 #ifdef IP_BROADCAST_IF
701         { IP_BROADCAST_IF,      "IP_BROADCAST_IF"       },
702 #endif
703 #ifdef IP_RECVIFINDEX
704         { IP_RECVIFINDEX,       "IP_RECVIFINDEX"        },
705 #endif
706 #ifdef IP_MSFILTER
707         { IP_MSFILTER,          "IP_MSFILTER"           },
708 #endif
709 #ifdef MCAST_MSFILTER
710         { MCAST_MSFILTER,       "MCAST_MSFILTER"        },
711 #endif
712 #ifdef IP_FREEBIND
713         { IP_FREEBIND,          "IP_FREEBIND"           },
714 #endif
715         { 0,                    NULL                    },
716 };
717 #endif /* SOL_IP */
718
719 #ifdef SOL_IPV6
720 static const struct xlat sockipv6options[] = {
721 #ifdef IPV6_ADDRFORM
722         { IPV6_ADDRFORM,        "IPV6_ADDRFORM"         },
723 #endif
724 #ifdef MCAST_FILTER
725         { MCAST_FILTER,         "MCAST_FILTER"          },
726 #endif
727 #ifdef IPV6_PKTOPTIONS
728         { IPV6_PKTOPTIONS,      "IPV6_PKTOPTIONS"       },
729 #endif
730 #ifdef IPV6_MTU
731         { IPV6_MTU,             "IPV6_MTU"              },
732 #endif
733 #ifdef IPV6_V6ONLY
734         { IPV6_V6ONLY,          "IPV6_V6ONLY"           },
735 #endif
736 #ifdef IPV6_PKTINFO
737         { IPV6_PKTINFO,         "IPV6_PKTINFO"          },
738 #endif
739 #ifdef IPV6_HOPLIMIT
740         { IPV6_HOPLIMIT,        "IPV6_HOPLIMIT"         },
741 #endif
742 #ifdef IPV6_RTHDR
743         { IPV6_RTHDR,           "IPV6_RTHDR"            },
744 #endif
745 #ifdef IPV6_HOPOPTS
746         { IPV6_HOPOPTS,         "IPV6_HOPOPTS"          },
747 #endif
748 #ifdef IPV6_DSTOPTS
749         { IPV6_DSTOPTS,         "IPV6_DSTOPTS"          },
750 #endif
751 #ifdef IPV6_FLOWINFO
752         { IPV6_FLOWINFO,        "IPV6_FLOWINFO"         },
753 #endif
754 #ifdef IPV6_UNICAST_HOPS
755         { IPV6_UNICAST_HOPS,    "IPV6_UNICAST_HOPS"     },
756 #endif
757 #ifdef IPV6_MULTICAST_HOPS
758         { IPV6_MULTICAST_HOPS,  "IPV6_MULTICAST_HOPS"   },
759 #endif
760 #ifdef IPV6_MULTICAST_LOOP
761         { IPV6_MULTICAST_LOOP,  "IPV6_MULTICAST_LOOP"   },
762 #endif
763 #ifdef IPV6_MULTICAST_IF
764         { IPV6_MULTICAST_IF,    "IPV6_MULTICAST_IF"     },
765 #endif
766 #ifdef IPV6_MTU_DISCOVER
767         { IPV6_MTU_DISCOVER,    "IPV6_MTU_DISCOVER"     },
768 #endif
769 #ifdef IPV6_RECVERR
770         { IPV6_RECVERR,         "IPV6_RECVERR"          },
771 #endif
772 #ifdef IPV6_FLOWINFO_SEND
773         { IPV6_FLOWINFO_SEND,   "IPV6_FLOWINFO_SEND"    },
774 #endif
775 #ifdef IPV6_ADD_MEMBERSHIP
776         { IPV6_ADD_MEMBERSHIP,  "IPV6_ADD_MEMBERSHIP"   },
777 #endif
778 #ifdef IPV6_DROP_MEMBERSHIP
779         { IPV6_DROP_MEMBERSHIP, "IPV6_DROP_MEMBERSHIP"  },
780 #endif
781 #ifdef IPV6_ROUTER_ALERT
782         { IPV6_ROUTER_ALERT,    "IPV6_ROUTER_ALERT"     },
783 #endif
784         { 0,                    NULL                    },
785 };
786 #endif /* SOL_IPV6 */
787
788 #ifdef SOL_IPX
789 static const struct xlat sockipxoptions[] = {
790         { IPX_TYPE,     "IPX_TYPE"      },
791         { 0,            NULL            },
792 };
793 #endif /* SOL_IPX */
794
795 #ifdef SOL_RAW
796 static const struct xlat sockrawoptions[] = {
797 #if defined(ICMP_FILTER)
798         { ICMP_FILTER,          "ICMP_FILTER"   },
799 #endif
800         { 0,                    NULL            },
801 };
802 #endif /* SOL_RAW */
803
804 #ifdef SOL_PACKET
805 static const struct xlat sockpacketoptions[] = {
806 #ifdef PACKET_ADD_MEMBERSHIP
807         { PACKET_ADD_MEMBERSHIP,        "PACKET_ADD_MEMBERSHIP" },
808 #endif
809 #ifdef PACKET_DROP_MEMBERSHIP
810         { PACKET_DROP_MEMBERSHIP,       "PACKET_DROP_MEMBERSHIP"},
811 #endif
812 #if defined(PACKET_RECV_OUTPUT)
813         { PACKET_RECV_OUTPUT,           "PACKET_RECV_OUTPUT"    },
814 #endif
815 #if defined(PACKET_RX_RING)
816         { PACKET_RX_RING,               "PACKET_RX_RING"        },
817 #endif
818 #if defined(PACKET_STATISTICS)
819         { PACKET_STATISTICS,            "PACKET_STATISTICS"     },
820 #endif
821         { 0,                            NULL                    },
822 };
823 #endif /* SOL_PACKET */
824
825 #if  !defined (SOL_TCP) && defined (IPPROTO_TCP)
826 #define SOL_TCP IPPROTO_TCP
827 #endif
828
829 #ifdef SOL_TCP
830 static const struct xlat socktcpoptions[] = {
831         { TCP_NODELAY,          "TCP_NODELAY"   },
832         { TCP_MAXSEG,           "TCP_MAXSEG"    },
833 #if defined(TCP_CORK)
834         { TCP_CORK,             "TCP_CORK"      },
835 #endif
836 #if defined(TCP_KEEPIDLE)
837         { TCP_KEEPIDLE,         "TCP_KEEPIDLE" },
838 #endif
839 #if defined(TCP_KEEPINTVL)
840         { TCP_KEEPINTVL,        "TCP_KEEPINTVL" },
841 #endif
842 #if defined(TCP_KEEPCNT)
843         { TCP_KEEPCNT,          "TCP_KEEPCNT" },
844 #endif
845 #if defined(TCP_NKEEP)
846         { TCP_NKEEP,            "TCP_NKEEP"     },
847 #endif
848 #if defined(TCP_SYNCNT)
849         { TCP_SYNCNT,           "TCP_SYNCNT" },
850 #endif
851 #if defined(TCP_LINGER2)
852         { TCP_LINGER2,          "TCP_LINGER2" },
853 #endif
854 #if defined(TCP_DEFER_ACCEPT)
855         { TCP_DEFER_ACCEPT,     "TCP_DEFER_ACCEPT" },
856 #endif
857 #if defined(TCP_WINDOW_CLAMP)
858         { TCP_WINDOW_CLAMP,     "TCP_WINDOW_CLAMP" },
859 #endif
860 #if defined(TCP_INFO)
861         { TCP_INFO,             "TCP_INFO" },
862 #endif
863 #if defined(TCP_QUICKACK)
864         { TCP_QUICKACK,         "TCP_QUICKACK" },
865 #endif
866         { 0,                    NULL            },
867 };
868 #endif /* SOL_TCP */
869
870 #ifdef SOL_RAW
871 static const struct xlat icmpfilterflags[] = {
872 #if defined(ICMP_ECHOREPLY)
873         { (1<<ICMP_ECHOREPLY),          "ICMP_ECHOREPLY"        },
874 #endif
875 #if defined(ICMP_DEST_UNREACH)
876         { (1<<ICMP_DEST_UNREACH),       "ICMP_DEST_UNREACH"     },
877 #endif
878 #if defined(ICMP_SOURCE_QUENCH)
879         { (1<<ICMP_SOURCE_QUENCH),      "ICMP_SOURCE_QUENCH"    },
880 #endif
881 #if defined(ICMP_REDIRECT)
882         { (1<<ICMP_REDIRECT),           "ICMP_REDIRECT"         },
883 #endif
884 #if defined(ICMP_ECHO)
885         { (1<<ICMP_ECHO),               "ICMP_ECHO"             },
886 #endif
887 #if defined(ICMP_TIME_EXCEEDED)
888         { (1<<ICMP_TIME_EXCEEDED),      "ICMP_TIME_EXCEEDED"    },
889 #endif
890 #if defined(ICMP_PARAMETERPROB)
891         { (1<<ICMP_PARAMETERPROB),      "ICMP_PARAMETERPROB"    },
892 #endif
893 #if defined(ICMP_TIMESTAMP)
894         { (1<<ICMP_TIMESTAMP),          "ICMP_TIMESTAMP"        },
895 #endif
896 #if defined(ICMP_TIMESTAMPREPLY)
897         { (1<<ICMP_TIMESTAMPREPLY),     "ICMP_TIMESTAMPREPLY"   },
898 #endif
899 #if defined(ICMP_INFO_REQUEST)
900         { (1<<ICMP_INFO_REQUEST),       "ICMP_INFO_REQUEST"     },
901 #endif
902 #if defined(ICMP_INFO_REPLY)
903         { (1<<ICMP_INFO_REPLY),         "ICMP_INFO_REPLY"       },
904 #endif
905 #if defined(ICMP_ADDRESS)
906         { (1<<ICMP_ADDRESS),            "ICMP_ADDRESS"          },
907 #endif
908 #if defined(ICMP_ADDRESSREPLY)
909         { (1<<ICMP_ADDRESSREPLY),       "ICMP_ADDRESSREPLY"     },
910 #endif
911         { 0,                            NULL                    },
912 };
913 #endif /* SOL_RAW */
914
915 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
916 static const struct xlat af_packet_types[] = {
917 #if defined(PACKET_HOST)
918         { PACKET_HOST,                  "PACKET_HOST"           },
919 #endif
920 #if defined(PACKET_BROADCAST)
921         { PACKET_BROADCAST,             "PACKET_BROADCAST"      },
922 #endif
923 #if defined(PACKET_MULTICAST)
924         { PACKET_MULTICAST,             "PACKET_MULTICAST"      },
925 #endif
926 #if defined(PACKET_OTHERHOST)
927         { PACKET_OTHERHOST,             "PACKET_OTHERHOST"      },
928 #endif
929 #if defined(PACKET_OUTGOING)
930         { PACKET_OUTGOING,              "PACKET_OUTGOING"       },
931 #endif
932 #if defined(PACKET_LOOPBACK)
933         { PACKET_LOOPBACK,              "PACKET_LOOPBACK"       },
934 #endif
935 #if defined(PACKET_FASTROUTE)
936         { PACKET_FASTROUTE,             "PACKET_FASTROUTE"      },
937 #endif
938         { 0,                            NULL                    },
939 };
940 #endif /* defined(AF_PACKET) */
941
942
943 void
944 printsock(struct tcb *tcp, long addr, int addrlen)
945 {
946         union {
947                 char pad[128];
948                 struct sockaddr sa;
949                 struct sockaddr_in sin;
950                 struct sockaddr_un sau;
951 #ifdef HAVE_INET_NTOP
952                 struct sockaddr_in6 sa6;
953 #endif
954 #if defined(LINUX) && defined(AF_IPX)
955                 struct sockaddr_ipx sipx;
956 #endif
957 #ifdef AF_PACKET
958                 struct sockaddr_ll ll;
959 #endif
960 #ifdef AF_NETLINK
961                 struct sockaddr_nl nl;
962 #endif
963         } addrbuf;
964         char string_addr[100];
965
966         if (addr == 0) {
967                 tprintf("NULL");
968                 return;
969         }
970         if (!verbose(tcp)) {
971                 tprintf("%#lx", addr);
972                 return;
973         }
974
975         if (addrlen < 2 || addrlen > sizeof(addrbuf))
976                 addrlen = sizeof(addrbuf);
977
978         memset(&addrbuf, 0, sizeof(addrbuf));
979         if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
980                 tprintf("{...}");
981                 return;
982         }
983         addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
984
985         tprintf("{sa_family=");
986         printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
987         tprintf(", ");
988
989         switch (addrbuf.sa.sa_family) {
990         case AF_UNIX:
991                 if (addrlen == 2) {
992                         tprintf("NULL");
993                 } else if (addrbuf.sau.sun_path[0]) {
994                         tprintf("path=");
995                         printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
996                 } else {
997                         tprintf("path=@");
998                         printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
999                 }
1000                 break;
1001         case AF_INET:
1002                 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
1003                         ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
1004                 break;
1005 #ifdef HAVE_INET_NTOP
1006         case AF_INET6:
1007                 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
1008                 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
1009                                 ntohs(addrbuf.sa6.sin6_port), string_addr,
1010                                 addrbuf.sa6.sin6_flowinfo);
1011 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
1012                 {
1013 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
1014                     int numericscope = 0;
1015                     if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
1016                             || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
1017                         char scopebuf[IFNAMSIZ + 1];
1018
1019                         if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
1020                             numericscope++;
1021                         else
1022                             tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
1023                     } else
1024                         numericscope++;
1025
1026                     if (numericscope)
1027 #endif
1028                         tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
1029                 }
1030 #endif
1031                     break;
1032 #endif
1033 #if defined(AF_IPX) && defined(linux)
1034         case AF_IPX:
1035                 {
1036                         int i;
1037                         tprintf("sipx_port=htons(%u), ",
1038                                         ntohs(addrbuf.sipx.sipx_port));
1039                         /* Yes, I know, this does not look too
1040                          * strace-ish, but otherwise the IPX
1041                          * addresses just look monstrous...
1042                          * Anyways, feel free if you don't like
1043                          * this way.. :)
1044                          */
1045                         tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
1046                         for (i = 0; i<IPX_NODE_LEN; i++)
1047                                 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
1048                         tprintf("/[%02x]", addrbuf.sipx.sipx_type);
1049                 }
1050                 break;
1051 #endif /* AF_IPX && linux */
1052 #ifdef AF_PACKET
1053         case AF_PACKET:
1054                 {
1055                         int i;
1056                         tprintf("proto=%#04x, if%d, pkttype=",
1057                                         ntohs(addrbuf.ll.sll_protocol),
1058                                         addrbuf.ll.sll_ifindex);
1059                         printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
1060                         tprintf(", addr(%d)={%d, ",
1061                                         addrbuf.ll.sll_halen,
1062                                         addrbuf.ll.sll_hatype);
1063                         for (i=0; i<addrbuf.ll.sll_halen; i++)
1064                                 tprintf("%02x", addrbuf.ll.sll_addr[i]);
1065                 }
1066                 break;
1067
1068 #endif /* AF_APACKET */
1069 #ifdef AF_NETLINK
1070         case AF_NETLINK:
1071                 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
1072                 break;
1073 #endif /* AF_NETLINK */
1074         /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
1075         AF_X25 AF_ROSE etc. still need to be done */
1076
1077         default:
1078                 tprintf("sa_data=");
1079                 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
1080                         sizeof addrbuf.sa.sa_data);
1081                 break;
1082         }
1083         tprintf("}");
1084 }
1085
1086 #if HAVE_SENDMSG
1087 static const struct xlat scmvals[] = {
1088 #ifdef SCM_RIGHTS
1089         { SCM_RIGHTS,           "SCM_RIGHTS"            },
1090 #endif
1091 #ifdef SCM_CREDENTIALS
1092         { SCM_CREDENTIALS,      "SCM_CREDENTIALS"       },
1093 #endif
1094         { 0,                    NULL                    }
1095 };
1096
1097 static void
1098 printcmsghdr(tcp, addr, len)
1099 struct tcb *tcp;
1100 unsigned long addr;
1101 unsigned long len;
1102 {
1103         struct cmsghdr *cmsg = len < sizeof(struct cmsghdr) ?
1104                                NULL : malloc(len);
1105         if (cmsg == NULL || umoven(tcp, addr, len, (char *) cmsg) < 0) {
1106                 tprintf(", msg_control=%#lx", addr);
1107                 free(cmsg);
1108                 return;
1109         }
1110
1111         tprintf(", {cmsg_len=%zu, cmsg_level=", cmsg->cmsg_len);
1112         printxval(socketlayers, cmsg->cmsg_level, "SOL_???");
1113         tprintf(", cmsg_type=");
1114
1115         if (cmsg->cmsg_level == SOL_SOCKET) {
1116                 unsigned long cmsg_len;
1117
1118                 printxval(scmvals, cmsg->cmsg_type, "SCM_???");
1119                 cmsg_len = (len < cmsg->cmsg_len) ? len : cmsg->cmsg_len;
1120
1121                 if (cmsg->cmsg_type == SCM_RIGHTS
1122                     && CMSG_LEN(sizeof(int)) <= cmsg_len) {
1123                         int *fds = (int *) CMSG_DATA (cmsg);
1124                         int first = 1;
1125
1126                         tprintf(", {");
1127                         while ((char *) fds < ((char *) cmsg + cmsg_len)) {
1128                                 if (!first)
1129                                         tprintf(", ");
1130                                 tprintf("%d", *fds++);
1131                                 first = 0;
1132                         }
1133                         tprintf("}}");
1134                         free(cmsg);
1135                         return;
1136                 }
1137                 if (cmsg->cmsg_type == SCM_CREDENTIALS
1138                     && CMSG_LEN(sizeof(struct ucred)) <= cmsg_len) {
1139                         struct ucred *uc = (struct ucred *) CMSG_DATA (cmsg);
1140
1141                         tprintf("{pid=%ld, uid=%ld, gid=%ld}}",
1142                                 (long)uc->pid, (long)uc->uid, (long)uc->gid);
1143                         free(cmsg);
1144                         return;
1145                 }
1146         }
1147         free(cmsg);
1148         tprintf(", ...}");
1149 }
1150
1151 static void
1152 printmsghdr(tcp, addr)
1153 struct tcb *tcp;
1154 long addr;
1155 {
1156         struct msghdr msg;
1157
1158         if (umove(tcp, addr, &msg) < 0) {
1159                 tprintf("%#lx", addr);
1160                 return;
1161         }
1162         tprintf("{msg_name(%d)=", msg.msg_namelen);
1163         printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
1164
1165         tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
1166         tprint_iov(tcp, (unsigned long)msg.msg_iovlen,
1167                    (unsigned long)msg.msg_iov);
1168
1169 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
1170         tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
1171         if (msg.msg_controllen)
1172                 printcmsghdr(tcp, (unsigned long) msg.msg_control,
1173                              msg.msg_controllen);
1174         tprintf(", msg_flags=");
1175         printflags(msg_flags, msg.msg_flags, "MSG_???");
1176 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1177         tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
1178                 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
1179 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
1180         tprintf("}");
1181 }
1182
1183 #endif /* HAVE_SENDMSG */
1184
1185 int
1186 sys_socket(tcp)
1187 struct tcb *tcp;
1188 {
1189         if (entering(tcp)) {
1190                 printxval(domains, tcp->u_arg[0], "PF_???");
1191                 tprintf(", ");
1192                 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1193                 tprintf(", ");
1194                 switch (tcp->u_arg[0]) {
1195                 case PF_INET:
1196 #ifdef PF_INET6
1197                 case PF_INET6:
1198 #endif
1199                         printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1200                         break;
1201 #ifdef PF_IPX
1202                 case PF_IPX:
1203                         /* BTW: I don't believe this.. */
1204                         tprintf("[");
1205                         printxval(domains, tcp->u_arg[2], "PF_???");
1206                         tprintf("]");
1207                         break;
1208 #endif /* PF_IPX */
1209                 default:
1210                         tprintf("%lu", tcp->u_arg[2]);
1211                         break;
1212                 }
1213         }
1214         return 0;
1215 }
1216
1217 #ifdef SVR4
1218 int
1219 sys_so_socket(tcp)
1220 struct tcb *tcp;
1221 {
1222         if (entering(tcp)) {
1223                 /* not sure really what these args are... but this
1224                  * is how truss prints it
1225                  */
1226                 tprintf("%ld, %ld, %ld, ",
1227                   tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1228                 printpath(tcp, tcp->u_arg[3]);
1229                 tprintf(", %ld", tcp->u_arg[4]);
1230         }
1231         return 0;
1232 }
1233
1234 int
1235 sys_so_socketpair(tcp)
1236 struct tcb *tcp;
1237 {
1238         if (entering(tcp)) {
1239                 /* not sure what this arg is */
1240                 tprintf("0x%lx", tcp->u_arg[0]);
1241         }
1242         return 0;
1243 }
1244 #endif /* SVR4 */
1245
1246 int
1247 sys_bind(tcp)
1248 struct tcb *tcp;
1249 {
1250         if (entering(tcp)) {
1251                 tprintf("%ld, ", tcp->u_arg[0]);
1252                 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1253                 tprintf(", %lu", tcp->u_arg[2]);
1254         }
1255         return 0;
1256 }
1257
1258 int
1259 sys_connect(tcp)
1260 struct tcb *tcp;
1261 {
1262         return sys_bind(tcp);
1263 }
1264
1265 int
1266 sys_listen(tcp)
1267 struct tcb *tcp;
1268 {
1269         if (entering(tcp)) {
1270                 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1271         }
1272         return 0;
1273 }
1274
1275 int
1276 sys_accept(tcp)
1277 struct tcb *tcp;
1278 {
1279         if (entering(tcp)) {
1280                 tprintf("%ld, ", tcp->u_arg[0]);
1281         } else if (!tcp->u_arg[2])
1282                 tprintf("%#lx, NULL", tcp->u_arg[1]);
1283         else {
1284                 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
1285                         tprintf("%#lx", tcp->u_arg[1]);
1286                 } else {
1287                         printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1288                 }
1289                 tprintf(", ");
1290                 printnum(tcp, tcp->u_arg[2], "%lu");
1291         }
1292         return 0;
1293 }
1294
1295 int
1296 sys_send(tcp)
1297 struct tcb *tcp;
1298 {
1299         if (entering(tcp)) {
1300                 tprintf("%ld, ", tcp->u_arg[0]);
1301                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1302                 tprintf(", %lu, ", tcp->u_arg[2]);
1303                 /* flags */
1304                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1305         }
1306         return 0;
1307 }
1308
1309 int
1310 sys_sendto(tcp)
1311 struct tcb *tcp;
1312 {
1313         if (entering(tcp)) {
1314                 tprintf("%ld, ", tcp->u_arg[0]);
1315                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1316                 tprintf(", %lu, ", tcp->u_arg[2]);
1317                 /* flags */
1318                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1319                 /* to address */
1320                 tprintf(", ");
1321                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1322                 /* to length */
1323                 tprintf(", %lu", tcp->u_arg[5]);
1324         }
1325         return 0;
1326 }
1327
1328 #ifdef HAVE_SENDMSG
1329
1330 int
1331 sys_sendmsg(tcp)
1332 struct tcb *tcp;
1333 {
1334         if (entering(tcp)) {
1335                 tprintf("%ld, ", tcp->u_arg[0]);
1336                 printmsghdr(tcp, tcp->u_arg[1]);
1337                 /* flags */
1338                 tprintf(", ");
1339                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1340         }
1341         return 0;
1342 }
1343
1344 #endif /* HAVE_SENDMSG */
1345
1346 int
1347 sys_recv(tcp)
1348 struct tcb *tcp;
1349 {
1350         if (entering(tcp)) {
1351                 tprintf("%ld, ", tcp->u_arg[0]);
1352         } else {
1353                 if (syserror(tcp))
1354                         tprintf("%#lx", tcp->u_arg[1]);
1355                 else
1356                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1357
1358                 tprintf(", %lu, ", tcp->u_arg[2]);
1359                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1360         }
1361         return 0;
1362 }
1363
1364 int
1365 sys_recvfrom(tcp)
1366 struct tcb *tcp;
1367 {
1368         int fromlen;
1369
1370         if (entering(tcp)) {
1371                 tprintf("%ld, ", tcp->u_arg[0]);
1372         } else {
1373                 if (syserror(tcp)) {
1374                         tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1375                                 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1376                                 tcp->u_arg[4], tcp->u_arg[5]);
1377                         return 0;
1378                 }
1379                 /* buf */
1380                 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1381                 /* len */
1382                 tprintf(", %lu, ", tcp->u_arg[2]);
1383                 /* flags */
1384                 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1385                 /* from address, len */
1386                 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1387                         if (tcp->u_arg[4] == 0)
1388                                 tprintf(", NULL");
1389                         else
1390                                 tprintf(", %#lx", tcp->u_arg[4]);
1391                         if (tcp->u_arg[5] == 0)
1392                                 tprintf(", NULL");
1393                         else
1394                                 tprintf(", %#lx", tcp->u_arg[5]);
1395                         return 0;
1396                 }
1397                 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1398                         tprintf(", {...}, [?]");
1399                         return 0;
1400                 }
1401                 tprintf(", ");
1402                 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1403                 /* from length */
1404                 tprintf(", [%u]", fromlen);
1405         }
1406         return 0;
1407 }
1408
1409 #ifdef HAVE_SENDMSG
1410
1411 int
1412 sys_recvmsg(tcp)
1413 struct tcb *tcp;
1414 {
1415         if (entering(tcp)) {
1416                 tprintf("%ld, ", tcp->u_arg[0]);
1417         } else {
1418                 if (syserror(tcp) || !verbose(tcp))
1419                         tprintf("%#lx", tcp->u_arg[1]);
1420                 else
1421                         printmsghdr(tcp, tcp->u_arg[1]);
1422                 /* flags */
1423                 tprintf(", ");
1424                 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1425         }
1426         return 0;
1427 }
1428
1429 #endif /* HAVE_SENDMSG */
1430
1431 int
1432 sys_shutdown(tcp)
1433 struct tcb *tcp;
1434 {
1435         if (entering(tcp)) {
1436                 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1437                 switch (tcp->u_arg[1]) {
1438                 case 0:
1439                         tprintf("%s", " /* receive */");
1440                         break;
1441                 case 1:
1442                         tprintf("%s", " /* send */");
1443                         break;
1444                 case 2:
1445                         tprintf("%s", " /* send and receive */");
1446                         break;
1447                 }
1448         }
1449         return 0;
1450 }
1451
1452 int
1453 sys_getsockname(tcp)
1454 struct tcb *tcp;
1455 {
1456         return sys_accept(tcp);
1457 }
1458
1459 int
1460 sys_getpeername(tcp)
1461 struct tcb *tcp;
1462 {
1463         return sys_accept(tcp);
1464 }
1465
1466 int
1467 sys_pipe(tcp)
1468 struct tcb *tcp;
1469 {
1470
1471 #if defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1472         int fds[2];
1473
1474         if (exiting(tcp)) {
1475                 if (syserror(tcp)) {
1476                         tprintf("%#lx", tcp->u_arg[0]);
1477                         return 0;
1478                 }
1479                 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1480                         tprintf("[...]");
1481                 else
1482                         tprintf("[%u, %u]", fds[0], fds[1]);
1483         }
1484 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
1485         if (exiting(tcp))
1486                 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1487 #endif
1488         return 0;
1489 }
1490
1491 int
1492 sys_socketpair(tcp)
1493 struct tcb *tcp;
1494 {
1495 #ifdef LINUX
1496         int fds[2];
1497 #endif
1498
1499         if (entering(tcp)) {
1500                 printxval(domains, tcp->u_arg[0], "PF_???");
1501                 tprintf(", ");
1502                 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1503                 tprintf(", ");
1504                 switch (tcp->u_arg[0]) {
1505                 case PF_INET:
1506                         printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1507                         break;
1508 #ifdef PF_IPX
1509                 case PF_IPX:
1510                         /* BTW: I don't believe this.. */
1511                         tprintf("[");
1512                         printxval(domains, tcp->u_arg[2], "PF_???");
1513                         tprintf("]");
1514                         break;
1515 #endif /* PF_IPX */
1516                 default:
1517                         tprintf("%lu", tcp->u_arg[2]);
1518                         break;
1519                 }
1520         } else {
1521                 if (syserror(tcp)) {
1522                         tprintf(", %#lx", tcp->u_arg[3]);
1523                         return 0;
1524                 }
1525 #ifdef LINUX
1526                 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1527                         tprintf(", [...]");
1528                 else
1529                         tprintf(", [%u, %u]", fds[0], fds[1]);
1530 #endif /* LINUX */
1531 #if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
1532                 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
1533 #endif /* SUNOS4 || SVR4 || FREEBSD */
1534         }
1535         return 0;
1536 }
1537
1538 int
1539 sys_getsockopt(tcp)
1540 struct tcb *tcp;
1541 {
1542         if (entering(tcp)) {
1543                 tprintf("%ld, ", tcp->u_arg[0]);
1544                 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1545                 tprintf (", ");
1546                 switch (tcp->u_arg[1]) {
1547                 case SOL_SOCKET:
1548                         printxval(sockoptions, tcp->u_arg[2], "SO_???");
1549                         break;
1550 #ifdef SOL_IP
1551                 case SOL_IP:
1552                         printxval(sockipoptions, tcp->u_arg[2], "IP_???");
1553                         break;
1554 #endif
1555 #ifdef SOL_IPV6
1556                 case SOL_IPV6:
1557                         printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1558                         break;
1559 #endif
1560 #ifdef SOL_IPX
1561                 case SOL_IPX:
1562                         printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
1563                         break;
1564 #endif
1565 #ifdef SOL_PACKET
1566                 case SOL_PACKET:
1567                         printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
1568                         break;
1569 #endif
1570 #ifdef SOL_TCP
1571                 case SOL_TCP:
1572                         printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
1573                         break;
1574 #endif
1575
1576                 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1577                  * etc. still need work */
1578                 default:
1579                         tprintf("%lu", tcp->u_arg[2]);
1580                         break;
1581                 }
1582         } else {
1583                 int len;
1584                 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1585                         tprintf(", %#lx, %#lx",
1586                                 tcp->u_arg[3], tcp->u_arg[4]);
1587                         return 0;
1588                 }
1589
1590                 switch (tcp->u_arg[1]) {
1591                 case SOL_SOCKET:
1592                         switch (tcp->u_arg[2]) {
1593 #ifdef SO_LINGER
1594                         case SO_LINGER:
1595                                 if (len == sizeof (struct linger)) {
1596                                         struct linger linger;
1597                                         if (umove (tcp,
1598                                                    tcp->u_arg[3],
1599                                                    &linger) < 0)
1600                                                 break;
1601                                         tprintf(", {onoff=%d, linger=%d}, "
1602                                                 "[%d]",
1603                                                 linger.l_onoff,
1604                                                 linger.l_linger,
1605                                                 len);
1606                                         return 0;
1607                                 }
1608                                 break;
1609 #endif
1610                         }
1611                         break;
1612                 }
1613
1614                 tprintf (", ");
1615                 if (len == sizeof (int)) {
1616                         printnum(tcp, tcp->u_arg[3], "%ld");
1617                 }
1618                 else {
1619                         printstr (tcp, tcp->u_arg[3], len);
1620                 }
1621                 tprintf(", [%d]", len);
1622         }
1623         return 0;
1624 }
1625
1626 #if defined(ICMP_FILTER)
1627 static void printicmpfilter(tcp, addr)
1628 struct tcb *tcp;
1629 long addr;
1630 {
1631         struct icmp_filter      filter;
1632
1633         if (!addr) {
1634                 tprintf("NULL");
1635                 return;
1636         }
1637         if (syserror(tcp) || !verbose(tcp)) {
1638                 tprintf("%#lx", addr);
1639                 return;
1640         }
1641         if (umove(tcp, addr, &filter) < 0) {
1642                 tprintf("{...}");
1643                 return;
1644         }
1645
1646         tprintf("~(");
1647         printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1648         tprintf(")");
1649 }
1650 #endif /* ICMP_FILTER */
1651
1652 static int
1653 printsockopt (tcp, level, name, addr, len)
1654 struct tcb *tcp;
1655 int level;
1656 int name;
1657 long addr;
1658 int len;
1659 {
1660         printxval(socketlayers, level, "SOL_??");
1661         tprintf (", ");
1662         switch (level) {
1663             case SOL_SOCKET:
1664                 printxval(sockoptions, name, "SO_???");
1665                 switch (name) {
1666 #if defined(SO_LINGER)
1667                     case SO_LINGER:
1668                         if (len == sizeof (struct linger)) {
1669                                 struct linger linger;
1670                                 if (umove (tcp, addr, &linger) < 0)
1671                                         break;
1672                                 tprintf(", {onoff=%d, linger=%d}",
1673                                         linger.l_onoff,
1674                                         linger.l_linger);
1675                                 return 0;
1676                         }
1677                         break;
1678 #endif
1679                 }
1680                 break;
1681 #ifdef SOL_IP
1682             case SOL_IP:
1683                 printxval(sockipoptions, name, "IP_???");
1684                 break;
1685 #endif
1686 #ifdef SOL_IPV6
1687             case SOL_IPV6:
1688                 printxval(sockipv6options, name, "IPV6_???");
1689                 break;
1690 #endif
1691 #ifdef SOL_IPX
1692             case SOL_IPX:
1693                 printxval(sockipxoptions, name, "IPX_???");
1694                 break;
1695 #endif
1696 #ifdef SOL_PACKET
1697             case SOL_PACKET:
1698                 printxval(sockpacketoptions, name, "PACKET_???");
1699                 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1700                 break;
1701 #endif
1702 #ifdef SOL_TCP
1703             case SOL_TCP:
1704                 printxval(socktcpoptions, name, "TCP_???");
1705                 break;
1706 #endif
1707 #ifdef SOL_RAW
1708             case SOL_RAW:
1709                 printxval(sockrawoptions, name, "RAW_???");
1710                 switch (name) {
1711 #if defined(ICMP_FILTER)
1712                     case ICMP_FILTER:
1713                         tprintf(", ");
1714                         printicmpfilter(tcp, addr);
1715                         return 0;
1716 #endif
1717                 }
1718                 break;
1719 #endif
1720
1721                 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1722                  * etc. still need work  */
1723
1724             default:
1725                 tprintf("%u", name);
1726         }
1727
1728         /* default arg printing */
1729
1730         tprintf (", ");
1731
1732         if (len == sizeof (int)) {
1733                 printnum_int (tcp, addr, "%d");
1734         }
1735         else {
1736                 printstr (tcp, addr, len);
1737         }
1738         return 0;
1739 }
1740
1741
1742 #ifdef HAVE_STRUCT_OPTHDR
1743
1744 void
1745 print_sock_optmgmt (tcp, addr, len)
1746 struct tcb *tcp;
1747 long addr;
1748 int len;
1749 {
1750         int c = 0;
1751         struct opthdr hdr;
1752
1753         while (len >= (int) sizeof hdr) {
1754                 if (umove(tcp, addr, &hdr) < 0) break;
1755                 if (c++) {
1756                         tprintf (", ");
1757                 }
1758                 else if (len > hdr.len + sizeof hdr) {
1759                         tprintf ("[");
1760                 }
1761                 tprintf ("{");
1762                 addr += sizeof hdr;
1763                 len -= sizeof hdr;
1764                 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
1765                 if (hdr.len > 0) {
1766                         addr += hdr.len;
1767                         len -= hdr.len;
1768                 }
1769                 tprintf ("}");
1770         }
1771         if (len > 0) {
1772                 if (c++) tprintf (", ");
1773                 printstr (tcp, addr, len);
1774         }
1775         if (c > 1) tprintf ("]");
1776 }
1777
1778 #endif
1779
1780 int
1781 sys_setsockopt(tcp)
1782 struct tcb *tcp;
1783 {
1784         if (entering(tcp)) {
1785                 tprintf("%ld, ", tcp->u_arg[0]);
1786                 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1787                               tcp->u_arg[3], tcp->u_arg[4]);
1788                 tprintf(", %lu", tcp->u_arg[4]);
1789         }
1790         return 0;
1791 }
1792
1793 #if UNIXWARE >= 7
1794
1795 static const struct xlat sock_version[] = {
1796         { __NETLIB_UW211_SVR4,  "UW211_SVR4" },
1797         { __NETLIB_UW211_XPG4,  "UW211_XPG4" },
1798         { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1799         { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1800         { __NETLIB_FP1_SVR4,    "FP1_SVR4" },
1801         { __NETLIB_FP1_XPG4,    "FP1_XPG4" },
1802         { 0,            NULL            },
1803 };
1804
1805
1806 int
1807 netlib_call(tcp, func)
1808 struct tcb *tcp;
1809 int (*func) ();
1810 {
1811         if (entering(tcp)) {
1812                 int i;
1813                 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1814                 tprintf(", ");
1815                 --tcp->u_nargs;
1816                 for (i = 0; i < tcp->u_nargs; i++)
1817                         tcp->u_arg[i] = tcp->u_arg[i + 1];
1818                 return func (tcp);
1819
1820         }
1821
1822         return func (tcp);
1823 }
1824
1825 int
1826 sys_xsocket(tcp)
1827 struct tcb *tcp;
1828 {
1829         return netlib_call (tcp, sys_socket);
1830 }
1831
1832 int
1833 sys_xsocketpair(tcp)
1834 struct tcb *tcp;
1835 {
1836         return netlib_call (tcp, sys_socketpair);
1837 }
1838
1839 int
1840 sys_xbind(tcp)
1841 struct tcb *tcp;
1842 {
1843         return netlib_call (tcp, sys_bind);
1844 }
1845
1846 int
1847 sys_xconnect(tcp)
1848 struct tcb *tcp;
1849 {
1850         return netlib_call (tcp, sys_connect);
1851 }
1852
1853 int
1854 sys_xlisten(tcp)
1855 struct tcb *tcp;
1856 {
1857         return netlib_call (tcp, sys_listen);
1858 }
1859
1860 int
1861 sys_xaccept(tcp)
1862 struct tcb *tcp;
1863 {
1864         return netlib_call (tcp, sys_accept);
1865 }
1866
1867 int
1868 sys_xsendmsg(tcp)
1869 struct tcb *tcp;
1870 {
1871         return netlib_call (tcp, sys_sendmsg);
1872 }
1873
1874 int
1875 sys_xrecvmsg(tcp)
1876 struct tcb *tcp;
1877 {
1878         return netlib_call (tcp, sys_recvmsg);
1879 }
1880
1881 int
1882 sys_xgetsockaddr(tcp)
1883 struct tcb *tcp;
1884 {
1885         if (entering(tcp)) {
1886                 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1887                 tprintf(", ");
1888                 if (tcp->u_arg[1] == 0) {
1889                         tprintf ("LOCALNAME, ");
1890                 }
1891                 else if (tcp->u_arg[1] == 1) {
1892                         tprintf ("REMOTENAME, ");
1893                 }
1894                 else {
1895                         tprintf ("%ld, ", tcp->u_arg [1]);
1896                 }
1897                 tprintf ("%ld, ", tcp->u_arg [2]);
1898         }
1899         else {
1900                 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1901                         tprintf("%#lx", tcp->u_arg[3]);
1902                 } else {
1903                         printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1904                 }
1905                 tprintf(", ");
1906                 printnum(tcp, tcp->u_arg[4], "%lu");
1907         }
1908
1909         return 0;
1910
1911 }
1912
1913 #if 0
1914
1915 int
1916 sys_xsetsockaddr(tcp)
1917 struct tcb *tcp;
1918 {
1919         return netlib_call (tcp, sys_setsockaddr);
1920 }
1921
1922 #endif
1923
1924 int
1925 sys_xgetsockopt(tcp)
1926 struct tcb *tcp;
1927 {
1928         return netlib_call (tcp, sys_getsockopt);
1929 }
1930
1931 int
1932 sys_xsetsockopt(tcp)
1933 struct tcb *tcp;
1934 {
1935         return netlib_call (tcp, sys_setsockopt);
1936 }
1937
1938 int
1939 sys_xshutdown(tcp)
1940 struct tcb *tcp;
1941 {
1942         return netlib_call (tcp, sys_shutdown);
1943 }
1944
1945 #endif