Updated to fedora-glibc-20050627T0850
[glibc.git] / glibc-compat / nss_files / files-hosts.c
blob1b96f74b35ab6d0731ae0a1ed69d1357146b83af
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>
23 #include <glibc-compat/include/netdb.h>
24 #include <resolv.h>
27 /* Get implementation for some internal functions. */
28 #include "../resolv/mapv4v6addr.h"
31 #define ENTNAME hostent
32 #define DATABASE "hosts"
33 #define NEED_H_ERRNO
35 #define ENTDATA hostent_data
36 struct 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"
45 LINE_PARSER
46 ("#",
48 char *addr;
50 STRING_FIELD (addr, isspace, 1);
52 /* Parse address. */
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;
62 else
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;
73 else
74 /* Illegal address: ignore line. */
75 return 0;
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))
91 continue;
92 LOOKUP_NAME_CASE (h_name, h_aliases)
93 }, const char *name)
95 DB_LOOKUP (hostbyname2, ,,
97 if (result->h_addrtype != af)
98 continue;
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))
106 break;
107 }, const char *addr, int len, int type)