Fix bytesex issues on in.s_addr

svn:r826
This commit is contained in:
Nick Mathewson 2003-11-17 07:37:45 +00:00
parent 42b5ed754f
commit 44ced0952f
2 changed files with 15 additions and 14 deletions

View File

@ -618,7 +618,7 @@ static void connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t
crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id); crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id);
/* FIXME check for collisions */ /* FIXME check for collisions */
in.s_addr = client_dns_lookup_entry(ap_conn->socks_request->address); in.s_addr = htonl(client_dns_lookup_entry(ap_conn->socks_request->address));
string_addr = in.s_addr ? inet_ntoa(in) : NULL; string_addr = in.s_addr ? inet_ntoa(in) : NULL;
memcpy(payload, ap_conn->stream_id, STREAM_ID_SIZE); memcpy(payload, ap_conn->stream_id, STREAM_ID_SIZE);
@ -831,8 +831,9 @@ static uint32_t client_dns_lookup_entry(const char *address)
assert(address); assert(address);
if (inet_aton(address, &in)) { if (inet_aton(address, &in)) {
log_fn(LOG_DEBUG, "Using static address %s (%08X)", address, in.s_addr); log_fn(LOG_DEBUG, "Using static address %s (%08X)", address,
return in.s_addr; ntohl(in.s_addr));
return ntohl(in.s_addr);
} }
search.address = (char*)address; search.address = (char*)address;
ent = SPLAY_FIND(client_dns_tree, &client_dns_root, &search); ent = SPLAY_FIND(client_dns_tree, &client_dns_root, &search);
@ -848,7 +849,7 @@ static uint32_t client_dns_lookup_entry(const char *address)
--client_dns_size; --client_dns_size;
return 0; return 0;
} }
in.s_addr = ent->addr; in.s_addr = htonl(ent->addr);
log_fn(LOG_DEBUG, "Found cached entry for address %s: %s", address, log_fn(LOG_DEBUG, "Found cached entry for address %s: %s", address,
inet_ntoa(in)); inet_ntoa(in));
return ent->addr; return ent->addr;
@ -865,9 +866,9 @@ static void client_dns_set_entry(const char *address, uint32_t val)
assert(val); assert(val);
if (inet_aton(address, &in)) { if (inet_aton(address, &in)) {
if (in.s_addr == val) if (ntohl(in.s_addr) == val)
return; return;
in.s_addr = val; in.s_addr = htonl(val);
log_fn(LOG_WARN, log_fn(LOG_WARN,
"Trying to store incompatible cached value %s for static address %s", "Trying to store incompatible cached value %s for static address %s",
inet_ntoa(in), address); inet_ntoa(in), address);
@ -881,7 +882,7 @@ static void client_dns_set_entry(const char *address, uint32_t val)
ent->addr = val; ent->addr = val;
ent->expires = now+MAX_DNS_ENTRY_AGE; ent->expires = now+MAX_DNS_ENTRY_AGE;
} else { } else {
in.s_addr = val; in.s_addr = htonl(val);
log_fn(LOG_DEBUG, "Caching result for address %s: %s", address, log_fn(LOG_DEBUG, "Caching result for address %s: %s", address,
inet_ntoa(in)); inet_ntoa(in));
ent = tor_malloc(sizeof(struct client_dns_entry)); ent = tor_malloc(sizeof(struct client_dns_entry));

View File

@ -996,7 +996,7 @@ static int router_add_exit_policy(routerinfo_t *router,
if (strcmp(address, "*") == 0) { if (strcmp(address, "*") == 0) {
newe->addr = 0; newe->addr = 0;
} else if (inet_aton(address, &in) != 0) { } else if (inet_aton(address, &in) != 0) {
newe->addr = in.s_addr; newe->addr = ntohl(in.s_addr);
} else { } else {
log_fn(LOG_WARN, "Malformed IP %s in exit policy; rejecting.", log_fn(LOG_WARN, "Malformed IP %s in exit policy; rejecting.",
address); address);
@ -1014,7 +1014,7 @@ static int router_add_exit_policy(routerinfo_t *router,
/* strtol handled the whole mask. */ /* strtol handled the whole mask. */
newe->msk = ~((1<<(32-bits))-1); newe->msk = ~((1<<(32-bits))-1);
} else if (inet_aton(mask, &in) != 0) { } else if (inet_aton(mask, &in) != 0) {
newe->msk = in.s_addr; newe->msk = ntohl(in.s_addr);
} else { } else {
log_fn(LOG_WARN, "Malformed mask %s on exit policy; rejecting.", log_fn(LOG_WARN, "Malformed mask %s on exit policy; rejecting.",
mask); mask);
@ -1033,9 +1033,9 @@ static int router_add_exit_policy(routerinfo_t *router,
} }
} }
in.s_addr = newe->addr; in.s_addr = htonl(newe->addr);
address = tor_strdup(inet_ntoa(in)); address = tor_strdup(inet_ntoa(in));
in.s_addr = newe->msk; in.s_addr = htonl(newe->msk);
log_fn(LOG_DEBUG,"%s %s/%s:%d", log_fn(LOG_DEBUG,"%s %s/%s:%d",
newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept", newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept",
address, inet_ntoa(in), newe->prt); address, inet_ntoa(in), newe->prt);
@ -1106,7 +1106,7 @@ int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
} }
} }
if (match) { if (match) {
in.s_addr = addr; in.s_addr = htonl(addr);
log_fn(LOG_INFO,"Address %s:%d matches exit policy '%s'", log_fn(LOG_INFO,"Address %s:%d matches exit policy '%s'",
inet_ntoa(in), port, tmpe->string); inet_ntoa(in), port, tmpe->string);
if(tmpe->policy_type == EXIT_POLICY_ACCEPT) if(tmpe->policy_type == EXIT_POLICY_ACCEPT)
@ -1276,7 +1276,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
written = result; written = result;
for(tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) { for(tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) {
in.s_addr = tmpe->addr; in.s_addr = htonl(tmpe->addr);
result = snprintf(s+written, maxlen-written, "%s %s", result = snprintf(s+written, maxlen-written, "%s %s",
tmpe->policy_type == EXIT_POLICY_ACCEPT ? "accept" : "reject", tmpe->policy_type == EXIT_POLICY_ACCEPT ? "accept" : "reject",
tmpe->msk == 0 ? "*" : inet_ntoa(in)); tmpe->msk == 0 ? "*" : inet_ntoa(in));
@ -1286,7 +1286,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
} }
written += result; written += result;
if (tmpe->msk != 0xFFFFFFFFu) { if (tmpe->msk != 0xFFFFFFFFu) {
in.s_addr = tmpe->msk; in.s_addr = htonl(tmpe->msk);
result = snprintf(s+written, maxlen-written, "/%s", inet_ntoa(in)); result = snprintf(s+written, maxlen-written, "/%s", inet_ntoa(in));
if (result<0 || result+written > maxlen) if (result<0 || result+written > maxlen)
return -1; return -1;