]> granicus.if.org Git - strace/commitdiff
2004-07-12 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Mon, 12 Jul 2004 07:13:06 +0000 (07:13 +0000)
committerRoland McGrath <roland@redhat.com>
Mon, 12 Jul 2004 07:13:06 +0000 (07:13 +0000)
* net.c (addrfams): Make variable global.
* sock.c (sock_ioctl): Decode the arguments for SIOCGIFNAME,
SIOCGIFINDEX, and SIOCGIFCONF.
From Ulrich Drepper <drepper@redhat.com>.
Fixes RH#126917.

net.c
sock.c

diff --git a/net.c b/net.c
index 3c23b41759f14e4ea8f791b717a72f3732349e30..206518f8765e0c8fcde148ce52b5be2633c0ed63 100644 (file)
--- a/net.c
+++ b/net.c
@@ -218,7 +218,7 @@ static struct xlat domains[] = {
 #endif
        { 0,            NULL            },
 };
-static struct xlat addrfams[] = {
+struct xlat addrfams[] = {
 #ifdef AF_APPLETALK
        { AF_APPLETALK, "AF_APPLETALK"  },
 #endif
diff --git a/sock.c b/sock.c
index 7d1f244a59908636f89aa2a90e58d2c4fc6954ac..412577a241f1a4f78f2a13c855810b6d75bbf1b6 100644 (file)
--- a/sock.c
+++ b/sock.c
 
 #ifdef LINUX
 #include <sys/socket.h>
+#include <linux/sockios.h>
 #else
 #include <sys/sockio.h>
 #endif
+#include <arpa/inet.h>
 
 #if defined (ALPHA) || defined(SH) || defined(SH64)
 #ifdef HAVE_SYS_IOCTL_H
 #include <ioctls.h>
 #endif
 #endif
+#include <net/if.h>
+
+extern struct xlat addrfams[];
 
 int
 sock_ioctl(tcp, code, arg)
 struct tcb *tcp;
 long code, arg;
 {
-       if (entering(tcp))
+       struct ifreq ifr;
+       struct ifconf ifc;
+
+       if (entering(tcp)) {
+               if (code == SIOCGIFCONF) {
+                       umove(tcp, tcp->u_arg[2], &ifc);
+                       if (ifc.ifc_buf == NULL)
+                               tprintf(", {%d -> ", ifc.ifc_len);
+                       else
+                               tprintf(", {");
+               }
                return 0;
+       }
 
        switch (code) {
 #ifdef SIOCSHIWAT
@@ -81,6 +97,61 @@ long code, arg;
 #endif
                printnum(tcp, arg, ", %#d");
                return 1;
+#ifdef LINUX
+       case SIOCGIFNAME:
+       case SIOCGIFINDEX:
+               umove(tcp, tcp->u_arg[2], &ifr);
+                if (syserror(tcp)) {
+                       if (code == SIOCGIFNAME)
+                               tprintf(", {%d, ???}", ifr.ifr_ifindex);
+                       else if (code == SIOCGIFINDEX)
+                               tprintf(", {???, \"%s\"}", ifr.ifr_name);
+               } else
+                       tprintf(", {%d, \"%s\"}",
+                               ifr.ifr_ifindex, ifr.ifr_name);
+               return 1;
+       case SIOCGIFCONF:
+               umove(tcp, tcp->u_arg[2], &ifc);
+               tprintf("%d, ", ifc.ifc_len);
+                if (syserror(tcp)) {
+                       tprintf("%lx", (unsigned long) ifc.ifc_buf);
+               } else if (ifc.ifc_buf == NULL) {
+                       tprintf("NULL");
+               } else {
+                       int i;
+                       unsigned nifra = ifc.ifc_len / sizeof(struct ifreq);
+                       struct ifreq ifra[nifra];
+                       umoven(tcp, (unsigned long) ifc.ifc_buf, sizeof(ifra),
+                              (char *) ifra);
+                       tprintf("{");
+                       for (i = 0; i < nifra; ++i ) {
+                               if (i > 0)
+                                       tprintf(", ");
+                               tprintf("{\"%s\", {",
+                                       ifra[i].ifr_name);
+                               if (verbose(tcp)) {
+                                       printxval(addrfams,
+                                                 ifra[i].ifr_addr.sa_family,
+                                                 "AF_???");
+                                       tprintf(", ");
+                                       if (ifra[i].ifr_addr.sa_family == AF_INET) {
+                                               struct sockaddr_in *sinp;
+                                               sinp = (struct sockaddr_in *) &ifra[i].ifr_addr;
+                                               tprintf("inet_addr(\"%s\")",
+                                                       inet_ntoa(sinp->sin_addr));
+                                       } else
+                                               printstr(tcp,
+                                                        (long) &ifra[i].ifr_addr.sa_data,
+                                                        sizeof(ifra[i].ifr_addr.sa_data));
+                               } else
+                                       tprintf("...");
+                               tprintf("}}");
+                       }
+                       tprintf("}");
+               }
+               tprintf("}");
+               return 1;
+#endif
        default:
                return 0;
        }