tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Patch to implement SIOCGIFINDEX



The following short patch implements SIOCGIFINDEX as found on Linux
(and maybe elsewhere), which translates an interface name to its index.

Index: net/if.c
===================================================================
RCS file: /cvsroot/src/sys/net/if.c,v
retrieving revision 1.262
diff -u -r1.262 if.c
--- net/if.c    10 Mar 2013 19:46:12 -0000      1.262
+++ net/if.c    1 Apr 2013 23:03:29 -0000
@@ -1613,6 +1613,11 @@
                ifdr->ifdr_data = ifp->if_data;
                break;
 
+       case SIOCGIFINDEX:
+               ifr = data;
+               ifr->ifr_ifindex = ifp->if_index;
+               break;
+
        case SIOCZIFDATA:
                ifdr = data;
                ifdr->ifdr_data = ifp->if_data;
Index: net/if.h
===================================================================
RCS file: /cvsroot/src/sys/net/if.h,v
retrieving revision 1.155
diff -u -r1.155 if.h
--- net/if.h    25 Oct 2012 11:53:14 -0000      1.155
+++ net/if.h    1 Apr 2013 23:03:30 -0000
@@ -598,6 +598,7 @@
                                                 */
 #define        ifr_buf         ifr_ifru.ifru_b.b_buf   /* new interface ioctls 
*/
 #define        ifr_buflen      ifr_ifru.ifru_b.b_buflen
+#define        ifr_ifindex     ifr_ifru.ifru_value     /* interface index */
 };
 
 #ifdef _KERNEL
Index: sys/sockio.h
===================================================================
RCS file: /cvsroot/src/sys/sys/sockio.h,v
retrieving revision 1.31
diff -u -r1.31 sockio.h
--- sys/sockio.h        31 Oct 2012 10:17:35 -0000      1.31
+++ sys/sockio.h        1 Apr 2013 23:03:30 -0000
@@ -137,6 +137,8 @@
 
 #define        SIOCGETHERCAP   _IOWR('i', 139, struct eccapreq) /* get 
ethercap */
 
+#define        SIOCGIFINDEX    _IOWR('i', 140, struct ifreq)   /* get ifnet 
index */
+
 #define        SIOCSETPFSYNC   _IOW('i', 247, struct ifreq)    
 #define        SIOCGETPFSYNC   _IOWR('i', 248, struct ifreq)
 



Home | Main Index | Thread Index | Old Index