aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_resolver_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/test_resolver_api.c
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/util/test_resolver_api.c')
-rw-r--r--src/util/test_resolver_api.c267
1 files changed, 133 insertions, 134 deletions
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 24c71b41f..4e248aa72 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -46,13 +46,12 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen)
46 int *ok = cls; 46 int *ok = cls;
47 47
48 if (salen == 0) 48 if (salen == 0)
49 { 49 {
50 (*ok) &= ~8; 50 (*ok) &= ~8;
51 return; 51 return;
52 } 52 }
53 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 53 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"),
54 _("Got IP address `%s' for our host.\n"), GNUNET_a2s (sa, 54 GNUNET_a2s (sa, salen));
55 salen));
56} 55}
57 56
58 57
@@ -64,21 +63,21 @@ check_localhost_num (void *cls, const char *hostname)
64 if (hostname == NULL) 63 if (hostname == NULL)
65 return; 64 return;
66 if (0 == strcmp (hostname, "127.0.0.1")) 65 if (0 == strcmp (hostname, "127.0.0.1"))
67 { 66 {
68#if DEBUG_RESOLVER 67#if DEBUG_RESOLVER
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
70 "Received correct hostname `%s'.\n", hostname); 69 hostname);
71#endif 70#endif
72 (*ok) &= ~4; 71 (*ok) &= ~4;
73 } 72 }
74 else 73 else
75 { 74 {
76#if DEBUG_RESOLVER 75#if DEBUG_RESOLVER
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n",
78 "Received invalid hostname `%s'.\n", hostname); 77 hostname);
79#endif 78#endif
80 GNUNET_break (0); 79 GNUNET_break (0);
81 } 80 }
82} 81}
83 82
84 83
@@ -90,19 +89,19 @@ check_localhost (void *cls, const char *hostname)
90 if (hostname == NULL) 89 if (hostname == NULL)
91 return; 90 return;
92 if (0 == strcmp (hostname, "localhost")) 91 if (0 == strcmp (hostname, "localhost"))
93 { 92 {
94#if DEBUG_RESOLVER 93#if DEBUG_RESOLVER
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
96 "Received correct hostname `%s'.\n", hostname); 95 hostname);
97#endif 96#endif
98 (*ok) &= ~2; 97 (*ok) &= ~2;
99 } 98 }
100 else 99 else
101 { 100 {
102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
103 "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", 102 "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n",
104 hostname); 103 hostname);
105 } 104 }
106} 105}
107 106
108static void 107static void
@@ -115,19 +114,19 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
115 return; 114 return;
116 GNUNET_assert (sizeof (struct sockaddr_in) == salen); 115 GNUNET_assert (sizeof (struct sockaddr_in) == salen);
117 if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) 116 if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK))
118 { 117 {
119#if DEBUG_RESOLVER 118#if DEBUG_RESOLVER
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n");
121#endif 120#endif
122 (*ok) &= ~1; 121 (*ok) &= ~1;
123 } 122 }
124 else 123 else
125 { 124 {
126#if DEBUG_RESOLVER 125#if DEBUG_RESOLVER
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); 126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n");
128#endif 127#endif
129 GNUNET_break (0); 128 GNUNET_break (0);
130 } 129 }
131} 130}
132 131
133static void 132static void
@@ -139,32 +138,32 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn)
139 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 138 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
140 139
141 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 140 if (0 != gethostname (hostname, sizeof (hostname) - 1))
142 { 141 {
143 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
144 "gethostname"); 143 "gethostname");
145 return; 144 return;
146 } 145 }
147#if DEBUG_RESOLVER 146#if DEBUG_RESOLVER
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
149 hostname); 148 hostname);
150#endif 149#endif
151 host = gethostbyname (hostname); 150 host = gethostbyname (hostname);
152 if (NULL == host) 151 if (NULL == host)
153 { 152 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 _("Could not resolve our FQDN : %s %u\n"), 154 _("Could not resolve our FQDN : %s %u\n"), hstrerror (h_errno),
156 hstrerror (h_errno), h_errno); 155 h_errno);
157 return; 156 return;
158 } 157 }
159 158
160 GNUNET_assert (0 != host); 159 GNUNET_assert (0 != host);
161 160
162 result = strcmp (host->h_name, gnunet_fqdn); 161 result = strcmp (host->h_name, gnunet_fqdn);
163 if (0 != result) 162 if (0 != result)
164 { 163 {
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
166 "Local resolved and resolver resolved fqdns are not equal\n"); 165 "Local resolved and resolver resolved fqdns are not equal\n");
167 } 166 }
168 GNUNET_assert (0 == result); 167 GNUNET_assert (0 == result);
169} 168}
170 169
@@ -181,21 +180,21 @@ check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
181 GNUNET_assert (sizeof (struct sockaddr_in) == salen); 180 GNUNET_assert (sizeof (struct sockaddr_in) == salen);
182 181
183 if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP)) 182 if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP))
184 { 183 {
185#if DEBUG_RESOLVER 184#if DEBUG_RESOLVER
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Received correct rootserver ip address.\n"); 186 "Received correct rootserver ip address.\n");
188#endif 187#endif
189 (*ok) &= ~1; 188 (*ok) &= ~1;
190 } 189 }
191 else 190 else
192 { 191 {
193#if DEBUG_RESOLVER 192#if DEBUG_RESOLVER
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Received incorrect rootserver ip address.\n"); 194 "Received incorrect rootserver ip address.\n");
196#endif 195#endif
197 GNUNET_break (0); 196 GNUNET_break (0);
198 } 197 }
199} 198}
200 199
201static void 200static void
@@ -207,21 +206,21 @@ check_rootserver_name (void *cls, const char *hostname)
207 return; 206 return;
208 207
209 if (0 == strcmp (hostname, ROOTSERVER_NAME)) 208 if (0 == strcmp (hostname, ROOTSERVER_NAME))
210 { 209 {
211#if DEBUG_RESOLVER 210#if DEBUG_RESOLVER
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Received correct rootserver hostname `%s'.\n", hostname); 212 "Received correct rootserver hostname `%s'.\n", hostname);
214#endif 213#endif
215 (*ok) &= ~2; 214 (*ok) &= ~2;
216 } 215 }
217 else 216 else
218 { 217 {
219#if DEBUG_RESOLVER 218#if DEBUG_RESOLVER
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "Received invalid rootserver hostname `%s'.\n", hostname); 220 "Received invalid rootserver hostname `%s'.\n", hostname);
222#endif 221#endif
223 GNUNET_break (0); 222 GNUNET_break (0);
224 } 223 }
225} 224}
226 225
227static void 226static void
@@ -231,7 +230,7 @@ run (void *cls, char *const *args, const char *cfgfile,
231 int *ok = cls; 230 int *ok = cls;
232 struct sockaddr_in sa; 231 struct sockaddr_in sa;
233 struct GNUNET_TIME_Relative timeout = 232 struct GNUNET_TIME_Relative timeout =
234 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 233 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
235 int count_ips = 0; 234 int count_ips = 0;
236 char *own_fqdn; 235 char *own_fqdn;
237 236
@@ -258,50 +257,50 @@ run (void *cls, char *const *args, const char *cfgfile,
258 257
259 rootserver = gethostbyname (rootserver_name); 258 rootserver = gethostbyname (rootserver_name);
260 if (rootserver == NULL) 259 if (rootserver == NULL)
261 { 260 {
262 /* Error: resolving ip addresses does not work */ 261 /* Error: resolving ip addresses does not work */
263#if DEBUG_RESOLVER 262#if DEBUG_RESOLVER
264 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 263 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
265 _("gethostbyname() could not lookup IP address: %s\n"), 264 _("gethostbyname() could not lookup IP address: %s\n"),
266 hstrerror (h_errno)); 265 hstrerror (h_errno));
267#endif 266#endif
268 fprintf (stderr, 267 fprintf (stderr,
269 "System seems to be off-line, will not run all DNS tests\n"); 268 "System seems to be off-line, will not run all DNS tests\n");
270 *ok = 0; /* mark test as passing anyway */ 269 *ok = 0; /* mark test as passing anyway */
271 return; 270 return;
272 } 271 }
273 272
274 /* Counting returned IP addresses */ 273 /* Counting returned IP addresses */
275 while (rootserver->h_addr_list[count_ips] != NULL) 274 while (rootserver->h_addr_list[count_ips] != NULL)
276 count_ips++; 275 count_ips++;
277 if (count_ips > 1) 276 if (count_ips > 1)
278 { 277 {
279#if DEBUG_RESOLVER 278#if DEBUG_RESOLVER
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "IP received range for root name server, but a root name server has only 1 IP\n"); 280 "IP received range for root name server, but a root name server has only 1 IP\n");
282#endif 281#endif
283 GNUNET_break (0); 282 GNUNET_break (0);
284 } 283 }
285 284
286 /* Comparing to resolved address to the address the root name server should have */ 285 /* Comparing to resolved address to the address the root name server should have */
287 if (strcmp 286 if (strcmp
288 (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), 287 (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]),
289 ROOTSERVER_IP) != 0) 288 ROOTSERVER_IP) != 0)
290 { 289 {
291#if DEBUG_RESOLVER 290#if DEBUG_RESOLVER
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "IP received and IP for root name server differ\n"); 292 "IP received and IP for root name server differ\n");
294#endif 293#endif
295 GNUNET_break (0); 294 GNUNET_break (0);
296 } 295 }
297#if DEBUG_RESOLVER 296#if DEBUG_RESOLVER
298 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 297 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
299 "System's own forward name resolution is working\n"); 298 "System's own forward name resolution is working\n");
300#endif 299#endif
301 300
302 /* Resolve the same using GNUNET */ 301 /* Resolve the same using GNUNET */
303 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, 302 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
304 &check_rootserver_ip, cls); 303 &check_rootserver_ip, cls);
305 304
306 /* 305 /*
307 * Success: forward lookups work as expected 306 * Success: forward lookups work as expected
@@ -312,41 +311,41 @@ run (void *cls, char *const *args, const char *cfgfile,
312 311
313 rootserver->h_name = ""; 312 rootserver->h_name = "";
314 if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) 313 if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr))
315 { 314 {
316#if DEBUG_RESOLVER 315#if DEBUG_RESOLVER
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 "Could not transform root name server IP address\n"); 317 "Could not transform root name server IP address\n");
319#endif 318#endif
320 GNUNET_break (0); 319 GNUNET_break (0);
321 } 320 }
322 321
323 rootserver = 322 rootserver =
324 gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); 323 gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET);
325 if (rootserver == NULL) 324 if (rootserver == NULL)
326 { 325 {
327 /* Error: resolving IP addresses does not work */ 326 /* Error: resolving IP addresses does not work */
328#if DEBUG_RESOLVER 327#if DEBUG_RESOLVER
329 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
330 _("gethostbyaddr() could not lookup hostname: %s\n"), 329 _("gethostbyaddr() could not lookup hostname: %s\n"),
331 hstrerror (h_errno)); 330 hstrerror (h_errno));
332#endif 331#endif
333 GNUNET_break (0); 332 GNUNET_break (0);
334 } 333 }
335 else 334 else
335 {
336 if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
336 { 337 {
337 if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
338 {
339#if DEBUG_RESOLVER 338#if DEBUG_RESOLVER
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Received hostname and hostname for root name server differ\n"); 340 "Received hostname and hostname for root name server differ\n");
342#endif 341#endif
343 GNUNET_break (0); 342 GNUNET_break (0);
344 }
345 } 343 }
344 }
346 345
347#if DEBUG_RESOLVER 346#if DEBUG_RESOLVER
348 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "System's own reverse name resolution is working\n"); 348 "System's own reverse name resolution is working\n");
350#endif 349#endif
351 350
352 /* Resolve the same using GNUNET */ 351 /* Resolve the same using GNUNET */
@@ -361,8 +360,8 @@ run (void *cls, char *const *args, const char *cfgfile,
361 sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP); 360 sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP);
362#endif 361#endif
363 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 362 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
364 sizeof (struct sockaddr), GNUNET_YES, timeout, 363 sizeof (struct sockaddr), GNUNET_YES, timeout,
365 &check_rootserver_name, cls); 364 &check_rootserver_name, cls);
366 365
367 memset (&sa, 0, sizeof (sa)); 366 memset (&sa, 0, sizeof (sa));
368 sa.sin_family = AF_INET; 367 sa.sin_family = AF_INET;
@@ -373,12 +372,12 @@ run (void *cls, char *const *args, const char *cfgfile,
373 372
374 GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls); 373 GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls);
375 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 374 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
376 sizeof (struct sockaddr), GNUNET_YES, timeout, 375 sizeof (struct sockaddr), GNUNET_YES, timeout,
377 &check_localhost, cls); 376 &check_localhost, cls);
378 377
379 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 378 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
380 sizeof (struct sockaddr), GNUNET_NO, timeout, 379 sizeof (struct sockaddr), GNUNET_NO, timeout,
381 &check_localhost_num, cls); 380 &check_localhost_num, cls);
382 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls); 381 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls);
383 382
384} 383}
@@ -392,33 +391,33 @@ check ()
392 struct GNUNET_OS_Process *proc; 391 struct GNUNET_OS_Process *proc;
393 392
394 char *const argv[] = 393 char *const argv[] =
395 { "test-resolver-api", "-c", "test_resolver_api_data.conf", 394 { "test-resolver-api", "-c", "test_resolver_api_data.conf",
396#if VERBOSE 395#if VERBOSE
397 "-L", "DEBUG", 396 "-L", "DEBUG",
398#endif 397#endif
399 NULL 398 NULL
400 }; 399 };
401 struct GNUNET_GETOPT_CommandLineOption options[] = 400 struct GNUNET_GETOPT_CommandLineOption options[] =
402 { GNUNET_GETOPT_OPTION_END }; 401 { GNUNET_GETOPT_OPTION_END };
403 pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); 402 pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
404 GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); 403 GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR);
405 GNUNET_free (pfx); 404 GNUNET_free (pfx);
406 proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver", 405 proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver",
407#if VERBOSE 406#if VERBOSE
408 "-L", "DEBUG", 407 "-L", "DEBUG",
409#endif 408#endif
410 "-c", "test_resolver_api_data.conf", NULL); 409 "-c", "test_resolver_api_data.conf", NULL);
411 GNUNET_assert (NULL != proc); 410 GNUNET_assert (NULL != proc);
412 GNUNET_free (fn); 411 GNUNET_free (fn);
413 GNUNET_assert (GNUNET_OK == 412 GNUNET_assert (GNUNET_OK ==
414 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 413 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
415 argv, "test-resolver-api", "nohelp", 414 argv, "test-resolver-api", "nohelp",
416 options, &run, &ok)); 415 options, &run, &ok));
417 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 416 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
418 { 417 {
419 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 418 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
420 ok = 1; 419 ok = 1;
421 } 420 }
422 GNUNET_OS_process_wait (proc); 421 GNUNET_OS_process_wait (proc);
423 GNUNET_OS_process_close (proc); 422 GNUNET_OS_process_close (proc);
424 proc = NULL; 423 proc = NULL;
@@ -434,11 +433,11 @@ main (int argc, char *argv[])
434 433
435 GNUNET_log_setup ("test-resolver-api", 434 GNUNET_log_setup ("test-resolver-api",
436#if VERBOSE 435#if VERBOSE
437 "DEBUG", 436 "DEBUG",
438#else 437#else
439 "WARNING", 438 "WARNING",
440#endif 439#endif
441 NULL); 440 NULL);
442 ret = check (); 441 ret = check ();
443 442
444 return ret; 443 return ret;