2.9
[glibc/nacl-glibc.git] / nss / nss_files / files-network.c
blob9f4a3e032462fec64b370bc1d455308957b84132
1 /* Networks file parser in nss_files module.
2 Copyright (C) 1996, 1997, 1998, 2000, 2001 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <netdb.h>
24 #define ENTNAME netent
25 #define DATABASE "networks"
26 #define NEED_H_ERRNO
28 struct netent_data {};
30 #define TRAILING_LIST_MEMBER n_aliases
31 #define TRAILING_LIST_SEPARATOR_P isspace
32 #include "files-parse.c"
33 LINE_PARSER
34 ("#",
36 char *addr;
37 char *cp;
38 int n = 1;
40 STRING_FIELD (result->n_name, isspace, 1);
42 STRING_FIELD (addr, isspace, 1);
43 /* 'inet_network' does not add zeroes at the end if the network number
44 does not four byte values. We add them outselves if necessary. */
45 cp = strchr (addr, '.');
46 if (cp != NULL)
48 ++n;
49 cp = strchr (cp + 1, '.');
50 if (cp != NULL)
52 ++n;
53 cp = strchr (cp + 1, '.');
54 if (cp != NULL)
55 ++n;
58 if (n < 4)
60 char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
61 cp = stpcpy (newp, addr);
64 *cp++ = '.';
65 *cp++ = '0';
67 while (++n < 4);
68 *cp = '\0';
69 addr = newp;
71 result->n_net = inet_network (addr);
72 result->n_addrtype = AF_INET;
76 #include "files-XXX.c"
78 DB_LOOKUP (netbyname, ,,
79 LOOKUP_NAME_CASE (n_name, n_aliases),
80 const char *name)
82 DB_LOOKUP (netbyaddr, ,,
84 if (result->n_addrtype == type && result->n_net == net)
85 /* Bingo! */
86 break;
87 }, uint32_t net, int type)