|
Packit |
6c4009 |
/* Networks 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 <arpa/inet.h>
|
|
Packit |
6c4009 |
#include <netdb.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define ENTNAME netent
|
|
Packit |
6c4009 |
#define DATABASE "networks"
|
|
Packit |
6c4009 |
#define NEED_H_ERRNO
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct netent_data {};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TRAILING_LIST_MEMBER n_aliases
|
|
Packit |
6c4009 |
#define TRAILING_LIST_SEPARATOR_P isspace
|
|
Packit |
6c4009 |
#include "files-parse.c"
|
|
Packit |
6c4009 |
LINE_PARSER
|
|
Packit |
6c4009 |
("#",
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char *addr;
|
|
Packit |
6c4009 |
char *cp;
|
|
Packit |
6c4009 |
int n = 1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
STRING_FIELD (result->n_name, isspace, 1);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
STRING_FIELD (addr, isspace, 1);
|
|
Packit |
6c4009 |
/* 'inet_network' does not add zeroes at the end if the network number
|
|
Packit |
6c4009 |
does not four byte values. We add them outselves if necessary. */
|
|
Packit |
6c4009 |
cp = strchr (addr, '.');
|
|
Packit |
6c4009 |
if (cp != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
++n;
|
|
Packit |
6c4009 |
cp = strchr (cp + 1, '.');
|
|
Packit |
6c4009 |
if (cp != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
++n;
|
|
Packit |
6c4009 |
cp = strchr (cp + 1, '.');
|
|
Packit |
6c4009 |
if (cp != NULL)
|
|
Packit |
6c4009 |
++n;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (n < 4)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
|
|
Packit |
6c4009 |
cp = stpcpy (newp, addr);
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
*cp++ = '.';
|
|
Packit |
6c4009 |
*cp++ = '0';
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (++n < 4);
|
|
Packit |
6c4009 |
*cp = '\0';
|
|
Packit |
6c4009 |
addr = newp;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
result->n_net = inet_network (addr);
|
|
Packit |
6c4009 |
result->n_addrtype = AF_INET;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "files-XXX.c"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
DB_LOOKUP (netbyname, ,,,
|
|
Packit |
6c4009 |
LOOKUP_NAME_CASE (n_name, n_aliases),
|
|
Packit |
6c4009 |
const char *name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
DB_LOOKUP (netbyaddr, ,,,
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if ((type == AF_UNSPEC || result->n_addrtype == type)
|
|
Packit |
6c4009 |
&& result->n_net == net)
|
|
Packit |
6c4009 |
/* Bingo! */
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
}, uint32_t net, int type)
|