diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-04-30 14:50:21 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-04-30 14:50:38 +0200 |
commit | 63a984dbdf8a4d1249838e0708a4bed2dfaff476 (patch) | |
tree | 3e635753451d6662ed8b98bfc2e9d157e2656cc0 | |
parent | cb7867a867e45949950e03de0ea845e483ffc6eb (diff) | |
download | uclient-63a984dbdf8a4d1249838e0708a4bed2dfaff476.tar.gz |
http: get address at initial connect time
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | uclient-http.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/uclient-http.c b/uclient-http.c index ee354c7..83eac58 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -101,6 +101,7 @@ static const char * const uclient_http_prefix[] = { static int uclient_do_connect(struct uclient_http *uh, const char *port) { + socklen_t sl; int fd; if (uh->uc.url->port) @@ -111,6 +112,14 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port) return -1; ustream_fd_init(&uh->ufd, fd); + + memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr)); + memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr)); + + sl = sizeof(uh->uc.local_addr); + getsockname(fd, &uh->uc.local_addr.sa, &sl); + getpeername(fd, &uh->uc.remote_addr.sa, &sl); + return 0; } @@ -503,7 +512,6 @@ uclient_http_send_headers(struct uclient_http *uh) static void uclient_http_headers_complete(struct uclient_http *uh) { enum auth_type auth_type = uh->auth_type; - socklen_t sl; uh->state = HTTP_STATE_RECV_DATA; uh->uc.meta = uh->meta.head; @@ -516,13 +524,6 @@ static void uclient_http_headers_complete(struct uclient_http *uh) return; } - memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr)); - memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr)); - - sl = sizeof(uh->uc.local_addr); - getsockname(uh->ufd.fd.fd, &uh->uc.local_addr.sa, &sl); - getpeername(uh->ufd.fd.fd, &uh->uc.remote_addr.sa, &sl); - if (uh->uc.cb->header_done) uh->uc.cb->header_done(&uh->uc); |