#include <dlfcn.h>
#include <gnu/lib-names.h>
+#include <netdb.h>
#include <nss.h>
#include <stdio.h>
#include <stdlib.h>
0, depending on whether a UTF-8 locale is used or a Latin-1
locale. */
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
<https://www.gnu.org/licenses/>. */
#include <errno.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <netdb.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <netdb.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <netdb.h>
#include <resolv.h>
#include <support/check.h>
#include <support/resolv_test.h>
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <netdb.h>
#include <resolv.h>
#include <support/check.h>
#include <support/resolv_test.h>
#include <resolv_context.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <support/check.h>
#include <support/check_nss.h>
support_can_chroot \
support_capture_subprocess \
support_capture_subprocess_check \
+ support_check_nss \
support_check_stat_fd \
support_check_stat_path \
support_chroot \
#include <support/check_nss.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <support/check.h>
#include <support/format_nss.h>
-#include <support/run_diff.h>
void
-check_addrinfo (const char *query_description, struct addrinfo *ai, int ret,
- const char *expected)
+check_addrinfo (const char *query_description, const struct addrinfo *ai,
+ int ret, const char *expected)
{
char *formatted = support_format_addrinfo (ai, ret);
- if (strcmp (formatted, expected) != 0)
- {
- support_record_failure ();
- printf ("error: addrinfo comparison failure\n");
- if (query_description != NULL)
- printf ("query: %s\n", query_description);
- support_run_diff ("expected", expected,
- "actual", formatted);
- }
- free (formatted);
+ support_check_nss (query_description, "addrinfo", formatted, expected);
}
#include <support/check_nss.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <support/check.h>
#include <support/format_nss.h>
-#include <support/run_diff.h>
void
check_dns_packet (const char *query_description,
const char *expected)
{
char *formatted = support_format_dns_packet (buffer, length);
- if (strcmp (formatted, expected) != 0)
- {
- support_record_failure ();
- printf ("error: packet comparison failure\n");
- if (query_description != NULL)
- printf ("query: %s\n", query_description);
- support_run_diff ("expected", expected, "actual", formatted);
- }
- free (formatted);
+ support_check_nss (query_description, "packet", formatted, expected);
}
#include <support/check_nss.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <support/check.h>
#include <support/format_nss.h>
-#include <support/run_diff.h>
void
-check_hostent (const char *query_description, struct hostent *h,
+check_hostent (const char *query_description, const struct hostent *h,
const char *expected)
{
char *formatted = support_format_hostent (h);
- if (strcmp (formatted, expected) != 0)
- {
- support_record_failure ();
- printf ("error: hostent comparison failure\n");
- if (query_description != NULL)
- printf ("query: %s\n", query_description);
- support_run_diff ("expected", expected,
- "actual", formatted);
- }
- free (formatted);
+ support_check_nss (query_description, "hostent", formatted, expected);
}
#include <support/check_nss.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <support/check.h>
#include <support/format_nss.h>
-#include <support/run_diff.h>
void
-check_netent (const char *query_description, struct netent *e,
+check_netent (const char *query_description, const struct netent *e,
const char *expected)
{
char *formatted = support_format_netent (e);
- if (strcmp (formatted, expected) != 0)
- {
- support_record_failure ();
- printf ("error: netent comparison failure\n");
- if (query_description != NULL)
- printf ("query: %s\n", query_description);
- support_run_diff ("expected", expected,
- "actual", formatted);
- }
- free (formatted);
+ support_check_nss (query_description, "netent", formatted, expected);
}
#ifndef SUPPORT_CHECK_NSS_H
#define SUPPORT_CHECK_NSS_H
-#include <netdb.h>
#include <sys/cdefs.h>
+#include <stddef.h>
__BEGIN_DECLS
+struct addrinfo;
+struct hostent;
+struct netent;
+
/* Compare the data structures against the expected values (which have
to be formatted according to the support_format_* functions in
<support/format_nss.h>). If there is a difference, a delayed test
failure is recorded, and a diff is written to standard output. */
void check_addrinfo (const char *query_description,
- struct addrinfo *, int ret, const char *expected);
+ const struct addrinfo *, int ret, const char *expected);
void check_dns_packet (const char *query_description,
const unsigned char *, size_t, const char *expected);
void check_hostent (const char *query_description,
- struct hostent *, const char *expected);
+ const struct hostent *, const char *expected);
void check_netent (const char *query_description,
- struct netent *, const char *expected);
+ const struct netent *, const char *expected);
+
+/* Helper routine for implementing the functions above. Report an
+ error if ACTUAL and EXPECTED are not equal. ACTUAL is always freed. */
+void support_check_nss (const char *query_description,
+ const char *type_name,
+ char *actual, const char *expected);
__END_DECLS
#ifndef SUPPORT_FORMAT_NSS_H
#define SUPPORT_FORMAT_NSS_H
-#include <netdb.h>
#include <sys/cdefs.h>
+#include <stddef.h>
__BEGIN_DECLS
+struct addrinfo;
+struct hostent;
+struct netent;
+
/* The following functions format their arguments as human-readable
strings (which can span multiple lines). The caller must free the
returned buffer. For NULL pointers or failure status arguments,
error variables such as h_errno and errno are included in the
result. */
char *support_format_address_family (int);
-char *support_format_addrinfo (struct addrinfo *, int ret);
+char *support_format_addrinfo (const struct addrinfo *, int ret);
char *support_format_dns_packet (const unsigned char *buffer, size_t length);
char *support_format_herrno (int);
-char *support_format_hostent (struct hostent *);
-char *support_format_netent (struct netent *);
+char *support_format_hostent (const struct hostent *);
+char *support_format_netent (const struct netent *);
__END_DECLS
--- /dev/null
+/* Report a NSS struct comparison failure.
+ Copyright (C) 2016-2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <support/check_nss.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/run_diff.h>
+
+void
+support_check_nss (const char *query_description, const char *type_name,
+ char *actual, const char *expected)
+{
+ if (strcmp (actual, expected) != 0)
+ {
+ support_record_failure ();
+ printf ("error: %s comparison failure\n", type_name);
+ if (query_description != NULL)
+ printf ("query: %s\n", query_description);
+ support_run_diff ("expected", expected,
+ "actual", actual);
+ }
+ free (actual);
+}
#include <support/format_nss.h>
+#include <netdb.h>
#include <support/support.h>
char *
#include <arpa/inet.h>
#include <errno.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
static void
-format_ai_flags_1 (FILE *out, struct addrinfo *ai, int flag, const char *name,
- int * flags_printed)
+format_ai_flags_1 (FILE *out, const struct addrinfo *ai, int flag,
+ const char *name, int *flags_printed)
{
if ((ai->ai_flags & flag) != 0)
fprintf (out, " %s", name);
}
static void
-format_ai_flags (FILE *out, struct addrinfo *ai)
+format_ai_flags (FILE *out, const struct addrinfo *ai)
{
if (ai == NULL)
return;
}
static void
-format_ai_canonname (FILE *out, struct addrinfo *ai)
+format_ai_canonname (FILE *out, const struct addrinfo *ai)
{
if (ai == NULL)
return;
}
static void
-format_ai_one (FILE *out, struct addrinfo *ai)
+format_ai_one (FILE *out, const struct addrinfo *ai)
{
{
char type_buf[32];
/* Format all the addresses in one address family. */
static void
-format_ai_family (FILE *out, struct addrinfo *ai, int family)
+format_ai_family (FILE *out, const struct addrinfo *ai, int family)
{
while (ai)
{
}
char *
-support_format_addrinfo (struct addrinfo *ai, int ret)
+support_format_addrinfo (const struct addrinfo *ai, int ret)
{
int errno_copy = errno;
#include <support/format_nss.h>
+#include <netdb.h>
#include <support/support.h>
char *
#include <arpa/inet.h>
#include <errno.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/support.h>
}
char *
-support_format_hostent (struct hostent *h)
+support_format_hostent (const struct hostent *h)
{
if (h == NULL)
{
#include <support/format_nss.h>
#include <arpa/inet.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/support.h>
#include <support/xmemstream.h>
char *
-support_format_netent (struct netent *e)
+support_format_netent (const struct netent *e)
{
if (e == NULL)
{