diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-13 08:58:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-13 08:58:42 +0000 |
commit | f7de70d68cfad378a9b4f3b1f572196e8fa23e2a (patch) | |
tree | 458f632a19f37ee071be657e099b3f0e9f99980c /src/util/test_resolver_api.c | |
parent | 10cb56ae4e463e404d4d3ba2147340809d608ed8 (diff) | |
download | gnunet-f7de70d68cfad378a9b4f3b1f572196e8fa23e2a.tar.gz gnunet-f7de70d68cfad378a9b4f3b1f572196e8fa23e2a.zip |
-fixes and cleanup
Diffstat (limited to 'src/util/test_resolver_api.c')
-rw-r--r-- | src/util/test_resolver_api.c | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 4a3a20375..f924661dd 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include "gnunet_resolver_service.h" | 30 | #include "gnunet_resolver_service.h" |
31 | #include "resolver.h" | 31 | #include "resolver.h" |
32 | 32 | ||
33 | #define VERBOSE GNUNET_NO | ||
34 | 33 | ||
35 | /** | 34 | /** |
36 | * Using DNS root servers to check gnunet's resolver service | 35 | * Using DNS root servers to check gnunet's resolver service |
@@ -40,12 +39,13 @@ | |||
40 | #define ROOTSERVER_NAME "a.root-servers.net" | 39 | #define ROOTSERVER_NAME "a.root-servers.net" |
41 | #define ROOTSERVER_IP "198.41.0.4" | 40 | #define ROOTSERVER_IP "198.41.0.4" |
42 | 41 | ||
42 | |||
43 | static void | 43 | static void |
44 | check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) | 44 | check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) |
45 | { | 45 | { |
46 | int *ok = cls; | 46 | int *ok = cls; |
47 | 47 | ||
48 | if (salen == 0) | 48 | if (0 == salen) |
49 | { | 49 | { |
50 | (*ok) &= ~8; | 50 | (*ok) &= ~8; |
51 | return; | 51 | return; |
@@ -82,7 +82,7 @@ check_localhost (void *cls, const char *hostname) | |||
82 | { | 82 | { |
83 | int *ok = cls; | 83 | int *ok = cls; |
84 | 84 | ||
85 | if (hostname == NULL) | 85 | if (NULL == hostname) |
86 | return; | 86 | return; |
87 | if (0 == strcmp (hostname, "localhost")) | 87 | if (0 == strcmp (hostname, "localhost")) |
88 | { | 88 | { |
@@ -98,13 +98,14 @@ check_localhost (void *cls, const char *hostname) | |||
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | |||
101 | static void | 102 | static void |
102 | check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) | 103 | check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) |
103 | { | 104 | { |
104 | int *ok = cls; | 105 | int *ok = cls; |
105 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 106 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
106 | 107 | ||
107 | if (sa == NULL) | 108 | if (NULL == sa) |
108 | return; | 109 | return; |
109 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); | 110 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
110 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) | 111 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) |
@@ -122,6 +123,7 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) | |||
122 | } | 123 | } |
123 | } | 124 | } |
124 | 125 | ||
126 | |||
125 | static void | 127 | static void |
126 | check_local_fqdn (void *cls, const char *gnunet_fqdn) | 128 | check_local_fqdn (void *cls, const char *gnunet_fqdn) |
127 | { | 129 | { |
@@ -159,14 +161,13 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn) | |||
159 | } | 161 | } |
160 | 162 | ||
161 | 163 | ||
162 | |||
163 | static void | 164 | static void |
164 | check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) | 165 | check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) |
165 | { | 166 | { |
166 | int *ok = cls; | 167 | int *ok = cls; |
167 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 168 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
168 | 169 | ||
169 | if (sa == NULL) | 170 | if (NULL == sa) |
170 | return; | 171 | return; |
171 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); | 172 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
172 | 173 | ||
@@ -184,12 +185,13 @@ check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) | |||
184 | } | 185 | } |
185 | } | 186 | } |
186 | 187 | ||
188 | |||
187 | static void | 189 | static void |
188 | check_rootserver_name (void *cls, const char *hostname) | 190 | check_rootserver_name (void *cls, const char *hostname) |
189 | { | 191 | { |
190 | int *ok = cls; | 192 | int *ok = cls; |
191 | 193 | ||
192 | if (hostname == NULL) | 194 | if (NULL == hostname) |
193 | return; | 195 | return; |
194 | 196 | ||
195 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) | 197 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) |
@@ -206,6 +208,7 @@ check_rootserver_name (void *cls, const char *hostname) | |||
206 | } | 208 | } |
207 | } | 209 | } |
208 | 210 | ||
211 | |||
209 | static void | 212 | static void |
210 | run (void *cls, char *const *args, const char *cfgfile, | 213 | run (void *cls, char *const *args, const char *cfgfile, |
211 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 214 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -347,36 +350,33 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
347 | 350 | ||
348 | } | 351 | } |
349 | 352 | ||
350 | static int | 353 | |
351 | check () | 354 | int |
355 | main (int argc, char *argv[]) | ||
352 | { | 356 | { |
353 | int ok = 1 + 2 + 4 + 8; | 357 | int ok = 1 + 2 + 4 + 8; |
354 | char *fn; | 358 | char *fn; |
355 | char *pfx; | 359 | char *pfx; |
356 | struct GNUNET_OS_Process *proc; | 360 | struct GNUNET_OS_Process *proc; |
357 | 361 | char *const argvx[] = { | |
358 | char *const argv[] = | 362 | "test-resolver-api", "-c", "test_resolver_api_data.conf", NULL |
359 | { "test-resolver-api", "-c", "test_resolver_api_data.conf", | ||
360 | #if VERBOSE | ||
361 | "-L", "DEBUG", | ||
362 | #endif | ||
363 | NULL | ||
364 | }; | 363 | }; |
365 | struct GNUNET_GETOPT_CommandLineOption options[] = | 364 | struct GNUNET_GETOPT_CommandLineOption options[] = |
366 | { GNUNET_GETOPT_OPTION_END }; | 365 | { GNUNET_GETOPT_OPTION_END }; |
366 | |||
367 | GNUNET_log_setup ("test-resolver-api", | ||
368 | "WARNING", | ||
369 | NULL); | ||
367 | pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); | 370 | pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); |
368 | GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); | 371 | GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); |
369 | GNUNET_free (pfx); | 372 | GNUNET_free (pfx); |
370 | proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-service-resolver", | 373 | proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-service-resolver", |
371 | #if VERBOSE | ||
372 | "-L", "DEBUG", | ||
373 | #endif | ||
374 | "-c", "test_resolver_api_data.conf", NULL); | 374 | "-c", "test_resolver_api_data.conf", NULL); |
375 | GNUNET_assert (NULL != proc); | 375 | GNUNET_assert (NULL != proc); |
376 | GNUNET_free (fn); | 376 | GNUNET_free (fn); |
377 | GNUNET_assert (GNUNET_OK == | 377 | GNUNET_assert (GNUNET_OK == |
378 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 378 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, |
379 | argv, "test-resolver-api", "nohelp", | 379 | argvx, "test-resolver-api", "nohelp", |
380 | options, &run, &ok)); | 380 | options, &run, &ok)); |
381 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 381 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
382 | { | 382 | { |
@@ -386,26 +386,10 @@ check () | |||
386 | GNUNET_OS_process_wait (proc); | 386 | GNUNET_OS_process_wait (proc); |
387 | GNUNET_OS_process_destroy (proc); | 387 | GNUNET_OS_process_destroy (proc); |
388 | proc = NULL; | 388 | proc = NULL; |
389 | if (ok != 0) | 389 | if (0 != ok) |
390 | FPRINTF (stderr, "Missed some resolutions: %u\n", ok); | 390 | FPRINTF (stderr, "Missed some resolutions: %u\n", ok); |
391 | return ok; | 391 | return ok; |
392 | } | 392 | } |
393 | 393 | ||
394 | int | ||
395 | main (int argc, char *argv[]) | ||
396 | { | ||
397 | int ret; | ||
398 | |||
399 | GNUNET_log_setup ("test-resolver-api", | ||
400 | #if VERBOSE | ||
401 | "DEBUG", | ||
402 | #else | ||
403 | "WARNING", | ||
404 | #endif | ||
405 | NULL); | ||
406 | ret = check (); | ||
407 | |||
408 | return ret; | ||
409 | } | ||
410 | 394 | ||
411 | /* end of test_resolver_api.c */ | 395 | /* end of test_resolver_api.c */ |