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.
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/>.
21 #include "nss_gns_query.h"
22 #include <arpa/inet.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
30 * Wrapper function that uses gnunet-gns cli tool to resolve
33 * @param af address family
34 * @param name the name to resolve
35 * @param u the userdata (result struct)
36 * @return -1 on internal error,
37 * -2 if request is not for GNS,
42 gns_resolve_name (int af,
54 if (-1 == asprintf (&cmd,
62 if (-1 == asprintf (&cmd,
68 if (NULL == (p = popen (cmd, "r")))
75 while (NULL != fgets (line,
79 if (u->count >= MAX_ENTRIES)
81 if (line[strlen(line)-1] == '\n')
83 line[strlen(line)-1] = '\0';
88 &u->data.ipv4[u->count]))
91 u->data_len += sizeof(ipv4_address_t);
101 else if (AF_INET6 == af)
105 &u->data.ipv6[u->count]))
108 u->data_len += sizeof(ipv6_address_t);
122 if (! WIFEXITED (ret))
124 if (4 == WEXITSTATUS (ret))
125 return -2; /* not for GNS */
127 return -3; /* timeout -> not found */
128 if ( (2 == WEXITSTATUS (ret)) ||
129 (1 == WEXITSTATUS (ret)) )
130 return -2; /* launch failure -> service unavailable */
134 /* end of nss_gns_query.c */