Blame resolv/tst-resolv-basic.c

Packit 6c4009
/* Test basic nss_dns functionality and the resolver test harness itself.
Packit 6c4009
   Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <support/check.h>
Packit 6c4009
#include <support/check_nss.h>
Packit 6c4009
#include <support/format_nss.h>
Packit 6c4009
#include <support/resolv_test.h>
Packit 6c4009
#include <support/support.h>
Packit 6c4009
Packit 6c4009
#define LONG_NAME                                                       \
Packit 6c4009
  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax."    \
Packit 6c4009
  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay."    \
Packit 6c4009
  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz."    \
Packit 6c4009
  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat"
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
response (const struct resolv_response_context *ctx,
Packit 6c4009
          struct resolv_response_builder *b,
Packit 6c4009
          const char *qname, uint16_t qclass, uint16_t qtype)
Packit 6c4009
{
Packit 6c4009
  TEST_VERIFY_EXIT (qname != NULL);
Packit 6c4009
Packit 6c4009
  /* The "t." prefix can be used to request TCP fallback.  */
Packit 6c4009
  bool force_tcp;
Packit 6c4009
  if (strncmp ("t.", qname, 2) == 0)
Packit 6c4009
    force_tcp = true;
Packit 6c4009
  else
Packit 6c4009
    force_tcp = false;
Packit 6c4009
  const char *qname_compare;
Packit 6c4009
  if (force_tcp)
Packit 6c4009
    qname_compare = qname + 2;
Packit 6c4009
  else
Packit 6c4009
    qname_compare = qname;
Packit 6c4009
  enum {www, alias, nxdomain, long_name, nodata} requested_qname;
Packit 6c4009
  if (strcmp (qname_compare, "www.example") == 0)
Packit 6c4009
    requested_qname = www;
Packit 6c4009
  else if (strcmp (qname_compare, "alias.example") == 0)
Packit 6c4009
    requested_qname = alias;
Packit 6c4009
  else if (strcmp (qname_compare, "nxdomain.example") == 0)
Packit 6c4009
    requested_qname = nxdomain;
Packit 6c4009
  else if (strcmp (qname_compare, LONG_NAME) == 0)
Packit 6c4009
    requested_qname = long_name;
Packit 6c4009
  else if (strcmp (qname_compare, "nodata.example") == 0)
Packit 6c4009
    requested_qname = nodata;
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      support_record_failure ();
Packit 6c4009
      printf ("error: unexpected QNAME: %s\n", qname);
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  TEST_VERIFY_EXIT (qclass == C_IN);
Packit 6c4009
  struct resolv_response_flags flags = {.tc = force_tcp && !ctx->tcp};
Packit 6c4009
  if (requested_qname == nxdomain)
Packit 6c4009
    flags.rcode = 3;            /* NXDOMAIN */
Packit 6c4009
  resolv_response_init (b, flags);
Packit 6c4009
  resolv_response_add_question (b, qname, qclass, qtype);
Packit 6c4009
  if (requested_qname == nxdomain || flags.tc)
Packit 6c4009
    return;
Packit 6c4009
Packit 6c4009
  resolv_response_section (b, ns_s_an);
Packit 6c4009
  switch (requested_qname)
Packit 6c4009
    {
Packit 6c4009
    case www:
Packit 6c4009
    case long_name:
Packit 6c4009
      resolv_response_open_record (b, qname, qclass, qtype, 0);
Packit 6c4009
      break;
Packit 6c4009
    case alias:
Packit 6c4009
      resolv_response_open_record (b, qname, qclass, T_CNAME, 0);
Packit 6c4009
      resolv_response_add_name (b, "www.example");
Packit 6c4009
      resolv_response_close_record (b);
Packit 6c4009
      resolv_response_open_record (b, "www.example", qclass, qtype, 0);
Packit 6c4009
      break;
Packit 6c4009
    case nodata:
Packit 6c4009
      return;
Packit 6c4009
    case nxdomain:
Packit 6c4009
      FAIL_EXIT1 ("unreachable");
Packit 6c4009
    }
Packit 6c4009
  switch (qtype)
Packit 6c4009
    {
Packit 6c4009
    case T_A:
Packit 6c4009
      {
Packit 6c4009
        char ipv4[4] = {192, 0, 2, 17};
Packit 6c4009
        ipv4[3] += requested_qname + 2 * ctx->tcp + 4 * ctx->server_index;
Packit 6c4009
        resolv_response_add_data (b, &ipv4, sizeof (ipv4));
Packit 6c4009
      }
Packit 6c4009
      break;
Packit 6c4009
    case T_AAAA:
Packit 6c4009
      {
Packit 6c4009
        char ipv6[16]
Packit 6c4009
          = {0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
Packit 6c4009
        ipv6[15] += requested_qname + 2 * ctx->tcp + 4 * ctx->server_index;
Packit 6c4009
        resolv_response_add_data (b, &ipv6, sizeof (ipv6));
Packit 6c4009
      }
Packit 6c4009
      break;
Packit 6c4009
    default:
Packit 6c4009
      support_record_failure ();
Packit 6c4009
      printf ("error: unexpected QTYPE: %s/%u/%u\n",
Packit 6c4009
              qname, qclass, qtype);
Packit 6c4009
    }
Packit 6c4009
  resolv_response_close_record (b);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
check_h (const char *name, int family, const char *expected)
Packit 6c4009
{
Packit 6c4009
  if (family == AF_INET)
Packit 6c4009
    {
Packit 6c4009
      char *query = xasprintf ("gethostbyname (\"%s\")", name);
Packit 6c4009
      check_hostent (query, gethostbyname (name), expected);
Packit 6c4009
      free (query);
Packit 6c4009
    }
Packit 6c4009
  {
Packit 6c4009
    char *query = xasprintf ("gethostbyname2 (\"%s\", %d)", name, family);
Packit 6c4009
    check_hostent (query, gethostbyname2 (name, family), expected);
Packit 6c4009
    free (query);
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
  bool too_small = true;
Packit 6c4009
  for (unsigned int offset = 0; offset < 8; ++offset)
Packit 6c4009
    for (unsigned int size = 1; too_small; ++size)
Packit 6c4009
      {
Packit 6c4009
        char *buf = xmalloc (offset + size);
Packit 6c4009
        too_small = false;
Packit 6c4009
Packit 6c4009
        struct hostent hostbuf;
Packit 6c4009
        struct hostent *result;
Packit 6c4009
        int herror;
Packit 6c4009
        if (family == AF_INET)
Packit 6c4009
          {
Packit 6c4009
            char *query = xasprintf ("gethostbyname (\"%s\") %u/%u",
Packit 6c4009
                                     name, offset, size);
Packit 6c4009
            int ret = gethostbyname_r
Packit 6c4009
              (name, &hostbuf, buf + offset, size, &result, &herror);
Packit 6c4009
            if (ret == 0)
Packit 6c4009
              {
Packit 6c4009
                h_errno = herror;
Packit 6c4009
                check_hostent (query, result, expected);
Packit 6c4009
              }
Packit 6c4009
            else if (ret == ERANGE)
Packit 6c4009
              too_small = true;
Packit 6c4009
            else
Packit 6c4009
              {
Packit 6c4009
                errno = ret;
Packit 6c4009
                FAIL_EXIT1 ("gethostbyname_r: %m");
Packit 6c4009
              }
Packit 6c4009
            free (query);
Packit 6c4009
            memset (buf, 0, offset + size);
Packit 6c4009
          }
Packit 6c4009
        char *query = xasprintf ("gethostbyname2 (\"%s\", %d) %u/%u",
Packit 6c4009
                                 name, family, offset, size);
Packit 6c4009
        int ret = gethostbyname2_r
Packit 6c4009
          (name, family, &hostbuf, buf + offset, size, &result, &herror);
Packit 6c4009
        if (ret == 0)
Packit 6c4009
          {
Packit 6c4009
            h_errno = herror;
Packit 6c4009
            check_hostent (query, result, expected);
Packit 6c4009
          }
Packit 6c4009
        else if (ret == ERANGE)
Packit 6c4009
          too_small = true;
Packit 6c4009
        else
Packit 6c4009
          {
Packit 6c4009
            errno = ret;
Packit 6c4009
            FAIL_EXIT1 ("gethostbyname_r: %m");
Packit 6c4009
          }
Packit 6c4009
        free (buf);
Packit 6c4009
        free (query);
Packit 6c4009
      }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
check_ai_hints (const char *name, const char *service,
Packit 6c4009
                struct addrinfo hints, const char *expected)
Packit 6c4009
{
Packit 6c4009
  struct addrinfo *ai;
Packit 6c4009
  char *query = xasprintf ("%s:%s [%d]/0x%x", name, service,
Packit 6c4009
                           hints.ai_family, hints.ai_flags);
Packit 6c4009
  int ret = getaddrinfo (name, service, &hints, &ai;;
Packit 6c4009
  check_addrinfo (query, ai, ret, expected);
Packit 6c4009
  if (ret == 0)
Packit 6c4009
    freeaddrinfo (ai);
Packit 6c4009
  free (query);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
check_ai (const char *name, const char *service,
Packit 6c4009
          int family, const char *expected)
Packit 6c4009
{
Packit 6c4009
  return check_ai_hints (name, service,
Packit 6c4009
                         (struct addrinfo) { .ai_family = family, },
Packit 6c4009
                         expected);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Test for bug 21295: getaddrinfo used to discard address information
Packit 6c4009
   instead of merging it.  */
Packit 6c4009
static void
Packit 6c4009
test_bug_21295 (void)
Packit 6c4009
{
Packit 6c4009
  /* The address order is unpredictable.  There are two factors which
Packit 6c4009
     contribute to that: The stub resolver does not perform proper
Packit 6c4009
     response matching for A/AAAA queries (an A response could be
Packit 6c4009
     associated with an AAAA query and vice versa), and without
Packit 6c4009
     namespaces, system configuration could affect address
Packit 6c4009
     ordering.  */
Packit 6c4009
  for (int do_tcp = 0; do_tcp < 2; ++do_tcp)
Packit 6c4009
    {
Packit 6c4009
      const struct addrinfo hints =
Packit 6c4009
        {
Packit 6c4009
          .ai_family = AF_INET6,
Packit 6c4009
          .ai_socktype = SOCK_STREAM,
Packit 6c4009
          .ai_flags = AI_V4MAPPED | AI_ALL,
Packit 6c4009
        };
Packit 6c4009
      const char *qname;
Packit 6c4009
      if (do_tcp)
Packit 6c4009
        qname = "t.www.example";
Packit 6c4009
      else
Packit 6c4009
        qname = "www.example";
Packit 6c4009
      struct addrinfo *ai = NULL;
Packit 6c4009
      int ret = getaddrinfo (qname, "80", &hints, &ai;;
Packit 6c4009
      TEST_VERIFY_EXIT (ret == 0);
Packit 6c4009
Packit 6c4009
      const char *expected_a;
Packit 6c4009
      const char *expected_b;
Packit 6c4009
      if (do_tcp)
Packit 6c4009
        {
Packit 6c4009
          expected_a = "flags: AI_V4MAPPED AI_ALL\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::3 80\n"
Packit 6c4009
            "address: STREAM/TCP ::ffff:192.0.2.19 80\n";
Packit 6c4009
          expected_b = "flags: AI_V4MAPPED AI_ALL\n"
Packit 6c4009
            "address: STREAM/TCP ::ffff:192.0.2.19 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::3 80\n";
Packit 6c4009
        }
Packit 6c4009
      else
Packit 6c4009
        {
Packit 6c4009
          expected_a = "flags: AI_V4MAPPED AI_ALL\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::1 80\n"
Packit 6c4009
            "address: STREAM/TCP ::ffff:192.0.2.17 80\n";
Packit 6c4009
          expected_b = "flags: AI_V4MAPPED AI_ALL\n"
Packit 6c4009
            "address: STREAM/TCP ::ffff:192.0.2.17 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::1 80\n";
Packit 6c4009
        }
Packit 6c4009
Packit 6c4009
      char *actual = support_format_addrinfo (ai, ret);
Packit 6c4009
      if (!(strcmp (actual, expected_a) == 0
Packit 6c4009
            || strcmp (actual, expected_b) == 0))
Packit 6c4009
        {
Packit 6c4009
          support_record_failure ();
Packit 6c4009
          printf ("error: %s: unexpected response (TCP: %d):\n%s\n",
Packit 6c4009
                  __func__, do_tcp, actual);
Packit 6c4009
        }
Packit 6c4009
      free (actual);
Packit 6c4009
      freeaddrinfo (ai);
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Run tests which do not expect any data.  */
Packit 6c4009
static void
Packit 6c4009
test_nodata_nxdomain (void)
Packit 6c4009
{
Packit 6c4009
  /* Iterate through different address families.  */
Packit 6c4009
  int families[] = { AF_UNSPEC, AF_INET, AF_INET6, -1 };
Packit 6c4009
  for (int i = 0; families[i] >= 0; ++i)
Packit 6c4009
    /* If do_tcp, prepend "t." to the name to trigger TCP
Packit 6c4009
       fallback.  */
Packit 6c4009
    for (int do_tcp = 0; do_tcp < 2; ++do_tcp)
Packit 6c4009
      /* If do_nxdomain, trigger an NXDOMAIN error (DNS failure),
Packit 6c4009
         otherwise use a NODATA response (empty but successful
Packit 6c4009
         answer).  */
Packit 6c4009
      for (int do_nxdomain = 0; do_nxdomain < 2; ++do_nxdomain)
Packit 6c4009
        {
Packit 6c4009
          int family = families[i];
Packit 6c4009
          char *name = xasprintf ("%s%s.example",
Packit 6c4009
                                  do_tcp ? "t." : "",
Packit 6c4009
                                  do_nxdomain ? "nxdomain" : "nodata");
Packit 6c4009
Packit 6c4009
          if (family != AF_UNSPEC)
Packit 6c4009
            {
Packit 6c4009
              if (do_nxdomain)
Packit 6c4009
                check_h (name, family, "error: HOST_NOT_FOUND\n");
Packit 6c4009
              else
Packit 6c4009
                check_h (name, family, "error: NO_ADDRESS\n");
Packit 6c4009
            }
Packit 6c4009
Packit 6c4009
          const char *expected;
Packit 6c4009
          if (do_nxdomain)
Packit 6c4009
            expected = "error: Name or service not known\n";
Packit 6c4009
          else
Packit 6c4009
            expected = "error: No address associated with hostname\n";
Packit 6c4009
Packit 6c4009
          check_ai (name, "80", family, expected);
Packit 6c4009
Packit 6c4009
          struct addrinfo hints =
Packit 6c4009
            {
Packit 6c4009
              .ai_family = family,
Packit 6c4009
              .ai_flags = AI_V4MAPPED | AI_ALL,
Packit 6c4009
            };
Packit 6c4009
          check_ai_hints (name, "80", hints, expected);
Packit 6c4009
          hints.ai_flags |= AI_CANONNAME;
Packit 6c4009
          check_ai_hints (name, "80", hints, expected);
Packit 6c4009
Packit 6c4009
          free (name);
Packit 6c4009
        }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  struct resolv_test *aux = resolv_test_start
Packit 6c4009
    ((struct resolv_redirect_config)
Packit 6c4009
     {
Packit 6c4009
       .response_callback = response,
Packit 6c4009
     });
Packit 6c4009
Packit 6c4009
  check_h ("www.example", AF_INET,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "address: 192.0.2.17\n");
Packit 6c4009
  check_h ("alias.example", AF_INET,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "alias: alias.example\n"
Packit 6c4009
           "address: 192.0.2.18\n");
Packit 6c4009
  check_h ("www.example", AF_INET6,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "address: 2001:db8::1\n");
Packit 6c4009
  check_h ("alias.example", AF_INET6,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "alias: alias.example\n"
Packit 6c4009
           "address: 2001:db8::2\n");
Packit 6c4009
  check_h (LONG_NAME, AF_INET,
Packit 6c4009
           "name: " LONG_NAME "\n"
Packit 6c4009
           "address: 192.0.2.20\n");
Packit 6c4009
Packit 6c4009
  check_ai ("www.example", "80", AF_UNSPEC,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.17 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.17 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.17 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::1 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::1 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::1 80\n");
Packit 6c4009
  check_ai_hints ("www.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_UNSPEC,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 192.0.2.17 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 192.0.2.17 80\n"
Packit 6c4009
                  "address: RAW/IP 192.0.2.17 80\n"
Packit 6c4009
                  "address: STREAM/TCP 2001:db8::1 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 2001:db8::1 80\n"
Packit 6c4009
                  "address: RAW/IP 2001:db8::1 80\n");
Packit 6c4009
  check_ai ("alias.example", "80", AF_UNSPEC,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.18 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.18 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.18 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::2 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::2 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::2 80\n");
Packit 6c4009
  check_ai_hints ("alias.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_UNSPEC,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 192.0.2.18 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 192.0.2.18 80\n"
Packit 6c4009
                  "address: RAW/IP 192.0.2.18 80\n"
Packit 6c4009
                  "address: STREAM/TCP 2001:db8::2 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 2001:db8::2 80\n"
Packit 6c4009
                  "address: RAW/IP 2001:db8::2 80\n");
Packit 6c4009
  check_ai (LONG_NAME, "80", AF_UNSPEC,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.20 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.20 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.20 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::4 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::4 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::4 80\n");
Packit 6c4009
  check_ai ("www.example", "80", AF_INET,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.17 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.17 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.17 80\n");
Packit 6c4009
  check_ai_hints ("www.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_INET,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 192.0.2.17 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 192.0.2.17 80\n"
Packit 6c4009
                  "address: RAW/IP 192.0.2.17 80\n");
Packit 6c4009
  check_ai ("alias.example", "80", AF_INET,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.18 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.18 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.18 80\n");
Packit 6c4009
  check_ai_hints ("alias.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_INET,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 192.0.2.18 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 192.0.2.18 80\n"
Packit 6c4009
                  "address: RAW/IP 192.0.2.18 80\n");
Packit 6c4009
  check_ai (LONG_NAME, "80", AF_INET,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.20 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.20 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.20 80\n");
Packit 6c4009
  check_ai ("www.example", "80", AF_INET6,
Packit 6c4009
            "address: STREAM/TCP 2001:db8::1 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::1 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::1 80\n");
Packit 6c4009
  check_ai_hints ("www.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_INET6,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 2001:db8::1 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 2001:db8::1 80\n"
Packit 6c4009
                  "address: RAW/IP 2001:db8::1 80\n");
Packit 6c4009
  check_ai ("alias.example", "80", AF_INET6,
Packit 6c4009
            "address: STREAM/TCP 2001:db8::2 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::2 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::2 80\n");
Packit 6c4009
  check_ai_hints ("alias.example", "80",
Packit 6c4009
                  (struct addrinfo) { .ai_family = AF_INET6,
Packit 6c4009
                      .ai_flags = AI_CANONNAME, },
Packit 6c4009
                  "flags: AI_CANONNAME\n"
Packit 6c4009
                  "canonname: www.example\n"
Packit 6c4009
                  "address: STREAM/TCP 2001:db8::2 80\n"
Packit 6c4009
                  "address: DGRAM/UDP 2001:db8::2 80\n"
Packit 6c4009
                  "address: RAW/IP 2001:db8::2 80\n");
Packit 6c4009
  check_ai (LONG_NAME, "80", AF_INET6,
Packit 6c4009
            "address: STREAM/TCP 2001:db8::4 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::4 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::4 80\n");
Packit 6c4009
Packit 6c4009
  check_h ("t.www.example", AF_INET,
Packit 6c4009
           "name: t.www.example\n"
Packit 6c4009
           "address: 192.0.2.19\n");
Packit 6c4009
  check_h ("t.alias.example", AF_INET,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "alias: t.alias.example\n"
Packit 6c4009
           "address: 192.0.2.20\n");
Packit 6c4009
  check_h ("t.www.example", AF_INET6,
Packit 6c4009
           "name: t.www.example\n"
Packit 6c4009
           "address: 2001:db8::3\n");
Packit 6c4009
  check_h ("t.alias.example", AF_INET6,
Packit 6c4009
           "name: www.example\n"
Packit 6c4009
           "alias: t.alias.example\n"
Packit 6c4009
           "address: 2001:db8::4\n");
Packit 6c4009
  check_ai ("t.www.example", "80", AF_UNSPEC,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.19 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.19 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.19 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::3 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::3 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::3 80\n");
Packit 6c4009
  check_ai ("t.alias.example", "80", AF_UNSPEC,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.20 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.20 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.20 80\n"
Packit 6c4009
            "address: STREAM/TCP 2001:db8::4 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::4 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::4 80\n");
Packit 6c4009
  check_ai ("t.www.example", "80", AF_INET,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.19 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.19 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.19 80\n");
Packit 6c4009
  check_ai ("t.alias.example", "80", AF_INET,
Packit 6c4009
            "address: STREAM/TCP 192.0.2.20 80\n"
Packit 6c4009
            "address: DGRAM/UDP 192.0.2.20 80\n"
Packit 6c4009
            "address: RAW/IP 192.0.2.20 80\n");
Packit 6c4009
  check_ai ("t.www.example", "80", AF_INET6,
Packit 6c4009
            "address: STREAM/TCP 2001:db8::3 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::3 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::3 80\n");
Packit 6c4009
  check_ai ("t.alias.example", "80", AF_INET6,
Packit 6c4009
            "address: STREAM/TCP 2001:db8::4 80\n"
Packit 6c4009
            "address: DGRAM/UDP 2001:db8::4 80\n"
Packit 6c4009
            "address: RAW/IP 2001:db8::4 80\n");
Packit 6c4009
Packit 6c4009
  test_bug_21295 ();
Packit 6c4009
  test_nodata_nxdomain ();
Packit 6c4009
Packit 6c4009
  resolv_test_end (aux);
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#include <support/test-driver.c>