test_resolver_api.c | test_resolver_api.c | |||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
*/ | */ | |||
#include "platform.h" | #include "platform.h" | |||
#include "gnunet_common.h" | #include "gnunet_common.h" | |||
#include "gnunet_getopt_lib.h" | #include "gnunet_getopt_lib.h" | |||
#include "gnunet_os_lib.h" | #include "gnunet_os_lib.h" | |||
#include "gnunet_program_lib.h" | #include "gnunet_program_lib.h" | |||
#include "gnunet_scheduler_lib.h" | #include "gnunet_scheduler_lib.h" | |||
#include "gnunet_resolver_service.h" | #include "gnunet_resolver_service.h" | |||
#include "resolver.h" | #include "resolver.h" | |||
#define VERBOSE GNUNET_EXTRA_LOGGING | #define VERBOSE GNUNET_NO | |||
/** | /** | |||
* Using DNS root servers to check gnunet's resolver service | * Using DNS root servers to check gnunet's resolver service | |||
* a.root-servers.net <-> 198.41.0.4 is a fix 1:1 mapping that should not c hange over years | * a.root-servers.net <-> 198.41.0.4 is a fix 1:1 mapping that should not c hange over years | |||
* For more information have a look at IANA's website http://www.root-serve rs.org/ | * For more information have a look at IANA's website http://www.root-serve rs.org/ | |||
*/ | */ | |||
#define ROOTSERVER_NAME "a.root-servers.net" | #define ROOTSERVER_NAME "a.root-servers.net" | |||
#define ROOTSERVER_IP "198.41.0.4" | #define ROOTSERVER_IP "198.41.0.4" | |||
static void | static void | |||
skipping to change at line 74 | skipping to change at line 74 | |||
if (0 == strcmp (hostname, "127.0.0.1")) | if (0 == strcmp (hostname, "127.0.0.1")) | |||
{ | { | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n ", | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n ", | |||
hostname); | hostname); | |||
#endif | #endif | |||
(*ok) &= ~4; | (*ok) &= ~4; | |||
} | } | |||
else | else | |||
{ | { | |||
#if DEBUG_RESOLVER | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received invalid hostname `%s'.\n | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n | ", | |||
", | ||||
hostname); | hostname); | |||
#endif | ||||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
} | } | |||
static void | static void | |||
check_localhost (void *cls, const char *hostname) | check_localhost (void *cls, const char *hostname) | |||
{ | { | |||
int *ok = cls; | int *ok = cls; | |||
if (hostname == NULL) | if (hostname == NULL) | |||
skipping to change at line 123 | skipping to change at line 121 | |||
GNUNET_assert (sizeof (struct sockaddr_in) == salen); | GNUNET_assert (sizeof (struct sockaddr_in) == salen); | |||
if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) | |||
{ | { | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); | |||
#endif | #endif | |||
(*ok) &= ~1; | (*ok) &= ~1; | |||
} | } | |||
else | else | |||
{ | { | |||
#if DEBUG_RESOLVER | char buf[INET_ADDRSTRLEN]; | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); | ||||
#endif | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received incorrect address`%s'.\n | |||
", | ||||
inet_ntop (AF_INET, &sai->sin_addr, buf, sizeof (buf))); | ||||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
} | } | |||
static void | static void | |||
check_local_fqdn (void *cls, const char *gnunet_fqdn) | check_local_fqdn (void *cls, const char *gnunet_fqdn) | |||
{ | { | |||
int result = 0; | int result = 0; | |||
struct hostent *host; | struct hostent *host; | |||
skipping to change at line 152 | skipping to change at line 151 | |||
return; | return; | |||
} | } | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), | |||
hostname); | hostname); | |||
#endif | #endif | |||
host = gethostbyname (hostname); | host = gethostbyname (hostname); | |||
if (NULL == host) | if (NULL == host) | |||
{ | { | |||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
_("Could not resolve our FQDN : %s %u\n"), hstrerror (h_err no), | _("Could not resolve our FQDN: %s %u\n"), hstrerror (h_errn o), | |||
h_errno); | h_errno); | |||
return; | return; | |||
} | } | |||
GNUNET_assert (0 != host); | GNUNET_assert (0 != host); | |||
result = strcmp (host->h_name, gnunet_fqdn); | result = strcmp (host->h_name, gnunet_fqdn); | |||
if (0 != result) | if (0 != result) | |||
{ | { | |||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
skipping to change at line 214 | skipping to change at line 213 | |||
if (0 == strcmp (hostname, ROOTSERVER_NAME)) | if (0 == strcmp (hostname, ROOTSERVER_NAME)) | |||
{ | { | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |||
"Received correct rootserver hostname `%s'.\n", hostname); | "Received correct rootserver hostname `%s'.\n", hostname); | |||
#endif | #endif | |||
(*ok) &= ~2; | (*ok) &= ~2; | |||
} | } | |||
else | else | |||
{ | { | |||
#if DEBUG_RESOLVER | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||||
"Received invalid rootserver hostname `%s'.\n", hostname); | "Received invalid rootserver hostname `%s'.\n", hostname); | |||
#endif | ||||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
} | } | |||
static void | static void | |||
run (void *cls, char *const *args, const char *cfgfile, | run (void *cls, char *const *args, const char *cfgfile, | |||
const struct GNUNET_CONFIGURATION_Handle *cfg) | const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
{ | { | |||
int *ok = cls; | int *ok = cls; | |||
struct sockaddr_in sa; | struct sockaddr_in sa; | |||
skipping to change at line 258 | skipping to change at line 255 | |||
* Testing non-local DNS resolution | * Testing non-local DNS resolution | |||
* DNS rootserver to test: a.root-servers.net - 198.41.0.4 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | |||
*/ | */ | |||
const char *rootserver_name = ROOTSERVER_NAME; | const char *rootserver_name = ROOTSERVER_NAME; | |||
struct hostent *rootserver; | struct hostent *rootserver; | |||
rootserver = gethostbyname (rootserver_name); | rootserver = gethostbyname (rootserver_name); | |||
if (rootserver == NULL) | if (rootserver == NULL) | |||
{ | { | |||
/* Error: resolving ip addresses does not work */ | /* Error: resolving ip addresses does not work */ | |||
#if DEBUG_RESOLVER | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||||
_("gethostbyname() could not lookup IP address: %s\n"), | _("gethostbyname() could not lookup IP address: %s\n"), | |||
hstrerror (h_errno)); | hstrerror (h_errno)); | |||
#endif | FPRINTF (stderr, | |||
fprintf (stderr, | "%s", "System seems to be off-line, will not run all DNS tests | |||
"System seems to be off-line, will not run all DNS tests\n"); | \n"); | |||
*ok = 0; /* mark test as passing anyway */ | *ok = 0; /* mark test as passing anyway */ | |||
return; | return; | |||
} | } | |||
/* Counting returned IP addresses */ | /* Counting returned IP addresses */ | |||
while (rootserver->h_addr_list[count_ips] != NULL) | while (rootserver->h_addr_list[count_ips] != NULL) | |||
count_ips++; | count_ips++; | |||
if (count_ips > 1) | if (count_ips > 1) | |||
{ | { | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
skipping to change at line 286 | skipping to change at line 281 | |||
"IP received range for root name server, but a root name se rver has only 1 IP\n"); | "IP received range for root name server, but a root name se rver has only 1 IP\n"); | |||
#endif | #endif | |||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
/* Comparing to resolved address to the address the root name server shou ld have */ | /* Comparing to resolved address to the address the root name server shou ld have */ | |||
if (strcmp | if (strcmp | |||
(inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), | (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), | |||
ROOTSERVER_IP) != 0) | ROOTSERVER_IP) != 0) | |||
{ | { | |||
#if DEBUG_RESOLVER | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||||
"IP received and IP for root name server differ\n"); | "IP received and IP for root name server differ\n"); | |||
#endif | ||||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_INFO, | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | |||
"System's own forward name resolution is working\n"); | "System's own forward name resolution is working\n"); | |||
#endif | #endif | |||
/* Resolve the same using GNUNET */ | /* Resolve the same using GNUNET */ | |||
GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, | GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, | |||
&check_rootserver_ip, cls); | &check_rootserver_ip, cls); | |||
skipping to change at line 323 | skipping to change at line 316 | |||
"Could not transform root name server IP address\n"); | "Could not transform root name server IP address\n"); | |||
#endif | #endif | |||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
rootserver = | rootserver = | |||
gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); | gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); | |||
if (rootserver == NULL) | if (rootserver == NULL) | |||
{ | { | |||
/* Error: resolving IP addresses does not work */ | /* Error: resolving IP addresses does not work */ | |||
#if DEBUG_RESOLVER | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||||
_("gethostbyaddr() could not lookup hostname: %s\n"), | _("gethostbyaddr() could not lookup hostname: %s\n"), | |||
hstrerror (h_errno)); | hstrerror (h_errno)); | |||
#endif | ||||
GNUNET_break (0); | GNUNET_break (0); | |||
} | } | |||
else | else | |||
{ | { | |||
if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) | if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) | |||
{ | { | |||
#if DEBUG_RESOLVER | #if DEBUG_RESOLVER | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |||
"Received hostname and hostname for root name server diff er\n"); | "Received hostname and hostname for root name server diff er\n"); | |||
#endif | #endif | |||
skipping to change at line 401 | skipping to change at line 392 | |||
#if VERBOSE | #if VERBOSE | |||
"-L", "DEBUG", | "-L", "DEBUG", | |||
#endif | #endif | |||
NULL | NULL | |||
}; | }; | |||
struct GNUNET_GETOPT_CommandLineOption options[] = | struct GNUNET_GETOPT_CommandLineOption options[] = | |||
{ GNUNET_GETOPT_OPTION_END }; | { GNUNET_GETOPT_OPTION_END }; | |||
pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); | pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); | |||
GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); | GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); | |||
GNUNET_free (pfx); | GNUNET_free (pfx); | |||
proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver" , | proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-servi ce-resolver", | |||
#if VERBOSE | #if VERBOSE | |||
"-L", "DEBUG", | "-L", "DEBUG", | |||
#endif | #endif | |||
"-c", "test_resolver_api_data.conf", NULL ); | "-c", "test_resolver_api_data.conf", NULL ); | |||
GNUNET_assert (NULL != proc); | GNUNET_assert (NULL != proc); | |||
GNUNET_free (fn); | GNUNET_free (fn); | |||
GNUNET_assert (GNUNET_OK == | GNUNET_assert (GNUNET_OK == | |||
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | |||
argv, "test-resolver-api", "nohelp", | argv, "test-resolver-api", "nohelp", | |||
options, &run, &ok)); | options, &run, &ok)); | |||
if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | |||
{ | { | |||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | |||
ok = 1; | ok = 1; | |||
} | } | |||
GNUNET_OS_process_wait (proc); | GNUNET_OS_process_wait (proc); | |||
GNUNET_OS_process_close (proc); | GNUNET_OS_process_close (proc); | |||
proc = NULL; | proc = NULL; | |||
if (ok != 0) | if (ok != 0) | |||
fprintf (stderr, "Missed some resolutions: %u\n", ok); | FPRINTF (stderr, "Missed some resolutions: %u\n", ok); | |||
return ok; | return ok; | |||
} | } | |||
int | int | |||
main (int argc, char *argv[]) | main (int argc, char *argv[]) | |||
{ | { | |||
int ret; | int ret; | |||
GNUNET_log_setup ("test-resolver-api", | GNUNET_log_setup ("test-resolver-api", | |||
#if VERBOSE | #if VERBOSE | |||
End of changes. 15 change blocks. | ||||
25 lines changed or deleted | 18 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |