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>
28 check_packet (const void *buffer
, size_t length
,
29 const char *name
, const char *expected
)
31 char *actual
= support_format_dns_packet (buffer
, length
);
32 if (strcmp (actual
, expected
) != 0)
34 support_record_failure ();
35 printf ("error: formatted packet does not match: %s\n", name
);
36 support_run_diff ("expected", expected
,
43 test_aaaa_length (void)
45 static const char packet
[] =
46 /* Header: Response with two records. */
47 "\x12\x34\x80\x00\x00\x01\x00\x02\x00\x00\x00\x00"
48 /* Question section. www.example/IN/AAAA. */
49 "\x03www\x07""example\x00\x00\x1c\x00\x01"
50 /* Answer section. www.example AAAA [corrupted]. */
52 "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x10"
53 "\x20\x01\x0d\xb8\x05\x06\x07\x08"
54 "\x11\x12\x13\x14\x15\x16\x17\x18"
55 /* www.example AAAA [corrupted]. */
57 "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x11"
58 "\x01\x02\x03\x04\x05\x06\x07\x08"
59 "\x11\x12\x13\x14\x15\x16\x17\x18" "\xff";
60 check_packet (packet
, sizeof (packet
) - 1, __func__
,
62 "address: 2001:db8:506:708:1112:1314:1516:1718\n"
63 "error: AAAA record of size 17: www.example\n");
67 test_multiple_cnames (void)
69 static const char packet
[] =
70 /* Header: Response with three records. */
71 "\x12\x34\x80\x00\x00\x01\x00\x03\x00\x00\x00\x00"
72 /* Question section. www.example/IN/A. */
73 "\x03www\x07""example\x00\x00\x01\x00\x01"
74 /* Answer section. www.example CNAME www1.example. */
76 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
78 /* www1 CNAME www2. */
80 "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
82 /* www2 A 192.0.2.1. */
84 "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04"
86 check_packet (packet
, sizeof (packet
) - 1, __func__
,
88 "name: www1.example\n"
89 "name: www2.example\n"
90 "address: 192.0.2.1\n");
97 test_multiple_cnames ();
101 #include <support/test-driver.c>