+int
+get_iface_index(const char *ifname)
+{
+ struct ifreq ir;
+ int sock;
+
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0)
+ return 0;
+
+ memset(&ir, 0, sizeof(struct ifreq));
+
+ strncpy(ir.ifr_name, ifname, sizeof(ir.ifr_name));
+
+ if (ioctl(sock, SIOCGIFINDEX, &ir) < 0)
+ return 0;
+
+ close(sock);
+
+ return ir.ifr_ifindex;
+}
+