2.9.90-4
[glibc/history.git] / nss / nss_files / files-service.c
blob13532ddc9bab42ed868b494b4b4353e8ed7eea5e
1 /* Services file parser in nss_files module.
2 Copyright (C) 1996, 1997, 1998 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 <netdb.h>
24 #define ENTNAME servent
25 #define DATABASE "services"
27 struct servent_data {};
29 #define TRAILING_LIST_MEMBER s_aliases
30 #define TRAILING_LIST_SEPARATOR_P isspace
31 #include "files-parse.c"
32 #define ISSLASH(c) ((c) == '/')
33 LINE_PARSER
34 ("#",
35 STRING_FIELD (result->s_name, isspace, 1);
36 INT_FIELD (result->s_port, ISSLASH, 10, 0, htons);
37 STRING_FIELD (result->s_proto, isspace, 1);
40 #include GENERIC
42 DB_LOOKUP (servbyname, 2 + strlen (name) + (proto ? strlen (proto) : 0),
43 (".%s/%s", name, proto ?: ""),
45 /* Must match both protocol (if specified) and name. */
46 if (proto != NULL && strcmp (result->s_proto, proto))
47 continue;
48 LOOKUP_NAME (s_name, s_aliases)
50 const char *name, const char *proto)
52 DB_LOOKUP (servbyport, 21 + (proto ? strlen (proto) : 0),
53 ("=%d/%s", ntohs (port), proto ?: ""),
55 /* Must match both port and protocol. */
56 if (result->s_port == port
57 && (proto == NULL
58 || strcmp (result->s_proto, proto) == 0))
59 break;
60 }, int port, const char *proto)