http: get address at initial connect time
[project/uclient.git] / uclient-http.c
index 05dd3aa..83eac58 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;
 }