/**
- * Output the given DNS query to stdout.
+ * Modify the given DNS record.
*
- * @param query query to display.
+ * @param record record to modify
*/
static void
modify_record (const struct GNUNET_DNSPARSER_Record *record)
switch (record->type)
{
- case GNUNET_DNSPARSER_TYPE_A:
+ case GNUNET_DNSPARSER_TYPE_A:
if (record->data.raw.data_len != sizeof (struct in_addr))
return;
if (NULL != n4)
{
if (verbosity > 1)
- fprintf (stderr,
+ fprintf (stderr,
"Changing A record from `%s' to `%s'\n",
inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)),
n4);
- inet_pton (AF_INET, n4, record->data.raw.data);
+ GNUNET_assert (1 == inet_pton (AF_INET, n4, record->data.raw.data));
}
break;
case GNUNET_DNSPARSER_TYPE_AAAA:
if (NULL != n6)
{
if (verbosity > 1)
- fprintf (stderr,
+ fprintf (stderr,
"Changing AAAA record from `%s' to `%s'\n",
inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)),
n6);
- inet_pton (AF_INET6, n6, record->data.raw.data);
+ GNUNET_assert (1 == inet_pton (AF_INET6, n6, record->data.raw.data));
}
break;
case GNUNET_DNSPARSER_TYPE_NS:
* @param request_length number of bytes in request
* @param request udp payload of the DNS request
*/
-static void
+static void
modify_request (void *cls,
struct GNUNET_DNS_RequestHandle *rh,
size_t request_length,
if (GNUNET_OK != ret)
{
if (GNUNET_NO == ret)
- fprintf (stderr,
+ fprintf (stderr,
"Modified DNS response did not fit, keeping old response\n");
else
GNUNET_break (0); /* our modifications should have been sane! */
"Injecting modified DNS response\n");
GNUNET_DNS_request_answer (rh, len, buf);
}
- GNUNET_free_non_null (buf);
+ GNUNET_free_non_null (buf);
}
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ struct in_addr i4;
+ struct in6_addr i6;
+ if ( (n4 != NULL) &&
+ (1 != inet_pton (AF_INET, n4, &i4)) )
+ {
+ fprintf (stderr,
+ "`%s' is nto a valid IPv4 address!\n",
+ n4);
+ return;
+ }
+ if ( (n6 != NULL) &&
+ (1 != inet_pton (AF_INET6, n6, &i6)) )
+ {
+ fprintf (stderr,
+ "`%s' is nto a valid IPv6 address!\n",
+ n6);
+ return;
+ }
+
handle =
- GNUNET_DNS_connect (cfg,
+ GNUNET_DNS_connect (cfg,
GNUNET_DNS_FLAG_POST_RESOLUTION,
&modify_request,
NULL);
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-redirector",
- gettext_noop
- ("Change DNS replies to point elsewhere."), options,
- &run, NULL)) ? ret : 1;
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
+ ret = (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-redirector",
+ gettext_noop
+ ("Change DNS replies to point elsewhere."), options,
+ &run, NULL)) ? ret : 1;
+ GNUNET_free ((void*) argv);
+ return ret;
}