diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-01 09:07:19 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-01 09:07:19 +0000 |
commit | 6de4e547529a948c11423868e768b0a8d39a6cee (patch) | |
tree | 9faa0dc3fb903c0fa8738f669d166491a89dbfdc /src/util/test_resolver_api.c | |
parent | eb48917c720068f8f305638d6104e7f1ca686719 (diff) | |
download | gnunet-6de4e547529a948c11423868e768b0a8d39a6cee.tar.gz gnunet-6de4e547529a948c11423868e768b0a8d39a6cee.zip |
source code changed to meet coding conventions
Diffstat (limited to 'src/util/test_resolver_api.c')
-rw-r--r-- | src/util/test_resolver_api.c | 123 |
1 files changed, 58 insertions, 65 deletions
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 5fcf53210..30b455aed 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #define VERBOSE GNUNET_NO | 33 | #define VERBOSE GNUNET_NO |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Using dns rootservers to check gnunet's resolver service | 36 | * Using DNS root servers to check gnunet's resolver service |
37 | * a.root-servers.net <-> 198.41.0.4 is a fix 1:1 mapping that should not change over years | 37 | * a.root-servers.net <-> 198.41.0.4 is a fix 1:1 mapping that should not change over years |
38 | * For more information have a look at IANA's website http://www.root-servers.org/ | 38 | * For more information have a look at IANA's website http://www.root-servers.org/ |
39 | */ | 39 | */ |
@@ -188,121 +188,116 @@ run (void *cls, | |||
188 | { | 188 | { |
189 | struct sockaddr_in sa; | 189 | struct sockaddr_in sa; |
190 | struct GNUNET_TIME_Relative timeout = | 190 | struct GNUNET_TIME_Relative timeout = |
191 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 191 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
192 | 2500); | 192 | 2500); |
193 | int count_ips =0 ; | ||
194 | |||
193 | memset (&sa, 0, sizeof (sa)); | 195 | memset (&sa, 0, sizeof (sa)); |
194 | sa.sin_family = AF_INET; | 196 | sa.sin_family = AF_INET; |
195 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 197 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
196 | GNUNET_RESOLVER_ip_get (sched, | 198 | GNUNET_RESOLVER_ip_get (sched, |
197 | cfg, | 199 | cfg, |
198 | "localhost", AF_INET, timeout, &check_127, cls); | 200 | "localhost", AF_INET, timeout, &check_127, cls); |
199 | GNUNET_RESOLVER_hostname_get (sched, | 201 | GNUNET_RESOLVER_hostname_get (sched, |
200 | cfg, | 202 | cfg, |
201 | (const struct sockaddr *) &sa, | 203 | (const struct sockaddr *) &sa, |
202 | sizeof (struct sockaddr), | 204 | sizeof (struct sockaddr), |
203 | GNUNET_YES, timeout, &check_localhost, cls); | 205 | GNUNET_YES, timeout, &check_localhost, cls); |
204 | GNUNET_RESOLVER_hostname_get (sched, | 206 | GNUNET_RESOLVER_hostname_get (sched, |
205 | cfg, | 207 | cfg, |
206 | (const struct sockaddr *) &sa, | 208 | (const struct sockaddr *) &sa, |
207 | sizeof (struct sockaddr), | 209 | sizeof (struct sockaddr), |
208 | GNUNET_NO, | 210 | GNUNET_NO, |
209 | timeout, &check_localhost_num, cls); | 211 | timeout, &check_localhost_num, cls); |
210 | GNUNET_RESOLVER_hostname_resolve (sched, | 212 | GNUNET_RESOLVER_hostname_resolve (sched, |
211 | cfg, | 213 | cfg, |
212 | AF_UNSPEC, timeout, &check_hostname, cls); | 214 | AF_UNSPEC, timeout, &check_hostname, cls); |
213 | // Testing non-local dns resolution | 215 | /* |
214 | // DNS Rootserver to test: a.root-servers.net - 198.41.0.4 | 216 | * Testing non-local DNS resolution |
217 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | ||
218 | */ | ||
215 | 219 | ||
216 | char const * rootserver_name = ROOTSERVER_NAME; | 220 | char const * rootserver_name = ROOTSERVER_NAME; |
217 | |||
218 | struct hostent *rootserver; | 221 | struct hostent *rootserver; |
219 | 222 | ||
220 | rootserver = gethostbyname(rootserver_name); | 223 | rootserver = gethostbyname(rootserver_name); |
221 | if (rootserver == NULL) | 224 | if (rootserver == NULL) |
222 | { | 225 | { |
223 | // Error: resolving ip addresses does not work | 226 | /* Error: resolving ip addresses does not work */ |
224 | #if DEBUG_RESOLVER | 227 | #if DEBUG_RESOLVER |
225 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 228 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
226 | _("gethostbyname() could not lookup IP address: %s\n"), | 229 | _("gethostbyname() could not lookup IP address: %s\n"), |
227 | hstrerror (h_errno)); | 230 | hstrerror (h_errno)); |
228 | #endif | 231 | #endif |
229 | GNUNET_break (0); | 232 | GNUNET_break (0); |
230 | return; | 233 | return; |
231 | } | 234 | } |
232 | // Counting returned ip addresses | 235 | |
233 | int count_ips =0 ; | 236 | /* Counting returned IP addresses */ |
234 | while (rootserver->h_addr_list[count_ips]!=NULL) | 237 | while (rootserver->h_addr_list[count_ips]!=NULL) |
235 | { | ||
236 | count_ips++; | 238 | count_ips++; |
237 | } | ||
238 | if ( count_ips > 1) | 239 | if ( count_ips > 1) |
239 | { | 240 | { |
240 | #if DEBUG_RESOLVER | 241 | #if DEBUG_RESOLVER |
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ip range for root name server, but a root nameserver has only 1 ip\n"); | 242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received range for root name server, but a root name server has only 1 IP\n"); |
242 | #endif | 243 | #endif |
243 | GNUNET_break (0); | 244 | GNUNET_break (0); |
244 | } | 245 | } |
245 | 246 | ||
246 | // Comparing to resolved address to the address the root nameserver should have | 247 | /* Comparing to resolved address to the address the root name server should have */ |
247 | if ( strcmp(inet_ntoa( *(struct in_addr *) rootserver->h_addr_list[0]),ROOTSERVER_IP) !=0) | 248 | if ( strcmp(inet_ntoa( *(struct in_addr *) rootserver->h_addr_list[0]),ROOTSERVER_IP) !=0) |
248 | { | 249 | { |
249 | #if DEBUG_RESOLVER | 250 | #if DEBUG_RESOLVER |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ip and ip for root name server differ\n"); | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received and IP for root name server differ\n"); |
251 | #endif | 252 | #endif |
252 | GNUNET_break (0); | 253 | GNUNET_break (0); |
253 | } | 254 | } |
254 | 255 | #if DEBUG_RESOLVER | |
255 | #if DEBUG_RESOLVER | ||
256 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own forward name resolution is working\n"); | 256 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own forward name resolution is working\n"); |
257 | #endif | 257 | #endif |
258 | 258 | ||
259 | // Resolve the same using GNUNET | 259 | /* Resolve the same using GNUNET */ |
260 | GNUNET_RESOLVER_ip_get (sched, cfg, ROOTSERVER_NAME, AF_INET, timeout, &check_rootserver_ip, cls); | 260 | GNUNET_RESOLVER_ip_get (sched, cfg, ROOTSERVER_NAME, AF_INET, timeout, &check_rootserver_ip, cls); |
261 | 261 | ||
262 | // Success: forward lookups work as exptected | 262 | /* |
263 | * Success: forward lookups work as expected | ||
264 | * Next step: reverse lookups | ||
265 | */ | ||
263 | 266 | ||
264 | |||
265 | // Next step: reverse lookups | ||
266 | |||
267 | struct in_addr rootserver_addr; | 267 | struct in_addr rootserver_addr; |
268 | rootserver->h_name=""; | 268 | rootserver->h_name=""; |
269 | if ( 1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr)) | 269 | if ( 1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr)) |
270 | { | 270 | { |
271 | #if DEBUG_RESOLVER | 271 | #if DEBUG_RESOLVER |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transform root nameserver ip addressr\n"); | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transform root name server IP address\n"); |
273 | #endif | 273 | #endif |
274 | GNUNET_break (0); | 274 | GNUNET_break (0); |
275 | } | 275 | } |
276 | 276 | ||
277 | rootserver = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET); | 277 | rootserver = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET); |
278 | if (rootserver == NULL) | 278 | if (rootserver == NULL) |
279 | { | 279 | { |
280 | // Error: resolving ip addresses does not work | 280 | /* Error: resolving ip addresses does not work */ |
281 | #if DEBUG_RESOLVER | 281 | #if DEBUG_RESOLVER |
282 | switch (h_errno) | 282 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
283 | { | 283 | _("gethostbyaddr() could not lookup hostname: %s\n"), |
284 | 284 | hstrerror (h_errno)); | |
285 | case HOST_NOT_FOUND: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "gethostbyaddr() could not lookup ip address: HOST_NOT_FOUND\n");break; | 285 | #endif |
286 | case NO_ADDRESS: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "gethostbyaddr() could not lookup ip address: NO_ADDRESS\n");break; | ||
287 | case NO_RECOVERY: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "gethostbyaddr() could not lookup ip address: NO_RECOVERY\n");break; | ||
288 | case TRY_AGAIN: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "gethostbyaddr() could not lookup ip address: TRY_AGAIN\n");break; | ||
289 | } | ||
290 | #endif | ||
291 | GNUNET_break (0); | 286 | GNUNET_break (0); |
292 | } | 287 | } |
293 | 288 | ||
294 | if ( 0 != strcmp( rootserver->h_name,ROOTSERVER_NAME)) | 289 | if ( 0 != strcmp( rootserver->h_name,ROOTSERVER_NAME)) |
295 | { | 290 | { |
296 | #if DEBUG_RESOLVER | 291 | #if DEBUG_RESOLVER |
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received hostname and hostname for root name server differ\n"); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received hostname and hostname for root name server differ\n"); |
298 | #endif | 293 | #endif |
299 | GNUNET_break (0); | 294 | GNUNET_break (0); |
300 | } | 295 | } |
301 | 296 | ||
302 | #if DEBUG_RESOLVER | 297 | #if DEBUG_RESOLVER |
303 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is working\n"); | 298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is working\n"); |
304 | #endif | 299 | #endif |
305 | // Resolve the same using GNUNET | 300 | /* Resolve the same using GNUNET */ |
306 | 301 | ||
307 | memset (&sa, 0, sizeof (sa)); | 302 | memset (&sa, 0, sizeof (sa)); |
308 | sa.sin_family = AF_INET; | 303 | sa.sin_family = AF_INET; |
@@ -314,8 +309,6 @@ run (void *cls, | |||
314 | sizeof (struct sockaddr), | 309 | sizeof (struct sockaddr), |
315 | GNUNET_YES, | 310 | GNUNET_YES, |
316 | timeout, &check_rootserver_name, cls); | 311 | timeout, &check_rootserver_name, cls); |
317 | |||
318 | |||
319 | } | 312 | } |
320 | 313 | ||
321 | static int | 314 | static int |