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 DATAFILE _PATH_HOSTS
37 unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
38 char *h_addr_ptrs[2]; /* Points to that and null terminator. */
41 #define TRAILING_LIST_MEMBER h_aliases
42 #define TRAILING_LIST_SEPARATOR_P isspace
43 #include "files-parse.c"
48 STRING_FIELD (addr, isspace, 1);
51 if ((_res.options & RES_USE_INET6)
52 && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
54 result->h_addrtype = AF_INET6;
55 result->h_length = IN6ADDRSZ;
57 else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
59 if (_res.options & RES_USE_INET6)
61 map_v4v6_address ((char *) entdata->host_addr,
62 (char *) entdata->host_addr);
63 result->h_addrtype = AF_INET6;
64 result->h_length = IN6ADDRSZ;
68 result->h_addrtype = AF_INET;
69 result->h_length = INADDRSZ;
73 /* Illegal address: ignore line. */
76 /* Store a pointer to the addressin the expected form. */
77 entdata->h_addr_ptrs[0] = entdata->host_addr;
78 entdata->h_addr_ptrs[1] = NULL;
79 result->h_addr_list = entdata->h_addr_ptrs;
81 /* If we need the host entry in IPv6 form change it now. */
82 if (_res.options & RES_USE_INET6)
84 char *bufptr = data->linebuffer;
85 int buflen = (char *) data + datalen - bufptr;
86 map_v4v6_hostent (result, &bufptr, &buflen);
89 STRING_FIELD (result->h_name, isspace, 1);
92 #include "files-XXX.c"
94 DB_LOOKUP (hostbyname,
97 if (! strcmp (name, result->h_name))
99 for (ap = result->h_aliases; *ap; ++ap)
100 if (! strcmp (name, *ap))
106 DB_LOOKUP (hostbyaddr,
108 if (result->h_addrtype == type && result->h_length == len &&
109 ! memcmp (addr, result->h_addr_list[0], len))
111 }, const char *addr, int len, int type)