From: Rich Felker Date: Wed, 3 Aug 2011 16:13:13 +0000 (-0400) Subject: implement if_nameindex and if_freenameindex X-Git-Tag: v0.8.0~58 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fc0ecd35d8e0041c81bbe08c10c7fcb946da85e0;p=oweals%2Fmusl.git implement if_nameindex and if_freenameindex --- diff --git a/src/network/if_freenameindex.c b/src/network/if_freenameindex.c new file mode 100644 index 00000000..89bafcc0 --- /dev/null +++ b/src/network/if_freenameindex.c @@ -0,0 +1,7 @@ +#include +#include + +void if_freenameindex(struct if_nameindex *idx) +{ + free(idx); +} diff --git a/src/network/if_nameindex.c b/src/network/if_nameindex.c new file mode 100644 index 00000000..580acce0 --- /dev/null +++ b/src/network/if_nameindex.c @@ -0,0 +1,58 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "syscall.h" + +#include + +static void *do_nameindex(int s, size_t n) +{ + size_t i, len; + struct ifconf conf; + struct if_nameindex *idx; + + idx = malloc(n * (sizeof(struct if_nameindex)+sizeof(struct ifreq))); + if (!idx) return 0; + + conf.ifc_buf = (void *)&idx[n]; + conf.ifc_len = len = n * sizeof(struct ifreq); + if (ioctl(s, SIOCGIFCONF, &conf) < 0) { + free(idx); + return 0; + } + if (conf.ifc_len == len) { + free(idx); + return (void *)-1; + } + + n = conf.ifc_len / sizeof(struct ifreq); + for (i=0; i=0) { + for (n=0; (p=do_nameindex(s, n)) == (void *)-1; n++); + __syscall(SYS_close, s); + } + errno = ENOBUFS; + return p; +}