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 #if defined ALPHA || defined SH || defined SH64
31 # include <linux/ioctl.h>
33 #include <linux/sockios.h>
34 #include <arpa/inet.h>
37 #include "xlat/iffflags.h"
39 #define PRINT_IFREQ_ADDR(tcp, ifr, sockaddr) \
41 tprints(#sockaddr "="); \
42 print_sockaddr(tcp, &((ifr)->sockaddr), \
43 sizeof((ifr)->sockaddr)); \
47 print_ifname(const char *ifname)
49 print_quoted_string(ifname, IFNAMSIZ + 1, QUOTE_0_TERMINATED);
53 print_ifreq(struct tcb *tcp, const unsigned int code, const long arg,
54 const struct ifreq *ifr)
59 PRINT_IFREQ_ADDR(tcp, ifr, ifr_addr);
63 PRINT_IFREQ_ADDR(tcp, ifr, ifr_dstaddr);
67 PRINT_IFREQ_ADDR(tcp, ifr, ifr_broadaddr);
71 PRINT_IFREQ_ADDR(tcp, ifr, ifr_netmask);
75 /* XXX Are there other hardware addresses
77 const unsigned char *bytes =
78 (unsigned char *) &ifr->ifr_hwaddr.sa_data;
79 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
80 bytes[0], bytes[1], bytes[2],
81 bytes[3], bytes[4], bytes[5]);
86 tprints("ifr_flags=");
87 printflags(iffflags, (unsigned short) ifr->ifr_flags, "IFF_???");
91 tprintf("ifr_metric=%d", ifr->ifr_metric);
95 tprintf("ifr_mtu=%d", ifr->ifr_mtu);
99 tprints("ifr_slave=");
100 print_ifname(ifr->ifr_slave);
104 tprintf("ifr_qlen=%d", ifr->ifr_qlen);
108 tprintf("ifr_map={mem_start=%#lx, "
109 "mem_end=%#lx, base_addr=%#x, "
110 "irq=%u, dma=%u, port=%u}",
111 ifr->ifr_map.mem_start,
112 ifr->ifr_map.mem_end,
113 (unsigned) ifr->ifr_map.base_addr,
114 (unsigned) ifr->ifr_map.irq,
115 (unsigned) ifr->ifr_map.dma,
116 (unsigned) ifr->ifr_map.port);
122 print_ifc_len(int len)
124 const unsigned int n = (unsigned int) len / sizeof(struct ifreq);
126 if (len < 0 || n * sizeof(struct ifreq) != (unsigned int) len)
129 tprintf("%u * sizeof(struct ifreq)", n);
135 decode_ifconf(struct tcb *tcp, const long addr)
141 if (umove_or_printaddr(tcp, addr, &ifc))
142 return RVAL_DECODED | 1;
145 print_ifc_len(ifc.ifc_len);
150 if (syserror(tcp) || umove(tcp, addr, &ifc) < 0) {
155 return RVAL_DECODED | 1;
160 print_ifc_len(ifc.ifc_len);
162 return RVAL_DECODED | 1;
166 const unsigned int nifra = print_ifc_len(ifc.ifc_len);
169 return RVAL_DECODED | 1;
172 struct ifreq ifra[nifra > max_strlen ? max_strlen : nifra];
174 if (umove_or_printaddr(tcp, (unsigned long) ifc.ifc_buf, &ifra)) {
176 return RVAL_DECODED | 1;
181 for (i = 0; i < ARRAY_SIZE(ifra); ++i) {
184 tprints("{ifr_name=");
185 print_ifname(ifra[i].ifr_name);
187 PRINT_IFREQ_ADDR(tcp, &ifra[i], ifr_addr);
194 return RVAL_DECODED | 1;
198 sock_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
204 return decode_ifconf(tcp, arg);
210 printstr(tcp, arg, -1);
221 printnum_int(tcp, arg, "%d");
236 printnum_int(tcp, arg, "%d");
261 if (umove_or_printaddr(tcp, arg, &ifr))
264 tprints("{ifr_name=");
265 print_ifname(ifr.ifr_name);
267 if (code == SIOCSIFNAME) {
268 tprints("ifr_newname=");
269 print_ifname(ifr.ifr_newname);
271 print_ifreq(tcp, code, arg, &ifr);
291 if (umove_or_printaddr(tcp, arg, &ifr))
294 if (SIOCGIFNAME == code) {
295 tprintf("{ifr_index=%d", ifr.ifr_ifindex);
297 tprints("{ifr_name=");
298 print_ifname(ifr.ifr_name);
308 if (umove(tcp, arg, &ifr) < 0) {
313 if (SIOCGIFNAME == code) {
314 tprints("ifr_name=");
315 print_ifname(ifr.ifr_name);
317 print_ifreq(tcp, code, arg, &ifr);
327 return RVAL_DECODED | 1;