#include "query.h"
-#ifdef NSS_IPV4_ONLY
-#define _nss_mdns_gethostbyname2_r _nss_gns4_minimal_gethostbyname2_r
-#define _nss_mdns_gethostbyname_r _nss_gns4_minimal_gethostbyname_r
-#define _nss_mdns_gethostbyaddr_r _nss_gns4_minimal_gethostbyaddr_r
-#endif
-
-#ifdef NSS_IPV6_ONLY
-#define _nss_mdns_gethostbyname2_r _nss_gns6_gethostbyname2_r
-#define _nss_mdns_gethostbyname_r _nss_gns6_gethostbyname_r
-#define _nss_mdns_gethostbyaddr_r _nss_gns6_gethostbyaddr_r
-#endif
-
-#ifndef NSS_IPV4_ONLY
-#ifndef NSS_IPV6_ONLY
-#define _nss_mdns_gethostbyname2_r _nss_gns_gethostbyname2_r
-#define _nss_mdns_gethostbyname_r _nss_gns_gethostbyname_r
-#define _nss_mdns_gethostbyaddr_r _nss_gns_gethostbyaddr_r
-#endif
-#endif
-
-/* Maximum number of entries to return */
-#define MAX_ENTRIES 16
+#include <arpa/inet.h>
#define ALIGN(idx) do { \
if (idx % sizeof(void*)) \
idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \
} while(0)
-struct userdata {
- int count;
- int data_len; /* only valid when doing reverse lookup */
- union {
- ipv4_address_t ipv4[MAX_ENTRIES];
- ipv6_address_t ipv6[MAX_ENTRIES];
- char *name[MAX_ENTRIES];
- } data;
-};
-
#ifndef NSS_IPV6_ONLY
static void ipv4_callback(const ipv4_address_t *ipv4, void *userdata) {
struct userdata *u = userdata;
- assert(ipv4 && userdata);
+
+ /*test!*/
+ ipv4_address_t *ipv4_test;
+ struct in_addr testaddr;
+ inet_pton(AF_INET, "5.5.5.5", &testaddr);
+ ipv4_test = (ipv4_address_t *)&testaddr;
+ /*test!*/
+ /*assert(ipv4 && userdata);*/
if (u->count >= MAX_ENTRIES)
return;
- u->data.ipv4[u->count++] = *ipv4;
+ u->data.ipv4[u->count++] = *ipv4_test;
u->data_len += sizeof(ipv4_address_t);
}
#endif
enum nss_status status = NSS_STATUS_UNAVAIL;
int i;
size_t address_length, l, idx, astart;
- void (*ipv4_func)(const ipv4_address_t *ipv4, void *userdata);
- void (*ipv6_func)(const ipv6_address_t *ipv6, void *userdata);
int name_allowed;
+
+ printf("v6: %d\n", af == AF_INET6);
if (af == AF_UNSPEC)
#ifdef NSS_IPV6_ONLY
u.count = 0;
u.data_len = 0;
-#ifdef NSS_IPV6_ONLY
- ipv4_func = NULL;
-#else
- ipv4_func = af == AF_INET ? ipv4_callback : NULL;
-#endif
-
-#ifdef NSS_IPV4_ONLY
- ipv6_func = NULL;
-#else
- ipv6_func = af == AF_INET6 ? ipv6_callback : NULL;
-#endif
-
-#ifdef ENABLE_GNS
name_allowed = verify_name_allowed(name);
- if (gns_works && name_allowed) {
- int r;
-
- if ((r = gns_resolve_name(af, name, data)) < 0)
- gns_works = 0;
- else if (r == 0) {
- if (af == AF_INET && ipv4_func)
- ipv4_func((ipv4_address_t*) data, &u);
- if (af == AF_INET6 && ipv6_func)
- ipv6_func((ipv6_address_t*)data, &u);
+ if (name_allowed) {
+
+ if (gns_resolve_name(af, name, &u) == 0)
+ {
+ printf("GNS success\n");
} else
status = NSS_STATUS_NOTFOUND;
}
-#endif /* ENABLE_GNS */
-
if (u.count == 0) {
*errnop = ETIMEDOUT;
*h_errnop = HOST_NOT_FOUND;
+ printf("not found\n");
goto finish;
}
-
+
+
/* Alias names */
*((char**) buffer) = NULL;
result->h_aliases = (char**) buffer;
/* we dont do this */
- struct userdata u;
enum nss_status status = NSS_STATUS_UNAVAIL;
- int r;
- size_t address_length, idx, astart;
*errnop = EINVAL;
*h_errnop = NO_RECOVERY;
- u.count = 0;
- u.data_len = 0;
-
/* Check for address types */
*h_errnop = NO_RECOVERY;
--- /dev/null
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "query.h"
+#include <arpa/inet.h>
+
+int gns_resolve_name(int af, const char *name, struct userdata *u)
+{
+ FILE *p;
+ char *cmd;
+ char line[128];
+
+ if (af == AF_INET6)
+ asprintf(&cmd, "%s -t AAAA -u %s\n", "gnunet-gns -r", name);
+ else
+ asprintf(&cmd, "%s %s\n", "gnunet-gns -r -u", name);
+
+ p = popen(cmd,"r");
+
+ if (p != NULL )
+ {
+ while (fgets( line, sizeof(line), p ) != NULL)
+ {
+
+ if (u->count >= MAX_ENTRIES)
+ break;
+
+ if (line[strlen(line)-1] == '\n')
+ {
+ 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);
+ }
+ else if ((af == AF_INET6))
+ {
+ inet_pton(af, line, &(u->data.ipv6[u->count++]));
+ u->data_len += sizeof(ipv6_address_t);
+ }
+ }
+ }
+ }
+ fclose(p);
+ free(cmd);
+
+ return 0;
+
+}
#include <inttypes.h>
+/* Maximum number of entries to return */
+#define MAX_ENTRIES 16
+
typedef struct {
uint32_t address;
} ipv4_address_t;
uint8_t address[16];
} ipv6_address_t;
-int gns_open_socket(void);
-int gns_query_name(int fd,
+struct userdata {
+ int count;
+ int data_len; /* only valid when doing reverse lookup */
+ union {
+ ipv4_address_t ipv4[MAX_ENTRIES];
+ ipv6_address_t ipv6[MAX_ENTRIES];
+ char *name[MAX_ENTRIES];
+ } data;
+};
+
+int gns_resolve_name(int af,
const char *name,
- void (*ipv4_func)(const ipv4_address_t *ipv4, void *userdata),
- void (*ipv6_func)(const ipv6_address_t *ipv6, void *userdata),
- void *userdata);
-
-#ifndef NSS_IPV6_ONLY
-int gns_query_ipv4(int fd,
- const ipv4_address_t *ipv4,
- void (*name_func)(const char *name, void *userdata),
- void *userdata);
-#endif
-#ifndef NSS_IPV4_ONLY
-int gns_query_ipv6(int fd,
- const ipv6_address_t *ipv6,
- void (*name_func)(const char *name, void *userdata),
- void *userdata);
-#endif
+ struct userdata *userdata);
#endif