[tor-commits] [tor/master] Fixup tor_addr_to_sockaddr return convention
nickm at torproject.org
nickm at torproject.org
Thu Apr 7 16:19:39 UTC 2011
commit 41380fa3b3bc3647699116866afda4286ba90f8b
Author: Nick Mathewson <nickm at torproject.org>
Date: Fri Mar 25 15:41:19 2011 -0400
Fixup tor_addr_to_sockaddr return convention
---
src/common/address.c | 18 ++++++++++--------
src/or/dns.c | 2 +-
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/common/address.c b/src/common/address.c
index 0046d2d..a4f8d34 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -50,11 +50,13 @@
#include <assert.h>
/** Convert the tor_addr_t in <b>a</b>, with port in <b>port</b>, into a
- * socklen object in *<b>sa_out</b> of object size <b>len</b>. If not enough
- * room is free, or on error, return -1. Else return the length of the
- * sockaddr. */
-/* XXXX021 This returns socklen_t. socklen_t is sometimes unsigned. This
- * function claims to return -1 sometimes. Problematic! */
+ * sockaddr object in *<b>sa_out</b> of object size <b>len</b>. If not enough
+ * room is available in sa_out, or on error, return 0 On success, return
+ * the length of the sockaddr.
+ *
+ * Interface note: ordinarly, we return -1 for error. We can't do that here,
+ * since socklen is unsigned on some platforms.
+ **/
socklen_t
tor_addr_to_sockaddr(const tor_addr_t *a,
uint16_t port,
@@ -65,7 +67,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
if (family == AF_INET) {
struct sockaddr_in *sin;
if (len < (int)sizeof(struct sockaddr_in))
- return -1;
+ return 0;
sin = (struct sockaddr_in *)sa_out;
memset(sin, 0, sizeof(struct sockaddr_in));
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
@@ -78,7 +80,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
} else if (family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (len < (int)sizeof(struct sockaddr_in6))
- return -1;
+ return 0;
sin6 = (struct sockaddr_in6 *)sa_out;
memset(sin6, 0, sizeof(struct sockaddr_in6));
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
@@ -89,7 +91,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
memcpy(&sin6->sin6_addr, tor_addr_to_in6(a), sizeof(struct in6_addr));
return sizeof(struct sockaddr_in6);
} else {
- return -1;
+ return 0;
}
}
diff --git a/src/or/dns.c b/src/or/dns.c
index dcccd13..61c8f32 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -1206,7 +1206,7 @@ configure_nameservers(int force)
struct sockaddr_storage ss;
socklen = tor_addr_to_sockaddr(&addr, 0,
(struct sockaddr *)&ss, sizeof(ss));
- if (socklen < 0) {
+ if (socklen <= 0) {
log_warn(LD_BUG, "Couldn't convert outbound bind address to sockaddr."
" Ignoring.");
} else {
More information about the tor-commits
mailing list