blob: 6efa8710a4676fb2287e3a363fe7d05e31c00d03 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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>
Wichert Akkermanf1850652001-02-16 20:29:03 +000038
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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000046#ifdef HAVE_NETINET_TCP_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000047#include <netinet/tcp.h>
48#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000049#ifdef HAVE_NETINET_UDP_H
50#include <netinet/udp.h>
51#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000053#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054#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
Wichert Akkermanf1850652001-02-16 20:29:03 +000063#if defined (__GLIBC__) && (((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)) || defined(HAVE_SIN6_SCOPE_ID_LINUX))
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000064#if defined(HAVE_LINUX_IN6_H)
Wichert Akkermanf1850652001-02-16 20:29:03 +000065#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
Wichert Akkerman505e1761999-11-01 19:39:08 +000073#include <linux/in6.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000074#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
Wichert Akkerman505e1761999-11-01 19:39:08 +000082#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000083#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000084
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#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
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000097#if defined(HAVE_LINUX_ICMP_H)
98#include <linux/icmp.h>
99#endif
100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101#ifndef PF_UNSPEC
102#define PF_UNSPEC AF_UNSPEC
103#endif
104
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000105#if UNIXWARE >= 7
106#define HAVE_SENDMSG 1 /* HACK - *FIXME* */
107#endif
108
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109#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
119static struct xlat domains[] = {
120 { PF_UNSPEC, "PF_UNSPEC" },
121 { PF_UNIX, "PF_UNIX" },
122 { PF_INET, "PF_INET" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000123#ifdef PF_NETLINK
124 { PF_NETLINK, "PF_NETLINK" },
125#endif
126#ifdef PF_PACKET
127 { PF_PACKET, "PF_PACKET" },
128#endif
129#ifdef PF_INET6
130 { PF_INET6, "PF_INET6" },
131#endif
132#ifdef PF_ATMSVC
133 { PF_ATMSVC, "PF_INET6" },
134#endif
135#ifdef PF_INET6
136 { PF_INET6, "PF_INET6" },
137#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138#ifdef PF_LOCAL
139 { PF_LOCAL, "PS_LOCAL" },
140#endif
141#ifdef PF_ISO
142 { PF_ISO, "PF_ISO" },
143#endif
144#ifdef PF_AX25
145 { PF_AX25, "PF_AX25" },
146#endif
147#ifdef PF_IPX
148 { PF_IPX, "PF_IPX" },
149#endif
150#ifdef PF_APPLETALK
151 { PF_APPLETALK, "PF_APPLETALK" },
152#endif
153#ifdef PF_NETROM
154 { PF_NETROM, "PF_NETROM" },
155#endif
156#ifdef PF_BRIDGE
157 { PF_BRIDGE, "PF_BRIDGE" },
158#endif
159#ifdef PF_AAL5
160 { PF_AAL5, "PF_AAL5" },
161#endif
162#ifdef PF_X25
163 { PF_X25, "PF_X25" },
164#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165#ifdef PF_ROSE
166 { PF_ROSE, "PF_ROSE" },
167#endif
168#ifdef PF_DECNET
169 { PF_DECNET, "PF_DECNET" },
170#endif
171#ifdef PF_NETBEUI
172 { PF_NETBEUI, "PF_NETBEUI" },
173#endif
174#ifdef PF_IMPLINK
175 { PF_IMPLINK, "PF_IMPLINK" },
176#endif
177 { 0, NULL },
178};
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000179static struct xlat addrfams[] = {
180 { AF_UNSPEC, "AF_UNSPEC" },
181 { AF_UNIX, "AF_UNIX" },
182 { AF_INET, "AF_INET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000183#ifdef AF_INET6
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000184 { AF_INET6, "AF_INET6" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000185#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000186 { AF_DECnet, "AF_DECnet" },
187#ifdef PF_ATMSVC
188 { AF_ATMSVC, "AF_ATMSVC" },
189#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000190#ifdef AF_PACKET
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000191 { AF_PACKET, "AF_PACKET" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000192#endif
193#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000194 { AF_NETLINK, "AF_NETLINK" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000195#endif
196#ifdef AF_ISO
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000197 { AF_ISO, "AF_ISO" },
198#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000199#ifdef AF_IMPLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000200 { AF_IMPLINK, "AF_IMPLINK" },
201#endif
202 { 0, NULL },
203};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204static struct xlat socktypes[] = {
205 { SOCK_STREAM, "SOCK_STREAM" },
206 { SOCK_DGRAM, "SOCK_DGRAM" },
207#ifdef SOCK_RAW
208 { SOCK_RAW, "SOCK_RAW" },
209#endif
210#ifdef SOCK_SEQPACKET
211 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
212#endif
213#ifdef SOCK_RDM
214 { SOCK_RDM, "SOCK_RDM" },
215#endif
216#ifdef SOCK_PACKET
217 { SOCK_PACKET, "SOCK_PACKET" },
218#endif
219 { 0, NULL },
220};
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000221static struct xlat socketlayers[] = {
John Hughes1e4cb342001-03-06 09:25:46 +0000222#if defined(SOL_IP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000223 { SOL_IP, "SOL_IP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000224#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000225#if defined(SOL_ICMP)
226 { SOL_ICMP, "SOL_ICMP" },
227#endif
John Hughes1e4cb342001-03-06 09:25:46 +0000228#if defined(SOL_TCP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000229 { SOL_TCP, "SOL_TCP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000230#endif
231#if defined(SOL_UDP)
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000232 { SOL_UDP, "SOL_UDP" },
John Hughes1e4cb342001-03-06 09:25:46 +0000233#endif
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000234#if defined(SOL_IPV6)
235 { SOL_IPV6, "SOL_IPV6" },
236#endif
237#if defined(SOL_ICMPV6)
238 { SOL_ICMPV6, "SOL_ICMPV6" },
239#endif
240#if defined(SOL_RAW)
241 { SOL_RAW, "SOL_RAW" },
242#endif
243#if defined(SOL_IPX)
244 { SOL_IPX, "SOL_IPX" },
245#endif
246#if defined(SOL_IPX)
247 { SOL_IPX, "SOL_IPX" },
248#endif
249#if defined(SOL_AX25)
250 { SOL_AX25, "SOL_AX25" },
251#endif
252#if defined(SOL_ATALK)
253 { SOL_ATALK, "SOL_ATALK" },
254#endif
255#if defined(SOL_NETROM)
256 { SOL_NETROM, "SOL_NETROM" },
257#endif
258#if defined(SOL_ROSE)
259 { SOL_ROSE, "SOL_ROSE" },
260#endif
261#if defined(SOL_DECNET)
262 { SOL_DECNET, "SOL_DECNET" },
263#endif
264#if defined(SOL_X25)
265 { SOL_X25, "SOL_X25" },
266#endif
267#if defined(SOL_PACKET)
268 { SOL_PACKET, "SOL_PACKET" },
269#endif
270#if defined(SOL_ATM)
271 { SOL_ATM, "SOL_ATM" },
272#endif
273#if defined(SOL_AAL)
274 { SOL_AAL, "SOL_AAL" },
275#endif
276#if defined(SOL_IRDA)
277 { SOL_IRDA, "SOL_IRDA" },
278#endif
John Hughes61563572001-03-27 16:47:36 +0000279 { SOL_SOCKET, "SOL_SOCKET" }, /* Never used! */
Wichert Akkermanefdecac2000-11-26 03:59:21 +0000280};
John Hughes93f7fcc2002-05-22 15:46:49 +0000281/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
282 falls into "protocols" array below!!!! This is intended!!! ***/
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283static struct xlat protocols[] = {
284 { IPPROTO_IP, "IPPROTO_IP" },
285 { IPPROTO_ICMP, "IPPROTO_ICMP" },
286 { IPPROTO_TCP, "IPPROTO_TCP" },
287 { IPPROTO_UDP, "IPPROTO_UDP" },
288#ifdef IPPROTO_GGP
289 { IPPROTO_GGP, "IPPROTO_GGP" },
290#endif
291#ifdef IPPROTO_EGP
292 { IPPROTO_EGP, "IPPROTO_EGP" },
293#endif
294#ifdef IPPROTO_PUP
295 { IPPROTO_PUP, "IPPROTO_PUP" },
296#endif
297#ifdef IPPROTO_IDP
298 { IPPROTO_IDP, "IPPROTO_IDP" },
299#endif
300#ifdef IPPROTO_IPV6
301 { IPPROTO_IPV6, "IPPROTO_IPV6" },
302#endif
303#ifdef IPPROTO_ICMPV6
304 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
305#endif
306#ifdef IPPROTO_IGMP
307 { IPPROTO_IGMP, "IPPROTO_IGMP" },
308#endif
309#ifdef IPPROTO_HELLO
310 { IPPROTO_HELLO,"IPPROTO_HELLO" },
311#endif
312#ifdef IPPROTO_ND
313 { IPPROTO_ND, "IPPROTO_ND" },
314#endif
315#ifdef IPPROTO_RAW
316 { IPPROTO_RAW, "IPPROTO_RAW" },
317#endif
318#ifdef IPPROTO_MAX
319 { IPPROTO_MAX, "IPPROTO_MAX" },
320#endif
321#ifdef IPPROTO_IPIP
322 { IPPROTO_IPIP, "IPPROTO_IPIP" },
323#endif
324 { 0, NULL },
325};
326static struct xlat msg_flags[] = {
327 { MSG_OOB, "MSG_OOB" },
328#ifdef MSG_DONTROUTE
329 { MSG_DONTROUTE,"MSG_DONTROUTE" },
330#endif
331#ifdef MSG_PEEK
332 { MSG_PEEK, "MSG_PEEK" },
333#endif
334#ifdef MSG_CTRUNC
335 { MSG_CTRUNC, "MSG_CTRUNC" },
336#endif
337#ifdef MSG_PROXY
338 { MSG_PROXY, "MSG_PROXY" },
339#endif
340#ifdef MSG_EOR
341 { MSG_EOR, "MSG_EOR" },
342#endif
343#ifdef MSG_WAITALL
344 { MSG_WAITALL, "MSG_WAITALL" },
345#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000346#ifdef MSG_TRUNC
347 { MSG_TRUNC, "MSG_TRUNC" },
348#endif
349#ifdef MSG_CTRUNC
350 { MSG_CTRUNC, "MSG_CTRUNC" },
351#endif
352#ifdef MSG_ERRQUEUE
353 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
354#endif
355#ifdef MSG_DONTWAIT
356 { MSG_DONTWAIT, "MSG_DONTWAIT" },
357#endif
358#ifdef MSG_CONFIRM
359 { MSG_CONFIRM, "MSG_CONFIRM" },
360#endif
361#ifdef MSG_PROBE
362 { MSG_PROBE, "MSG_PROBE" },
363#endif
Roland McGrath05e5e792004-04-14 02:53:54 +0000364#ifdef MSG_FIN
365 { MSG_FIN, "MSG_FIN" },
366#endif
367#ifdef MSG_SYN
368 { MSG_SYN, "MSG_SYN" },
369#endif
370#ifdef MSG_RST
371 { MSG_RST, "MSG_RST" },
372#endif
373#ifdef MSG_NOSIGNAL
374 { MSG_NOSIGNAL, "MSG_NOSIGNAL" },
375#endif
376#ifdef MSG_MORE
377 { MSG_MORE, "MSG_MORE" },
378#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 { 0, NULL },
380};
381
382static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000383#ifdef SO_PEERCRED
384 { SO_PEERCRED, "SO_PEERCRED" },
385#endif
386#ifdef SO_PASSCRED
387 { SO_PASSCRED, "SO_PASSCRED" },
388#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389#ifdef SO_DEBUG
390 { SO_DEBUG, "SO_DEBUG" },
391#endif
392#ifdef SO_REUSEADDR
393 { SO_REUSEADDR, "SO_REUSEADDR" },
394#endif
395#ifdef SO_KEEPALIVE
396 { SO_KEEPALIVE, "SO_KEEPALIVE" },
397#endif
398#ifdef SO_DONTROUTE
399 { SO_DONTROUTE, "SO_DONTROUTE" },
400#endif
401#ifdef SO_BROADCAST
402 { SO_BROADCAST, "SO_BROADCAST" },
403#endif
404#ifdef SO_LINGER
405 { SO_LINGER, "SO_LINGER" },
406#endif
407#ifdef SO_OOBINLINE
408 { SO_OOBINLINE, "SO_OOBINLINE" },
409#endif
410#ifdef SO_TYPE
411 { SO_TYPE, "SO_TYPE" },
412#endif
413#ifdef SO_ERROR
414 { SO_ERROR, "SO_ERROR" },
415#endif
416#ifdef SO_SNDBUF
417 { SO_SNDBUF, "SO_SNDBUF" },
418#endif
419#ifdef SO_RCVBUF
420 { SO_RCVBUF, "SO_RCVBUF" },
421#endif
422#ifdef SO_NO_CHECK
423 { SO_NO_CHECK, "SO_NO_CHECK" },
424#endif
425#ifdef SO_PRIORITY
426 { SO_PRIORITY, "SO_PRIORITY" },
427#endif
428#ifdef SO_ACCEPTCONN
429 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
430#endif
431#ifdef SO_USELOOPBACK
432 { SO_USELOOPBACK,"SO_USELOOPBACK"},
433#endif
434#ifdef SO_SNDLOWAT
435 { SO_SNDLOWAT, "SO_SNDLOWAT" },
436#endif
437#ifdef SO_RCVLOWAT
438 { SO_RCVLOWAT, "SO_RCVLOWAT" },
439#endif
440#ifdef SO_SNDTIMEO
441 { SO_SNDTIMEO, "SO_SNDTIMEO" },
442#endif
443#ifdef SO_RCVTIMEO
444 { SO_RCVTIMEO, "SO_RCVTIMEO" },
445#endif
446#ifdef SO_BSDCOMPAT
447 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
448#endif
449#ifdef SO_REUSEPORT
450 { SO_REUSEPORT, "SO_REUSEPORT" },
451#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000452#ifdef SO_ORDREL
453 { SO_ORDREL, "SO_ORDREL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000455#ifdef SO_IMASOCKET
456 { SO_IMASOCKET, "SO_IMASOCKET" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000458#ifdef SO_MGMT
459 { SO_MGMT, "SO_MGMT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000461#ifdef SO_LISTENING
462 { SO_LISTENING, "SO_LISTENING" },
463#endif
464#ifdef SO_RDWR
465 { SO_RDWR, "SO_RDWR" },
466#endif
467#ifdef SO_SEMA
468 { SO_SEMA, "SO_SEMA" },
469#endif
470#ifdef SO_PARALLELSVR
471 { SO_PARALLELSVR,"SO_PARALLELSVR"},
472#endif
473#ifdef SO_PROTOTYPE
474 { SO_PROTOTYPE, "SO_PROTOTYPE" },
475#endif
476#ifdef SO_ALLRAW
477 { SO_ALLRAW, "SO_ALLRAW" },
478#endif
479#ifdef SO_ICS
480 { SO_ICS, "SO_ICS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481#endif
482 { 0, NULL },
483};
484
John Hughes93f7fcc2002-05-22 15:46:49 +0000485#if !defined (SOL_IP) && defined (IPPROTO_IP)
486#define SOL_IP IPPROTO_IP
487#endif
488
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489#ifdef SOL_IP
490static struct xlat sockipoptions[] = {
John Hughes93f7fcc2002-05-22 15:46:49 +0000491#ifdef IP_TOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000492 { IP_TOS, "IP_TOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000493#endif
494#ifdef IP_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000495 { IP_TTL, "IP_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000496#endif
497#ifdef IP_HDRINCL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000498 { IP_HDRINCL, "IP_HDRINCL" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000500#ifdef IP_OPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000501 { IP_OPTIONS, "IP_OPTIONS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000503#ifdef IP_ROUTER_ALERT
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000504 { IP_ROUTER_ALERT, "IP_ROUTER_ALERT" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000505#endif
506#ifdef IP_RECVOPTIONS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000507 { IP_RECVOPTIONS, "IP_RECVOPTIONS" },
508#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000509#ifdef IP_RECVOPTS
510 { IP_RECVOPTS, "IP_RECVOPTS" },
511#endif
512#ifdef IP_RECVRETOPTS
513 { IP_RECVRETOPTS, "IP_RECVRETOPTS" },
514#endif
515#ifdef IP_RECVDSTADDR
516 { IP_RECVDSTADDR, "IP_RECVDSTADDR" },
517#endif
518#ifdef IP_RETOPTS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000519 { IP_RETOPTS, "IP_RETOPTS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000520#endif
521#ifdef IP_PKTINFO
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000522 { IP_PKTINFO, "IP_PKTINFO" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000523#endif
524#ifdef IP_PKTOPTIONS
525 { IP_PKTOPTIONS, "IP_PKTOPTIONS" },
526#endif
527#ifdef IP_MTU_DISCOVER
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000528 { IP_MTU_DISCOVER, "IP_MTU_DISCOVER" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000529#endif
530#ifdef IP_RECVERR
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000531 { IP_RECVERR, "IP_RECVERR" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000532#endif
533#ifdef IP_RECVTTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000534 { IP_RECVTTL, "IP_RECRECVTTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000535#endif
536#ifdef IP_RECVTOS
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000537 { IP_RECVTOS, "IP_RECRECVTOS" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000538#endif
539#ifdef IP_MTU
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000540 { IP_MTU, "IP_MTU" },
541#endif
John Hughes93f7fcc2002-05-22 15:46:49 +0000542#ifdef IP_MULTICAST_IF
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000543 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000544#endif
545#ifdef IP_MULTICAST_TTL
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000546 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000547#endif
548#ifdef IP_MULTICAST_LOOP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000549 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000550#endif
551#ifdef IP_ADD_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000552 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000553#endif
554#ifdef IP_DROP_MEMBERSHIP
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000555 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
John Hughes93f7fcc2002-05-22 15:46:49 +0000556#endif
557#ifdef IP_BROADCAST_IF
558 { IP_BROADCAST_IF, "IP_BROADCAST_IF" },
559#endif
560#ifdef IP_RECVIFINDEX
561 { IP_RECVIFINDEX, "IP_RECVIFINDEX" },
562#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000563 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564};
565#endif /* SOL_IP */
566
567#ifdef SOL_IPX
568static struct xlat sockipxoptions[] = {
569 { IPX_TYPE, "IPX_TYPE" },
570 { 0, NULL },
571};
572#endif /* SOL_IPX */
573
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000574#ifdef SOL_RAW
575static struct xlat sockrawoptions[] = {
576#if defined(ICMP_FILTER)
577 { ICMP_FILTER, "ICMP_FILTER" },
578#endif
579 { 0, NULL },
580};
581#endif /* SOL_RAW */
582
583#ifdef SOL_PACKET
584static struct xlat sockpacketoptions[] = {
585 { PACKET_ADD_MEMBERSHIP, "PACKET_ADD_MEMBERSHIP" },
586 { PACKET_DROP_MEMBERSHIP, "PACKET_DROP_MEMBERSHIP"},
587#if defined(PACKET_RECV_OUTPUT)
588 { PACKET_RECV_OUTPUT, "PACKET_RECV_OUTPUT" },
589#endif
590#if defined(PACKET_RX_RING)
591 { PACKET_RX_RING, "PACKET_RX_RING" },
592#endif
593#if defined(PACKET_STATISTICS)
594 { PACKET_STATISTICS, "PACKET_STATISTICS" },
595#endif
596 { 0, NULL },
597};
598#endif /* SOL_PACKET */
599
John Hughes93f7fcc2002-05-22 15:46:49 +0000600#if !defined (SOL_TCP) && defined (IPPROTO_TCP)
601#define SOL_TCP IPPROTO_TCP
602#endif
603
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604#ifdef SOL_TCP
605static struct xlat socktcpoptions[] = {
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000606 { TCP_NODELAY, "TCP_NODELAY" },
607 { TCP_MAXSEG, "TCP_MAXSEG" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000608#if defined(TCP_CORK)
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000609 { TCP_CORK, "TCP_CORK" },
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000610#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000611#if defined(TCP_KEEPIDLE)
612 { TCP_KEEPIDLE, "TCP_KEEPIDLE" },
613#endif
614#if defined(TCP_KEEPINTVL)
615 { TCP_KEEPINTVL, "TCP_KEEPINTVL" },
616#endif
617#if defined(TCP_KEEPCNT)
618 { TCP_KEEPCNT, "TCP_KEEPCNT" },
619#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000620#if defined(TCP_NKEEP)
621 { TCP_NKEEP, "TCP_NKEEP" },
622#endif
Wichert Akkerman8b8ff7c2001-12-27 22:27:30 +0000623#if defined(TCP_SYNCNT)
624 { TCP_SYNCNT, "TCP_SYNCNT" },
625#endif
626#if defined(TCP_LINGER2)
627 { TCP_LINGER2, "TCP_LINGER2" },
628#endif
629#if defined(TCP_DEFER_ACCEPT)
630 { TCP_DEFER_ACCEPT, "TCP_DEFER_ACCEPT" },
631#endif
632#if defined(TCP_WINDOW_CLAMP)
633 { TCP_WINDOW_CLAMP, "TCP_WINDOW_CLAMP" },
634#endif
635#if defined(TCP_INFO)
636 { TCP_INFO, "TCP_INFO" },
637#endif
638#if defined(TCP_QUICKACK)
639 { TCP_QUICKACK, "TCP_QUICKACK" },
640#endif
641 { 0, NULL },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642};
643#endif /* SOL_TCP */
644
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000645#ifdef SOL_RAW
646static struct xlat icmpfilterflags[] = {
647#if defined(ICMP_ECHOREPLY)
648 { (1<<ICMP_ECHOREPLY), "ICMP_ECHOREPLY" },
649#endif
650#if defined(ICMP_DEST_UNREACH)
651 { (1<<ICMP_DEST_UNREACH), "ICMP_DEST_UNREACH" },
652#endif
653#if defined(ICMP_SOURCE_QUENCH)
654 { (1<<ICMP_SOURCE_QUENCH), "ICMP_SOURCE_QUENCH" },
655#endif
656#if defined(ICMP_REDIRECT)
657 { (1<<ICMP_REDIRECT), "ICMP_REDIRECT" },
658#endif
659#if defined(ICMP_ECHO)
660 { (1<<ICMP_ECHO), "ICMP_ECHO" },
661#endif
662#if defined(ICMP_TIME_EXCEEDED)
663 { (1<<ICMP_TIME_EXCEEDED), "ICMP_TIME_EXCEEDED" },
664#endif
665#if defined(ICMP_PARAMETERPROB)
666 { (1<<ICMP_PARAMETERPROB), "ICMP_PARAMETERPROB" },
667#endif
668#if defined(ICMP_TIMESTAMP)
669 { (1<<ICMP_TIMESTAMP), "ICMP_TIMESTAMP" },
670#endif
671#if defined(ICMP_TIMESTAMPREPLY)
672 { (1<<ICMP_TIMESTAMPREPLY), "ICMP_TIMESTAMPREPLY" },
673#endif
674#if defined(ICMP_INFO_REQUEST)
675 { (1<<ICMP_INFO_REQUEST), "ICMP_INFO_REQUEST" },
676#endif
677#if defined(ICMP_INFO_REPLY)
678 { (1<<ICMP_INFO_REPLY), "ICMP_INFO_REPLY" },
679#endif
680#if defined(ICMP_ADDRESS)
681 { (1<<ICMP_ADDRESS), "ICMP_ADDRESS" },
682#endif
683#if defined(ICMP_ADDRESSREPLY)
684 { (1<<ICMP_ADDRESSREPLY), "ICMP_ADDRESSREPLY" },
685#endif
686 { 0, NULL },
687};
688#endif /* SOL_RAW */
689
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000690#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
691static struct xlat af_packet_types[] = {
692#if defined(PACKET_HOST)
693 { PACKET_HOST, "PACKET_HOST" },
694#endif
695#if defined(PACKET_BROADCAST)
696 { PACKET_BROADCAST, "PACKET_BROADCAST" },
697#endif
698#if defined(PACKET_MULTICAST)
699 { PACKET_MULTICAST, "PACKET_MULTICAST" },
700#endif
701#if defined(PACKET_OTHERHOST)
702 { PACKET_OTHERHOST, "PACKET_OTHERHOST" },
703#endif
704#if defined(PACKET_OUTGOING)
705 { PACKET_OUTGOING, "PACKET_OUTGOING" },
706#endif
707#if defined(PACKET_LOOPBACK)
708 { PACKET_LOOPBACK, "PACKET_LOOPBACK" },
709#endif
710#if defined(PACKET_FASTROUTE)
711 { PACKET_FASTROUTE, "PACKET_FASTROUTE" },
712#endif
713 { 0, NULL },
714};
715#endif /* defined(AF_PACKET) */
716
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000717
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000719printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720struct tcb *tcp;
721long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000722int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000724 union {
725 char pad[128];
726 struct sockaddr sa;
727 struct sockaddr_in sin;
728 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000729#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000730 struct sockaddr_in6 sa6;
731#endif
732#if defined(LINUX) && defined(AF_IPX)
733 struct sockaddr_ipx sipx;
734#endif
735#ifdef AF_PACKET
736 struct sockaddr_ll ll;
737#endif
738#ifdef AF_NETLINK
739 struct sockaddr_nl nl;
740#endif
741 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000742 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743
744 if (addr == 0) {
745 tprintf("NULL");
746 return;
747 }
748 if (!verbose(tcp)) {
749 tprintf("%#lx", addr);
750 return;
751 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000752 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
753 addrlen=sizeof(addrbuf);
754
755 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 tprintf("{...}");
757 return;
758 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000759
John Hughes1fcb1d62001-09-18 15:56:53 +0000760 tprintf("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000761 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
762 tprintf(", ");
763
764 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000766 if (addrlen==2) {
767 tprintf("<nil>");
768 } else if (addrbuf.sau.sun_path[0]) {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000769 tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000770 } else {
Wichert Akkermanfa306182001-02-21 16:42:26 +0000771 tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000772 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000773 break;
774 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000775 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000776 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000778#ifdef HAVE_INET_NTOP
779 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000780 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000781 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
782 ntohs(addrbuf.sa6.sin6_port), string_addr,
783 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000784#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000785 {
786#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
787 int numericscope = 0;
788 if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)
789 || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {
790 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000791
Wichert Akkermanf1850652001-02-16 20:29:03 +0000792 if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
793 numericscope++;
794 else
795 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
796 } else
797 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000798
Wichert Akkermanf1850652001-02-16 20:29:03 +0000799 if (numericscope)
800#endif
801 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
802 }
803#endif
804 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000805#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000806#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000808 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000810 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000811 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812 /* Yes, I know, this does not look too
813 * strace-ish, but otherwise the IPX
814 * addresses just look monstrous...
815 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000816 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000818 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000820 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
821 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822 }
823 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000824#endif /* AF_IPX && linux */
825#ifdef AF_PACKET
826 case AF_PACKET:
827 {
828 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000829 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000830 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000831 addrbuf.ll.sll_ifindex);
832 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
833 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000834 addrbuf.ll.sll_halen,
835 addrbuf.ll.sll_hatype);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000836 for (i=0; i<addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000837 tprintf("%02x", addrbuf.ll.sll_addr[i]);
838 }
839 break;
840
841#endif /* AF_APACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000842#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000843 case AF_NETLINK:
844 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
845 break;
846#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000848 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849
850 default:
John Hughes1fcb1d62001-09-18 15:56:53 +0000851 tprintf("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000853 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854 break;
855 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000856 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857}
858
859#if HAVE_SENDMSG
860
861static void
862printmsghdr(tcp, addr)
863struct tcb *tcp;
864long addr;
865{
866 struct msghdr msg;
867
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000868 if (umove(tcp, addr, &msg) < 0) {
869 tprintf("%#lx", addr);
870 return;
871 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000872 tprintf("{msg_name(%d)=", msg.msg_namelen);
873 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
874
875 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
John Hughes1d08dcf2001-07-10 13:48:44 +0000876 tprint_iov(tcp, msg.msg_iovlen, (long) msg.msg_iov);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000877
Roland McGrath6d2b3492002-12-30 00:51:30 +0000878#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000879 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000880 if (msg.msg_controllen)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000881 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
882 tprintf(", msg_flags=");
883 if (printflags(msg_flags, msg.msg_flags)==0)
884 tprintf("0");
Roland McGrath6d2b3492002-12-30 00:51:30 +0000885#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000886 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000888#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000889 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890}
891
892#endif /* HAVE_SENDMSG */
893
894int
895sys_socket(tcp)
896struct tcb *tcp;
897{
898 if (entering(tcp)) {
899 printxval(domains, tcp->u_arg[0], "PF_???");
900 tprintf(", ");
901 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
902 tprintf(", ");
903 switch (tcp->u_arg[0]) {
904 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000905#ifdef PF_INET6
906 case PF_INET6:
907#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000908 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
909 break;
910#ifdef PF_IPX
911 case PF_IPX:
912 /* BTW: I don't believe this.. */
913 tprintf("[");
914 printxval(domains, tcp->u_arg[2], "PF_???");
915 tprintf("]");
916 break;
917#endif /* PF_IPX */
918 default:
919 tprintf("%lu", tcp->u_arg[2]);
920 break;
921 }
922 }
923 return 0;
924}
925
926int
John Hughesbdf48f52001-03-06 15:08:09 +0000927sys_so_socket(tcp)
928struct tcb *tcp;
929{
930 if (entering(tcp)) {
931 /* not sure really what these args are... but this
932 * is how truss prints it
933 */
934 tprintf("%ld, %ld, %ld, ",
935 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
936 printpath(tcp, tcp->u_arg[3]);
937 tprintf(", %ld", tcp->u_arg[4]);
938 }
939 return 0;
940}
941
942int
943sys_so_socketpair(tcp)
944struct tcb *tcp;
945{
946 if (entering(tcp)) {
947 /* not sure what this arg is */
948 tprintf("0x%lx", tcp->u_arg[0]);
949 }
950 return 0;
951}
952
953int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954sys_bind(tcp)
955struct tcb *tcp;
956{
957 if (entering(tcp)) {
958 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000959 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960 tprintf(", %lu", tcp->u_arg[2]);
961 }
962 return 0;
963}
964
965int
966sys_connect(tcp)
967struct tcb *tcp;
968{
969 return sys_bind(tcp);
970}
971
972int
973sys_listen(tcp)
974struct tcb *tcp;
975{
976 if (entering(tcp)) {
977 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
978 }
979 return 0;
980}
981
982int
983sys_accept(tcp)
984struct tcb *tcp;
985{
986 if (entering(tcp)) {
987 tprintf("%ld, ", tcp->u_arg[0]);
988 } else if (!tcp->u_arg[2])
989 tprintf("%#lx, NULL", tcp->u_arg[1]);
990 else {
991 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
992 tprintf("%#lx", tcp->u_arg[1]);
993 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000994 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 }
996 tprintf(", ");
997 printnum(tcp, tcp->u_arg[2], "%lu");
998 }
999 return 0;
1000}
1001
1002int
1003sys_send(tcp)
1004struct tcb *tcp;
1005{
1006 if (entering(tcp)) {
1007 tprintf("%ld, ", tcp->u_arg[0]);
1008 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1009 tprintf(", %lu, ", tcp->u_arg[2]);
1010 /* flags */
1011 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1012 tprintf("0");
1013 }
1014 return 0;
1015}
1016
1017int
1018sys_sendto(tcp)
1019struct tcb *tcp;
1020{
1021 if (entering(tcp)) {
1022 tprintf("%ld, ", tcp->u_arg[0]);
1023 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1024 tprintf(", %lu, ", tcp->u_arg[2]);
1025 /* flags */
1026 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1027 tprintf("0");
1028 /* to address */
1029 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001030 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 /* to length */
1032 tprintf(", %lu", tcp->u_arg[5]);
1033 }
1034 return 0;
1035}
1036
1037#ifdef HAVE_SENDMSG
1038
1039int
1040sys_sendmsg(tcp)
1041struct tcb *tcp;
1042{
1043 if (entering(tcp)) {
1044 tprintf("%ld, ", tcp->u_arg[0]);
1045 printmsghdr(tcp, tcp->u_arg[1]);
1046 /* flags */
1047 tprintf(", ");
1048 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1049 tprintf("0");
1050 }
1051 return 0;
1052}
1053
1054#endif /* HAVE_SENDMSG */
1055
1056int
1057sys_recv(tcp)
1058struct tcb *tcp;
1059{
1060 if (entering(tcp)) {
1061 tprintf("%ld, ", tcp->u_arg[0]);
1062 } else {
1063 if (syserror(tcp))
1064 tprintf("%#lx", tcp->u_arg[1]);
1065 else
1066 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1067
1068 tprintf(", %lu, ", tcp->u_arg[2]);
1069 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1070 tprintf("0");
1071 }
1072 return 0;
1073}
1074
1075int
1076sys_recvfrom(tcp)
1077struct tcb *tcp;
1078{
1079 int fromlen;
1080
1081 if (entering(tcp)) {
1082 tprintf("%ld, ", tcp->u_arg[0]);
1083 } else {
1084 if (syserror(tcp)) {
1085 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
1086 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
1087 tcp->u_arg[4], tcp->u_arg[5]);
1088 return 0;
1089 }
1090 /* buf */
1091 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
1092 /* len */
1093 tprintf(", %lu, ", tcp->u_arg[2]);
1094 /* flags */
1095 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
1096 tprintf("0");
1097 /* from address, len */
1098 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
1099 if (tcp->u_arg[4] == 0)
1100 tprintf(", NULL");
1101 else
1102 tprintf(", %#lx", tcp->u_arg[4]);
1103 if (tcp->u_arg[5] == 0)
1104 tprintf(", NULL");
1105 else
1106 tprintf(", %#lx", tcp->u_arg[5]);
1107 return 0;
1108 }
1109 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
1110 tprintf(", {...}, [?]");
1111 return 0;
1112 }
1113 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001114 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115 /* from length */
1116 tprintf(", [%u]", fromlen);
1117 }
1118 return 0;
1119}
1120
1121#ifdef HAVE_SENDMSG
1122
1123int
1124sys_recvmsg(tcp)
1125struct tcb *tcp;
1126{
1127 if (entering(tcp)) {
1128 tprintf("%ld, ", tcp->u_arg[0]);
1129 } else {
1130 if (syserror(tcp) || !verbose(tcp))
1131 tprintf("%#lx", tcp->u_arg[1]);
1132 else
1133 printmsghdr(tcp, tcp->u_arg[1]);
1134 /* flags */
1135 tprintf(", ");
1136 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
1137 tprintf("0");
1138 }
1139 return 0;
1140}
1141
1142#endif /* HAVE_SENDMSG */
1143
1144int
1145sys_shutdown(tcp)
1146struct tcb *tcp;
1147{
1148 if (entering(tcp)) {
1149 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
1150 switch (tcp->u_arg[1]) {
1151 case 0:
1152 tprintf("%s", " /* receive */");
1153 break;
1154 case 1:
1155 tprintf("%s", " /* send */");
1156 break;
1157 case 2:
1158 tprintf("%s", " /* send and receive */");
1159 break;
1160 }
1161 }
1162 return 0;
1163}
1164
1165int
1166sys_getsockname(tcp)
1167struct tcb *tcp;
1168{
1169 return sys_accept(tcp);
1170}
1171
1172int
1173sys_getpeername(tcp)
1174struct tcb *tcp;
1175{
1176 return sys_accept(tcp);
1177}
1178
1179int
1180sys_pipe(tcp)
1181struct tcb *tcp;
1182{
1183
Roland McGrathb4ce1762004-03-01 20:30:48 +00001184#if defined(LINUX) && !defined(SPARC) && !defined(SH) && !defined(IA64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001185 int fds[2];
1186
1187 if (exiting(tcp)) {
1188 if (syserror(tcp)) {
1189 tprintf("%#lx", tcp->u_arg[0]);
1190 return 0;
1191 }
1192 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1193 tprintf("[...]");
1194 else
1195 tprintf("[%u, %u]", fds[0], fds[1]);
1196 }
Roland McGrathb4ce1762004-03-01 20:30:48 +00001197#elif defined(SPARC) || defined(SH) || defined(SVR4) || defined(FREEBSD) || defined(IA64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 if (exiting(tcp))
1199 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001200#endif
1201 return 0;
1202}
1203
1204int
1205sys_socketpair(tcp)
1206struct tcb *tcp;
1207{
1208#ifdef LINUX
1209 int fds[2];
1210#endif
1211
1212 if (entering(tcp)) {
1213 printxval(domains, tcp->u_arg[0], "PF_???");
1214 tprintf(", ");
1215 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
1216 tprintf(", ");
1217 switch (tcp->u_arg[0]) {
1218 case PF_INET:
1219 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
1220 break;
1221#ifdef PF_IPX
1222 case PF_IPX:
1223 /* BTW: I don't believe this.. */
1224 tprintf("[");
1225 printxval(domains, tcp->u_arg[2], "PF_???");
1226 tprintf("]");
1227 break;
1228#endif /* PF_IPX */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001229 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001230 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231 break;
1232 }
1233 } else {
1234 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001235 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236 return 0;
1237 }
1238#ifdef LINUX
1239 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001240 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241 else
1242 tprintf(", [%u, %u]", fds[0], fds[1]);
1243#endif /* LINUX */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001244#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +00001246#endif /* SUNOS4 || SVR4 || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247 }
1248 return 0;
1249}
1250
1251int
1252sys_getsockopt(tcp)
1253struct tcb *tcp;
1254{
1255 if (entering(tcp)) {
1256 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001257 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
1258 tprintf (", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259 switch (tcp->u_arg[1]) {
1260 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001262 break;
1263#ifdef SOL_IP
1264 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266 break;
1267#endif
1268#ifdef SOL_IPX
1269 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271 break;
1272#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001273#ifdef SOL_PACKET
1274 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001275 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001276 break;
1277#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278#ifdef SOL_TCP
1279 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281 break;
1282#endif
1283
1284 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1285 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001286 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001287 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 break;
1289 }
1290 } else {
John Hughes93f7fcc2002-05-22 15:46:49 +00001291 long len;
1292 if (syserror(tcp) || umove (tcp, tcp->u_arg[4], &len) < 0) {
1293 tprintf(", %#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 tcp->u_arg[3], tcp->u_arg[4]);
1295 return 0;
1296 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001297
1298 switch (tcp->u_arg[1]) {
1299 case SOL_SOCKET:
1300 switch (tcp->u_arg[2]) {
1301#ifdef SO_LINGER
1302 case SO_LINGER:
1303 if (len == sizeof (struct linger)) {
1304 struct linger linger;
1305 if (umove (tcp,
1306 tcp->u_arg[3],
1307 &linger) < 0)
1308 break;
1309 tprintf(", {onoff=%d, linger=%d}, "
1310 "[%ld]",
1311 linger.l_onoff,
1312 linger.l_linger,
1313 len);
1314 return 0;
1315 }
1316 break;
1317#endif
1318 }
1319 break;
1320 }
1321
1322 tprintf (", ");
1323 if (len == sizeof (int)) {
1324 printnum(tcp, tcp->u_arg[3], "%ld");
1325 }
1326 else {
1327 printstr (tcp, tcp->u_arg[3], len);
1328 }
1329 tprintf(", [%ld]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330 }
1331 return 0;
1332}
1333
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001334#if defined(ICMP_FILTER)
1335static void printicmpfilter(tcp, addr)
1336struct tcb *tcp;
1337long addr;
1338{
1339 struct icmp_filter filter;
1340
1341 if (!addr) {
1342 tprintf("NULL");
1343 return;
1344 }
1345 if (syserror(tcp) || !verbose(tcp)) {
1346 tprintf("%#lx", addr);
1347 return;
1348 }
1349 if (umove(tcp, addr, &filter) < 0) {
1350 tprintf("{...}");
1351 return;
1352 }
1353
1354 tprintf("~(");
1355 if (printflags(icmpfilterflags, ~filter.data) == 0)
1356 tprintf("0");
1357 tprintf(")");
1358}
1359#endif /* ICMP_FILTER */
1360
John Hughes38ae88d2002-05-23 11:48:58 +00001361static int
1362printsockopt (tcp, level, name, addr, len)
1363struct tcb *tcp;
1364int level;
1365int name;
1366long addr;
1367int len;
1368{
1369 printxval(socketlayers, level, "SOL_??");
1370 tprintf (", ");
1371 switch (level) {
1372 case SOL_SOCKET:
1373 printxval(sockoptions, name, "SO_???");
1374 switch (name) {
1375#if defined(SO_LINGER)
1376 case SO_LINGER:
1377 if (len == sizeof (struct linger)) {
1378 struct linger linger;
1379 if (umove (tcp, addr, &linger) < 0)
1380 break;
1381 tprintf(", {onoff=%d, linger=%d}",
1382 linger.l_onoff,
1383 linger.l_linger);
1384 return 0;
1385 }
1386 break;
1387#endif
1388 }
1389 break;
1390#ifdef SOL_IP
1391 case SOL_IP:
1392 printxval(sockipoptions, name, "IP_???");
1393 break;
1394#endif
1395#ifdef SOL_IPX
1396 case SOL_IPX:
1397 printxval(sockipxoptions, name, "IPX_???");
1398 break;
1399#endif
1400#ifdef SOL_PACKET
1401 case SOL_PACKET:
1402 printxval(sockpacketoptions, name, "PACKET_???");
1403 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
1404 break;
1405#endif
1406#ifdef SOL_TCP
1407 case SOL_TCP:
1408 printxval(socktcpoptions, name, "TCP_???");
1409 break;
1410#endif
1411#ifdef SOL_RAW
1412 case SOL_RAW:
1413 printxval(sockrawoptions, name, "RAW_???");
1414 switch (name) {
1415#if defined(ICMP_FILTER)
1416 case ICMP_FILTER:
1417 tprintf(", ");
1418 printicmpfilter(tcp, addr);
1419 return 0;
1420#endif
1421 }
1422 break;
1423#endif
1424
Roland McGrath6d2b3492002-12-30 00:51:30 +00001425 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001426 * etc. still need work */
1427
1428 default:
1429 tprintf("%u", name);
1430 }
1431
1432 /* default arg printing */
1433
1434 tprintf (", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001435
John Hughes38ae88d2002-05-23 11:48:58 +00001436 if (len == sizeof (int)) {
1437 printnum(tcp, addr, "%ld");
1438 }
1439 else {
1440 printstr (tcp, addr, len);
1441 }
1442 return 0;
1443}
1444
1445
Roland McGrathc3ca0d82003-01-14 07:53:38 +00001446#ifdef HAVE_STRUCT_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +00001447
1448void
1449print_sock_optmgmt (tcp, addr, len)
1450struct tcb *tcp;
1451long addr;
1452int len;
1453{
1454 int c = 0;
1455 struct opthdr hdr;
1456
John Hughes2c4e3a82002-05-24 10:19:44 +00001457 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +00001458 if (umove(tcp, addr, &hdr) < 0) break;
1459 if (c++) {
1460 tprintf (", ");
1461 }
1462 else if (len > hdr.len + sizeof hdr) {
1463 tprintf ("[");
1464 }
1465 tprintf ("{");
1466 addr += sizeof hdr;
1467 len -= sizeof hdr;
1468 printsockopt (tcp, hdr.level, hdr.name, addr, hdr.len);
John Hughes2c4e3a82002-05-24 10:19:44 +00001469 if (hdr.len > 0) {
1470 addr += hdr.len;
1471 len -= hdr.len;
1472 }
John Hughes38ae88d2002-05-23 11:48:58 +00001473 tprintf ("}");
1474 }
1475 if (len > 0) {
1476 if (c++) tprintf (", ");
1477 printstr (tcp, addr, len);
1478 }
1479 if (c > 1) tprintf ("]");
1480}
1481
1482#endif
1483
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484int
1485sys_setsockopt(tcp)
1486struct tcb *tcp;
1487{
1488 if (entering(tcp)) {
1489 tprintf("%ld, ", tcp->u_arg[0]);
John Hughes38ae88d2002-05-23 11:48:58 +00001490 printsockopt (tcp, tcp->u_arg[1], tcp->u_arg[2],
1491 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001492 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493 }
1494 return 0;
1495}
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001496
1497#if UNIXWARE >= 7
1498
1499static struct xlat sock_version[] = {
1500 { __NETLIB_UW211_SVR4, "UW211_SVR4" },
1501 { __NETLIB_UW211_XPG4, "UW211_XPG4" },
1502 { __NETLIB_GEMINI_SVR4, "GEMINI_SVR4" },
1503 { __NETLIB_GEMINI_XPG4, "GEMINI_XPG4" },
1504 { __NETLIB_FP1_SVR4, "FP1_SVR4" },
1505 { __NETLIB_FP1_XPG4, "FP1_XPG4" },
1506 { 0, NULL },
1507};
1508
1509
1510int
1511netlib_call(tcp, func)
1512struct tcb *tcp;
1513int (*func) ();
1514{
1515 if (entering(tcp)) {
1516 int i;
1517 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1518 tprintf(", ");
1519 --tcp->u_nargs;
1520 for (i = 0; i < tcp->u_nargs; i++)
1521 tcp->u_arg[i] = tcp->u_arg[i + 1];
1522 return func (tcp);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001523
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001524 }
1525
1526 return func (tcp);
1527}
1528
1529int
1530sys_xsocket(tcp)
1531struct tcb *tcp;
1532{
1533 return netlib_call (tcp, sys_socket);
1534}
1535
1536int
1537sys_xsocketpair(tcp)
1538struct tcb *tcp;
1539{
1540 return netlib_call (tcp, sys_socketpair);
1541}
1542
1543int
1544sys_xbind(tcp)
1545struct tcb *tcp;
1546{
1547 return netlib_call (tcp, sys_bind);
1548}
1549
1550int
1551sys_xconnect(tcp)
1552struct tcb *tcp;
1553{
1554 return netlib_call (tcp, sys_connect);
1555}
1556
1557int
1558sys_xlisten(tcp)
1559struct tcb *tcp;
1560{
1561 return netlib_call (tcp, sys_listen);
1562}
1563
1564int
1565sys_xaccept(tcp)
1566struct tcb *tcp;
1567{
1568 return netlib_call (tcp, sys_accept);
1569}
1570
1571int
1572sys_xsendmsg(tcp)
1573struct tcb *tcp;
1574{
1575 return netlib_call (tcp, sys_sendmsg);
1576}
1577
1578int
1579sys_xrecvmsg(tcp)
1580struct tcb *tcp;
1581{
1582 return netlib_call (tcp, sys_recvmsg);
1583}
1584
1585int
1586sys_xgetsockaddr(tcp)
1587struct tcb *tcp;
1588{
1589 if (entering(tcp)) {
1590 printxval (sock_version, tcp->u_arg[0], "__NETLIB_???");
1591 tprintf(", ");
1592 if (tcp->u_arg[1] == 0) {
1593 tprintf ("LOCALNAME, ");
1594 }
1595 else if (tcp->u_arg[1] == 1) {
1596 tprintf ("REMOTENAME, ");
1597 }
1598 else {
1599 tprintf ("%ld, ", tcp->u_arg [1]);
1600 }
1601 tprintf ("%ld, ", tcp->u_arg [2]);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001602 }
Wichert Akkerman16a03d22000-08-10 02:14:04 +00001603 else {
1604 if (tcp->u_arg[3] == 0 || syserror(tcp)) {
1605 tprintf("%#lx", tcp->u_arg[3]);
1606 } else {
1607 printsock(tcp, tcp->u_arg[3], tcp->u_arg[4]);
1608 }
1609 tprintf(", ");
1610 printnum(tcp, tcp->u_arg[4], "%lu");
1611 }
1612
1613 return 0;
1614
1615}
1616
1617#if 0
1618
1619int
1620sys_xsetsockaddr(tcp)
1621struct tcb *tcp;
1622{
1623 return netlib_call (tcp, sys_setsockaddr);
1624}
1625
1626#endif
1627
1628int
1629sys_xgetsockopt(tcp)
1630struct tcb *tcp;
1631{
1632 return netlib_call (tcp, sys_getsockopt);
1633}
1634
1635int
1636sys_xsetsockopt(tcp)
1637struct tcb *tcp;
1638{
1639 return netlib_call (tcp, sys_setsockopt);
1640}
1641
1642int
1643sys_xshutdown(tcp)
1644struct tcb *tcp;
1645{
1646 return netlib_call (tcp, sys_shutdown);
1647}
1648
1649#endif