Rename LDFLAGS-XXX to LDLIBS-XXX for -lstdc++
[glibc.git] / nss / nss_files / files-network.c
blob7cd688f3bf58a9d22642ea13cf4a5b22fd0208d3
1 /* Networks file parser in nss_files module.
2 Copyright (C) 1996-1998, 2000, 2001, 2009, 2011 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 <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <netdb.h>
23 #define ENTNAME netent
24 #define DATABASE "networks"
25 #define NEED_H_ERRNO
27 struct netent_data {};
29 #define TRAILING_LIST_MEMBER n_aliases
30 #define TRAILING_LIST_SEPARATOR_P isspace
31 #include "files-parse.c"
32 LINE_PARSER
33 ("#",
35 char *addr;
36 char *cp;
37 int n = 1;
39 STRING_FIELD (result->n_name, isspace, 1);
41 STRING_FIELD (addr, isspace, 1);
42 /* 'inet_network' does not add zeroes at the end if the network number
43 does not four byte values. We add them outselves if necessary. */
44 cp = strchr (addr, '.');
45 if (cp != NULL)
47 ++n;
48 cp = strchr (cp + 1, '.');
49 if (cp != NULL)
51 ++n;
52 cp = strchr (cp + 1, '.');
53 if (cp != NULL)
54 ++n;
57 if (n < 4)
59 char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
60 cp = stpcpy (newp, addr);
63 *cp++ = '.';
64 *cp++ = '0';
66 while (++n < 4);
67 *cp = '\0';
68 addr = newp;
70 result->n_net = inet_network (addr);
71 result->n_addrtype = AF_INET;
75 #include "files-XXX.c"
77 DB_LOOKUP (netbyname, ,,,
78 LOOKUP_NAME_CASE (n_name, n_aliases),
79 const char *name)
81 DB_LOOKUP (netbyaddr, ,,,
83 if ((type == AF_UNSPEC || result->n_addrtype == type)
84 && result->n_net == net)
85 /* Bingo! */
86 break;
87 }, uint32_t net, int type)