From 09826bb34acd134c00fe6eab81af663ecb67dcd7 Mon Sep 17 00:00:00 2001 From: MissValeska Date: Thu, 6 Nov 2014 15:44:02 -0800 Subject: [PATCH] Massive experimental work done on implementing ntk netsplit as defined in the rfc http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split --- src/andns.c | 10 ++++--- src/dnslib.c | 2 +- src/getaddrinfodnstest.c | 58 ++++++++++++++++++++++++++++++++++++++++ src/netsukuku.c | 9 +++++-- 4 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 src/getaddrinfodnstest.c diff --git a/src/andns.c b/src/andns.c index 0f5dace..ebfd272 100644 --- a/src/andns.c +++ b/src/andns.c @@ -104,6 +104,8 @@ store_ns(char *ns) ai = &_andns_ns_[_andns_ns_count_]; res = getaddrinfo(ns, DNS_PORT_STR, &_ns_filter_, ai); + printf("store_ns getaddrinfo nameserver: %s " + "res: %i: %s",ns ,res, gai_strerror(errno)); if (res) { debug(DBG_NORMAL, "In store_ns(): gai `%s' -> %s", ns, gai_strerror(errno)); @@ -195,8 +197,8 @@ andns_init(int restricted, char *resolv_conf, int family) setzero(_andns_ns_, sizeof(struct addrinfo *) * MAXNSSERVERS); memset(msg, 0, (INET_ADDRSTRLEN + 2) * MAXNSSERVERS); - - if (_default_realm_ == NTK_REALM) { + +if (_default_realm_ == NTK_REALM) { /* We are in NTK realm, every IP is assigned to Netsukuku, * therefore dns forwarding is meaningless */ loginfo("We are in the ntk realm %s\n", strerror(errno)); @@ -663,7 +665,7 @@ dns_forward(dns_pkt * dp, char *msg, int msglen, char *answer) int res; if (!_dns_forwarding_) { - error("In rslv: dns forwardind is disable."); + error("In rslv: dns forwarding is disabled."); goto safe_failing; } debug(DBG_INSANE, "Forwarding dns query to inet nameservers..."); @@ -937,7 +939,7 @@ nk_forward(andns_pkt * ap, char *msg, int msglen, char *answer) * * Returns: * NULL if the pkt has to be discarded. - * A ptr to the answer to be sended if OK: + * A ptr to the answer to be sent if OK: * in this case, answ_len is filled with * the answer len. */ diff --git a/src/dnslib.c b/src/dnslib.c index da350a7..dfe27b6 100644 --- a/src/dnslib.c +++ b/src/dnslib.c @@ -555,7 +555,7 @@ d_as_u(char *start_buf, char *buf, dns_pkt_a ** dpa, int limit_len, * Returns: * -1 on E_INTRPRT * 0 if pkt must be discarded. - * Number of bytes readed otherwise + * Number of bytes read otherwise */ int d_u(char *buf, int pktlen, dns_pkt ** dpp) diff --git a/src/getaddrinfodnstest.c b/src/getaddrinfodnstest.c new file mode 100644 index 0000000..11941ae --- /dev/null +++ b/src/getaddrinfodnstest.c @@ -0,0 +1,58 @@ +#include +#include +#include /* getaddrinfo, getnameinfo */ +#include /* fprintf, printf */ +#include /* exit */ +#include /* memset */ + +int +getaddrinfodnsresolution(char *domain) +{ + struct addrinfo hints, *res, *res0; + int error; + char host[NI_MAXHOST]; + + /* + * Request only one socket type from getaddrinfo(). Else we + * would get both SOCK_DGRAM and SOCK_STREAM, and print two + * copies of each numeric address. + */ + memset(&hints, 0, sizeof hints); + hints.ai_family = PF_UNSPEC; /* IPv4, IPv6, or anything */ + hints.ai_socktype = SOCK_DGRAM; /* Dummy socket type */ + + /* + * Use getaddrinfo() to resolve "www.kame.net" and allocate + * a linked list of addresses. + */ + error = getaddrinfo(domain, NULL, &hints, &res0); + if (error) { + fprintf(stderr, "%s\n", gai_strerror(error)); + exit(1); + } + + /* Iterate the linked list. */ + for (res = res0; res; res = res->ai_next) { + /* + * Use getnameinfo() to convert res->ai_addr to a + * printable string. + * + * NI_NUMERICHOST means to present the numeric address + * without doing reverse DNS to get a domain name. + */ + error = getnameinfo(res->ai_addr, res->ai_addrlen, + host, sizeof host, NULL, 0, NI_NUMERICHOST); + + if (error) { + fprintf(stderr, "%s\n", gai_strerror(error)); + } else { + /* Print the numeric address. */ + printf("%s\n", host); + } + } + + /* Free the linked list. */ + freeaddrinfo(res0); + + return 0; +} diff --git a/src/netsukuku.c b/src/netsukuku.c index 58bc143..feebf0b 100644 --- a/src/netsukuku.c +++ b/src/netsukuku.c @@ -179,8 +179,9 @@ usage(void) " -h Shows this help\n" " -v Shows the version you are using\n" " -k Kills the running instance of ntkd\n" - " -C Runs the console server for Ntk-Console to connect to\n" - " -e Excludes an interface from usage I.E all interfaces except this one\n"); + " -C Runs the console server for Ntk-Console to connect to\n" + " -e Excludes an interface from usage I.E all interfaces except this one\n" + " -n Experimental, Currently meaningless argument\n to implement ntk netsplit\n http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split\n"); } /* @@ -425,6 +426,7 @@ parse_options(int argc, char **argv) {"kill", 0, 0, 'k'}, {"exclude", 1, 0, 'e'}, {"console", 0, 0, 'C'}, + {"netsplit", 1, 0, 'n'}, {0, 0, 0, 0} }; @@ -434,6 +436,9 @@ parse_options(int argc, char **argv) break; switch (c) { + case 'n': + + break; case 'C': ntk_thread_creatation(); break;