@@ -111,6 +111,7 @@ endif
tests = \
README-testing \
tst-support-namespace \
+ tst-support_format_dns_packet \
tst-support_record_failure \
ifeq ($(run-built-tests),yes)
@@ -125,4 +126,6 @@ $(objpfx)tst-support_record_failure-2.out: tst-support_record_failure-2.sh \
$(evaluate-test)
endif
+$(objpfx)tst-support_format_dns_packet: $(common-objpfx)resolv/libresolv.so
+
include ../Rules
@@ -174,7 +174,7 @@ support_format_dns_packet (const unsigned char *buffer, size_t length)
goto out;
}
/* Skip non-matching record types. */
- if (rtype != qtype || rclass != qclass)
+ if ((rtype != qtype && rtype != T_CNAME) || rclass != qclass)
continue;
switch (rtype)
{
@@ -201,7 +201,7 @@ support_format_dns_packet (const unsigned char *buffer, size_t length)
case T_PTR:
{
struct dname name;
- if (extract_name (full, &in, &name))
+ if (extract_name (full, &rdata, &name))
fprintf (mem.out, "name: %s\n", name.name);
else
fprintf (mem.out, "error: malformed CNAME/PTR record\n");
new file mode 100644
@@ -0,0 +1,62 @@
+/* Tests for the support_format_dns_packet function.
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check.h>
+#include <support/format_nss.h>
+
+static void
+test_multiple_cnames (void)
+{
+ static const char packet[] =
+ /* Header: Response with three records. */
+ "\x12\x34\x80\x00\x00\x01\x00\x03\x00\x00\x00\x00"
+ /* Question section. www.example/IN/A. */
+ "\x03www\x07""example\x00\x00\x01\x00\x01"
+ /* Answer section. www.example CNAME www1.example. */
+ "\xc0\x0c"
+ "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
+ "\x04www1\xc0\x10"
+ /* www1 CNAME www2. */
+ "\x04www1\xc0\x10"
+ "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07"
+ "\x04www2\xc0\x10"
+ /* www2 A 192.0.2.1. */
+ "\x04www2\xc0\x10"
+ "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04"
+ "\xc0\x00\x02\x01";
+
+ char *formatted = support_format_dns_packet
+ ((unsigned char *) packet, sizeof (packet) - 1);
+ puts ("info: test_multiple_cnames output:");
+ puts (formatted);
+ TEST_VERIFY (strcmp (formatted,
+ "name: www.example\n"
+ "name: www1.example\n"
+ "name: www2.example\n"
+ "address: 192.0.2.1\n") == 0);
+ free (formatted);
+}
+
+static int
+do_test (void)
+{
+ test_multiple_cnames ();
+ return 0;
+}
+
+#include <support/test-driver.c>