From 63a984dbdf8a4d1249838e0708a4bed2dfaff476 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 30 Apr 2014 14:50:21 +0200 Subject: [PATCH] http: get address at initial connect time Signed-off-by: Felix Fietkau --- uclient-http.c | 17 +++++++++-------- 1 file 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); -- 2.30.2