diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-01-02 13:23:55 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-01-02 13:23:55 +0100 |
commit | a6aca5fc1be4409c47f88f730814b41dc9c95475 (patch) | |
tree | f883efdeb876353c6934f45be8b8c4263437a0ca /client.c | |
parent | 24c193233ddf29cd9f0ccf6f1914db85aa9b5dc7 (diff) |
add local/remote address env vars for cgi
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -300,6 +300,21 @@ static void client_notify_state(struct ustream *s) return client_close(cl); } +static void set_addr(struct uh_addr *addr, void *src) +{ + struct sockaddr_in *sin = src; + struct sockaddr_in6 *sin6 = src; + + addr->family = sin->sin_family; + if (addr->family == AF_INET) { + addr->port = ntohs(sin->sin_port); + memcpy(&addr->in, &sin->sin_addr, sizeof(addr->in)); + } else { + addr->port = ntohs(sin6->sin6_port); + memcpy(&addr->in6, &sin6->sin6_addr, sizeof(addr->in6)); + } +} + void uh_accept_client(int fd) { static struct client *next_client; @@ -307,19 +322,22 @@ void uh_accept_client(int fd) unsigned int sl; int sfd; static int client_id = 0; + struct sockaddr_in6 addr; if (!next_client) next_client = calloc(1, sizeof(*next_client)); cl = next_client; - sl = sizeof(cl->peeraddr); - sfd = accept(fd, (struct sockaddr *) &cl->peeraddr, &sl); + sl = sizeof(addr); + sfd = accept(fd, (struct sockaddr *) &addr, &sl); if (sfd < 0) return; - sl = sizeof(cl->servaddr); - getsockname(fd, (struct sockaddr *) &cl->servaddr, &sl); + set_addr(&cl->peer_addr, &addr); + sl = sizeof(addr); + getsockname(fd, (struct sockaddr *) &addr, &sl); + set_addr(&cl->srv_addr, &addr); cl->us = &cl->sfd.stream; cl->us->string_data = true; cl->us->notify_read = client_ustream_read_cb; |