]>
Commit | Line | Data |
---|---|---|
f3d945d5 | 1 | /* Test host lookup with double dots at the end, [BZ #16469]. |
b168057a | 2 | Copyright (C) 2014-2015 Free Software Foundation, Inc. |
f3d945d5 AO |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <sys/types.h> | |
20 | #include <sys/socket.h> | |
21 | #include <netdb.h> | |
22 | #include <string.h> | |
23 | ||
24 | static int | |
25 | test (void) | |
26 | { | |
27 | static char host1[] = "localhost.."; | |
28 | static char host2[] = "www.gnu.org.."; | |
29 | static char *hosts[] = { host1, host2 }; | |
30 | int i; | |
31 | int pass = 0; | |
32 | ||
33 | for (i = 0; i < sizeof (hosts) / sizeof (*hosts); i++) | |
34 | { | |
35 | char *host = hosts[i]; | |
36 | size_t len = strlen (host); | |
37 | struct addrinfo *ai; | |
38 | ||
39 | /* If the name doesn't resolve with a single dot at the | |
40 | end, skip it. */ | |
41 | host[len-1] = 0; | |
42 | if (getaddrinfo (host, NULL, NULL, &ai) != 0) | |
43 | { | |
44 | printf ("resolving \"%s\" failed, skipping this hostname\n", host); | |
45 | continue; | |
46 | } | |
47 | printf ("resolving \"%s\" worked, proceeding to test\n", host); | |
48 | freeaddrinfo (ai); | |
49 | ||
50 | /* If it resolved with a single dot, check that it doesn't with | |
51 | a second trailing dot. */ | |
52 | host[len-1] = '.'; | |
53 | if (getaddrinfo (host, NULL, NULL, &ai) == 0) | |
54 | { | |
55 | printf ("resolving \"%s\" worked, test failed\n", host); | |
56 | return 1; | |
57 | } | |
58 | printf ("resolving \"%s\" failed, test passed\n", host); | |
59 | pass = 1; | |
60 | } | |
61 | ||
62 | /* We want at least one successful name resolution for the test to | |
63 | succeed. */ | |
64 | return pass ? 0 : 2; | |
65 | } | |
66 | ||
67 | #define TEST_FUNCTION test () | |
68 | #define TIMEOUT 10 | |
69 | #include "../test-skeleton.c" |