Blame resolv/tst-inet_aton_exact.c

Packit Service 50534c
/* Test internal legacy IPv4 text-to-address function __inet_aton_exact.
Packit Service 50534c
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Service 50534c
   This file is part of the GNU C Library.
Packit Service 50534c
Packit Service 50534c
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 50534c
   modify it under the terms of the GNU Lesser General Public
Packit Service 50534c
   License as published by the Free Software Foundation; either
Packit Service 50534c
   version 2.1 of the License, or (at your option) any later version.
Packit Service 50534c
Packit Service 50534c
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 50534c
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 50534c
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 50534c
   Lesser General Public License for more details.
Packit Service 50534c
Packit Service 50534c
   You should have received a copy of the GNU Lesser General Public
Packit Service 50534c
   License along with the GNU C Library; if not, see
Packit Service 50534c
   <http://www.gnu.org/licenses/>.  */
Packit Service 50534c
Packit Service 50534c
#include <arpa/inet.h>
Packit Service 50534c
#include <support/check.h>
Packit Service 50534c
Packit Service 50534c
static int
Packit Service 50534c
do_test (void)
Packit Service 50534c
{
Packit Service 50534c
  struct in_addr addr = { };
Packit Service 50534c
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.1", &addr), 1);
Packit Service 50534c
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000201);
Packit Service 50534c
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.000.002.010", &addr), 1);
Packit Service 50534c
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000208);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("0xC0000234", &addr), 1);
Packit Service 50534c
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000234);
Packit Service 50534c
Packit Service 50534c
  /* Trailing content is not accepted.  */
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.2X", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.3 Y", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.4\nZ", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.5\tT", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.6 Y", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.7\n", &addr), 0);
Packit Service 50534c
  TEST_COMPARE (__inet_aton_exact ("192.0.2.8\t", &addr), 0);
Packit Service 50534c
Packit Service 50534c
  return 0;
Packit Service 50534c
}
Packit Service 50534c
Packit Service 50534c
#include <support/test-driver.c>