]>
Commit | Line | Data |
---|---|---|
5f0e6fc7 | 1 | /* Networks file parser in nss_files module. |
d614a753 | 2 | Copyright (C) 1996-2020 Free Software Foundation, Inc. |
19361cb7 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
19361cb7 UD |
9 | |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
19361cb7 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
5f0e6fc7 RM |
18 | |
19 | #include <netinet/in.h> | |
20 | #include <arpa/inet.h> | |
21 | #include <netdb.h> | |
e054f494 | 22 | #include <stdint.h> |
680f1093 FW |
23 | #include <nss.h> |
24 | ||
25 | NSS_DECLARE_MODULE_FUNCTIONS (files) | |
5f0e6fc7 RM |
26 | |
27 | #define ENTNAME netent | |
96bda0ea | 28 | #define DATABASE "networks" |
51eecc4a | 29 | #define NEED_H_ERRNO |
5f0e6fc7 RM |
30 | |
31 | struct netent_data {}; | |
32 | ||
33 | #define TRAILING_LIST_MEMBER n_aliases | |
34 | #define TRAILING_LIST_SEPARATOR_P isspace | |
35 | #include "files-parse.c" | |
36 | LINE_PARSER | |
ffee1316 RM |
37 | ("#", |
38 | { | |
39 | char *addr; | |
9d0881aa UD |
40 | char *cp; |
41 | int n = 1; | |
5f0e6fc7 | 42 | |
ffee1316 | 43 | STRING_FIELD (result->n_name, isspace, 1); |
5f0e6fc7 | 44 | |
ffee1316 | 45 | STRING_FIELD (addr, isspace, 1); |
9d0881aa UD |
46 | /* 'inet_network' does not add zeroes at the end if the network number |
47 | does not four byte values. We add them outselves if necessary. */ | |
48 | cp = strchr (addr, '.'); | |
49 | if (cp != NULL) | |
50 | { | |
51 | ++n; | |
52 | cp = strchr (cp + 1, '.'); | |
53 | if (cp != NULL) | |
54 | { | |
55 | ++n; | |
56 | cp = strchr (cp + 1, '.'); | |
57 | if (cp != NULL) | |
58 | ++n; | |
59 | } | |
60 | } | |
61 | if (n < 4) | |
62 | { | |
63 | char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1); | |
64 | cp = stpcpy (newp, addr); | |
65 | do | |
66 | { | |
67 | *cp++ = '.'; | |
68 | *cp++ = '0'; | |
69 | } | |
70 | while (++n < 4); | |
71 | *cp = '\0'; | |
72 | addr = newp; | |
73 | } | |
ffee1316 | 74 | result->n_net = inet_network (addr); |
af69217f | 75 | result->n_addrtype = AF_INET; |
5f0e6fc7 | 76 | |
ffee1316 | 77 | }) |
5f0e6fc7 RM |
78 | |
79 | #include "files-XXX.c" | |
80 | ||
2666d441 | 81 | DB_LOOKUP (netbyname, ,,, |
74015205 | 82 | LOOKUP_NAME_CASE (n_name, n_aliases), |
5f0e6fc7 RM |
83 | const char *name) |
84 | ||
2666d441 | 85 | DB_LOOKUP (netbyaddr, ,,, |
5f0e6fc7 | 86 | { |
29ba9812 | 87 | if ((type == AF_UNSPEC || result->n_addrtype == type) |
5cd1f906 | 88 | && result->n_net == net) |
5f0e6fc7 RM |
89 | /* Bingo! */ |
90 | break; | |
9b48fa9b | 91 | }, uint32_t net, int type) |