Blame resolv/tst-inet_aton_exact.c

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