2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
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.
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.
18 #include "nss_gns_query.h"
19 #include <arpa/inet.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
26 * Wrapper function that uses gnunet-gns cli tool to resolve
29 * @param af address family
30 * @param name the name to resolve
31 * @param u the userdata (result struct)
32 * @return -1 on error else 0
35 gns_resolve_name (int af,
46 if (-1 == asprintf (&cmd,
48 "gnunet-gns -r", name))
53 if (-1 == asprintf (&cmd,
55 "gnunet-gns -r -u", name))
58 if (NULL == (p = popen (cmd, "r")))
63 while (NULL != fgets (line, sizeof(line), p))
65 if (u->count >= MAX_ENTRIES)
67 if (line[strlen(line)-1] == '\n')
69 line[strlen(line)-1] = '\0';
72 if (inet_pton(af, line, &(u->data.ipv4[u->count])))
75 u->data_len += sizeof(ipv4_address_t);
84 else if (AF_INET6 == af)
86 if (inet_pton(af, line, &(u->data.ipv6[u->count])))
89 u->data_len += sizeof(ipv6_address_t);
103 return -2; /* not for GNS */
105 return -3; /* timeout */
108 /* end of nss_gns_query.c */