From 0441cc221bb2356cb4502fcb0df1a8d6d2cb61c8 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Sun, 9 Feb 2020 22:34:39 +0100 Subject: [PATCH] explicity ping ipv4/ipv6 addresses --- src/ext-cmd.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ext-cmd.c b/src/ext-cmd.c index 2905a39e..8152a4ac 100644 --- a/src/ext-cmd.c +++ b/src/ext-cmd.c @@ -58,19 +58,20 @@ const char* g_server_usage_debug = static int g_cmd_sock = -1; -static void cmd_ping(FILE *fp, const char addr_str[]) +static int cmd_ping(FILE *fp, const char addr_str[], int af) { IP addr; - if (addr_parse(&addr, addr_str, STR(DHT_PORT), gconf->af) == EXIT_SUCCESS) { + if (addr_parse(&addr, addr_str, STR(DHT_PORT), af) == EXIT_SUCCESS) { if (kad_ping(&addr) == 0) { fprintf(fp, "Send ping to: %s\n", str_addr(&addr)); + return 1; } else { fprintf(fp, "Failed to send ping.\n"); } - } else { - fprintf(fp, "Failed to parse/resolve address.\n"); } + + return 0; } static void cmd_blacklist(FILE *fp, const char *addr_str) @@ -138,7 +139,16 @@ static void cmd_exec(FILE *fp, const char request[], int allow_debug) int rc = 0; if (sscanf(request, " ping%*[ ]%255[^ \n\t] %c", hostname, &d) == 1) { - cmd_ping(fp, hostname); + if (gconf->af == AF_UNSPEC) { + count = cmd_ping(fp, hostname, AF_INET); + count += cmd_ping(fp, hostname, AF_INET6); + } else { + count = cmd_ping(fp, hostname, gconf->af); + } + + if (count == 0) { + fprintf(fp, "Failed to parse/resolve address.\n"); + } } else if (sscanf(request, " lookup%*[ ]%255[^: \n\t] %c", hostname, &d) == 1) { // Lookup hostname search = kad_lookup(hostname);