add support for querying local/remote address
[project/uclient.git] / uclient-http.c
index 7a54cce5c38a4b0e997157c984a305cdcea4aed5..ee354c7af6b9f1c167e6cbb5c4a4e74de243015a 100644 (file)
@@ -503,6 +503,7 @@ 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;
@@ -515,6 +516,13 @@ 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);
 
@@ -835,10 +843,11 @@ uclient_http_send_data(struct uclient *cl, char *buf, unsigned int len)
 
        uclient_http_send_headers(uh);
 
-       ustream_printf(uh->us, "%X\r\n", len);
-       if (len > 0)
+       if (len > 0) {
+               ustream_printf(uh->us, "%X\r\n", len);
                ustream_write(uh->us, buf, len, false);
-       ustream_printf(uh->us, "\r\n");
+               ustream_printf(uh->us, "\r\n");
+       }
 
        return len;
 }