x86-64: Improve branch predication in _dl_runtime_resolve_avx512_opt [BZ #21258]
[glibc.git] / support / tst-support_format_dns_packet.c
blobecd7abfe2b6d4785f3f814b3be3e46d9d6e5df93
1 /* Tests for the support_format_dns_packet function.
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/>. */
19 #include <support/check.h>
20 #include <support/format_nss.h>
21 #include <support/run_diff.h>
23 static void
24 check_packet (const void *buffer, size_t length,
25 const char *name, const char *expected)
27 char *actual = support_format_dns_packet (buffer, length);
28 if (strcmp (actual, expected) != 0)
30 support_record_failure ();
31 printf ("error: formatted packet does not match: %s\n", name);
32 support_run_diff ("expected", expected,
33 "actual", actual);
35 free (actual);
38 static void
39 test_aaaa_length (void)
41 static const char packet[] =
42 /* Header: Response with two records. */
43 "\x12\x34\x80\x00\x00\x01\x00\x02\x00\x00\x00\x00"
44 /* Question section. www.example/IN/AAAA. */
45 "\x03www\x07""example\x00\x00\x1c\x00\x01"
46 /* Answer section. www.example AAAA [corrupted]. */
47 "\xc0\x0c"
48 "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x10"
49 "\x20\x01\x0d\xb8\x05\x06\x07\x08"
50 "\x11\x12\x13\x14\x15\x16\x17\x18"
51 /* www.example AAAA [corrupted]. */
52 "\xc0\x0c"
53 "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x11"
54 "\x01\x02\x03\x04\x05\x06\x07\x08"
55 "\x11\x12\x13\x14\x15\x16\x17\x18" "\xff";
56 check_packet (packet, sizeof (packet) - 1, __func__,
57 "name: www.example\n"
58 "address: 2001:db8:506:708:1112:1314:1516:1718\n"
59 "error: AAAA record of size 17: www.example\n");
62 static void
63 test_multiple_cnames (void)
65 static const char packet[] =
66 /* Header: Response with three records. */
67 "\x12\x34\x80\x00\x00\x01\x00\x03\x00\x00\x00\x00"
68 /* Question section. www.example/IN/A. */
69 "\x03www\x07""example\x00\x00\x01\x00\x01"
70 /* Answer section. www.example CNAME www1.example. */
71 "\xc0\x0c"
72 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
73 "\x04www1\xc0\x10"
74 /* www1 CNAME www2. */
75 "\x04www1\xc0\x10"
76 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
77 "\x04www2\xc0\x10"
78 /* www2 A 192.0.2.1. */
79 "\x04www2\xc0\x10"
80 "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04"
81 "\xc0\x00\x02\x01";
82 check_packet (packet, sizeof (packet) - 1, __func__,
83 "name: www.example\n"
84 "name: www1.example\n"
85 "name: www2.example\n"
86 "address: 192.0.2.1\n");
89 static int
90 do_test (void)
92 test_aaaa_length ();
93 test_multiple_cnames ();
94 return 0;
97 #include <support/test-driver.c>