http: get address at initial connect time
authorFelix Fietkau <nbd@openwrt.org>
Wed, 30 Apr 2014 12:50:21 +0000 (14:50 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 30 Apr 2014 12:50:38 +0000 (14:50 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-http.c

index ee354c7af6b9f1c167e6cbb5c4a4e74de243015a..83eac58f1ea9e24fece60ac7ac259378c0893fa6 100644 (file)
@@ -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);