1 /* Hosts file parser in nss_files module.
2 Copyright (C) 1996 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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <arpa/nameser.h>
27 /* Get implementation for some internal functions. */
28 #include "../resolv/mapv4v6addr.h"
29 #include "../resolv/mapv4v6hostent.h"
32 #define ENTNAME hostent
33 #define DATABASE "hosts"
36 #define ENTDATA hostent_data
39 unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
40 char *h_addr_ptrs[2]; /* Points to that and null terminator. */
43 #define TRAILING_LIST_MEMBER h_aliases
44 #define TRAILING_LIST_SEPARATOR_P isspace
45 #include "files-parse.c"
51 STRING_FIELD (addr, isspace, 1);
54 if ((_res.options & RES_USE_INET6)
55 && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
57 result->h_addrtype = AF_INET6;
58 result->h_length = IN6ADDRSZ;
60 else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
62 if (_res.options & RES_USE_INET6)
64 map_v4v6_address ((char *) entdata->host_addr,
65 (char *) entdata->host_addr);
66 result->h_addrtype = AF_INET6;
67 result->h_length = IN6ADDRSZ;
71 result->h_addrtype = AF_INET;
72 result->h_length = INADDRSZ;
76 /* Illegal address: ignore line. */
79 /* Store a pointer to the address in the expected form. */
80 entdata->h_addr_ptrs[0] = entdata->host_addr;
81 entdata->h_addr_ptrs[1] = NULL;
82 result->h_addr_list = entdata->h_addr_ptrs;
84 /* If we need the host entry in IPv6 form change it now. */
85 if (_res.options & RES_USE_INET6)
87 char *bufptr = data->linebuffer;
88 int buflen = (char *) data + datalen - bufptr;
89 map_v4v6_hostent (result, &bufptr, &buflen);
92 STRING_FIELD (result->h_name, isspace, 1);
95 #include "files-XXX.c"
97 DB_LOOKUP (hostbyname, ,,
98 LOOKUP_NAME (h_name, h_aliases),
101 DB_LOOKUP (hostbyaddr, ,,
103 if (result->h_addrtype == type && result->h_length == len &&
104 ! memcmp (addr, result->h_addr_list[0], len))
106 }, const char *addr, int len, int type)