diff options
author | Ulrich Drepper <drepper@redhat.com> | 2005-09-26 21:10:16 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2005-09-26 21:10:16 +0000 |
commit | c6bad06ac443077ba123165fa28f876b1b91a906 (patch) | |
tree | 460ca337a1fd5889e53b7ea2b5d0e5b50a1690cf /sysdeps | |
parent | 43b0572f8ab3593241d1641d235f3fcf5c7a8a83 (diff) | |
download | glibc-c6bad06ac443077ba123165fa28f876b1b91a906.tar.gz glibc-c6bad06ac443077ba123165fa28f876b1b91a906.tar.xz glibc-c6bad06ac443077ba123165fa28f876b1b91a906.zip |
(fls): New function. (gaih_inet): Don't use ffs, use fls. Convert address to native byte order first.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/posix/getaddrinfo.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 4db98d942c..934aae009c 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1304,6 +1304,19 @@ get_precedence (const struct sockaddr_storage *ss) } +/* Find last bit set in a word. */ +static int +fls (uint32_t a) +{ + uint32_t mask; + int n = 0; + for (n = 0, mask = 1 << 31; n < 32; mask >>= 1, ++n) + if ((a & mask) != 0) + break; + return n; +} + + static int rfc3484_sort (const void *p1, const void *p2) { @@ -1407,8 +1420,10 @@ rfc3484_sort (const void *p1, const void *p2) in2_dst = (struct sockaddr_in *) a2->dest_addr->ai_addr; in2_src = (struct sockaddr_in *) &a2->source_addr; - bit1 = ffs (in1_dst->sin_addr.s_addr ^ in1_src->sin_addr.s_addr); - bit2 = ffs (in2_dst->sin_addr.s_addr ^ in2_src->sin_addr.s_addr); + bit1 = fls (ntohl (in1_dst->sin_addr.s_addr + ^ in1_src->sin_addr.s_addr)); + bit2 = fls (ntohl (in2_dst->sin_addr.s_addr + ^ in2_src->sin_addr.s_addr)); } else if (a1->dest_addr->ai_family == PF_INET6) { @@ -1435,10 +1450,10 @@ rfc3484_sort (const void *p1, const void *p2) if (i < 4) { - bit1 = ffs (in1_dst->sin6_addr.s6_addr32[i] - ^ in1_src->sin6_addr.s6_addr32[i]); - bit2 = ffs (in2_dst->sin6_addr.s6_addr32[i] - ^ in2_src->sin6_addr.s6_addr32[i]); + bit1 = fls (ntohl (in1_dst->sin6_addr.s6_addr32[i] + ^ in1_src->sin6_addr.s6_addr32[i])); + bit2 = fls (ntohl (in2_dst->sin6_addr.s6_addr32[i] + ^ in2_src->sin6_addr.s6_addr32[i])); } } |