1 /* Test for __libc_res_nsend buffer mismanagent (bug 18665), UDP case.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
24 #include <support/check.h>
25 #include <support/resolv_test.h>
26 #include <support/xthread.h>
28 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
30 static int initial_address_count;
31 static int response_count;
34 response (const struct resolv_response_context *ctx,
35 struct resolv_response_builder *b,
36 const char *qname, uint16_t qclass, uint16_t qtype)
38 TEST_VERIFY_EXIT (qname != NULL);
39 struct resolv_response_flags flags = {};
40 resolv_response_init (b, flags);
41 resolv_response_add_question (b, qname, qclass, qtype);
43 resolv_response_section (b, ns_s_an);
45 /* Add many A/AAAA records to the second response. */
47 xpthread_mutex_lock (&lock);
48 if (response_count == 0)
49 address_count = initial_address_count;
53 xpthread_mutex_unlock (&lock);
55 for (int i = 0; i < address_count; ++i)
57 resolv_response_open_record (b, qname, qclass, qtype, 0);
62 char ipv4[4] = {10, i >> 8, i, 0};
63 ipv4[3] = 2 * ctx->tcp + 4 * ctx->server_index;
64 resolv_response_add_data (b, &ipv4, sizeof (ipv4));
70 = {0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72 ipv6[15] = 2 * ctx->tcp + 4 * ctx->server_index;
73 resolv_response_add_data (b, &ipv6, sizeof (ipv6));
77 support_record_failure ();
78 printf ("error: unexpected QTYPE: %s/%u/%u\n",
79 qname, qclass, qtype);
81 resolv_response_close_record (b);
86 test_different_sizes (void)
88 struct addrinfo hints = { .ai_family = AF_UNSPEC, };
92 /* This magic number produces a response size close to 2048
94 initial_address_count = 126;
97 ret = getaddrinfo ("www.example", "80", &hints, &ai);
102 ret = getaddrinfo ("www123.example", "80", &hints, &ai);
107 ret = getaddrinfo ("www1234.example", "80", &hints, &ai);
112 ret = getaddrinfo ("www12345.example", "80", &hints, &ai);
120 struct resolv_test *obj = resolv_test_start
121 ((struct resolv_redirect_config)
123 .response_callback = response
126 test_different_sizes ();
128 _res.options |= RES_SNGLKUP;
129 test_different_sizes ();
131 _res.options |= RES_SNGLKUPREOP;
132 test_different_sizes ();
134 resolv_test_end (obj);
138 #include <support/test-driver.c>