blob: 2a5445355e08bb3cc57bfd950c8200d03c9f6c1a [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _RESOLV_CACHE_H_
29#define _RESOLV_CACHE_H_
30
31struct resolv_cache; /* forward */
32
Mattias Falk23d3e6b2011-04-04 16:12:35 +020033/* gets the cache for the default interface. Might be NULL*/
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034extern struct resolv_cache* __get_res_cache(void);
35
Mattias Falk23d3e6b2011-04-04 16:12:35 +020036/* get the cache for a specified interface. Can be NULL*/
37extern struct resolv_cache* __get_res_cache_for_iface(const char* ifname);
38
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039/* this gets called everytime we detect some changes in the DNS configuration
40 * and will flush the cache */
Mattias Falk23d3e6b2011-04-04 16:12:35 +020041extern void _resolv_cache_reset( unsigned generation );
42
43/* Gets the address of the n:th name server for the default interface
44 * Return length of address on success else 0.
45 * Note: The first name server is at n = 1 */
46extern int _resolv_cache_get_nameserver(int n, char* addr, int addrLen);
47
48/* Gets the address of the n:th name server for a certain interface
49 * Return length of address on success else 0.
50 * Note: The first name server is at n = 1 */
51extern int _resolv_cache_get_nameserver_for_iface(const char* ifname, int n,
52 char* addr, int addrLen);
53
54/* Gets addrinfo of the n:th name server associated with an interface.
55 * NULL is returned if no address if found.
56 * Note: The first name server is at n = 1. */
57extern struct addrinfo* _resolv_cache_get_nameserver_addr_for_iface(const char* ifname, int n);
58
59/* Gets addrinfo of the n:th name server associated with the default interface
60 * NULL is returned if no address if found.
61 * Note: The first name server is at n = 1. */
62extern struct addrinfo* _resolv_cache_get_nameserver_addr(int n);
63
64/* gets the address associated with the default interface */
65extern struct in_addr* _resolv_get_addr_of_default_iface();
66
67/* gets the address associated with the specified interface */
68extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
69
70/* Get name of default interface */
71extern char* _resolv_get_default_iface();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072
73typedef enum {
74 RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
75 /* or the answer buffer is too small */
76 RESOLV_CACHE_NOTFOUND, /* the cache doesn't know about this query */
77 RESOLV_CACHE_FOUND /* the cache found the answer */
78} ResolvCacheStatus;
79
80extern ResolvCacheStatus
81_resolv_cache_lookup( struct resolv_cache* cache,
82 const void* query,
83 int querylen,
84 void* answer,
85 int answersize,
86 int *answerlen );
87
88/* add a (query,answer) to the cache, only call if _resolv_cache_lookup
89 * did return RESOLV_CACHE_NOTFOUND
90 */
91extern void
92_resolv_cache_add( struct resolv_cache* cache,
93 const void* query,
94 int querylen,
95 const void* answer,
96 int answerlen );
97
98#endif /* _RESOLV_CACHE_H_ */