From 54d956c541aa6ea5a8e39d3db8bb3d4f3c9f4bb2 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 19 Mar 2002 11:28:17 +0000 Subject: Bart Visscher has added some missing IPV6 support, and added several additional reentrant networking functions such that iptables now runs with IPV6 support. --- libc/inet/if_nametoindex.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 libc/inet/if_nametoindex.c (limited to 'libc/inet/if_nametoindex.c') 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 , + * 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 +#include +#include +#include + +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; +} -- cgit v1.2.3