diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/util/test_resolver_api.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/util/test_resolver_api.c')
-rw-r--r-- | src/util/test_resolver_api.c | 360 |
1 files changed, 188 insertions, 172 deletions
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 39cfa43fc..8058fa287 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -41,112 +41,114 @@ | |||
41 | #define ROOTSERVER_IP "198.41.0.4" | 41 | #define ROOTSERVER_IP "198.41.0.4" |
42 | 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 (salen == 0) |
49 | { | 49 | { |
50 | (*ok) &= ~8; | 50 | (*ok) &= ~8; |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), | 53 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), |
54 | GNUNET_a2s(sa, salen)); | 54 | GNUNET_a2s (sa, salen)); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | static void | 58 | static void |
59 | check_localhost_num(void *cls, const char *hostname) | 59 | check_localhost_num (void *cls, const char *hostname) |
60 | { | 60 | { |
61 | int *ok = cls; | 61 | int *ok = cls; |
62 | |||
62 | if (hostname == NULL) | 63 | if (hostname == NULL) |
63 | return; | 64 | return; |
64 | if (0 == strcmp(hostname, "127.0.0.1")) | 65 | if (0 == strcmp (hostname, "127.0.0.1")) |
65 | { | 66 | { |
66 | #if DEBUG_RESOLVER | 67 | #if DEBUG_RESOLVER |
67 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
68 | "Received correct hostname `%s'.\n", hostname); | 69 | "Received correct hostname `%s'.\n", hostname); |
69 | #endif | 70 | #endif |
70 | (*ok) &= ~4; | 71 | (*ok) &= ~4; |
71 | } | 72 | } |
72 | else | 73 | else |
73 | { | 74 | { |
74 | #if DEBUG_RESOLVER | 75 | #if DEBUG_RESOLVER |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
76 | "Received invalid hostname `%s'.\n", hostname); | 77 | "Received invalid hostname `%s'.\n", hostname); |
77 | #endif | 78 | #endif |
78 | GNUNET_break(0); | 79 | GNUNET_break (0); |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | 83 | ||
83 | static void | 84 | static void |
84 | check_localhost(void *cls, const char *hostname) | 85 | check_localhost (void *cls, const char *hostname) |
85 | { | 86 | { |
86 | int *ok = cls; | 87 | int *ok = cls; |
88 | |||
87 | if (hostname == NULL) | 89 | if (hostname == NULL) |
88 | return; | 90 | return; |
89 | if (0 == strcmp(hostname, "localhost")) | 91 | if (0 == strcmp (hostname, "localhost")) |
90 | { | 92 | { |
91 | #if DEBUG_RESOLVER | 93 | #if DEBUG_RESOLVER |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | "Received correct hostname `%s'.\n", hostname); | 95 | "Received correct hostname `%s'.\n", hostname); |
94 | #endif | 96 | #endif |
95 | (*ok) &= ~2; | 97 | (*ok) &= ~2; |
96 | } | 98 | } |
97 | else | 99 | else |
98 | { | 100 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
100 | "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", | 102 | "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", |
101 | hostname); | 103 | hostname); |
102 | } | 104 | } |
103 | } | 105 | } |
104 | 106 | ||
105 | static void | 107 | static void |
106 | check_127(void *cls, const struct sockaddr *sa, socklen_t salen) | 108 | check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) |
107 | { | 109 | { |
108 | int *ok = cls; | 110 | int *ok = cls; |
109 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 111 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
110 | 112 | ||
111 | if (sa == NULL) | 113 | if (sa == NULL) |
112 | return; | 114 | return; |
113 | GNUNET_assert(sizeof(struct sockaddr_in) == salen); | 115 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
114 | if (sai->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) | 116 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) |
115 | { | 117 | { |
116 | #if DEBUG_RESOLVER | 118 | #if DEBUG_RESOLVER |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); |
118 | #endif | 120 | #endif |
119 | (*ok) &= ~1; | 121 | (*ok) &= ~1; |
120 | } | 122 | } |
121 | else | 123 | else |
122 | { | 124 | { |
123 | #if DEBUG_RESOLVER | 125 | #if DEBUG_RESOLVER |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); |
125 | #endif | 127 | #endif |
126 | GNUNET_break(0); | 128 | GNUNET_break (0); |
127 | } | 129 | } |
128 | } | 130 | } |
129 | 131 | ||
130 | static void | 132 | static void |
131 | check_local_fqdn(void *cls, const char *gnunet_fqdn) | 133 | check_local_fqdn (void *cls, const char *gnunet_fqdn) |
132 | { | 134 | { |
133 | int result = 0; | 135 | int result = 0; |
134 | 136 | ||
135 | struct hostent *host; | 137 | struct hostent *host; |
136 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 138 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
137 | 139 | ||
138 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 140 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
139 | { | 141 | { |
140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | 142 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | |
141 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | 143 | GNUNET_ERROR_TYPE_BULK, "gethostname"); |
142 | return; | 144 | return; |
143 | } | 145 | } |
144 | #if DEBUG_RESOLVER | 146 | #if DEBUG_RESOLVER |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | _("Resolving our FQDN `%s'\n"), hostname); | 148 | _("Resolving our FQDN `%s'\n"), hostname); |
147 | #endif | 149 | #endif |
148 | host = gethostbyname ( hostname ); | 150 | host = gethostbyname (hostname); |
149 | if ( NULL == host) | 151 | if (NULL == host) |
150 | { | 152 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
152 | _("Could not resolve our FQDN : %s %u\n"), | 154 | _("Could not resolve our FQDN : %s %u\n"), |
@@ -154,144 +156,150 @@ check_local_fqdn(void *cls, const char *gnunet_fqdn) | |||
154 | return; | 156 | return; |
155 | } | 157 | } |
156 | 158 | ||
157 | GNUNET_assert( 0 != host); | 159 | GNUNET_assert (0 != host); |
158 | 160 | ||
159 | result = strcmp(host->h_name, gnunet_fqdn); | 161 | result = strcmp (host->h_name, gnunet_fqdn); |
160 | if ( 0 != result ) | 162 | if (0 != result) |
161 | { | 163 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
163 | "Local resolved and resolver resolved fqdns are not equal\n"); | 165 | "Local resolved and resolver resolved fqdns are not equal\n"); |
164 | } | 166 | } |
165 | GNUNET_assert( 0 == result); | 167 | GNUNET_assert (0 == result); |
166 | } | 168 | } |
167 | 169 | ||
168 | 170 | ||
169 | 171 | ||
170 | static void | 172 | static void |
171 | check_rootserver_ip(void *cls, const struct sockaddr *sa, socklen_t salen) | 173 | check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) |
172 | { | 174 | { |
173 | int *ok = cls; | 175 | int *ok = cls; |
174 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 176 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
175 | 177 | ||
176 | if (sa == NULL) | 178 | if (sa == NULL) |
177 | return; | 179 | return; |
178 | GNUNET_assert(sizeof(struct sockaddr_in) == salen); | 180 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
179 | 181 | ||
180 | if (0 == strcmp(inet_ntoa(sai->sin_addr), ROOTSERVER_IP)) | 182 | if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP)) |
181 | { | 183 | { |
182 | #if DEBUG_RESOLVER | 184 | #if DEBUG_RESOLVER |
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct rootserver ip address.\n"); | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
186 | "Received correct rootserver ip address.\n"); | ||
184 | #endif | 187 | #endif |
185 | (*ok) &= ~1; | 188 | (*ok) &= ~1; |
186 | } | 189 | } |
187 | else | 190 | else |
188 | { | 191 | { |
189 | #if DEBUG_RESOLVER | 192 | #if DEBUG_RESOLVER |
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect rootserver ip address.\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Received incorrect rootserver ip address.\n"); | ||
191 | #endif | 195 | #endif |
192 | GNUNET_break(0); | 196 | GNUNET_break (0); |
193 | } | 197 | } |
194 | } | 198 | } |
195 | 199 | ||
196 | static void | 200 | static void |
197 | check_rootserver_name(void *cls, const char *hostname) | 201 | check_rootserver_name (void *cls, const char *hostname) |
198 | { | 202 | { |
199 | int *ok = cls; | 203 | int *ok = cls; |
204 | |||
200 | if (hostname == NULL) | 205 | if (hostname == NULL) |
201 | return; | 206 | return; |
202 | 207 | ||
203 | if (0 == strcmp(hostname, ROOTSERVER_NAME)) | 208 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) |
204 | { | 209 | { |
205 | #if DEBUG_RESOLVER | 210 | #if DEBUG_RESOLVER |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
207 | "Received correct rootserver hostname `%s'.\n", hostname); | 212 | "Received correct rootserver hostname `%s'.\n", hostname); |
208 | #endif | 213 | #endif |
209 | (*ok) &= ~2; | 214 | (*ok) &= ~2; |
210 | } | 215 | } |
211 | else | 216 | else |
212 | { | 217 | { |
213 | #if DEBUG_RESOLVER | 218 | #if DEBUG_RESOLVER |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "Received invalid rootserver hostname `%s'.\n", hostname); | 220 | "Received invalid rootserver hostname `%s'.\n", hostname); |
216 | #endif | 221 | #endif |
217 | GNUNET_break(0); | 222 | GNUNET_break (0); |
218 | } | 223 | } |
219 | } | 224 | } |
220 | 225 | ||
221 | static void | 226 | static void |
222 | run(void *cls, char * const *args, | 227 | run (void *cls, char *const *args, |
223 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 228 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
224 | { | 229 | { |
225 | int *ok = cls; | 230 | int *ok = cls; |
226 | struct sockaddr_in sa; | 231 | struct sockaddr_in sa; |
227 | struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply( | 232 | struct GNUNET_TIME_Relative timeout = |
228 | GNUNET_TIME_UNIT_SECONDS, 30); | 233 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
229 | int count_ips = 0; | 234 | int count_ips = 0; |
230 | char * own_fqdn; | 235 | char *own_fqdn; |
231 | 236 | ||
232 | memset(&sa, 0, sizeof(sa)); | 237 | memset (&sa, 0, sizeof (sa)); |
233 | sa.sin_family = AF_INET; | 238 | sa.sin_family = AF_INET; |
234 | #if HAVE_SOCKADDR_IN_SIN_LEN | 239 | #if HAVE_SOCKADDR_IN_SIN_LEN |
235 | sa.sin_len = (u_char) sizeof (sa); | 240 | sa.sin_len = (u_char) sizeof (sa); |
236 | #endif | 241 | #endif |
237 | sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 242 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
238 | 243 | ||
239 | /* | 244 | /* |
240 | * Looking up our own fqdn | 245 | * Looking up our own fqdn |
241 | */ | 246 | */ |
242 | own_fqdn = GNUNET_RESOLVER_local_fqdn_get(); | 247 | own_fqdn = GNUNET_RESOLVER_local_fqdn_get (); |
243 | check_local_fqdn( NULL, own_fqdn); | 248 | check_local_fqdn (NULL, own_fqdn); |
244 | GNUNET_free_non_null (own_fqdn); | 249 | GNUNET_free_non_null (own_fqdn); |
245 | 250 | ||
246 | /* | 251 | /* |
247 | * Testing non-local DNS resolution | 252 | * Testing non-local DNS resolution |
248 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | 253 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 |
249 | */ | 254 | */ |
250 | const char * rootserver_name = ROOTSERVER_NAME; | 255 | const char *rootserver_name = ROOTSERVER_NAME; |
251 | struct hostent *rootserver; | 256 | struct hostent *rootserver; |
252 | 257 | ||
253 | rootserver = gethostbyname(rootserver_name); | 258 | rootserver = gethostbyname (rootserver_name); |
254 | if (rootserver == NULL) | 259 | if (rootserver == NULL) |
255 | { | 260 | { |
256 | /* Error: resolving ip addresses does not work */ | 261 | /* Error: resolving ip addresses does not work */ |
257 | #if DEBUG_RESOLVER | 262 | #if DEBUG_RESOLVER |
258 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
259 | _("gethostbyname() could not lookup IP address: %s\n"), | 264 | _("gethostbyname() could not lookup IP address: %s\n"), |
260 | hstrerror (h_errno)); | 265 | hstrerror (h_errno)); |
261 | #endif | 266 | #endif |
262 | fprintf (stderr, | 267 | fprintf (stderr, |
263 | "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"); |
264 | *ok = 0; /* mark test as passing anyway */ | 269 | *ok = 0; /* mark test as passing anyway */ |
265 | return; | 270 | return; |
266 | } | 271 | } |
267 | 272 | ||
268 | /* Counting returned IP addresses */ | 273 | /* Counting returned IP addresses */ |
269 | while (rootserver->h_addr_list[count_ips] != NULL) | 274 | while (rootserver->h_addr_list[count_ips] != NULL) |
270 | count_ips++; | 275 | count_ips++; |
271 | if (count_ips > 1) | 276 | if (count_ips > 1) |
272 | { | 277 | { |
273 | #if DEBUG_RESOLVER | 278 | #if DEBUG_RESOLVER |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received range for root name server, but a root name server has only 1 IP\n"); | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
280 | "IP received range for root name server, but a root name server has only 1 IP\n"); | ||
275 | #endif | 281 | #endif |
276 | GNUNET_break(0); | 282 | GNUNET_break (0); |
277 | } | 283 | } |
278 | 284 | ||
279 | /* 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 */ |
280 | if (strcmp(inet_ntoa(*(struct in_addr *) rootserver->h_addr_list[0]), | 286 | if (strcmp (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), |
281 | ROOTSERVER_IP) != 0) | 287 | ROOTSERVER_IP) != 0) |
282 | { | 288 | { |
283 | #if DEBUG_RESOLVER | 289 | #if DEBUG_RESOLVER |
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received and IP for root name server differ\n"); | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "IP received and IP for root name server differ\n"); | ||
285 | #endif | 292 | #endif |
286 | GNUNET_break(0); | 293 | GNUNET_break (0); |
287 | } | 294 | } |
288 | #if DEBUG_RESOLVER | 295 | #if DEBUG_RESOLVER |
289 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own forward name resolution is working\n"); | 296 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
297 | "System's own forward name resolution is working\n"); | ||
290 | #endif | 298 | #endif |
291 | 299 | ||
292 | /* Resolve the same using GNUNET */ | 300 | /* Resolve the same using GNUNET */ |
293 | GNUNET_RESOLVER_ip_get(ROOTSERVER_NAME, AF_INET, timeout, | 301 | GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, |
294 | &check_rootserver_ip, cls); | 302 | &check_rootserver_ip, cls); |
295 | 303 | ||
296 | /* | 304 | /* |
297 | * Success: forward lookups work as expected | 305 | * Success: forward lookups work as expected |
@@ -299,129 +307,137 @@ run(void *cls, char * const *args, | |||
299 | */ | 307 | */ |
300 | 308 | ||
301 | struct in_addr rootserver_addr; | 309 | struct in_addr rootserver_addr; |
310 | |||
302 | rootserver->h_name = ""; | 311 | rootserver->h_name = ""; |
303 | if (1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr)) | 312 | if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) |
304 | { | 313 | { |
305 | #if DEBUG_RESOLVER | 314 | #if DEBUG_RESOLVER |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transform root name server IP address\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
316 | "Could not transform root name server IP address\n"); | ||
307 | #endif | 317 | #endif |
308 | GNUNET_break(0); | 318 | GNUNET_break (0); |
309 | } | 319 | } |
310 | 320 | ||
311 | rootserver | 321 | rootserver |
312 | = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET); | 322 | = gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); |
313 | if (rootserver == NULL) | 323 | if (rootserver == NULL) |
314 | { | 324 | { |
315 | /* Error: resolving IP addresses does not work */ | 325 | /* Error: resolving IP addresses does not work */ |
316 | #if DEBUG_RESOLVER | 326 | #if DEBUG_RESOLVER |
317 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
318 | _("gethostbyaddr() could not lookup hostname: %s\n"), | 328 | _("gethostbyaddr() could not lookup hostname: %s\n"), |
319 | hstrerror (h_errno)); | 329 | hstrerror (h_errno)); |
320 | #endif | 330 | #endif |
321 | GNUNET_break(0); | 331 | GNUNET_break (0); |
322 | } | 332 | } |
323 | else | 333 | else |
324 | { | 334 | { |
325 | if (0 != strcmp(rootserver->h_name, ROOTSERVER_NAME)) | 335 | if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) |
326 | { | 336 | { |
327 | #if DEBUG_RESOLVER | 337 | #if DEBUG_RESOLVER |
328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received hostname and hostname for root name server differ\n"); | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
339 | "Received hostname and hostname for root name server differ\n"); | ||
329 | #endif | 340 | #endif |
330 | GNUNET_break(0); | 341 | GNUNET_break (0); |
331 | } | 342 | } |
332 | } | 343 | } |
333 | 344 | ||
334 | #if DEBUG_RESOLVER | 345 | #if DEBUG_RESOLVER |
335 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
336 | "System's own reverse name resolution is working\n"); | 347 | "System's own reverse name resolution is working\n"); |
337 | #endif | 348 | #endif |
338 | 349 | ||
339 | /* Resolve the same using GNUNET */ | 350 | /* Resolve the same using GNUNET */ |
340 | memset(&sa, 0, sizeof(sa)); | 351 | memset (&sa, 0, sizeof (sa)); |
341 | sa.sin_family = AF_INET; | 352 | sa.sin_family = AF_INET; |
342 | #if HAVE_SOCKADDR_IN_SIN_LEN | 353 | #if HAVE_SOCKADDR_IN_SIN_LEN |
343 | sa.sin_len = (u_char) sizeof (sa); | 354 | sa.sin_len = (u_char) sizeof (sa); |
344 | #endif | 355 | #endif |
345 | #ifndef MINGW | 356 | #ifndef MINGW |
346 | inet_aton(ROOTSERVER_IP, &sa.sin_addr); | 357 | inet_aton (ROOTSERVER_IP, &sa.sin_addr); |
347 | #else | 358 | #else |
348 | sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP); | 359 | sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP); |
349 | #endif | 360 | #endif |
350 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 361 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
351 | sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls); | 362 | sizeof (struct sockaddr), GNUNET_YES, timeout, |
363 | &check_rootserver_name, cls); | ||
352 | 364 | ||
353 | memset(&sa, 0, sizeof(sa)); | 365 | memset (&sa, 0, sizeof (sa)); |
354 | sa.sin_family = AF_INET; | 366 | sa.sin_family = AF_INET; |
355 | #if HAVE_SOCKADDR_IN_SIN_LEN | 367 | #if HAVE_SOCKADDR_IN_SIN_LEN |
356 | sa.sin_len = (u_char) sizeof (sa); | 368 | sa.sin_len = (u_char) sizeof (sa); |
357 | #endif | 369 | #endif |
358 | sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 370 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
359 | 371 | ||
360 | GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127, | 372 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls); |
361 | cls); | 373 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
362 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 374 | sizeof (struct sockaddr), GNUNET_YES, timeout, |
363 | sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls); | 375 | &check_localhost, cls); |
364 | 376 | ||
365 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 377 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
366 | sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls); | 378 | sizeof (struct sockaddr), GNUNET_NO, timeout, |
367 | GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout, | 379 | &check_localhost_num, cls); |
368 | &check_hostname, cls); | 380 | GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls); |
369 | 381 | ||
370 | } | 382 | } |
371 | 383 | ||
372 | static int | 384 | static int |
373 | check() | 385 | check () |
374 | { | 386 | { |
375 | int ok = 1 + 2 + 4 + 8; | 387 | int ok = 1 + 2 + 4 + 8; |
376 | char *fn; | 388 | char *fn; |
377 | char *pfx; | 389 | char *pfx; |
378 | struct GNUNET_OS_Process *proc; | 390 | struct GNUNET_OS_Process *proc; |
379 | char * const argv[] = | 391 | |
380 | { "test-resolver-api", "-c", "test_resolver_api_data.conf", | 392 | char *const argv[] = |
393 | { "test-resolver-api", "-c", "test_resolver_api_data.conf", | ||
381 | #if VERBOSE | 394 | #if VERBOSE |
382 | "-L", "DEBUG", | 395 | "-L", "DEBUG", |
383 | #endif | 396 | #endif |
384 | NULL }; | 397 | NULL |
398 | }; | ||
385 | struct GNUNET_GETOPT_CommandLineOption options[] = | 399 | struct GNUNET_GETOPT_CommandLineOption options[] = |
386 | { GNUNET_GETOPT_OPTION_END }; | 400 | { GNUNET_GETOPT_OPTION_END }; |
387 | pfx = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_BINDIR); | 401 | pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); |
388 | GNUNET_asprintf(&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); | 402 | GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); |
389 | GNUNET_free(pfx); | 403 | GNUNET_free (pfx); |
390 | proc = GNUNET_OS_start_process(NULL, NULL, fn, "gnunet-service-resolver", | 404 | proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver", |
391 | #if VERBOSE | 405 | #if VERBOSE |
392 | "-L", "DEBUG", | 406 | "-L", "DEBUG", |
393 | #endif | 407 | #endif |
394 | "-c", "test_resolver_api_data.conf", NULL); | 408 | "-c", "test_resolver_api_data.conf", NULL); |
395 | GNUNET_assert (NULL != proc); | 409 | GNUNET_assert (NULL != proc); |
396 | GNUNET_free(fn); | 410 | GNUNET_free (fn); |
397 | GNUNET_assert(GNUNET_OK == GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) | 411 | GNUNET_assert (GNUNET_OK == |
398 | - 1, argv, "test-resolver-api", "nohelp", options, &run, &ok)); | 412 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
413 | argv, "test-resolver-api", "nohelp", | ||
414 | options, &run, &ok)); | ||
399 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 415 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
400 | { | 416 | { |
401 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 417 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
402 | ok = 1; | 418 | ok = 1; |
403 | } | 419 | } |
404 | GNUNET_OS_process_wait (proc); | 420 | GNUNET_OS_process_wait (proc); |
405 | GNUNET_OS_process_close (proc); | 421 | GNUNET_OS_process_close (proc); |
406 | proc = NULL; | 422 | proc = NULL; |
407 | if (ok != 0) | 423 | if (ok != 0) |
408 | fprintf(stderr, "Missed some resolutions: %u\n", ok); | 424 | fprintf (stderr, "Missed some resolutions: %u\n", ok); |
409 | return ok; | 425 | return ok; |
410 | } | 426 | } |
411 | 427 | ||
412 | int | 428 | int |
413 | main(int argc, char *argv[]) | 429 | main (int argc, char *argv[]) |
414 | { | 430 | { |
415 | int ret; | 431 | int ret; |
416 | 432 | ||
417 | GNUNET_log_setup("test-resolver-api", | 433 | GNUNET_log_setup ("test-resolver-api", |
418 | #if VERBOSE | 434 | #if VERBOSE |
419 | "DEBUG", | 435 | "DEBUG", |
420 | #else | 436 | #else |
421 | "WARNING", | 437 | "WARNING", |
422 | #endif | 438 | #endif |
423 | NULL); | 439 | NULL); |
424 | ret = check(); | 440 | ret = check (); |
425 | 441 | ||
426 | return ret; | 442 | return ret; |
427 | } | 443 | } |