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 | |
Roland McGrath | 561c799 | 2003-04-02 01:10:44 +0000 | [diff] [blame] | 32 | #ifdef LINUX |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 33 | #include <sys/socket.h> |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 34 | #include <linux/sockios.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #else |
Roland McGrath | 8988d1e | 2004-10-19 23:33:50 +0000 | [diff] [blame] | 36 | #include <sys/socket.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | #include <sys/sockio.h> |
| 38 | #endif |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 39 | #include <arpa/inet.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 40 | |
Roland McGrath | f5a4777 | 2003-06-26 22:40:42 +0000 | [diff] [blame] | 41 | #if defined (ALPHA) || defined(SH) || defined(SH64) |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 42 | #ifdef HAVE_SYS_IOCTL_H |
| 43 | #include <sys/ioctl.h> |
| 44 | #elif defined(HAVE_IOCTLS_H) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 45 | #include <ioctls.h> |
| 46 | #endif |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 47 | #endif |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 48 | #include <net/if.h> |
| 49 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 50 | extern const struct xlat addrfams[]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 51 | |
| 52 | int |
| 53 | sock_ioctl(tcp, code, arg) |
| 54 | struct tcb *tcp; |
| 55 | long code, arg; |
| 56 | { |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 57 | struct ifreq ifr; |
| 58 | struct ifconf ifc; |
| 59 | |
| 60 | if (entering(tcp)) { |
| 61 | if (code == SIOCGIFCONF) { |
| 62 | umove(tcp, tcp->u_arg[2], &ifc); |
| 63 | if (ifc.ifc_buf == NULL) |
| 64 | tprintf(", {%d -> ", ifc.ifc_len); |
| 65 | else |
| 66 | tprintf(", {"); |
| 67 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 68 | return 0; |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 69 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 70 | |
| 71 | switch (code) { |
| 72 | #ifdef SIOCSHIWAT |
| 73 | case SIOCSHIWAT: |
| 74 | #endif |
| 75 | #ifdef SIOCGHIWAT |
| 76 | case SIOCGHIWAT: |
| 77 | #endif |
| 78 | #ifdef SIOCSLOWAT |
| 79 | case SIOCSLOWAT: |
| 80 | #endif |
| 81 | #ifdef SIOCGLOWAT |
| 82 | case SIOCGLOWAT: |
| 83 | #endif |
| 84 | #ifdef FIOSETOWN |
| 85 | case FIOSETOWN: |
| 86 | #endif |
| 87 | #ifdef FIOGETOWN |
| 88 | case FIOGETOWN: |
| 89 | #endif |
| 90 | #ifdef SIOCSPGRP |
| 91 | case SIOCSPGRP: |
| 92 | #endif |
| 93 | #ifdef SIOCGPGRP |
| 94 | case SIOCGPGRP: |
| 95 | #endif |
| 96 | #ifdef SIOCATMARK |
| 97 | case SIOCATMARK: |
| 98 | #endif |
| 99 | printnum(tcp, arg, ", %#d"); |
| 100 | return 1; |
Roland McGrath | 5687ff1 | 2004-07-12 07:13:06 +0000 | [diff] [blame] | 101 | #ifdef LINUX |
| 102 | case SIOCGIFNAME: |
| 103 | case SIOCGIFINDEX: |
| 104 | umove(tcp, tcp->u_arg[2], &ifr); |
| 105 | if (syserror(tcp)) { |
| 106 | if (code == SIOCGIFNAME) |
| 107 | tprintf(", {%d, ???}", ifr.ifr_ifindex); |
| 108 | else if (code == SIOCGIFINDEX) |
| 109 | tprintf(", {???, \"%s\"}", ifr.ifr_name); |
| 110 | } else |
| 111 | tprintf(", {%d, \"%s\"}", |
| 112 | ifr.ifr_ifindex, ifr.ifr_name); |
| 113 | return 1; |
| 114 | case SIOCGIFCONF: |
| 115 | umove(tcp, tcp->u_arg[2], &ifc); |
| 116 | tprintf("%d, ", ifc.ifc_len); |
| 117 | if (syserror(tcp)) { |
| 118 | tprintf("%lx", (unsigned long) ifc.ifc_buf); |
| 119 | } else if (ifc.ifc_buf == NULL) { |
| 120 | tprintf("NULL"); |
| 121 | } else { |
| 122 | int i; |
| 123 | unsigned nifra = ifc.ifc_len / sizeof(struct ifreq); |
| 124 | struct ifreq ifra[nifra]; |
| 125 | umoven(tcp, (unsigned long) ifc.ifc_buf, sizeof(ifra), |
| 126 | (char *) ifra); |
| 127 | tprintf("{"); |
| 128 | for (i = 0; i < nifra; ++i ) { |
| 129 | if (i > 0) |
| 130 | tprintf(", "); |
| 131 | tprintf("{\"%s\", {", |
| 132 | ifra[i].ifr_name); |
| 133 | if (verbose(tcp)) { |
| 134 | printxval(addrfams, |
| 135 | ifra[i].ifr_addr.sa_family, |
| 136 | "AF_???"); |
| 137 | tprintf(", "); |
| 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)); |
| 143 | } else |
| 144 | printstr(tcp, |
| 145 | (long) &ifra[i].ifr_addr.sa_data, |
| 146 | sizeof(ifra[i].ifr_addr.sa_data)); |
| 147 | } else |
| 148 | tprintf("..."); |
| 149 | tprintf("}}"); |
| 150 | } |
| 151 | tprintf("}"); |
| 152 | } |
| 153 | tprintf("}"); |
| 154 | return 1; |
| 155 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 156 | default: |
| 157 | return 0; |
| 158 | } |
| 159 | } |