diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
commit | d9d94d0e53d26af75ec8241383d166544ebd79f3 (patch) | |
tree | 9080b73624389403a198257fe0547bb4634e64d2 /src/util/gnunet-service-resolver.c | |
parent | 2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff) | |
download | gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip |
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r-- | src/util/gnunet-service-resolver.c | 411 |
1 files changed, 206 insertions, 205 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 5d4c5c224..c15f0d3f5 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -89,7 +89,7 @@ getnameinfo_resolve (struct IPCache *cache) | |||
89 | 89 | ||
90 | if (0 == | 90 | if (0 == |
91 | getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL, | 91 | getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL, |
92 | 0, 0)) | 92 | 0, 0)) |
93 | cache->addr = GNUNET_strdup (hostname); | 93 | cache->addr = GNUNET_strdup (hostname); |
94 | } | 94 | } |
95 | #endif | 95 | #endif |
@@ -107,20 +107,20 @@ gethostbyaddr_resolve (struct IPCache *cache) | |||
107 | struct hostent *ent; | 107 | struct hostent *ent; |
108 | 108 | ||
109 | switch (cache->sa->sa_family) | 109 | switch (cache->sa->sa_family) |
110 | { | 110 | { |
111 | case AF_INET: | 111 | case AF_INET: |
112 | ent = | 112 | ent = |
113 | gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, | 113 | gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, |
114 | sizeof (struct in_addr), AF_INET); | 114 | sizeof (struct in_addr), AF_INET); |
115 | break; | 115 | break; |
116 | case AF_INET6: | 116 | case AF_INET6: |
117 | ent = | 117 | ent = |
118 | gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, | 118 | gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, |
119 | sizeof (struct in6_addr), AF_INET6); | 119 | sizeof (struct in6_addr), AF_INET6); |
120 | break; | 120 | break; |
121 | default: | 121 | default: |
122 | ent = NULL; | 122 | ent = NULL; |
123 | } | 123 | } |
124 | if (ent != NULL) | 124 | if (ent != NULL) |
125 | cache->addr = GNUNET_strdup (ent->h_name); | 125 | cache->addr = GNUNET_strdup (ent->h_name); |
126 | } | 126 | } |
@@ -158,7 +158,7 @@ cache_resolve (struct IPCache *cache) | |||
158 | */ | 158 | */ |
159 | static void | 159 | static void |
160 | get_ip_as_string (struct GNUNET_SERVER_Client *client, | 160 | get_ip_as_string (struct GNUNET_SERVER_Client *client, |
161 | const struct sockaddr *sa, socklen_t salen) | 161 | const struct sockaddr *sa, socklen_t salen) |
162 | { | 162 | { |
163 | struct IPCache *cache; | 163 | struct IPCache *cache; |
164 | struct IPCache *prev; | 164 | struct IPCache *prev; |
@@ -166,73 +166,73 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
166 | struct GNUNET_SERVER_TransmitContext *tc; | 166 | struct GNUNET_SERVER_TransmitContext *tc; |
167 | 167 | ||
168 | if (salen < sizeof (struct sockaddr)) | 168 | if (salen < sizeof (struct sockaddr)) |
169 | { | 169 | { |
170 | GNUNET_break (0); | 170 | GNUNET_break (0); |
171 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 171 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | now = GNUNET_TIME_absolute_get (); | 174 | now = GNUNET_TIME_absolute_get (); |
175 | cache = head; | 175 | cache = head; |
176 | prev = NULL; | 176 | prev = NULL; |
177 | while ((cache != NULL) && | 177 | while ((cache != NULL) && |
178 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) | 178 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) |
179 | { | ||
180 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
181 | 60 * 60 * 1000) | ||
182 | { | 179 | { |
183 | if (prev != NULL) | 180 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < |
184 | { | 181 | 60 * 60 * 1000) |
185 | prev->next = cache->next; | 182 | { |
186 | GNUNET_free_non_null (cache->addr); | 183 | if (prev != NULL) |
187 | GNUNET_free (cache->sa); | 184 | { |
188 | GNUNET_free (cache); | 185 | prev->next = cache->next; |
189 | cache = prev->next; | 186 | GNUNET_free_non_null (cache->addr); |
190 | } | 187 | GNUNET_free (cache->sa); |
191 | else | 188 | GNUNET_free (cache); |
192 | { | 189 | cache = prev->next; |
193 | head = cache->next; | 190 | } |
194 | GNUNET_free_non_null (cache->addr); | 191 | else |
195 | GNUNET_free (cache->sa); | 192 | { |
196 | GNUNET_free (cache); | 193 | head = cache->next; |
197 | cache = head; | 194 | GNUNET_free_non_null (cache->addr); |
198 | } | 195 | GNUNET_free (cache->sa); |
199 | continue; | 196 | GNUNET_free (cache); |
197 | cache = head; | ||
198 | } | ||
199 | continue; | ||
200 | } | ||
201 | prev = cache; | ||
202 | cache = cache->next; | ||
200 | } | 203 | } |
201 | prev = cache; | ||
202 | cache = cache->next; | ||
203 | } | ||
204 | if (cache != NULL) | 204 | if (cache != NULL) |
205 | { | ||
206 | cache->last_request = now; | ||
207 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
208 | 60 * 60 * 1000) | ||
209 | { | 205 | { |
210 | GNUNET_free_non_null (cache->addr); | 206 | cache->last_request = now; |
207 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
208 | 60 * 60 * 1000) | ||
209 | { | ||
210 | GNUNET_free_non_null (cache->addr); | ||
211 | cache->addr = NULL; | ||
212 | cache->salen = 0; | ||
213 | cache_resolve (cache); | ||
214 | } | ||
215 | } | ||
216 | else | ||
217 | { | ||
218 | cache = GNUNET_malloc (sizeof (struct IPCache)); | ||
219 | cache->next = head; | ||
220 | cache->salen = salen; | ||
221 | cache->sa = GNUNET_malloc (salen); | ||
222 | memcpy (cache->sa, sa, salen); | ||
223 | cache->last_request = GNUNET_TIME_absolute_get (); | ||
224 | cache->last_refresh = GNUNET_TIME_absolute_get (); | ||
211 | cache->addr = NULL; | 225 | cache->addr = NULL; |
212 | cache->salen = 0; | ||
213 | cache_resolve (cache); | 226 | cache_resolve (cache); |
227 | head = cache; | ||
214 | } | 228 | } |
215 | } | ||
216 | else | ||
217 | { | ||
218 | cache = GNUNET_malloc (sizeof (struct IPCache)); | ||
219 | cache->next = head; | ||
220 | cache->salen = salen; | ||
221 | cache->sa = GNUNET_malloc (salen); | ||
222 | memcpy (cache->sa, sa, salen); | ||
223 | cache->last_request = GNUNET_TIME_absolute_get (); | ||
224 | cache->last_refresh = GNUNET_TIME_absolute_get (); | ||
225 | cache->addr = NULL; | ||
226 | cache_resolve (cache); | ||
227 | head = cache; | ||
228 | } | ||
229 | tc = GNUNET_SERVER_transmit_context_create (client); | 229 | tc = GNUNET_SERVER_transmit_context_create (client); |
230 | if (cache->addr != NULL) | 230 | if (cache->addr != NULL) |
231 | GNUNET_SERVER_transmit_context_append_data (tc, cache->addr, | 231 | GNUNET_SERVER_transmit_context_append_data (tc, cache->addr, |
232 | strlen (cache->addr) + 1, | 232 | strlen (cache->addr) + 1, |
233 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 233 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
234 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 234 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
235 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 235 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
236 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 236 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
237 | } | 237 | } |
238 | 238 | ||
@@ -240,7 +240,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
240 | #if HAVE_GETADDRINFO | 240 | #if HAVE_GETADDRINFO |
241 | static int | 241 | static int |
242 | getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | 242 | getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, |
243 | const char *hostname, int domain) | 243 | const char *hostname, int domain) |
244 | { | 244 | { |
245 | int s; | 245 | int s; |
246 | struct addrinfo hints; | 246 | struct addrinfo hints; |
@@ -254,36 +254,37 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
254 | #else | 254 | #else |
255 | hints.ai_family = AF_INET; | 255 | hints.ai_family = AF_INET; |
256 | #endif | 256 | #endif |
257 | hints.ai_socktype = SOCK_STREAM; /* go for TCP */ | 257 | hints.ai_socktype = SOCK_STREAM; /* go for TCP */ |
258 | 258 | ||
259 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) | 259 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) |
260 | { | 260 | { |
261 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"), | 261 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
262 | hostname, | 262 | _("Could not resolve `%s' (%s): %s\n"), hostname, |
263 | (domain == | 263 | (domain == |
264 | AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"), | 264 | AF_INET) ? "IPv4" : ((domain == |
265 | gai_strerror (s)); | 265 | AF_INET6) ? "IPv6" : "any"), |
266 | if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) | 266 | gai_strerror (s)); |
267 | if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) | ||
267 | #ifndef MINGW | 268 | #ifndef MINGW |
268 | || (s == EAI_SYSTEM) | 269 | || (s == EAI_SYSTEM) |
269 | #else | 270 | #else |
270 | // FIXME NILS | 271 | // FIXME NILS |
271 | || 1 | 272 | || 1 |
272 | #endif | 273 | #endif |
273 | ) | 274 | ) |
274 | return GNUNET_NO; /* other function may still succeed */ | 275 | return GNUNET_NO; /* other function may still succeed */ |
275 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
276 | } | 277 | } |
277 | if (result == NULL) | 278 | if (result == NULL) |
278 | return GNUNET_SYSERR; | 279 | return GNUNET_SYSERR; |
279 | pos = result; | 280 | pos = result; |
280 | while (pos != NULL) | 281 | while (pos != NULL) |
281 | { | 282 | { |
282 | GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, | 283 | GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, |
283 | pos->ai_addrlen, | 284 | pos->ai_addrlen, |
284 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 285 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
285 | pos = pos->ai_next; | 286 | pos = pos->ai_next; |
286 | } | 287 | } |
287 | freeaddrinfo (result); | 288 | freeaddrinfo (result); |
288 | return GNUNET_OK; | 289 | return GNUNET_OK; |
289 | } | 290 | } |
@@ -292,7 +293,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
292 | #if HAVE_GETHOSTBYNAME2 | 293 | #if HAVE_GETHOSTBYNAME2 |
293 | static int | 294 | static int |
294 | gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | 295 | gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, |
295 | const char *hostname, int domain) | 296 | const char *hostname, int domain) |
296 | { | 297 | { |
297 | struct hostent *hp; | 298 | struct hostent *hp; |
298 | struct sockaddr_in a4; | 299 | struct sockaddr_in a4; |
@@ -301,48 +302,48 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
301 | int ret2; | 302 | int ret2; |
302 | 303 | ||
303 | if (domain == AF_UNSPEC) | 304 | if (domain == AF_UNSPEC) |
304 | { | 305 | { |
305 | ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); | 306 | ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); |
306 | ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); | 307 | ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); |
307 | if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) | 308 | if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) |
308 | return GNUNET_OK; | 309 | return GNUNET_OK; |
309 | if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) | 310 | if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) |
310 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |
311 | return GNUNET_NO; | 312 | return GNUNET_NO; |
312 | } | 313 | } |
313 | hp = gethostbyname2 (hostname, domain); | 314 | hp = gethostbyname2 (hostname, domain); |
314 | if (hp == NULL) | 315 | if (hp == NULL) |
315 | { | 316 | { |
316 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
317 | _("Could not find IP of host `%s': %s\n"), hostname, | 318 | _("Could not find IP of host `%s': %s\n"), hostname, |
318 | hstrerror (h_errno)); | 319 | hstrerror (h_errno)); |
319 | return GNUNET_SYSERR; | 320 | return GNUNET_SYSERR; |
320 | } | 321 | } |
321 | GNUNET_assert (hp->h_addrtype == domain); | 322 | GNUNET_assert (hp->h_addrtype == domain); |
322 | if (domain == AF_INET) | 323 | if (domain == AF_INET) |
323 | { | 324 | { |
324 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); | 325 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); |
325 | memset (&a4, 0, sizeof (a4)); | 326 | memset (&a4, 0, sizeof (a4)); |
326 | a4.sin_family = AF_INET; | 327 | a4.sin_family = AF_INET; |
327 | #if HAVE_SOCKADDR_IN_SIN_LEN | 328 | #if HAVE_SOCKADDR_IN_SIN_LEN |
328 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); | 329 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); |
329 | #endif | 330 | #endif |
330 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); | 331 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); |
331 | GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), | 332 | GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), |
332 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 333 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
333 | } | 334 | } |
334 | else | 335 | else |
335 | { | 336 | { |
336 | GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); | 337 | GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); |
337 | memset (&a6, 0, sizeof (a6)); | 338 | memset (&a6, 0, sizeof (a6)); |
338 | a6.sin6_family = AF_INET6; | 339 | a6.sin6_family = AF_INET6; |
339 | #if HAVE_SOCKADDR_IN_SIN_LEN | 340 | #if HAVE_SOCKADDR_IN_SIN_LEN |
340 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 341 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); |
341 | #endif | 342 | #endif |
342 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); | 343 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); |
343 | GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), | 344 | GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), |
344 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 345 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
345 | } | 346 | } |
346 | return GNUNET_OK; | 347 | return GNUNET_OK; |
347 | } | 348 | } |
348 | #endif | 349 | #endif |
@@ -350,24 +351,24 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
350 | #if HAVE_GETHOSTBYNAME | 351 | #if HAVE_GETHOSTBYNAME |
351 | static int | 352 | static int |
352 | gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | 353 | gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, |
353 | const char *hostname) | 354 | const char *hostname) |
354 | { | 355 | { |
355 | struct hostent *hp; | 356 | struct hostent *hp; |
356 | struct sockaddr_in addr; | 357 | struct sockaddr_in addr; |
357 | 358 | ||
358 | hp = GETHOSTBYNAME (hostname); | 359 | hp = GETHOSTBYNAME (hostname); |
359 | if (hp == NULL) | 360 | if (hp == NULL) |
360 | { | 361 | { |
361 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
362 | _("Could not find IP of host `%s': %s\n"), hostname, | 363 | _("Could not find IP of host `%s': %s\n"), hostname, |
363 | hstrerror (h_errno)); | 364 | hstrerror (h_errno)); |
364 | return GNUNET_SYSERR; | 365 | return GNUNET_SYSERR; |
365 | } | 366 | } |
366 | if (hp->h_addrtype != AF_INET) | 367 | if (hp->h_addrtype != AF_INET) |
367 | { | 368 | { |
368 | GNUNET_break (0); | 369 | GNUNET_break (0); |
369 | return GNUNET_SYSERR; | 370 | return GNUNET_SYSERR; |
370 | } | 371 | } |
371 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); | 372 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); |
372 | memset (&addr, 0, sizeof (addr)); | 373 | memset (&addr, 0, sizeof (addr)); |
373 | addr.sin_family = AF_INET; | 374 | addr.sin_family = AF_INET; |
@@ -376,7 +377,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
376 | #endif | 377 | #endif |
377 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); | 378 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); |
378 | GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr), | 379 | GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr), |
379 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 380 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
380 | return GNUNET_OK; | 381 | return GNUNET_OK; |
381 | } | 382 | } |
382 | #endif | 383 | #endif |
@@ -390,8 +391,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
390 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" | 391 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" |
391 | */ | 392 | */ |
392 | static void | 393 | static void |
393 | get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname, | 394 | get_ip_from_hostname (struct GNUNET_SERVER_Client *client, |
394 | int domain) | 395 | const char *hostname, int domain) |
395 | { | 396 | { |
396 | int ret; | 397 | int ret; |
397 | struct GNUNET_SERVER_TransmitContext *tc; | 398 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -411,7 +412,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname, | |||
411 | gethostbyname_resolve (tc, hostname); | 412 | gethostbyname_resolve (tc, hostname); |
412 | #endif | 413 | #endif |
413 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 414 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
414 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 415 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
415 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 416 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
416 | } | 417 | } |
417 | 418 | ||
@@ -425,7 +426,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname, | |||
425 | */ | 426 | */ |
426 | static void | 427 | static void |
427 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, | 428 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, |
428 | const struct GNUNET_MessageHeader *message) | 429 | const struct GNUNET_MessageHeader *message) |
429 | { | 430 | { |
430 | uint16_t msize; | 431 | uint16_t msize; |
431 | const struct GNUNET_RESOLVER_GetMessage *msg; | 432 | const struct GNUNET_RESOLVER_GetMessage *msg; |
@@ -437,78 +438,78 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client, | |||
437 | 438 | ||
438 | msize = ntohs (message->size); | 439 | msize = ntohs (message->size); |
439 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) | 440 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) |
440 | { | 441 | { |
441 | GNUNET_break (0); | 442 | GNUNET_break (0); |
442 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 443 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
443 | return; | 444 | return; |
444 | } | 445 | } |
445 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; | 446 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; |
446 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); | 447 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); |
447 | direction = ntohl (msg->direction); | 448 | direction = ntohl (msg->direction); |
448 | domain = ntohl (msg->domain); | 449 | domain = ntohl (msg->domain); |
449 | if (direction == GNUNET_NO) | 450 | if (direction == GNUNET_NO) |
450 | { | ||
451 | /* IP from hostname */ | ||
452 | hostname = (const char *) &msg[1]; | ||
453 | if (hostname[size - 1] != '\0') | ||
454 | { | 451 | { |
455 | GNUNET_break (0); | 452 | /* IP from hostname */ |
456 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 453 | hostname = (const char *) &msg[1]; |
457 | return; | 454 | if (hostname[size - 1] != '\0') |
458 | } | 455 | { |
456 | GNUNET_break (0); | ||
457 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
458 | return; | ||
459 | } | ||
459 | #if DEBUG_RESOLVER | 460 | #if DEBUG_RESOLVER |
460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"), | 461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
461 | hostname); | 462 | _("Resolver asked to look up `%s'.\n"), hostname); |
462 | #endif | 463 | #endif |
463 | get_ip_from_hostname (client, hostname, domain); | 464 | get_ip_from_hostname (client, hostname, domain); |
464 | } | 465 | } |
465 | else | 466 | else |
466 | { | 467 | { |
467 | #if DEBUG_RESOLVER | 468 | #if DEBUG_RESOLVER |
468 | char buf[INET6_ADDRSTRLEN]; | 469 | char buf[INET6_ADDRSTRLEN]; |
469 | #endif | 470 | #endif |
470 | if (size < sizeof (struct sockaddr)) | 471 | if (size < sizeof (struct sockaddr)) |
471 | { | 472 | { |
472 | GNUNET_break (0); | 473 | GNUNET_break (0); |
473 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 474 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
474 | return; | 475 | return; |
475 | } | 476 | } |
476 | sa = (const struct sockaddr *) &msg[1]; | 477 | sa = (const struct sockaddr *) &msg[1]; |
477 | switch (sa->sa_family) | 478 | switch (sa->sa_family) |
478 | { | 479 | { |
479 | case AF_INET: | 480 | case AF_INET: |
480 | if (size != sizeof (struct sockaddr_in)) | 481 | if (size != sizeof (struct sockaddr_in)) |
481 | { | 482 | { |
482 | GNUNET_break (0); | 483 | GNUNET_break (0); |
483 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 484 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
484 | return; | 485 | return; |
485 | } | 486 | } |
486 | #if DEBUG_RESOLVER | 487 | #if DEBUG_RESOLVER |
487 | inet_ntop (AF_INET, sa, buf, size); | 488 | inet_ntop (AF_INET, sa, buf, size); |
488 | #endif | 489 | #endif |
489 | break; | 490 | break; |
490 | case AF_INET6: | 491 | case AF_INET6: |
491 | if (size != sizeof (struct sockaddr_in6)) | 492 | if (size != sizeof (struct sockaddr_in6)) |
492 | { | 493 | { |
493 | GNUNET_break (0); | 494 | GNUNET_break (0); |
494 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 495 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
495 | return; | 496 | return; |
496 | } | 497 | } |
497 | #if DEBUG_RESOLVER | 498 | #if DEBUG_RESOLVER |
498 | inet_ntop (AF_INET6, sa, buf, size); | 499 | inet_ntop (AF_INET6, sa, buf, size); |
499 | #endif | 500 | #endif |
500 | break; | 501 | break; |
501 | default: | 502 | default: |
502 | GNUNET_break (0); | 503 | GNUNET_break (0); |
503 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 504 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
504 | return; | 505 | return; |
505 | } | 506 | } |
506 | #if DEBUG_RESOLVER | 507 | #if DEBUG_RESOLVER |
507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
508 | _("Resolver asked to look up IP address `%s'.\n"), buf); | 509 | _("Resolver asked to look up IP address `%s'.\n"), buf); |
509 | #endif | 510 | #endif |
510 | get_ip_as_string (client, sa, size); | 511 | get_ip_as_string (client, sa, size); |
511 | } | 512 | } |
512 | } | 513 | } |
513 | 514 | ||
514 | 515 | ||
@@ -545,18 +546,18 @@ main (int argc, char *const *argv) | |||
545 | struct IPCache *pos; | 546 | struct IPCache *pos; |
546 | 547 | ||
547 | ret = | 548 | ret = |
548 | (GNUNET_OK == | 549 | (GNUNET_OK == |
549 | GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, | 550 | GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, |
550 | &run, NULL)) ? 0 : 1; | 551 | &run, NULL)) ? 0 : 1; |
551 | 552 | ||
552 | while (head != NULL) | 553 | while (head != NULL) |
553 | { | 554 | { |
554 | pos = head->next; | 555 | pos = head->next; |
555 | GNUNET_free_non_null (head->addr); | 556 | GNUNET_free_non_null (head->addr); |
556 | GNUNET_free (head->sa); | 557 | GNUNET_free (head->sa); |
557 | GNUNET_free (head); | 558 | GNUNET_free (head); |
558 | head = pos; | 559 | head = pos; |
559 | } | 560 | } |
560 | return ret; | 561 | return ret; |
561 | } | 562 | } |
562 | 563 | ||