blob: be7a5b8075b74218b91073b30d1a2a3687c39a7d [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * $Id$
28 */
29
30#include "defs.h"
31
Roland McGrath561c7992003-04-02 01:10:44 +000032#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033#include <sys/socket.h>
Roland McGrath5687ff12004-07-12 07:13:06 +000034#include <linux/sockios.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#else
Roland McGrath8988d1e2004-10-19 23:33:50 +000036#include <sys/socket.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037#include <sys/sockio.h>
38#endif
Roland McGrath5687ff12004-07-12 07:13:06 +000039#include <arpa/inet.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040
Roland McGrathf5a47772003-06-26 22:40:42 +000041#if defined (ALPHA) || defined(SH) || defined(SH64)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000042#ifdef HAVE_SYS_IOCTL_H
43#include <sys/ioctl.h>
44#elif defined(HAVE_IOCTLS_H)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <ioctls.h>
46#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000047#endif
Roland McGrath5687ff12004-07-12 07:13:06 +000048#include <net/if.h>
49
Roland McGrathd9f816f2004-09-04 03:39:20 +000050extern const struct xlat addrfams[];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051
52int
53sock_ioctl(tcp, code, arg)
54struct tcb *tcp;
55long code, arg;
56{
Roland McGrath5687ff12004-07-12 07:13:06 +000057 struct ifreq ifr;
58 struct ifconf ifc;
59
60 if (entering(tcp)) {
61 if (code == SIOCGIFCONF) {
62 umove(tcp, tcp->u_arg[2], &ifc);
63 if (ifc.ifc_buf == NULL)
64 tprintf(", {%d -> ", ifc.ifc_len);
65 else
66 tprintf(", {");
67 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000068 return 0;
Roland McGrath5687ff12004-07-12 07:13:06 +000069 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070
71 switch (code) {
72#ifdef SIOCSHIWAT
73 case SIOCSHIWAT:
74#endif
75#ifdef SIOCGHIWAT
76 case SIOCGHIWAT:
77#endif
78#ifdef SIOCSLOWAT
79 case SIOCSLOWAT:
80#endif
81#ifdef SIOCGLOWAT
82 case SIOCGLOWAT:
83#endif
84#ifdef FIOSETOWN
85 case FIOSETOWN:
86#endif
87#ifdef FIOGETOWN
88 case FIOGETOWN:
89#endif
90#ifdef SIOCSPGRP
91 case SIOCSPGRP:
92#endif
93#ifdef SIOCGPGRP
94 case SIOCGPGRP:
95#endif
96#ifdef SIOCATMARK
97 case SIOCATMARK:
98#endif
99 printnum(tcp, arg, ", %#d");
100 return 1;
Roland McGrath5687ff12004-07-12 07:13:06 +0000101#ifdef LINUX
102 case SIOCGIFNAME:
103 case SIOCGIFINDEX:
104 umove(tcp, tcp->u_arg[2], &ifr);
105 if (syserror(tcp)) {
106 if (code == SIOCGIFNAME)
107 tprintf(", {%d, ???}", ifr.ifr_ifindex);
108 else if (code == SIOCGIFINDEX)
109 tprintf(", {???, \"%s\"}", ifr.ifr_name);
110 } else
111 tprintf(", {%d, \"%s\"}",
112 ifr.ifr_ifindex, ifr.ifr_name);
113 return 1;
114 case SIOCGIFCONF:
115 umove(tcp, tcp->u_arg[2], &ifc);
116 tprintf("%d, ", ifc.ifc_len);
117 if (syserror(tcp)) {
118 tprintf("%lx", (unsigned long) ifc.ifc_buf);
119 } else if (ifc.ifc_buf == NULL) {
120 tprintf("NULL");
121 } else {
122 int i;
123 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
124 struct ifreq ifra[nifra];
125 umoven(tcp, (unsigned long) ifc.ifc_buf, sizeof(ifra),
126 (char *) ifra);
127 tprintf("{");
128 for (i = 0; i < nifra; ++i ) {
129 if (i > 0)
130 tprintf(", ");
131 tprintf("{\"%s\", {",
132 ifra[i].ifr_name);
133 if (verbose(tcp)) {
134 printxval(addrfams,
135 ifra[i].ifr_addr.sa_family,
136 "AF_???");
137 tprintf(", ");
138 if (ifra[i].ifr_addr.sa_family == AF_INET) {
139 struct sockaddr_in *sinp;
140 sinp = (struct sockaddr_in *) &ifra[i].ifr_addr;
141 tprintf("inet_addr(\"%s\")",
142 inet_ntoa(sinp->sin_addr));
143 } else
144 printstr(tcp,
145 (long) &ifra[i].ifr_addr.sa_data,
146 sizeof(ifra[i].ifr_addr.sa_data));
147 } else
148 tprintf("...");
149 tprintf("}}");
150 }
151 tprintf("}");
152 }
153 tprintf("}");
154 return 1;
155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156 default:
157 return 0;
158 }
159}