2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include <sys/socket.h>
30 #include <linux/sockios.h>
31 #include <arpa/inet.h>
32 #if defined(ALPHA) || defined(SH) || defined(SH64)
33 # if defined(HAVE_SYS_IOCTL_H)
34 # include <sys/ioctl.h>
35 # elif defined(HAVE_IOCTLS_H)
41 static const struct xlat iffflags[] = {
43 { IFF_BROADCAST, "IFF_BROADCAST" },
44 { IFF_DEBUG, "IFF_DEBUG" },
45 { IFF_LOOPBACK, "IFF_LOOPBACK" },
46 { IFF_POINTOPOINT, "IFF_POINTOPOINT" },
47 { IFF_NOTRAILERS, "IFF_NOTRAILERS" },
48 { IFF_RUNNING, "IFF_RUNNING" },
49 { IFF_NOARP, "IFF_NOARP" },
50 { IFF_PROMISC, "IFF_PROMISC" },
51 { IFF_ALLMULTI, "IFF_ALLMULTI" },
52 { IFF_MASTER, "IFF_MASTER" },
53 { IFF_SLAVE, "IFF_SLAVE" },
54 { IFF_MULTICAST, "IFF_MULTICAST" },
55 { IFF_PORTSEL, "IFF_PORTSEL" },
56 { IFF_AUTOMEDIA, "IFF_AUTOMEDIA" },
61 print_addr(struct tcb *tcp, long addr, struct ifreq *ifr)
63 if (ifr->ifr_addr.sa_family == AF_INET) {
64 struct sockaddr_in *sinp;
65 sinp = (struct sockaddr_in *) &ifr->ifr_addr;
66 tprintf("inet_addr(\"%s\")", inet_ntoa(sinp->sin_addr));
68 printstr(tcp, addr, sizeof(ifr->ifr_addr.sa_data));
72 sock_ioctl(struct tcb *tcp, long code, long arg)
76 const char *str = NULL;
80 if (code == SIOCGIFCONF) {
81 if (umove(tcp, tcp->u_arg[2], &ifc) >= 0
82 && ifc.ifc_buf == NULL)
83 tprintf(", {%d -> ", ifc.ifc_len);
118 printnum(tcp, arg, ", %#d");
145 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
146 tprintf(", %#lx", tcp->u_arg[2]);
147 else if (syserror(tcp)) {
148 if (code == SIOCGIFNAME || code == SIOCSIFNAME)
149 tprintf(", {ifr_index=%d, ifr_name=???}", ifr.ifr_ifindex);
151 tprintf(", {ifr_name=\"%s\", ???}", ifr.ifr_name);
152 } else if (code == SIOCGIFNAME || code == SIOCSIFNAME)
153 tprintf(", {ifr_index=%d, ifr_name=\"%s\"}",
154 ifr.ifr_ifindex, ifr.ifr_name);
156 tprintf(", {ifr_name=\"%s\", ", ifr.ifr_name);
159 tprintf("ifr_index=%d", ifr.ifr_ifindex);
171 str = "ifr_broadaddr";
176 tprintf("%s={", str);
178 ifr.ifr_addr.sa_family,
181 print_addr(tcp, ((long) tcp->u_arg[2]
182 + offsetof(struct ifreq,
189 /* XXX Are there other hardware addresses
191 bytes = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
192 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
193 bytes[0], bytes[1], bytes[2],
194 bytes[3], bytes[4], bytes[5]);
198 tprints("ifr_flags=");
199 printflags(iffflags, ifr.ifr_flags, "IFF_???");
203 tprintf("ifr_metric=%d", ifr.ifr_metric);
207 tprintf("ifr_mtu=%d", ifr.ifr_mtu);
211 tprintf("ifr_slave=\"%s\"", ifr.ifr_slave);
215 tprintf("ifr_qlen=%d", ifr.ifr_qlen);
219 tprintf("ifr_map={mem_start=%#lx, "
220 "mem_end=%#lx, base_addr=%#x, "
221 "irq=%u, dma=%u, port=%u}",
222 ifr.ifr_map.mem_start,
224 (unsigned) ifr.ifr_map.base_addr,
225 (unsigned) ifr.ifr_map.irq,
226 (unsigned) ifr.ifr_map.dma,
227 (unsigned) ifr.ifr_map.port);
234 if (umove(tcp, tcp->u_arg[2], &ifc) < 0) {
238 tprintf("%d, ", ifc.ifc_len);
240 tprintf("%lx", (unsigned long) ifc.ifc_buf);
241 } else if (ifc.ifc_buf == NULL) {
245 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
246 struct ifreq ifra[nifra];
248 if (umoven(tcp, (unsigned long) ifc.ifc_buf,
249 sizeof(ifra), (char *) ifra) < 0) {
250 tprintf("%lx}", (unsigned long) ifc.ifc_buf);
254 for (i = 0; i < nifra; ++i ) {
257 tprintf("{\"%s\", {",
261 ifra[i].ifr_addr.sa_family,
264 print_addr(tcp, ((long) tcp->u_arg[2]
265 + offsetof(struct ifreq,
268 - (char *) &ifra[0])),
284 sys_socketcall(struct tcb *tcp)
286 return printargs(tcp);