X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fnetwork%2Fgetifaddrs.c;h=5a94cc7c4496fe4edda2938dc672c9a3301d0552;hb=7cbb6f70c8fe711644ec0dbede1973cc6641a283;hp=9ccf45796e71a95d48aeb2b533f52f81e7a47e6e;hpb=338cc31c4bb80fb5f703b3c4a2fb4210138592ba;p=musl diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c index 9ccf4579..5a94cc7c 100644 --- a/src/network/getifaddrs.c +++ b/src/network/getifaddrs.c @@ -11,6 +11,7 @@ #include /* inet_pton */ #include #include +#include typedef union { struct sockaddr_in6 v6; @@ -51,13 +52,22 @@ void freeifaddrs(struct ifaddrs *ifp) static void ipv6netmask(unsigned prefix_length, struct sockaddr_in6 *sa) { - // FIXME: left for bit-wizard rich - memset(&sa->sin6_addr, -1, sizeof(sa->sin6_addr)); + unsigned char* hb = sa->sin6_addr.s6_addr; + unsigned onebytes = prefix_length / 8; + unsigned bits = prefix_length % 8; + unsigned nullbytes = 16 - onebytes; + memset(hb, -1, onebytes); + memset(hb+onebytes, 0, nullbytes); + if(bits) { + unsigned char x = -1; + x <<= 8 - bits; + hb[onebytes] = x; + } } static void dealwithipv6(stor **list, stor** head) { - FILE* f = fopen("/proc/net/if_inet6", "r"); + FILE* f = fopen("/proc/net/if_inet6", "rbe"); /* 00000000000000000000000000000001 01 80 10 80 lo A B C D E F all numbers in hex @@ -118,7 +128,7 @@ int getifaddrs(struct ifaddrs **ifap) } if_freenameindex(ii); - int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + int sock = socket(PF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP); if(sock == -1) goto err2; struct ifreq reqs[32]; /* arbitrary chosen boundary */ struct ifconf conf = {.ifc_len = sizeof reqs, .ifc_req = reqs};