1 /* Test getaddrinfo return value, [BZ #15339].
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
25 try (const char *service
, int family
, int flags
)
27 struct addrinfo hints
, *h
, *ai
;
30 memset (&hints
, 0, sizeof hints
);
31 hints
.ai_family
= family
;
32 hints
.ai_flags
= flags
;
35 h
= (family
|| flags
) ? &hints
: NULL
;
36 res
= getaddrinfo ("example.net", service
, h
, &ai
);
42 printf ("SUCCESS getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
43 service
?: "NULL", family
, flags
, gai_strerror (res
));
46 printf ("FAIL getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
47 service
?: "NULL", family
, flags
, gai_strerror (res
));
55 err
|= try (NULL
, 0, 0);
56 err
|= try (NULL
, AF_UNSPEC
, AI_ADDRCONFIG
);
57 err
|= try (NULL
, AF_INET
, 0);
58 err
|= try (NULL
, AF_INET6
, 0);
59 err
|= try ("http", 0, 0);
60 err
|= try ("http", AF_UNSPEC
, AI_ADDRCONFIG
);
61 err
|= try ("http", AF_INET
, 0);
62 err
|= try ("http", AF_INET6
, 0);
66 #define TEST_FUNCTION do_test ()
67 #include "../test-skeleton.c"