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"
40 print_ifreq_addr(struct tcb *tcp, const struct ifreq *ifr, const long addr)
43 printxval(addrfams, ifr->ifr_addr.sa_family, "AF_???");
45 if (ifr->ifr_addr.sa_family == AF_INET) {
46 const struct sockaddr_in *sinp =
47 (struct sockaddr_in *) &ifr->ifr_addr;
48 tprintf("inet_addr(\"%s\")", inet_ntoa(sinp->sin_addr));
50 printstr(tcp, addr + offsetof(struct ifreq, ifr_addr.sa_data),
51 sizeof(ifr->ifr_addr.sa_data));
56 print_ifname(const char *ifname)
58 print_quoted_string(ifname, IFNAMSIZ + 1, QUOTE_0_TERMINATED);
62 print_ifreq(struct tcb *tcp, const unsigned int code, const long arg,
63 const struct ifreq *ifr)
69 print_ifreq_addr(tcp, ifr, arg);
73 tprints("ifr_dstaddr=");
74 print_ifreq_addr(tcp, ifr, arg);
78 tprints("ifr_broadaddr=");
79 print_ifreq_addr(tcp, ifr, arg);
83 tprints("ifr_netmask=");
84 print_ifreq_addr(tcp, ifr, arg);
88 /* XXX Are there other hardware addresses
90 const unsigned char *bytes =
91 (unsigned char *) &ifr->ifr_hwaddr.sa_data;
92 tprintf("ifr_hwaddr=%02x:%02x:%02x:%02x:%02x:%02x",
93 bytes[0], bytes[1], bytes[2],
94 bytes[3], bytes[4], bytes[5]);
99 tprints("ifr_flags=");
100 printflags(iffflags, (unsigned short) ifr->ifr_flags, "IFF_???");
104 tprintf("ifr_metric=%d", ifr->ifr_metric);
108 tprintf("ifr_mtu=%d", ifr->ifr_mtu);
112 tprints("ifr_slave=");
113 print_ifname(ifr->ifr_slave);
117 tprintf("ifr_qlen=%d", ifr->ifr_qlen);
121 tprintf("ifr_map={mem_start=%#lx, "
122 "mem_end=%#lx, base_addr=%#x, "
123 "irq=%u, dma=%u, port=%u}",
124 ifr->ifr_map.mem_start,
125 ifr->ifr_map.mem_end,
126 (unsigned) ifr->ifr_map.base_addr,
127 (unsigned) ifr->ifr_map.irq,
128 (unsigned) ifr->ifr_map.dma,
129 (unsigned) ifr->ifr_map.port);
135 print_ifc_len(int len)
137 const unsigned int n = (unsigned int) len / sizeof(struct ifreq);
139 if (len < 0 || n * sizeof(struct ifreq) != (unsigned int) len)
142 tprintf("%u * sizeof(struct ifreq)", n);
148 decode_ifconf(struct tcb *tcp, const long addr)
154 if (umove_or_printaddr(tcp, addr, &ifc))
155 return RVAL_DECODED | 1;
158 print_ifc_len(ifc.ifc_len);
163 if (syserror(tcp) || umove(tcp, addr, &ifc) < 0) {
168 return RVAL_DECODED | 1;
173 print_ifc_len(ifc.ifc_len);
175 return RVAL_DECODED | 1;
179 const unsigned int nifra = print_ifc_len(ifc.ifc_len);
182 return RVAL_DECODED | 1;
185 struct ifreq ifra[nifra > max_strlen ? max_strlen : nifra];
187 if (umove_or_printaddr(tcp, (unsigned long) ifc.ifc_buf, &ifra)) {
189 return RVAL_DECODED | 1;
194 for (i = 0; i < ARRAY_SIZE(ifra); ++i) {
197 tprints("{ifr_name=");
198 print_ifname(ifra[i].ifr_name);
201 tprints("ifr_addr=");
202 print_ifreq_addr(tcp, &ifra[i],
203 addr + i * sizeof(ifra[0]));
212 return RVAL_DECODED | 1;
216 sock_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
222 return decode_ifconf(tcp, arg);
228 printstr(tcp, arg, -1);
239 printnum_int(tcp, arg, "%d");
254 printnum_int(tcp, arg, "%d");
279 if (umove_or_printaddr(tcp, arg, &ifr))
282 tprints("{ifr_name=");
283 print_ifname(ifr.ifr_name);
285 if (code == SIOCSIFNAME) {
286 tprints("ifr_newname=");
287 print_ifname(ifr.ifr_newname);
289 print_ifreq(tcp, code, arg, &ifr);
309 if (umove_or_printaddr(tcp, arg, &ifr))
312 if (SIOCGIFNAME == code) {
313 tprintf("{ifr_index=%d", ifr.ifr_ifindex);
315 tprints("{ifr_name=");
316 print_ifname(ifr.ifr_name);
326 if (umove(tcp, arg, &ifr) < 0) {
331 if (SIOCGIFNAME == code) {
332 tprints("ifr_name=");
333 print_ifname(ifr.ifr_name);
335 print_ifreq(tcp, code, arg, &ifr);
345 return RVAL_DECODED | 1;