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.
32 #include <sys/socket.h>
33 #include <linux/sockios.h>
34 #include <arpa/inet.h>
36 #if defined(ALPHA) || defined(SH) || defined(SH64)
37 # ifdef HAVE_SYS_IOCTL_H
38 # include <sys/ioctl.h>
39 # elif defined(HAVE_IOCTLS_H)
45 static const struct xlat iffflags[] = {
47 { IFF_BROADCAST, "IFF_BROADCAST" },
48 { IFF_DEBUG, "IFF_DEBUG" },
49 { IFF_LOOPBACK, "IFF_LOOPBACK" },
50 { IFF_POINTOPOINT, "IFF_POINTOPOINT" },
51 { IFF_NOTRAILERS, "IFF_NOTRAILERS" },
52 { IFF_RUNNING, "IFF_RUNNING" },
53 { IFF_NOARP, "IFF_NOARP" },
54 { IFF_PROMISC, "IFF_PROMISC" },
55 { IFF_ALLMULTI, "IFF_ALLMULTI" },
56 { IFF_MASTER, "IFF_MASTER" },
57 { IFF_SLAVE, "IFF_SLAVE" },
58 { IFF_MULTICAST, "IFF_MULTICAST" },
59 { IFF_PORTSEL, "IFF_PORTSEL" },
60 { IFF_AUTOMEDIA, "IFF_AUTOMEDIA" },
65 print_addr(struct tcb *tcp, long addr, struct ifreq *ifr)
67 if (ifr->ifr_addr.sa_family == AF_INET) {
68 struct sockaddr_in *sinp;
69 sinp = (struct sockaddr_in *) &ifr->ifr_addr;
70 tprintf("inet_addr(\"%s\")", inet_ntoa(sinp->sin_addr));
72 printstr(tcp, addr, sizeof(ifr->ifr_addr.sa_data));
76 sock_ioctl(struct tcb *tcp, long code, long arg)
80 const char *str = NULL;
84 if (code == SIOCGIFCONF) {
85 if (umove(tcp, tcp->u_arg[2], &ifc) >= 0
86 && ifc.ifc_buf == NULL)
87 tprintf(", {%d -> ", ifc.ifc_len);
122 printnum(tcp, arg, ", %#d");
149 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
150 tprintf(", %#lx", tcp->u_arg[2]);
151 else if (syserror(tcp)) {
152 if (code == SIOCGIFNAME || code == SIOCSIFNAME)
153 tprintf(", {ifr_index=%d, ifr_name=???}", ifr.ifr_ifindex);
155 tprintf(", {ifr_name=\"%s\", ???}", ifr.ifr_name);
156 } else if (code == SIOCGIFNAME || code == SIOCSIFNAME)
157 tprintf(", {ifr_index=%d, ifr_name=\"%s\"}",
158 ifr.ifr_ifindex, ifr.ifr_name);
160 tprintf(", {ifr_name=\"%s\", ", ifr.ifr_name);
163 tprintf("ifr_index=%d", ifr.ifr_ifindex);
175 str = "ifr_broadaddr";
180 tprintf("%s={", str);
182 ifr.ifr_addr.sa_family,
185 print_addr(tcp, ((long) tcp->u_arg[2]
186 + offsetof(struct ifreq,
193 /* XXX Are there other hardware addresses
195 bytes = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
196 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
197 bytes[0], bytes[1], bytes[2],
198 bytes[3], bytes[4], bytes[5]);
202 tprints("ifr_flags=");
203 printflags(iffflags, ifr.ifr_flags, "IFF_???");
207 tprintf("ifr_metric=%d", ifr.ifr_metric);
211 tprintf("ifr_mtu=%d", ifr.ifr_mtu);
215 tprintf("ifr_slave=\"%s\"", ifr.ifr_slave);
219 tprintf("ifr_qlen=%d", ifr.ifr_qlen);
223 tprintf("ifr_map={mem_start=%#lx, "
224 "mem_end=%#lx, base_addr=%#x, "
225 "irq=%u, dma=%u, port=%u}",
226 ifr.ifr_map.mem_start,
228 (unsigned) ifr.ifr_map.base_addr,
229 (unsigned) ifr.ifr_map.irq,
230 (unsigned) ifr.ifr_map.dma,
231 (unsigned) ifr.ifr_map.port);
238 if (umove(tcp, tcp->u_arg[2], &ifc) < 0) {
242 tprintf("%d, ", ifc.ifc_len);
244 tprintf("%lx", (unsigned long) ifc.ifc_buf);
245 } else if (ifc.ifc_buf == NULL) {
249 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
250 struct ifreq ifra[nifra];
252 if (umoven(tcp, (unsigned long) ifc.ifc_buf,
253 sizeof(ifra), (char *) ifra) < 0) {
254 tprintf("%lx}", (unsigned long) ifc.ifc_buf);
258 for (i = 0; i < nifra; ++i ) {
261 tprintf("{\"%s\", {",
265 ifra[i].ifr_addr.sa_family,
268 print_addr(tcp, ((long) tcp->u_arg[2]
269 + offsetof(struct ifreq,
272 - (char *) &ifra[0])),
288 sys_socketcall(struct tcb *tcp)
290 return printargs(tcp);