1 /* Hosts file parser in nss_files module.
2 Copyright (C) 1996, 1997, 1998 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 not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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"
31 #define ENTNAME hostent
32 #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 (inet_pton (AF_INET
, addr
, entdata
->host_addr
) > 0)
55 if (_res
.options
& RES_USE_INET6
)
57 map_v4v6_address ((char *) entdata
->host_addr
,
58 (char *) entdata
->host_addr
);
59 result
->h_addrtype
= AF_INET6
;
60 result
->h_length
= IN6ADDRSZ
;
64 result
->h_addrtype
= AF_INET
;
65 result
->h_length
= INADDRSZ
;
68 else if (inet_pton (AF_INET6
, addr
, entdata
->host_addr
) > 0)
70 result
->h_addrtype
= AF_INET6
;
71 result
->h_length
= IN6ADDRSZ
;
74 /* Illegal address: ignore line. */
77 /* Store a pointer to the address in the expected form. */
78 entdata
->h_addr_ptrs
[0] = entdata
->host_addr
;
79 entdata
->h_addr_ptrs
[1] = NULL
;
80 result
->h_addr_list
= entdata
->h_addr_ptrs
;
82 STRING_FIELD (result
->h_name
, isspace
, 1);
85 #include "files-XXX.c"
87 DB_LOOKUP (hostbyname
, ,,
89 if (result
->h_addrtype
!= ((_res
.options
& RES_USE_INET6
)
90 ? AF_INET6
: AF_INET
))
92 LOOKUP_NAME_CASE (h_name
, h_aliases
)
95 DB_LOOKUP (hostbyname2
, ,,
97 if (result
->h_addrtype
!= af
)
99 LOOKUP_NAME_CASE (h_name
, h_aliases
)
100 }, const char *name
, int af
)
102 DB_LOOKUP (hostbyaddr
, ,,
104 if (result
->h_addrtype
== type
&& result
->h_length
== len
&&
105 ! memcmp (addr
, result
->h_addr_list
[0], len
))
107 }, const char *addr
, int len
, int type
)