diff options
author | Malek <malek@mit.edu> | 2016-02-06 16:30:49 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-02-08 08:33:18 -0500 |
commit | 061586e36cb8d34e0db761e77fa8407b993632ce (patch) | |
tree | 97477582d719d89ef92dd26102bca5e5ae65159d /src/or | |
parent | 1f5cdf2b6c72ae89eea630a2c4693273ff1aee6c (diff) | |
download | tor-061586e36cb8d34e0db761e77fa8407b993632ce.tar.gz tor-061586e36cb8d34e0db761e77fa8407b993632ce.zip |
decorated ipv6 address for directory send command
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/directory.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index c1fa37f242..13392d6a5e 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1159,6 +1159,23 @@ directory_get_consensus_url(const char *resource) return url; } +/** + * Copies the ipv6 from source to destination, subject to buffer size limit + * size. If decorate is true, makes sure the copied address is decorated. + */ +static void +copy_ipv6_address(char* destination, const char* source, size_t len, + int decorate) { + tor_assert(destination); + tor_assert(source); + + if (decorate && source[0] != '[') { + tor_snprintf(destination, len, "[%s]", source); + } else { + strlcpy(destination, source, len); + } +} + /** Queue an appropriate HTTP command on conn-\>outbuf. The other args * are as in directory_initiate_command(). */ @@ -1170,6 +1187,9 @@ directory_send_command(dir_connection_t *conn, { char proxystring[256]; char hoststring[128]; + /* NEEDS to be the same size hoststring. + Will be decorated with brackets around it if it is ipv6. */ + char decorated_address[128]; smartlist_t *headers = smartlist_new(); char *url; char request[8192]; @@ -1182,12 +1202,20 @@ directory_send_command(dir_connection_t *conn, if (resource) conn->requested_resource = tor_strdup(resource); + /* decorate the ip address if it is ipv6 */ + if(strchr(conn->base_.address, ':')) { + copy_ipv6_address(decorated_address, conn->base_.address, + sizeof(decorated_address), 1); + } else { + strlcpy(decorated_address, conn->base_.address, sizeof(decorated_address)); + } + /* come up with a string for which Host: we want */ if (conn->base_.port == 80) { - strlcpy(hoststring, conn->base_.address, sizeof(hoststring)); + strlcpy(hoststring, decorated_address, sizeof(hoststring)); } else { - tor_snprintf(hoststring, sizeof(hoststring),"%s:%d", - conn->base_.address, conn->base_.port); + tor_snprintf(hoststring, sizeof(hoststring), "%s:%d", + decorated_address, conn->base_.port); } /* Format if-modified-since */ @@ -4157,4 +4185,3 @@ dir_split_resource_into_fingerprints(const char *resource, smartlist_free(fp_tmp); return 0; } - |