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.
33 #include <sys/socket.h>
34 #include <linux/sockios.h>
36 #include <sys/socket.h>
37 #include <sys/sockio.h>
39 #include <arpa/inet.h>
41 #if defined (ALPHA) || defined(SH) || defined(SH64)
42 #ifdef HAVE_SYS_IOCTL_H
43 #include <sys/ioctl.h>
44 #elif defined(HAVE_IOCTLS_H)
50 extern const struct xlat addrfams[];
53 sock_ioctl(tcp, code, arg)
61 if (code == SIOCGIFCONF) {
62 umove(tcp, tcp->u_arg[2], &ifc);
63 if (ifc.ifc_buf == NULL)
64 tprintf(", {%d -> ", ifc.ifc_len);
99 printnum(tcp, arg, ", %#d");
104 umove(tcp, tcp->u_arg[2], &ifr);
106 if (code == SIOCGIFNAME)
107 tprintf(", {%d, ???}", ifr.ifr_ifindex);
108 else if (code == SIOCGIFINDEX)
109 tprintf(", {???, \"%s\"}", ifr.ifr_name);
111 tprintf(", {%d, \"%s\"}",
112 ifr.ifr_ifindex, ifr.ifr_name);
115 umove(tcp, tcp->u_arg[2], &ifc);
116 tprintf("%d, ", ifc.ifc_len);
118 tprintf("%lx", (unsigned long) ifc.ifc_buf);
119 } else if (ifc.ifc_buf == NULL) {
123 unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
124 struct ifreq ifra[nifra];
125 umoven(tcp, (unsigned long) ifc.ifc_buf, sizeof(ifra),
128 for (i = 0; i < nifra; ++i ) {
131 tprintf("{\"%s\", {",
135 ifra[i].ifr_addr.sa_family,
138 if (ifra[i].ifr_addr.sa_family == AF_INET) {
139 struct sockaddr_in *sinp;
140 sinp = (struct sockaddr_in *) &ifra[i].ifr_addr;
141 tprintf("inet_addr(\"%s\")",
142 inet_ntoa(sinp->sin_addr));
145 (long) &ifra[i].ifr_addr.sa_data,
146 sizeof(ifra[i].ifr_addr.sa_data));