powerpc64: Fix by using the configure value $libc_cv_cc_submachine [BZ #31629]
[glibc.git] / nss / nss_files / files-network.c
blob90a048b44e73688944683794599e0ae8868319b3
1 /* Networks file parser in nss_files module.
2 Copyright (C) 1996-2024 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/>. */
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <netdb.h>
22 #include <stdint.h>
23 #include <nss.h>
25 #define ENTNAME netent
26 #define DATABASE "networks"
27 #define NEED_H_ERRNO
29 struct netent_data {};
31 #define TRAILING_LIST_MEMBER n_aliases
32 #define TRAILING_LIST_SEPARATOR_P isspace
33 #include "files-parse.c"
34 LINE_PARSER
35 ("#",
37 char *addr;
38 char *cp;
39 int n = 1;
41 STRING_FIELD (result->n_name, isspace, 1);
43 STRING_FIELD (addr, isspace, 1);
44 /* 'inet_network' does not add zeroes at the end if the network number
45 does not four byte values. We add them ourselves if necessary. */
46 cp = strchr (addr, '.');
47 if (cp != NULL)
49 ++n;
50 cp = strchr (cp + 1, '.');
51 if (cp != NULL)
53 ++n;
54 cp = strchr (cp + 1, '.');
55 if (cp != NULL)
56 ++n;
59 if (n < 4)
61 char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
62 cp = stpcpy (newp, addr);
65 *cp++ = '.';
66 *cp++ = '0';
68 while (++n < 4);
69 *cp = '\0';
70 addr = newp;
72 result->n_net = __inet_network (addr);
73 result->n_addrtype = AF_INET;
77 #include "files-XXX.c"
79 DB_LOOKUP (netbyname, ,,,
80 LOOKUP_NAME_CASE (n_name, n_aliases),
81 const char *name)
83 DB_LOOKUP (netbyaddr, ,,,
85 if ((type == AF_UNSPEC || result->n_addrtype == type)
86 && result->n_net == net)
87 /* Bingo! */
88 break;
89 }, uint32_t net, int type)