| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> | 
|  | 3 | * All rights reserved. | 
|  | 4 | * | 
|  | 5 | * Redistribution and use in source and binary forms, with or without | 
|  | 6 | * modification, are permitted provided that the following conditions | 
|  | 7 | * are met: | 
|  | 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. | 
|  | 15 | * | 
|  | 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. | 
|  | 26 | * | 
|  | 27 | *	$Id$ | 
|  | 28 | */ | 
|  | 29 |  | 
|  | 30 | #include "defs.h" | 
|  | 31 |  | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include <sys/socket.h> | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 33 | #include <linux/sockios.h> | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 34 | #include <arpa/inet.h> | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 |  | 
| Denys Vlasenko | c36c352 | 2012-02-25 02:47:15 +0100 | [diff] [blame] | 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) | 
|  | 40 | #  include <ioctls.h> | 
|  | 41 | # endif | 
| Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 42 | #endif | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 43 | #include <net/if.h> | 
|  | 44 |  | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 45 | static const struct xlat iffflags[] = { | 
|  | 46 | { IFF_UP,		"IFF_UP"		}, | 
|  | 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"		}, | 
|  | 61 | { 0,			NULL			} | 
|  | 62 | }; | 
|  | 63 |  | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 64 | static void | 
| Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 65 | print_addr(struct tcb *tcp, long addr, struct ifreq *ifr) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 66 | { | 
|  | 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)); | 
|  | 71 | } else | 
|  | 72 | printstr(tcp, addr, sizeof(ifr->ifr_addr.sa_data)); | 
|  | 73 | } | 
|  | 74 |  | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 75 | int | 
| Dmitry V. Levin | 4028424 | 2007-03-21 13:52:14 +0000 | [diff] [blame] | 76 | sock_ioctl(struct tcb *tcp, long code, long arg) | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | { | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 78 | struct ifreq ifr; | 
|  | 79 | struct ifconf ifc; | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 80 | const char *str = NULL; | 
|  | 81 | unsigned char *bytes; | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 82 |  | 
|  | 83 | if (entering(tcp)) { | 
|  | 84 | if (code == SIOCGIFCONF) { | 
| Dmitry V. Levin | 652e448 | 2007-03-21 14:18:17 +0000 | [diff] [blame] | 85 | if (umove(tcp, tcp->u_arg[2], &ifc) >= 0 | 
|  | 86 | && ifc.ifc_buf == NULL) | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 87 | tprintf(", {%d -> ", ifc.ifc_len); | 
|  | 88 | else | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 89 | tprints(", {"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 90 | } | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | return 0; | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 92 | } | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 93 |  | 
|  | 94 | switch (code) { | 
|  | 95 | #ifdef SIOCSHIWAT | 
|  | 96 | case SIOCSHIWAT: | 
|  | 97 | #endif | 
|  | 98 | #ifdef SIOCGHIWAT | 
|  | 99 | case SIOCGHIWAT: | 
|  | 100 | #endif | 
|  | 101 | #ifdef SIOCSLOWAT | 
|  | 102 | case SIOCSLOWAT: | 
|  | 103 | #endif | 
|  | 104 | #ifdef SIOCGLOWAT | 
|  | 105 | case SIOCGLOWAT: | 
|  | 106 | #endif | 
|  | 107 | #ifdef FIOSETOWN | 
|  | 108 | case FIOSETOWN: | 
|  | 109 | #endif | 
|  | 110 | #ifdef FIOGETOWN | 
|  | 111 | case FIOGETOWN: | 
|  | 112 | #endif | 
|  | 113 | #ifdef SIOCSPGRP | 
|  | 114 | case SIOCSPGRP: | 
|  | 115 | #endif | 
|  | 116 | #ifdef SIOCGPGRP | 
|  | 117 | case SIOCGPGRP: | 
|  | 118 | #endif | 
|  | 119 | #ifdef SIOCATMARK | 
|  | 120 | case SIOCATMARK: | 
|  | 121 | #endif | 
|  | 122 | printnum(tcp, arg, ", %#d"); | 
|  | 123 | return 1; | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 124 | case SIOCGIFNAME: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 125 | case SIOCSIFNAME: | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 126 | case SIOCGIFINDEX: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 127 | case SIOCGIFADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 128 | case SIOCSIFADDR: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 129 | case SIOCGIFDSTADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 130 | case SIOCSIFDSTADDR: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 131 | case SIOCGIFBRDADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 132 | case SIOCSIFBRDADDR: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 133 | case SIOCGIFNETMASK: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 134 | case SIOCSIFNETMASK: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 135 | case SIOCGIFFLAGS: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 136 | case SIOCSIFFLAGS: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 137 | case SIOCGIFMETRIC: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 138 | case SIOCSIFMETRIC: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 139 | case SIOCGIFMTU: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 140 | case SIOCSIFMTU: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 141 | case SIOCGIFSLAVE: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 142 | case SIOCSIFSLAVE: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 143 | case SIOCGIFHWADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 144 | case SIOCSIFHWADDR: | 
| Dmitry V. Levin | 4028424 | 2007-03-21 13:52:14 +0000 | [diff] [blame] | 145 | case SIOCGIFTXQLEN: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 146 | case SIOCSIFTXQLEN: | 
| Dmitry V. Levin | ecdd0bb | 2007-03-21 13:57:50 +0000 | [diff] [blame] | 147 | case SIOCGIFMAP: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 148 | case SIOCSIFMAP: | 
| Dmitry V. Levin | 652e448 | 2007-03-21 14:18:17 +0000 | [diff] [blame] | 149 | if (umove(tcp, tcp->u_arg[2], &ifr) < 0) | 
|  | 150 | tprintf(", %#lx", tcp->u_arg[2]); | 
|  | 151 | else if (syserror(tcp)) { | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 152 | if (code == SIOCGIFNAME || code == SIOCSIFNAME) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 153 | tprintf(", {ifr_index=%d, ifr_name=???}", ifr.ifr_ifindex); | 
|  | 154 | else | 
|  | 155 | tprintf(", {ifr_name=\"%s\", ???}", ifr.ifr_name); | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 156 | } else if (code == SIOCGIFNAME || code == SIOCSIFNAME) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 157 | tprintf(", {ifr_index=%d, ifr_name=\"%s\"}", | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 158 | ifr.ifr_ifindex, ifr.ifr_name); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 159 | else { | 
|  | 160 | tprintf(", {ifr_name=\"%s\", ", ifr.ifr_name); | 
|  | 161 | switch (code) { | 
|  | 162 | case SIOCGIFINDEX: | 
|  | 163 | tprintf("ifr_index=%d", ifr.ifr_ifindex); | 
|  | 164 | break; | 
|  | 165 | case SIOCGIFADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 166 | case SIOCSIFADDR: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 167 | str = "ifr_addr"; | 
|  | 168 | case SIOCGIFDSTADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 169 | case SIOCSIFDSTADDR: | 
|  | 170 | if (!str) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 171 | str = "ifr_dstaddr"; | 
|  | 172 | case SIOCGIFBRDADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 173 | case SIOCSIFBRDADDR: | 
|  | 174 | if (!str) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 175 | str = "ifr_broadaddr"; | 
|  | 176 | case SIOCGIFNETMASK: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 177 | case SIOCSIFNETMASK: | 
|  | 178 | if (!str) | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 179 | str = "ifr_netmask"; | 
|  | 180 | tprintf("%s={", str); | 
|  | 181 | printxval(addrfams, | 
|  | 182 | ifr.ifr_addr.sa_family, | 
| Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 183 | "AF_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 184 | tprints(", "); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 185 | print_addr(tcp, ((long) tcp->u_arg[2] | 
| Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 186 | + offsetof(struct ifreq, | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 187 | ifr_addr.sa_data)), | 
|  | 188 | &ifr); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 189 | tprints("}"); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 190 | break; | 
|  | 191 | case SIOCGIFHWADDR: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 192 | case SIOCSIFHWADDR: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 193 | /* XXX Are there other hardware addresses | 
|  | 194 | than 6-byte MACs?  */ | 
|  | 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]); | 
|  | 199 | break; | 
|  | 200 | case SIOCGIFFLAGS: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 201 | case SIOCSIFFLAGS: | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 202 | tprints("ifr_flags="); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 203 | printflags(iffflags, ifr.ifr_flags, "IFF_???"); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 204 | break; | 
|  | 205 | case SIOCGIFMETRIC: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 206 | case SIOCSIFMETRIC: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 207 | tprintf("ifr_metric=%d", ifr.ifr_metric); | 
|  | 208 | break; | 
|  | 209 | case SIOCGIFMTU: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 210 | case SIOCSIFMTU: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 211 | tprintf("ifr_mtu=%d", ifr.ifr_mtu); | 
|  | 212 | break; | 
|  | 213 | case SIOCGIFSLAVE: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 214 | case SIOCSIFSLAVE: | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 215 | tprintf("ifr_slave=\"%s\"", ifr.ifr_slave); | 
|  | 216 | break; | 
| Dmitry V. Levin | 4028424 | 2007-03-21 13:52:14 +0000 | [diff] [blame] | 217 | case SIOCGIFTXQLEN: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 218 | case SIOCSIFTXQLEN: | 
| Dmitry V. Levin | 4028424 | 2007-03-21 13:52:14 +0000 | [diff] [blame] | 219 | tprintf("ifr_qlen=%d", ifr.ifr_qlen); | 
|  | 220 | break; | 
| Dmitry V. Levin | ecdd0bb | 2007-03-21 13:57:50 +0000 | [diff] [blame] | 221 | case SIOCGIFMAP: | 
| Dmitry V. Levin | 5414bf7 | 2008-12-10 13:51:40 +0000 | [diff] [blame] | 222 | case SIOCSIFMAP: | 
| Dmitry V. Levin | ecdd0bb | 2007-03-21 13:57:50 +0000 | [diff] [blame] | 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, | 
|  | 227 | ifr.ifr_map.mem_end, | 
|  | 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); | 
|  | 232 | break; | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 233 | } | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 234 | tprints("}"); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 235 | } | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 236 | return 1; | 
|  | 237 | case SIOCGIFCONF: | 
| Dmitry V. Levin | 652e448 | 2007-03-21 14:18:17 +0000 | [diff] [blame] | 238 | if (umove(tcp, tcp->u_arg[2], &ifc) < 0) { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 239 | tprints("???}"); | 
| Dmitry V. Levin | 652e448 | 2007-03-21 14:18:17 +0000 | [diff] [blame] | 240 | return 1; | 
|  | 241 | } | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 242 | tprintf("%d, ", ifc.ifc_len); | 
| Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 243 | if (syserror(tcp)) { | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 244 | tprintf("%lx", (unsigned long) ifc.ifc_buf); | 
|  | 245 | } else if (ifc.ifc_buf == NULL) { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 246 | tprints("NULL"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 247 | } else { | 
|  | 248 | int i; | 
|  | 249 | unsigned nifra = ifc.ifc_len / sizeof(struct ifreq); | 
|  | 250 | struct ifreq ifra[nifra]; | 
| Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 251 |  | 
|  | 252 | if (umoven(tcp, (unsigned long) ifc.ifc_buf, | 
|  | 253 | sizeof(ifra), (char *) ifra) < 0) { | 
|  | 254 | tprintf("%lx}", (unsigned long) ifc.ifc_buf); | 
|  | 255 | return 1; | 
|  | 256 | } | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 257 | tprints("{"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 258 | for (i = 0; i < nifra; ++i ) { | 
|  | 259 | if (i > 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 260 | tprints(", "); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 261 | tprintf("{\"%s\", {", | 
|  | 262 | ifra[i].ifr_name); | 
|  | 263 | if (verbose(tcp)) { | 
|  | 264 | printxval(addrfams, | 
|  | 265 | ifra[i].ifr_addr.sa_family, | 
|  | 266 | "AF_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 267 | tprints(", "); | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 268 | print_addr(tcp, ((long) tcp->u_arg[2] | 
| Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 269 | + offsetof(struct ifreq, | 
| Roland McGrath | e6a432d | 2005-02-02 20:25:17 +0000 | [diff] [blame] | 270 | ifr_addr.sa_data) | 
|  | 271 | + ((char *) &ifra[i] | 
|  | 272 | - (char *) &ifra[0])), | 
|  | 273 | &ifra[i]); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 274 | } else | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 275 | tprints("..."); | 
|  | 276 | tprints("}}"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 277 | } | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 278 | tprints("}"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 279 | } | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 280 | tprints("}"); | 
| Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 281 | return 1; | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 282 | default: | 
|  | 283 | return 0; | 
|  | 284 | } | 
|  | 285 | } | 
| Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 286 |  | 
|  | 287 | int | 
|  | 288 | sys_socketcall(struct tcb *tcp) | 
|  | 289 | { | 
|  | 290 | return printargs(tcp); | 
|  | 291 | } |