summaryrefslogtreecommitdiff
path: root/libc/inet/if_nametoindex.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-03-19 11:28:17 +0000
committerEric Andersen <andersen@codepoet.org>2002-03-19 11:28:17 +0000
commit54d956c541aa6ea5a8e39d3db8bb3d4f3c9f4bb2 (patch)
treeaadc83ae6ad21f6955b25ca5ab679e5c4d32304c /libc/inet/if_nametoindex.c
parent8c4fbefcd9afcd0f3a8776eb8309ee2ed91ba970 (diff)
Bart Visscher <magick@Linux-Fan.com> has added some missing IPV6 support, and
added several additional reentrant networking functions such that iptables now runs with IPV6 support.
Diffstat (limited to 'libc/inet/if_nametoindex.c')
-rw-r--r--libc/inet/if_nametoindex.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libc/inet/if_nametoindex.c b/libc/inet/if_nametoindex.c
new file mode 100644
index 000000000..40818aad9
--- /dev/null
+++ b/libc/inet/if_nametoindex.c
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>,
+ * The Silver Hammer Group, Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ */
+#define __FORCE_GLIBC
+#include <features.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+unsigned int if_nametoindex(const char* blub) {
+ struct ifreq ifr;
+ int fd;
+ char *tmp;
+ int len=sizeof(ifr.ifr_name);
+
+#ifdef __UCLIBC_HAS_IPV6__
+ fd=socket(AF_INET6,SOCK_DGRAM,0);
+ if (fd<0)
+#endif /* __UCLIBC_HAS_IPV6__ */
+ fd=socket(AF_INET,SOCK_DGRAM,0);
+
+ for (tmp=ifr.ifr_name; len>0; --len) {
+ if ((*tmp++ = *blub++)==0) break;
+ }
+
+ if (ioctl(fd,SIOCGIFINDEX,&ifr)==0) {
+ close(fd);
+ return ifr.ifr_ifindex;
+ }
+ close(fd);
+ return 0;
+}