Merge branch 'master' of gnunet.org:gnunet
[oweals/gnunet.git] / src / gns / nss / nss_gns_query.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef NSS_GNS_QUERY_H
19 #define NSS_GNS_QUERY_H
20
21 /**
22  * Parts taken from nss-mdns
23  */
24 #include <inttypes.h>
25
26 /* Maximum number of entries to return */
27 #define MAX_ENTRIES 16
28
29 typedef struct {
30     uint32_t address;
31 } ipv4_address_t;
32
33 typedef struct {
34     uint8_t address[16];
35 } ipv6_address_t;
36
37
38 struct userdata {
39   int count;
40   int data_len; /* only valid when doing reverse lookup */
41   union  {
42       ipv4_address_t ipv4[MAX_ENTRIES];
43       ipv6_address_t ipv6[MAX_ENTRIES];
44       char *name[MAX_ENTRIES];
45   } data;
46 };
47
48 /**
49  * Wrapper function that uses gnunet-gns cli tool to resolve
50  * an IPv4/6 address.
51  *
52  * @param af address family
53  * @param name the name to resolve
54  * @param u the userdata (result struct)
55  * @return -1 on error else 0
56  */
57 int gns_resolve_name(int af,
58                const char *name,
59                struct userdata *userdata);
60
61 #endif