Opened 14 years ago

Last modified 8 years ago

#280 closed defect (Fixed)

getaddrinfo does not set hints

Reported by: Safari Owned by: nickm
Priority: Low Milestone: 0.1.2.x-final
Component: Core Tor/Tor Version:
Severity: Keywords:
Cc: Safari Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


getaddrinfo in src/common/compat.c gives NULL as hints parameter, so tor servers usually end up doing useless AAAA queries.
also, I believe it's better if it gave random IP address, instead of the first one returned from DNS proxy.
there are many DNS proxies which do not randomize the returned resource record set.

in addition to this patch, makefiles need fixing to get crypto_pseudo_rand_int linked into tor-resolve.
I get undefined reference to smartlist_get, but it's supposed to be in libor.a. somebody else might want to sort this out.

[Automatically added by flyspray2trac: Operating System: All]

Child Tickets

Change History (4)

comment:1 Changed 14 years ago by Safari

adding attachment failed, although POST succeeded (file is readable).
1144243176.098 436 TCP_MISS/302 3262 POST - DIRECT/ text/html

sorry but I add patch here.

--- tor- 2006-01-24 01:42:02.000000000 +0200
+++ tor- 2006-04-05 16:15:49.960148016 +0300
@@ -10,6 +10,7 @@ const char compat_c_id[] = "$Id: compat.

#include "orconfig.h"
#include "compat.h"

+#include "crypto.h"

#include <process.h>

@@ -528,18 +529,31 @@ int tor_lookup_hostname(const char *name

int err;
struct addrinfo *res=NULL, *res_p;
struct addrinfo hints;

+ unsigned int v4count;
+ struct sockaddr_in *sin;

int result = -1;


memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;

  • err = getaddrinfo(name, NULL, NULL, &res);

+ err = getaddrinfo(name, NULL, &hints, &res);

if (!err) {

  • for (res_p = res; res_p; res_p = res_p->ai_next) {

+ for (res_p = res, v4count = 0; res_p; res_p = res_p->ai_next) {

if (res_p->ai_family == AF_INET) {

  • struct sockaddr_in *sin = (struct sockaddr_in *)res_p->ai_addr;
  • memcpy(addr, &sin->sin_addr, 4);
  • result = 0;
  • break;

+ v4count++;
+ }
+ }
+ if (v4count > 0) {
+ result = 0;
+ v4count = crypto_pseudo_rand_int(v4count);
+ for (res_p = res; res_p; res_p = res_p->ai_next) {
+ if (res_p->ai_family == AF_INET) {
+ if (v4count-- == 0) {
+ sin = (struct sockaddr_in *)res_p->ai_addr;
+ memcpy(addr, &sin->sin_addr, 4);
+ break;
+ }
+ }



comment:2 Changed 14 years ago by nickm

Setting hints is reasonable here. I'm not sure that this is the right point at which to randomize
the reply set, however. It would probably be better to have tor_lookup_hostname return the whole
list, so that exit nodes can send back all the addresses when clients want them all, and handle
round-robining on their own. This latter should be part of the larger resolver refactoring, already
in progress.

(I've checked in a patch to handle the hints issue, as of revision 7069.)

comment:3 Changed 14 years ago by nickm

flyspray2trac: bug closed.
Closing; the "hints" issue is fixed; the round robin issue is a larger design feature.

comment:4 Changed 8 years ago by nickm

Component: Tor RelayTor
Note: See TracTickets for help on using tickets.