Update.
[glibc.git] / nss / nss_files / files-service.c
blob369b27bf240a14d4d55cc3a7425898d821e7207a
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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 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)