1/* Test internal legacy IPv4 text-to-address function __inet_aton_exact.
2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19#include <arpa/inet.h>
20#include <support/check.h>
21
22static int
23do_test (void)
24{
25 struct in_addr addr = { };
26
27 TEST_COMPARE (__inet_aton_exact ("192.0.2.1", &addr), 1);
28 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000201);
29
30 TEST_COMPARE (__inet_aton_exact ("192.000.002.010", &addr), 1);
31 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000208);
32 TEST_COMPARE (__inet_aton_exact ("0xC0000234", &addr), 1);
33 TEST_COMPARE (ntohl (addr.s_addr), 0xC0000234);
34
35 /* Trailing content is not accepted. */
36 TEST_COMPARE (__inet_aton_exact ("192.0.2.2X", &addr), 0);
37 TEST_COMPARE (__inet_aton_exact ("192.0.2.3 Y", &addr), 0);
38 TEST_COMPARE (__inet_aton_exact ("192.0.2.4\nZ", &addr), 0);
39 TEST_COMPARE (__inet_aton_exact ("192.0.2.5\tT", &addr), 0);
40 TEST_COMPARE (__inet_aton_exact ("192.0.2.6 Y", &addr), 0);
41 TEST_COMPARE (__inet_aton_exact ("192.0.2.7\n", &addr), 0);
42 TEST_COMPARE (__inet_aton_exact ("192.0.2.8\t", &addr), 0);
43
44 return 0;
45}
46
47#include <support/test-driver.c>
48

source code of glibc/resolv/tst-inet_aton_exact.c