X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fdns%2Fgnunet-dns-monitor.c;h=8f05403fbd2f4fb403d349214f03869d439ac65a;hb=70466ec3c34f9a920e9e798e3169f886e9486a59;hp=96d2a4959bd21e477ea9d3e6f9bc02ce0514bf80;hpb=c217aa8750bebf75b4a4a0d020cc516e8efad7be;p=oweals%2Fgnunet.git diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c index 96d2a4959..8f05403fb 100644 --- a/src/dns/gnunet-dns-monitor.c +++ b/src/dns/gnunet-dns-monitor.c @@ -26,7 +26,7 @@ #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_dns_service-new.h" +#include "gnunet_dns_service.h" #include "gnunet_dnsparser_lib.h" /** @@ -35,9 +35,14 @@ static struct GNUNET_DNS_Handle *handle; /** - * Option -s. + * Option -i. */ -static int benchmark_send; +static int inbound_only; + +/** + * Option -o. + */ +static int outbound_only; /** * Global return value (0 success). @@ -70,6 +75,7 @@ get_type (uint16_t type) case GNUNET_DNSPARSER_TYPE_MX: return "MX"; case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; + case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; } GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) type); return buf; @@ -114,9 +120,9 @@ display_query (const struct GNUNET_DNSPARSER_Query *query) /** - * Output the given DNS query to stdout. + * Output the given DNS record to stdout. * - * @param query query to display. + * @param record record to display. */ static void display_record (const struct GNUNET_DNSPARSER_Record *record) @@ -129,16 +135,16 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) switch (record->type) { case GNUNET_DNSPARSER_TYPE_A: - if (record->data_len != sizeof (struct in_addr)) + if (record->data.raw.data_len != sizeof (struct in_addr)) format = ""; else - format = inet_ntop (AF_INET, record->data.raw, buf, sizeof (buf)); + format = inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)); break; case GNUNET_DNSPARSER_TYPE_AAAA: - if (record->data_len != sizeof (struct in6_addr)) + if (record->data.raw.data_len != sizeof (struct in6_addr)) format = ""; else - format = inet_ntop (AF_INET6, record->data.raw, buf, sizeof (buf)); + format = inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)); break; case GNUNET_DNSPARSER_TYPE_NS: case GNUNET_DNSPARSER_TYPE_CNAME: @@ -146,7 +152,7 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) format = record->data.hostname; break; case GNUNET_DNSPARSER_TYPE_SOA: - if (record->data.soa == NULL) + if (NULL == record->data.soa) format = ""; else { @@ -174,11 +180,28 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) format = tmp; } break; + case GNUNET_DNSPARSER_TYPE_SRV: + if (NULL == record->data.srv) + format = ""; + else + { + GNUNET_asprintf (&tmp, + "service: %s, protocol: %s, domain_name = %s, priority %u, weight = %s, port = %u, target = %s", + record->data.srv->service, + record->data.srv->proto, + record->data.srv->domain_name, + (unsigned int) record->data.srv->priority, + (unsigned int) record->data.srv->weight, + (unsigned int) record->data.srv->port, + record->data.srv->target); + format = tmp; + } + break; case GNUNET_DNSPARSER_TYPE_TXT: GNUNET_asprintf (&tmp, "%.*s", - (unsigned int) record->data_len, - record->data.raw); + (unsigned int) record->data.raw.data_len, + record->data.raw.data); format = tmp; break; default: @@ -186,12 +209,11 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) break; } fprintf (stdout, - "\t\t%s %s: %s = %s (%u bytes, %u s)\n", + "\t\t%s %s: %s = %s (%u s)\n", get_class (record->class), get_type (record->type), record->name, format, - (unsigned int) record->data_len, (unsigned int) (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value / 1000)); GNUNET_free_non_null (tmp); } @@ -306,9 +328,18 @@ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + enum GNUNET_DNS_Flags flags; + + flags = GNUNET_DNS_FLAG_REQUEST_MONITOR | GNUNET_DNS_FLAG_RESPONSE_MONITOR; + if (inbound_only | outbound_only) + flags = 0; + if (inbound_only) + flags |= GNUNET_DNS_FLAG_REQUEST_MONITOR; + if (outbound_only) + flags |= GNUNET_DNS_FLAG_RESPONSE_MONITOR; handle = GNUNET_DNS_connect (cfg, - GNUNET_DNS_FLAG_REQUEST_MONITOR | GNUNET_DNS_FLAG_RESPONSE_MONITOR, + flags, &display_request, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, @@ -320,12 +351,19 @@ int main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'s', "testoption", NULL, - gettext_noop ("not useful"), - 0, &GNUNET_GETOPT_set_one, &benchmark_send}, + {'i', "inbound-only", NULL, + gettext_noop ("only monitor DNS queries"), + 0, &GNUNET_GETOPT_set_one, &inbound_only}, + {'o', "outbound-only", NULL, + gettext_noop ("only monitor DNS replies"), + 0, &GNUNET_GETOPT_set_one, &outbound_only}, GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), GNUNET_GETOPT_OPTION_END }; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + return 2; + return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-monitor", gettext_noop