1 /* Convert a struct netent object to a string.
2 Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>. */
19 #include <support/format_nss.h>
21 #include <arpa/inet.h>
23 #include <support/support.h>
24 #include <support/xmemstream.h>
27 support_format_netent (struct netent
*e
)
31 char *value
= support_format_herrno (h_errno
);
32 char *result
= xasprintf ("error: %s\n", value
);
37 struct xmemstream mem
;
38 xopen_memstream (&mem
);
40 if (e
->n_name
!= NULL
)
41 fprintf (mem
.out
, "name: %s\n", e
->n_name
);
42 for (char **ap
= e
->n_aliases
; *ap
!= NULL
; ++ap
)
43 fprintf (mem
.out
, "alias: %s\n", *ap
);
44 if (e
->n_addrtype
!= AF_INET
)
45 fprintf (mem
.out
, "addrtype: %d\n", e
->n_addrtype
);
46 /* On alpha, e->n_net is an unsigned long. */
47 unsigned int n_net
= e
->n_net
;
48 fprintf (mem
.out
, "net: 0x%08x\n", n_net
);
50 xfclose_memstream (&mem
);