aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-service-resolver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r--src/util/gnunet-service-resolver.c411
1 files changed, 205 insertions, 206 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index c15f0d3f5..5d4c5c224 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 */
159static void 159static void
160get_ip_as_string (struct GNUNET_SERVER_Client *client, 160get_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)
179 { 182 {
180 if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < 183 if (prev != NULL)
181 60 * 60 * 1000) 184 {
182 { 185 prev->next = cache->next;
183 if (prev != NULL) 186 GNUNET_free_non_null (cache->addr);
184 { 187 GNUNET_free (cache->sa);
185 prev->next = cache->next; 188 GNUNET_free (cache);
186 GNUNET_free_non_null (cache->addr); 189 cache = prev->next;
187 GNUNET_free (cache->sa); 190 }
188 GNUNET_free (cache); 191 else
189 cache = prev->next; 192 {
190 } 193 head = cache->next;
191 else 194 GNUNET_free_non_null (cache->addr);
192 { 195 GNUNET_free (cache->sa);
193 head = cache->next; 196 GNUNET_free (cache);
194 GNUNET_free_non_null (cache->addr); 197 cache = head;
195 GNUNET_free (cache->sa); 198 }
196 GNUNET_free (cache); 199 continue;
197 cache = head;
198 }
199 continue;
200 }
201 prev = cache;
202 cache = cache->next;
203 } 200 }
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)
205 { 209 {
206 cache->last_request = now; 210 GNUNET_free_non_null (cache->addr);
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 ();
225 cache->addr = NULL; 211 cache->addr = NULL;
212 cache->salen = 0;
226 cache_resolve (cache); 213 cache_resolve (cache);
227 head = cache;
228 } 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 ();
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
241static int 241static int
242getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, 242getaddrinfo_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,37 +254,36 @@ 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, 261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"),
262 _("Could not resolve `%s' (%s): %s\n"), hostname, 262 hostname,
263 (domain == 263 (domain ==
264 AF_INET) ? "IPv4" : ((domain == 264 AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"),
265 AF_INET6) ? "IPv6" : "any"), 265 gai_strerror (s));
266 gai_strerror (s)); 266 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
267 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
268#ifndef MINGW 267#ifndef MINGW
269 || (s == EAI_SYSTEM) 268 || (s == EAI_SYSTEM)
270#else 269#else
271 // FIXME NILS 270 // FIXME NILS
272 || 1 271 || 1
273#endif 272#endif
274 ) 273 )
275 return GNUNET_NO; /* other function may still succeed */ 274 return GNUNET_NO; /* other function may still succeed */
276 return GNUNET_SYSERR; 275 return GNUNET_SYSERR;
277 } 276 }
278 if (result == NULL) 277 if (result == NULL)
279 return GNUNET_SYSERR; 278 return GNUNET_SYSERR;
280 pos = result; 279 pos = result;
281 while (pos != NULL) 280 while (pos != NULL)
282 { 281 {
283 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, 282 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
284 pos->ai_addrlen, 283 pos->ai_addrlen,
285 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
286 pos = pos->ai_next; 285 pos = pos->ai_next;
287 } 286 }
288 freeaddrinfo (result); 287 freeaddrinfo (result);
289 return GNUNET_OK; 288 return GNUNET_OK;
290} 289}
@@ -293,7 +292,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
293#if HAVE_GETHOSTBYNAME2 292#if HAVE_GETHOSTBYNAME2
294static int 293static int
295gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, 294gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
296 const char *hostname, int domain) 295 const char *hostname, int domain)
297{ 296{
298 struct hostent *hp; 297 struct hostent *hp;
299 struct sockaddr_in a4; 298 struct sockaddr_in a4;
@@ -302,48 +301,48 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
302 int ret2; 301 int ret2;
303 302
304 if (domain == AF_UNSPEC) 303 if (domain == AF_UNSPEC)
305 { 304 {
306 ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); 305 ret1 = gethostbyname2_resolve (tc, hostname, AF_INET);
307 ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); 306 ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6);
308 if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) 307 if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK))
309 return GNUNET_OK; 308 return GNUNET_OK;
310 if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) 309 if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR))
311 return GNUNET_SYSERR; 310 return GNUNET_SYSERR;
312 return GNUNET_NO; 311 return GNUNET_NO;
313 } 312 }
314 hp = gethostbyname2 (hostname, domain); 313 hp = gethostbyname2 (hostname, domain);
315 if (hp == NULL) 314 if (hp == NULL)
316 { 315 {
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 316 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
318 _("Could not find IP of host `%s': %s\n"), hostname, 317 _("Could not find IP of host `%s': %s\n"), hostname,
319 hstrerror (h_errno)); 318 hstrerror (h_errno));
320 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
321 } 320 }
322 GNUNET_assert (hp->h_addrtype == domain); 321 GNUNET_assert (hp->h_addrtype == domain);
323 if (domain == AF_INET) 322 if (domain == AF_INET)
324 { 323 {
325 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 324 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
326 memset (&a4, 0, sizeof (a4)); 325 memset (&a4, 0, sizeof (a4));
327 a4.sin_family = AF_INET; 326 a4.sin_family = AF_INET;
328#if HAVE_SOCKADDR_IN_SIN_LEN 327#if HAVE_SOCKADDR_IN_SIN_LEN
329 a4.sin_len = (u_char) sizeof (struct sockaddr_in); 328 a4.sin_len = (u_char) sizeof (struct sockaddr_in);
330#endif 329#endif
331 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); 330 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
332 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), 331 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
333 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 332 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
334 } 333 }
335 else 334 else
336 { 335 {
337 GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); 336 GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
338 memset (&a6, 0, sizeof (a6)); 337 memset (&a6, 0, sizeof (a6));
339 a6.sin6_family = AF_INET6; 338 a6.sin6_family = AF_INET6;
340#if HAVE_SOCKADDR_IN_SIN_LEN 339#if HAVE_SOCKADDR_IN_SIN_LEN
341 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 340 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
342#endif 341#endif
343 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); 342 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
344 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), 343 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
345 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 344 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
346 } 345 }
347 return GNUNET_OK; 346 return GNUNET_OK;
348} 347}
349#endif 348#endif
@@ -351,24 +350,24 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
351#if HAVE_GETHOSTBYNAME 350#if HAVE_GETHOSTBYNAME
352static int 351static int
353gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, 352gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
354 const char *hostname) 353 const char *hostname)
355{ 354{
356 struct hostent *hp; 355 struct hostent *hp;
357 struct sockaddr_in addr; 356 struct sockaddr_in addr;
358 357
359 hp = GETHOSTBYNAME (hostname); 358 hp = GETHOSTBYNAME (hostname);
360 if (hp == NULL) 359 if (hp == NULL)
361 { 360 {
362 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
363 _("Could not find IP of host `%s': %s\n"), hostname, 362 _("Could not find IP of host `%s': %s\n"), hostname,
364 hstrerror (h_errno)); 363 hstrerror (h_errno));
365 return GNUNET_SYSERR; 364 return GNUNET_SYSERR;
366 } 365 }
367 if (hp->h_addrtype != AF_INET) 366 if (hp->h_addrtype != AF_INET)
368 { 367 {
369 GNUNET_break (0); 368 GNUNET_break (0);
370 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
371 } 370 }
372 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 371 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
373 memset (&addr, 0, sizeof (addr)); 372 memset (&addr, 0, sizeof (addr));
374 addr.sin_family = AF_INET; 373 addr.sin_family = AF_INET;
@@ -377,7 +376,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
377#endif 376#endif
378 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); 377 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
379 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr), 378 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr),
380 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 379 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
381 return GNUNET_OK; 380 return GNUNET_OK;
382} 381}
383#endif 382#endif
@@ -391,8 +390,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
391 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" 390 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
392 */ 391 */
393static void 392static void
394get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 393get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
395 const char *hostname, int domain) 394 int domain)
396{ 395{
397 int ret; 396 int ret;
398 struct GNUNET_SERVER_TransmitContext *tc; 397 struct GNUNET_SERVER_TransmitContext *tc;
@@ -412,7 +411,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
412 gethostbyname_resolve (tc, hostname); 411 gethostbyname_resolve (tc, hostname);
413#endif 412#endif
414 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 413 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
415 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 414 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
416 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 415 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
417} 416}
418 417
@@ -426,7 +425,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
426 */ 425 */
427static void 426static void
428handle_get (void *cls, struct GNUNET_SERVER_Client *client, 427handle_get (void *cls, struct GNUNET_SERVER_Client *client,
429 const struct GNUNET_MessageHeader *message) 428 const struct GNUNET_MessageHeader *message)
430{ 429{
431 uint16_t msize; 430 uint16_t msize;
432 const struct GNUNET_RESOLVER_GetMessage *msg; 431 const struct GNUNET_RESOLVER_GetMessage *msg;
@@ -438,78 +437,78 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
438 437
439 msize = ntohs (message->size); 438 msize = ntohs (message->size);
440 if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) 439 if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage))
441 { 440 {
442 GNUNET_break (0); 441 GNUNET_break (0);
443 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 442 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
444 return; 443 return;
445 } 444 }
446 msg = (const struct GNUNET_RESOLVER_GetMessage *) message; 445 msg = (const struct GNUNET_RESOLVER_GetMessage *) message;
447 size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); 446 size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage);
448 direction = ntohl (msg->direction); 447 direction = ntohl (msg->direction);
449 domain = ntohl (msg->domain); 448 domain = ntohl (msg->domain);
450 if (direction == GNUNET_NO) 449 if (direction == GNUNET_NO)
450 {
451 /* IP from hostname */
452 hostname = (const char *) &msg[1];
453 if (hostname[size - 1] != '\0')
451 { 454 {
452 /* IP from hostname */ 455 GNUNET_break (0);
453 hostname = (const char *) &msg[1]; 456 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
454 if (hostname[size - 1] != '\0') 457 return;
455 { 458 }
456 GNUNET_break (0);
457 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
458 return;
459 }
460#if DEBUG_RESOLVER 459#if DEBUG_RESOLVER
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"),
462 _("Resolver asked to look up `%s'.\n"), hostname); 461 hostname);
463#endif 462#endif
464 get_ip_from_hostname (client, hostname, domain); 463 get_ip_from_hostname (client, hostname, domain);
465 } 464 }
466 else 465 else
467 { 466 {
468#if DEBUG_RESOLVER 467#if DEBUG_RESOLVER
469 char buf[INET6_ADDRSTRLEN]; 468 char buf[INET6_ADDRSTRLEN];
470#endif 469#endif
471 if (size < sizeof (struct sockaddr)) 470 if (size < sizeof (struct sockaddr))
472 { 471 {
473 GNUNET_break (0); 472 GNUNET_break (0);
474 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 473 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
475 return; 474 return;
476 } 475 }
477 sa = (const struct sockaddr *) &msg[1]; 476 sa = (const struct sockaddr *) &msg[1];
478 switch (sa->sa_family) 477 switch (sa->sa_family)
479 { 478 {
480 case AF_INET: 479 case AF_INET:
481 if (size != sizeof (struct sockaddr_in)) 480 if (size != sizeof (struct sockaddr_in))
482 { 481 {
483 GNUNET_break (0); 482 GNUNET_break (0);
484 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 483 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
485 return; 484 return;
486 } 485 }
487#if DEBUG_RESOLVER 486#if DEBUG_RESOLVER
488 inet_ntop (AF_INET, sa, buf, size); 487 inet_ntop (AF_INET, sa, buf, size);
489#endif 488#endif
490 break; 489 break;
491 case AF_INET6: 490 case AF_INET6:
492 if (size != sizeof (struct sockaddr_in6)) 491 if (size != sizeof (struct sockaddr_in6))
493 { 492 {
494 GNUNET_break (0); 493 GNUNET_break (0);
495 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 494 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
496 return; 495 return;
497 } 496 }
498#if DEBUG_RESOLVER 497#if DEBUG_RESOLVER
499 inet_ntop (AF_INET6, sa, buf, size); 498 inet_ntop (AF_INET6, sa, buf, size);
500#endif 499#endif
501 break; 500 break;
502 default: 501 default:
503 GNUNET_break (0); 502 GNUNET_break (0);
504 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 503 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
505 return; 504 return;
506 } 505 }
507#if DEBUG_RESOLVER 506#if DEBUG_RESOLVER
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
509 _("Resolver asked to look up IP address `%s'.\n"), buf); 508 _("Resolver asked to look up IP address `%s'.\n"), buf);
510#endif 509#endif
511 get_ip_as_string (client, sa, size); 510 get_ip_as_string (client, sa, size);
512 } 511 }
513} 512}
514 513
515 514
@@ -546,18 +545,18 @@ main (int argc, char *const *argv)
546 struct IPCache *pos; 545 struct IPCache *pos;
547 546
548 ret = 547 ret =
549 (GNUNET_OK == 548 (GNUNET_OK ==
550 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, 549 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
551 &run, NULL)) ? 0 : 1; 550 &run, NULL)) ? 0 : 1;
552 551
553 while (head != NULL) 552 while (head != NULL)
554 { 553 {
555 pos = head->next; 554 pos = head->next;
556 GNUNET_free_non_null (head->addr); 555 GNUNET_free_non_null (head->addr);
557 GNUNET_free (head->sa); 556 GNUNET_free (head->sa);
558 GNUNET_free (head); 557 GNUNET_free (head);
559 head = pos; 558 head = pos;
560 } 559 }
561 return ret; 560 return ret;
562} 561}
563 562