diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-09 21:51:21 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-09 21:51:21 +0000 |
commit | bc6a7f8d6cfbfc92128d1e6c495ee94c5508e26f (patch) | |
tree | 8469737d72e2f753a0e05889181dc0a0c3245478 /src/util/test_resolver_api.c | |
parent | b5b4131b1e9afca86880f209d2e7de19d5111be6 (diff) | |
download | gnunet-bc6a7f8d6cfbfc92128d1e6c495ee94c5508e26f.tar.gz gnunet-bc6a7f8d6cfbfc92128d1e6c495ee94c5508e26f.zip |
-making test nicer (indentation)
Diffstat (limited to 'src/util/test_resolver_api.c')
-rw-r--r-- | src/util/test_resolver_api.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index acc3ae6ae..77dae50d2 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -37,7 +37,9 @@ | |||
37 | 37 | ||
38 | 38 | ||
39 | static void | 39 | static void |
40 | check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) | 40 | check_hostname (void *cls, |
41 | const struct sockaddr *sa, | ||
42 | socklen_t salen) | ||
41 | { | 43 | { |
42 | int *ok = cls; | 44 | int *ok = cls; |
43 | 45 | ||
@@ -46,13 +48,15 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) | |||
46 | (*ok) &= ~8; | 48 | (*ok) &= ~8; |
47 | return; | 49 | return; |
48 | } | 50 | } |
49 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), | 51 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
52 | "Got IP address `%s' for our host.\n", | ||
50 | GNUNET_a2s (sa, salen)); | 53 | GNUNET_a2s (sa, salen)); |
51 | } | 54 | } |
52 | 55 | ||
53 | 56 | ||
54 | static void | 57 | static void |
55 | check_localhost_num (void *cls, const char *hostname) | 58 | check_localhost_num (void *cls, |
59 | const char *hostname) | ||
56 | { | 60 | { |
57 | int *ok = cls; | 61 | int *ok = cls; |
58 | 62 | ||
@@ -60,13 +64,15 @@ check_localhost_num (void *cls, const char *hostname) | |||
60 | return; | 64 | return; |
61 | if (0 == strcmp (hostname, "127.0.0.1")) | 65 | if (0 == strcmp (hostname, "127.0.0.1")) |
62 | { | 66 | { |
63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n", | 67 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
68 | "Received correct hostname `%s'.\n", | ||
64 | hostname); | 69 | hostname); |
65 | (*ok) &= ~4; | 70 | (*ok) &= ~4; |
66 | } | 71 | } |
67 | else | 72 | else |
68 | { | 73 | { |
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received invalid hostname `%s'.\n", | 74 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
75 | "Received invalid hostname `%s'.\n", | ||
70 | hostname); | 76 | hostname); |
71 | GNUNET_break (0); | 77 | GNUNET_break (0); |
72 | } | 78 | } |
@@ -74,7 +80,8 @@ check_localhost_num (void *cls, const char *hostname) | |||
74 | 80 | ||
75 | 81 | ||
76 | static void | 82 | static void |
77 | check_localhost (void *cls, const char *hostname) | 83 | check_localhost (void *cls, |
84 | const char *hostname) | ||
78 | { | 85 | { |
79 | int *ok = cls; | 86 | int *ok = cls; |
80 | 87 | ||
@@ -82,7 +89,8 @@ check_localhost (void *cls, const char *hostname) | |||
82 | return; | 89 | return; |
83 | if (0 == strcmp (hostname, "localhost")) | 90 | if (0 == strcmp (hostname, "localhost")) |
84 | { | 91 | { |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n", | 92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | "Received correct hostname `%s'.\n", | ||
86 | hostname); | 94 | hostname); |
87 | (*ok) &= ~2; | 95 | (*ok) &= ~2; |
88 | } | 96 | } |
@@ -106,15 +114,20 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) | |||
106 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); | 114 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
107 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) | 115 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) |
108 | { | 116 | { |
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
118 | "Received correct address.\n"); | ||
110 | (*ok) &= ~1; | 119 | (*ok) &= ~1; |
111 | } | 120 | } |
112 | else | 121 | else |
113 | { | 122 | { |
114 | char buf[INET_ADDRSTRLEN]; | 123 | char buf[INET_ADDRSTRLEN]; |
115 | 124 | ||
116 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received incorrect address`%s'.\n", | 125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
117 | inet_ntop (AF_INET, &sai->sin_addr, buf, sizeof (buf))); | 126 | "Received incorrect address `%s'.\n", |
127 | inet_ntop (AF_INET, | ||
128 | &sai->sin_addr, | ||
129 | buf, | ||
130 | sizeof (buf))); | ||
118 | GNUNET_break (0); | 131 | GNUNET_break (0); |
119 | } | 132 | } |
120 | } | 133 | } |
@@ -134,13 +147,15 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn) | |||
134 | "gethostname"); | 147 | "gethostname"); |
135 | return; | 148 | return; |
136 | } | 149 | } |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Resolving our FQDN `%s'\n", | ||
138 | hostname); | 152 | hostname); |
139 | host = gethostbyname (hostname); | 153 | host = gethostbyname (hostname); |
140 | if (NULL == host) | 154 | if (NULL == host) |
141 | { | 155 | { |
142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
143 | _("Could not resolve our FQDN: %s %u\n"), hstrerror (h_errno), | 157 | "Could not resolve our FQDN: %s %u\n", |
158 | hstrerror (h_errno), | ||
144 | h_errno); | 159 | h_errno); |
145 | return; | 160 | return; |
146 | } | 161 | } |
@@ -193,7 +208,8 @@ check_rootserver_name (void *cls, const char *hostname) | |||
193 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) | 208 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) |
194 | { | 209 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
196 | "Received correct rootserver hostname `%s'.\n", hostname); | 211 | "Received correct rootserver hostname `%s'.\n", |
212 | hostname); | ||
197 | (*ok) &= ~2; | 213 | (*ok) &= ~2; |
198 | } | 214 | } |
199 | else | 215 | else |
@@ -217,6 +233,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
217 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 233 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
218 | int count_ips = 0; | 234 | int count_ips = 0; |
219 | char *own_fqdn; | 235 | char *own_fqdn; |
236 | const char *rootserver_name = ROOTSERVER_NAME; | ||
237 | struct hostent *rootserver; | ||
238 | struct in_addr rootserver_addr; | ||
220 | 239 | ||
221 | memset (&sa, 0, sizeof (sa)); | 240 | memset (&sa, 0, sizeof (sa)); |
222 | sa.sin_family = AF_INET; | 241 | sa.sin_family = AF_INET; |
@@ -236,18 +255,17 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
236 | * Testing non-local DNS resolution | 255 | * Testing non-local DNS resolution |
237 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | 256 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 |
238 | */ | 257 | */ |
239 | const char *rootserver_name = ROOTSERVER_NAME; | ||
240 | struct hostent *rootserver; | ||
241 | 258 | ||
242 | rootserver = gethostbyname (rootserver_name); | 259 | rootserver = gethostbyname (rootserver_name); |
243 | if (rootserver == NULL) | 260 | if (NULL == rootserver) |
244 | { | 261 | { |
245 | /* Error: resolving ip addresses does not work */ | 262 | /* Error: resolving ip addresses does not work */ |
246 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
247 | _("gethostbyname() could not lookup IP address: %s\n"), | 264 | _("gethostbyname() could not lookup IP address: %s\n"), |
248 | hstrerror (h_errno)); | 265 | hstrerror (h_errno)); |
249 | FPRINTF (stderr, | 266 | FPRINTF (stderr, |
250 | "%s", "System seems to be off-line, will not run all DNS tests\n"); | 267 | "%s", |
268 | "System seems to be off-line, will not run all DNS tests\n"); | ||
251 | *ok = 0; /* mark test as passing anyway */ | 269 | *ok = 0; /* mark test as passing anyway */ |
252 | return; | 270 | return; |
253 | } | 271 | } |
@@ -263,9 +281,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
263 | } | 281 | } |
264 | 282 | ||
265 | /* Comparing to resolved address to the address the root name server should have */ | 283 | /* Comparing to resolved address to the address the root name server should have */ |
266 | if (strcmp | 284 | if (0 != |
267 | (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), | 285 | strcmp (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), |
268 | ROOTSERVER_IP) != 0) | 286 | ROOTSERVER_IP)) |
269 | { | 287 | { |
270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
271 | "IP received and IP for root name server differ\n"); | 289 | "IP received and IP for root name server differ\n"); |
@@ -281,11 +299,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
281 | * Success: forward lookups work as expected | 299 | * Success: forward lookups work as expected |
282 | * Next step: reverse lookups | 300 | * Next step: reverse lookups |
283 | */ | 301 | */ |
284 | 302 | if (1 != inet_pton (AF_INET, | |
285 | struct in_addr rootserver_addr; | 303 | ROOTSERVER_IP, |
286 | 304 | &rootserver_addr)) | |
287 | rootserver->h_name = ""; | ||
288 | if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) | ||
289 | { | 305 | { |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "Could not transform root name server IP address\n"); | 307 | "Could not transform root name server IP address\n"); |
@@ -293,7 +309,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
293 | } | 309 | } |
294 | 310 | ||
295 | rootserver = | 311 | rootserver = |
296 | gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); | 312 | gethostbyaddr (&rootserver_addr, |
313 | sizeof (rootserver_addr), | ||
314 | AF_INET); | ||
297 | if (NULL == rootserver) | 315 | if (NULL == rootserver) |
298 | { | 316 | { |
299 | /* Error: resolving IP addresses does not work */ | 317 | /* Error: resolving IP addresses does not work */ |