diff options
author | Ulrich Drepper <drepper@redhat.com> | 2005-09-26 21:17:54 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2005-09-26 21:17:54 +0000 |
commit | 419bcf40d791f84cbebaed50dfc488f24980ca31 (patch) | |
tree | 926d0a393202d936caf9f67ee11ef55c79a79646 | |
parent | c6bad06ac443077ba123165fa28f876b1b91a906 (diff) | |
download | glibc-419bcf40d791f84cbebaed50dfc488f24980ca31.zip glibc-419bcf40d791f84cbebaed50dfc488f24980ca31.tar.gz glibc-419bcf40d791f84cbebaed50dfc488f24980ca31.tar.bz2 |
[BZ #644]
* sysdeps/posix/getaddrinfo.c (fls): New function.
(gaih_inet): Don't use ffs, use fls. Convert address to native byte
order first.
* posix/Makefile (tests): Add tst-rfc3484.
* posix/tst-rfc3484.c: New file.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | posix/Makefile | 2 | ||||
-rw-r--r-- | posix/tst-rfc3484.c | 98 |
3 files changed, 106 insertions, 1 deletions
@@ -1,5 +1,12 @@ 2005-09-26 Ulrich Drepper <drepper@redhat.com> + [BZ #644] + * sysdeps/posix/getaddrinfo.c (fls): New function. + (gaih_inet): Don't use ffs, use fls. Convert address to native byte + order first. + * posix/Makefile (tests): Add tst-rfc3484. + * posix/tst-rfc3484.c: New file. + [BZ #627] * libio/iofclose.c (_IO_new_fclose): Unlock the internal lock before destroying it as part of the _IO_FINISH call. diff --git a/posix/Makefile b/posix/Makefile index 39b078c..8e53fda 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -87,7 +87,7 @@ tests := tstgetopt testfnm runtests runptests \ tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \ tst-execv1 tst-execv2 tst-execl1 tst-execl2 \ tst-execve1 tst-execve2 tst-execle1 tst-execle2 \ - tst-execvp3 tst-execvp4 + tst-execvp3 tst-execvp4 tst-rfc3484 xtests := bug-ga2 ifeq (yes,$(build-shared)) test-srcs := globtest diff --git a/posix/tst-rfc3484.c b/posix/tst-rfc3484.c new file mode 100644 index 0000000..378e43a --- /dev/null +++ b/posix/tst-rfc3484.c @@ -0,0 +1,98 @@ +#include <stdbool.h> +#include <stdio.h> + +/* Internal definitions used in the libc code. */ +#define __getservbyname_r getservbyname_r +#define __socket socket +#define __getsockname getsockname +#define __inet_aton inet_aton +#define __gethostbyaddr_r gethostbyaddr_r +#define __gethostbyname2_r gethostbyname2_r + +void +attribute_hidden +__check_pf (bool *p1, bool *p2) +{ + *p1 = *p2 = true; +} +int +__idna_to_ascii_lz (const char *input, char **output, int flags) +{ + return 0; +} +int +__idna_to_unicode_lzlz (const char *input, char **output, int flags) +{ + return 0; +} + +#include "../sysdeps/posix/getaddrinfo.c" + +service_user *__nss_hosts_database attribute_hidden; + + +/* This is the beginning of the real test code. The above defines + (among other things) the function rfc3484_sort. */ + + +#if __BYTE_ORDER == __BIG_ENDIAN +# define h(n) n +#else +# define h(n) __bswap_constant_32 (n) +#endif + +struct sockaddr_in addrs[] = +{ + { .sin_family = AF_INET, .sin_addr = { h (0xc0a86d1d) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a85d03) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a82c3d) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a86002) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a802f3) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a80810) } }, + { .sin_family = AF_INET, .sin_addr = { h (0xc0a85e02) } } +}; +#define naddrs (sizeof (addrs) / sizeof (addrs[0])) +static struct addrinfo ais[naddrs]; +static struct sort_result results[naddrs]; + +static int expected[naddrs] = + { + 6, 1, 0, 3, 2, 4, 5 + }; + + +static int +do_test (void) +{ + struct sockaddr_in so; + so.sin_family = AF_INET; + so.sin_addr.s_addr = h (0xc0a85f19); + + for (int i = 0; i < naddrs; ++i) + { + ais[i].ai_family = AF_INET; + ais[i].ai_addr = (struct sockaddr *) &addrs[i]; + results[i].dest_addr = &ais[i]; + results[i].got_source_addr = true; + memcpy(&results[i].source_addr, &so, sizeof (so)); + results[i].source_addr_len = sizeof (so); + } + + qsort (results, naddrs, sizeof (results[0]), rfc3484_sort); + + int result = 0; + for (int i = 0; i < naddrs; ++i) + { + struct in_addr addr = ((struct sockaddr_in *) (results[i].dest_addr->ai_addr))->sin_addr; + + int here = memcmp (&addr, &addrs[expected[i]].sin_addr, + sizeof (struct in_addr)); + printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK"); + result |= here; + } + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |