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"
35 #define ENTDATA hostent_data
38 unsigned char host_addr
[16]; /* IPv4 or IPv6 address. */
39 char *h_addr_ptrs
[2]; /* Points to that and null terminator. */
42 #define TRAILING_LIST_MEMBER h_aliases
43 #define TRAILING_LIST_SEPARATOR_P isspace
44 #include "files-parse.c"
50 STRING_FIELD (addr
, isspace
, 1);
53 if ((_res
.options
& RES_USE_INET6
)
54 && inet_pton (AF_INET6
, addr
, entdata
->host_addr
) > 0)
56 result
->h_addrtype
= AF_INET6
;
57 result
->h_length
= IN6ADDRSZ
;
59 else if (inet_pton (AF_INET
, addr
, entdata
->host_addr
) > 0)
61 if (_res
.options
& RES_USE_INET6
)
63 map_v4v6_address ((char *) entdata
->host_addr
,
64 (char *) entdata
->host_addr
);
65 result
->h_addrtype
= AF_INET6
;
66 result
->h_length
= IN6ADDRSZ
;
70 result
->h_addrtype
= AF_INET
;
71 result
->h_length
= INADDRSZ
;
75 /* Illegal address: ignore line. */
78 /* Store a pointer to the address in the expected form. */
79 entdata
->h_addr_ptrs
[0] = entdata
->host_addr
;
80 entdata
->h_addr_ptrs
[1] = NULL
;
81 result
->h_addr_list
= entdata
->h_addr_ptrs
;
83 /* If we need the host entry in IPv6 form change it now. */
84 if (_res
.options
& RES_USE_INET6
)
86 char *bufptr
= data
->linebuffer
;
87 int buflen
= (char *) data
+ datalen
- bufptr
;
88 map_v4v6_hostent (result
, &bufptr
, &buflen
);
91 STRING_FIELD (result
->h_name
, isspace
, 1);
94 #include "files-XXX.c"
96 DB_LOOKUP (hostbyname
, ,,
97 LOOKUP_NAME (h_name
, h_aliases
),
100 DB_LOOKUP (hostbyaddr
, ,,
102 if (result
->h_addrtype
== type
&& result
->h_length
== len
&&
103 ! memcmp (addr
, result
->h_addr_list
[0], len
))
105 }, const char *addr
, int len
, int type
)