#include "nss_gns_query.h"
#include <arpa/inet.h>
+
+/**
+ * Wrapper function that uses gnunet-gns cli tool to resolve
+ * an IPv4/6 address.
+ *
+ * @param af address family
+ * @param name the name to resolve
+ * @param u the userdata (result struct)
+ * @return -1 on error else 0
+ */
int gns_resolve_name(int af, const char *name, struct userdata *u)
{
FILE *p;
line[strlen(line)-1] = '\0';
if (af == AF_INET)
{
- inet_pton(af, line, &(u->data.ipv4[u->count++]));
- u->data_len += sizeof(ipv4_address_t);
+ if (inet_pton(af, line, &(u->data.ipv4[u->count])))
+ {
+ u->count++;
+ u->data_len += sizeof(ipv4_address_t);
+ }
+ else
+ {
+ fclose (p);
+ free (cmd);
+ return -1;
+ }
}
else if ((af == AF_INET6))
{
- inet_pton(af, line, &(u->data.ipv6[u->count++]));
- u->data_len += sizeof(ipv6_address_t);
+ if (inet_pton(af, line, &(u->data.ipv6[u->count])))
+ {
+ u->count++;
+ u->data_len += sizeof(ipv6_address_t);
+ }
+ else
+ {
+ fclose (p);
+ free (cmd);
+ return -1;
+ }
}
}
}
+ fclose (p);
}
- fclose(p);
- free(cmd);
+ free (cmd);
return 0;