Blame nss/nss_files/files-service.c

Packit 6c4009
/* Services file parser in nss_files module.
Packit 6c4009
   Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <netinet/in.h>
Packit 6c4009
#include <netdb.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
#define ENTNAME		servent
Packit 6c4009
#define DATABASE	"services"
Packit 6c4009
Packit 6c4009
struct servent_data {};
Packit 6c4009
Packit 6c4009
#define TRAILING_LIST_MEMBER		s_aliases
Packit 6c4009
#define TRAILING_LIST_SEPARATOR_P	isspace
Packit 6c4009
#include "files-parse.c"
Packit 6c4009
#define ISSLASH(c) ((c) == '/')
Packit 6c4009
LINE_PARSER
Packit 6c4009
("#",
Packit 6c4009
 STRING_FIELD (result->s_name, isspace, 1);
Packit 6c4009
 INT_FIELD (result->s_port, ISSLASH, 10, 0, htons);
Packit 6c4009
 STRING_FIELD (result->s_proto, isspace, 1);
Packit 6c4009
 )
Packit 6c4009
Packit 6c4009
#include GENERIC
Packit 6c4009
Packit 6c4009
DB_LOOKUP (servbyname, ':',
Packit 6c4009
	   strlen (name) + 2 + (proto == NULL ? 0 : strlen (proto)),
Packit 6c4009
	   ("%s/%s", name, proto ?: ""),
Packit 6c4009
	   {
Packit 6c4009
	     /* Must match both protocol (if specified) and name.  */
Packit 6c4009
	     if (proto != NULL && strcmp (result->s_proto, proto))
Packit 6c4009
	       /* A continue statement here breaks nss_db, because it
Packit 6c4009
		bypasses advancing to the next db entry, and it
Packit 6c4009
		doesn't make nss_files any more efficient.  */;
Packit 6c4009
	     else
Packit 6c4009
	       LOOKUP_NAME (s_name, s_aliases)
Packit 6c4009
	   },
Packit 6c4009
	   const char *name, const char *proto)
Packit 6c4009
Packit 6c4009
DB_LOOKUP (servbyport, '=', 21 + (proto ? strlen (proto) : 0),
Packit 6c4009
	   ("%zd/%s", (ssize_t) ntohs (port), proto ?: ""),
Packit 6c4009
	   {
Packit 6c4009
	     /* Must match both port and protocol.  */
Packit 6c4009
	     if (result->s_port == port
Packit 6c4009
		 && (proto == NULL
Packit 6c4009
		     || strcmp (result->s_proto, proto) == 0))
Packit 6c4009
	       break;
Packit 6c4009
	   }, int port, const char *proto)