[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Change connection create function



commit d1d2a4ab5e14dfd77c5f38b09efc021166df07d7
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Thu Jun 20 20:17:14 2013 -0400

    Change connection create function
    
    Don't need anymore the connection domain, take it directly form the
    sockaddr passed to the function.
    
    Also, set the refcount to 1 on creation.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/common/connection.c |   14 ++++++++------
 src/common/connection.h |    3 +--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/common/connection.c b/src/common/connection.c
index ba1890a..b926f15 100644
--- a/src/common/connection.c
+++ b/src/common/connection.c
@@ -170,8 +170,7 @@ error:
  *
  * Return a newly allocated connection object or else NULL.
  */
-struct connection *connection_create(int fd, enum connection_domain domain,
-		struct sockaddr *dest)
+struct connection *connection_create(int fd, const struct sockaddr *dest)
 {
 	struct connection *conn = NULL;
 
@@ -183,19 +182,22 @@ struct connection *connection_create(int fd, enum connection_domain domain,
 		goto error;
 	}
 
-	switch (domain) {
-	case CONNECTION_DOMAIN_INET:
+	switch (dest->sa_family) {
+	case AF_INET:
+		conn->dest_addr.domain = CONNECTION_DOMAIN_INET;
 		memcpy(&conn->dest_addr.u.sin, dest, sizeof(conn->dest_addr.u.sin));
 		break;
-	case CONNECTION_DOMAIN_INET6:
+	case AF_INET6:
+		conn->dest_addr.domain = CONNECTION_DOMAIN_INET6;
 		memcpy(&conn->dest_addr.u.sin6, dest, sizeof(conn->dest_addr.u.sin6));
 		break;
 	default:
-		ERR("Connection domain unknown %d", domain);
+		ERR("Connection domain unknown %d", dest->sa_family);
 		goto error;
 	}
 
 	conn->fd = fd;
+	conn->refcount.count = 1;
 
 	return conn;
 
diff --git a/src/common/connection.h b/src/common/connection.h
index d1163a9..17f940c 100644
--- a/src/common/connection.h
+++ b/src/common/connection.h
@@ -68,8 +68,7 @@ struct connection {
 int connection_addr_set(enum connection_domain domain, const char *ip,
 		in_port_t port, struct connection_addr *addr);
 
-struct connection *connection_create(int fd, enum connection_domain domain,
-		struct sockaddr *dest);
+struct connection *connection_create(int fd, const struct sockaddr *dest);
 struct connection *connection_find(int key);
 void connection_destroy(struct connection *conn);
 void connection_remove(struct connection *conn);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits