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 #include "xlat/iffflags.h"
44 print_addr(struct tcb *tcp, long addr, struct ifreq *ifr)
46 if (ifr->ifr_addr.sa_family == AF_INET) {
47 struct sockaddr_in *sinp;
48 sinp = (struct sockaddr_in *) &ifr->ifr_addr;
49 tprintf("inet_addr(\"%s\")", inet_ntoa(sinp->sin_addr));
51 printstr(tcp, addr, sizeof(ifr->ifr_addr.sa_data));
55 sock_ioctl(struct tcb *tcp, long code, long arg)
59 const char *str = NULL;
63 if (code == SIOCGIFCONF) {
64 if (umove(tcp, tcp->u_arg[2], &ifc) >= 0
65 && ifc.ifc_buf == NULL)
66 tprintf(", {%d -> ", ifc.ifc_len);
101 printnum(tcp, arg, ", %#d");
128 if (umove(tcp, tcp->u_arg[2], &ifr) < 0)
129 tprintf(", %#lx", tcp->u_arg[2]);
130 else if (syserror(tcp)) {
131 if (code == SIOCGIFNAME || code == SIOCSIFNAME)
132 tprintf(", {ifr_index=%d, ifr_name=???}", ifr.ifr_ifindex);
134 tprintf(", {ifr_name=\"%s\", ???}", ifr.ifr_name);
135 } else if (code == SIOCGIFNAME || code == SIOCSIFNAME)
136 tprintf(", {ifr_index=%d, ifr_name=\"%s\"}",
137 ifr.ifr_ifindex, ifr.ifr_name);
139 tprintf(", {ifr_name=\"%s\", ", ifr.ifr_name);
142 tprintf("ifr_index=%d", ifr.ifr_ifindex);
154 str = "ifr_broadaddr";
159 tprintf("%s={", str);
161 ifr.ifr_addr.sa_family,
164 print_addr(tcp, ((long) tcp->u_arg[2]
165 + offsetof(struct ifreq,
172 /* XXX Are there other hardware addresses
174 bytes = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
175 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
176 bytes[0], bytes[1], bytes[2],
177 bytes[3], bytes[4], bytes[5]);
181 tprints("ifr_flags=");
182 printflags(iffflags, ifr.ifr_flags, "IFF_???");
186 tprintf("ifr_metric=%d", ifr.ifr_metric);
190 tprintf("ifr_mtu=%d", ifr.ifr_mtu);
194 tprintf("ifr_slave=\"%s\"", ifr.ifr_slave);
198 tprintf("ifr_qlen=%d", ifr.ifr_qlen);
202 tprintf("ifr_map={mem_start=%#lx, "
203 "mem_end=%#lx, base_addr=%#x, "
204 "irq=%u, dma=%u, port=%u}",
205 ifr.ifr_map.mem_start,
207 (unsigned) ifr.ifr_map.base_addr,
208 (unsigned) ifr.ifr_map.irq,
209 (unsigned) ifr.ifr_map.dma,
210 (unsigned) ifr.ifr_map.port);
217 if (umove(tcp, tcp->u_arg[2], &ifc) < 0) {
221 tprintf("%d, ", ifc.ifc_len);
223 tprintf("%lx", (unsigned long) ifc.ifc_buf);
224 } else if (ifc.ifc_buf == NULL) {
228 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
229 struct ifreq ifra[nifra];
231 if (umoven(tcp, (unsigned long) ifc.ifc_buf,
232 sizeof(ifra), (char *) ifra) < 0) {
233 tprintf("%lx}", (unsigned long) ifc.ifc_buf);
237 for (i = 0; i < nifra; ++i ) {
240 tprintf("{\"%s\", {",
244 ifra[i].ifr_addr.sa_family,
247 print_addr(tcp, ((long) tcp->u_arg[2]
248 + offsetof(struct ifreq,
251 - (char *) &ifra[0])),
267 sys_socketcall(struct tcb *tcp)
269 return printargs(tcp);