]>
Commit | Line | Data |
---|---|---|
5f0e6fc7 | 1 | /* Services file parser in nss_files module. |
04277e02 | 2 | Copyright (C) 1996-2019 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/>. */ |
28f540f4 | 18 | |
5f0e6fc7 RM |
19 | #include <netinet/in.h> |
20 | #include <netdb.h> | |
28f540f4 | 21 | |
5f0e6fc7 RM |
22 | |
23 | #define ENTNAME servent | |
96bda0ea | 24 | #define DATABASE "services" |
5f0e6fc7 RM |
25 | |
26 | struct servent_data {}; | |
27 | ||
28 | #define TRAILING_LIST_MEMBER s_aliases | |
29 | #define TRAILING_LIST_SEPARATOR_P isspace | |
30 | #include "files-parse.c" | |
31 | #define ISSLASH(c) ((c) == '/') | |
32 | LINE_PARSER | |
ffee1316 | 33 | ("#", |
5f0e6fc7 RM |
34 | STRING_FIELD (result->s_name, isspace, 1); |
35 | INT_FIELD (result->s_port, ISSLASH, 10, 0, htons); | |
36 | STRING_FIELD (result->s_proto, isspace, 1); | |
37 | ) | |
38 | ||
96bda0ea | 39 | #include GENERIC |
5f0e6fc7 | 40 | |
2666d441 UD |
41 | DB_LOOKUP (servbyname, ':', |
42 | strlen (name) + 2 + (proto == NULL ? 0 : strlen (proto)), | |
43 | ("%s/%s", name, proto ?: ""), | |
adc6ff7f | 44 | { |
e61abf83 UD |
45 | /* Must match both protocol (if specified) and name. */ |
46 | if (proto != NULL && strcmp (result->s_proto, proto)) | |
49698902 AO |
47 | /* A continue statement here breaks nss_db, because it |
48 | bypasses advancing to the next db entry, and it | |
49 | doesn't make nss_files any more efficient. */; | |
50 | else | |
51 | LOOKUP_NAME (s_name, s_aliases) | |
adc6ff7f RM |
52 | }, |
53 | const char *name, const char *proto) | |
5f0e6fc7 | 54 | |
2666d441 UD |
55 | DB_LOOKUP (servbyport, '=', 21 + (proto ? strlen (proto) : 0), |
56 | ("%zd/%s", (ssize_t) ntohs (port), proto ?: ""), | |
5f0e6fc7 | 57 | { |
14bab8de | 58 | /* Must match both port and protocol. */ |
4775243a | 59 | if (result->s_port == port |
ecb9d3e1 UD |
60 | && (proto == NULL |
61 | || strcmp (result->s_proto, proto) == 0)) | |
5f0e6fc7 | 62 | break; |
14bab8de | 63 | }, int port, const char *proto) |