1 /* Services file parser in nss_files module.
2 Copyright (C) 1996-2013 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <netinet/in.h>
23 #define ENTNAME servent
24 #define DATABASE "services"
26 struct servent_data
{};
28 #define TRAILING_LIST_MEMBER s_aliases
29 #define TRAILING_LIST_SEPARATOR_P isspace
30 #include "files-parse.c"
31 #define ISSLASH(c) ((c) == '/')
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);
41 DB_LOOKUP (servbyname
, ':',
42 strlen (name
) + 2 + (proto
== NULL
? 0 : strlen (proto
)),
43 ("%s/%s", name
, proto
?: ""),
45 /* Must match both protocol (if specified) and name. */
46 if (proto
!= NULL
&& strcmp (result
->s_proto
, proto
))
48 LOOKUP_NAME (s_name
, s_aliases
)
50 const char *name
, const char *proto
)
52 DB_LOOKUP (servbyport
, '=', 21 + (proto
? strlen (proto
) : 0),
53 ("%zd/%s", (ssize_t
) ntohs (port
), proto
?: ""),
55 /* Must match both port and protocol. */
56 if (result
->s_port
== port
58 || strcmp (result
->s_proto
, proto
) == 0))
60 }, int port
, const char *proto
)