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>
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
,
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]. */
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]. */
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__
,
58 "address: 2001:db8:506:708:1112:1314:1516:1718\n"
59 "error: AAAA record of size 17: www.example\n");
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. */
72 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
74 /* www1 CNAME www2. */
76 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
78 /* www2 A 192.0.2.1. */
80 "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04"
82 check_packet (packet
, sizeof (packet
) - 1, __func__
,
84 "name: www1.example\n"
85 "name: www2.example\n"
86 "address: 192.0.2.1\n");
93 test_multiple_cnames ();
97 #include <support/test-driver.c>