mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-17 22:21:06 +03:00
Fix IPv6 for WinXP
This commit is contained in:
@@ -717,15 +717,21 @@ static void sockaddr_to_string(char *buf, size_t len,
|
|||||||
const union usa *usa)
|
const union usa *usa)
|
||||||
{
|
{
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
#if defined(_WIN32)
|
||||||
|
/* Only Windoze Vista (and newer) have inet_ntop() */
|
||||||
|
if (usa->sa.sa_family == AF_INET) {
|
||||||
|
strncpy(buf, inet_ntoa(usa->sin.sin_addr), len);
|
||||||
|
} else {
|
||||||
#if defined(USE_IPV6)
|
#if defined(USE_IPV6)
|
||||||
|
snprintf(buf, len, "%x:%x:%x:%x:%x:%x:%x:%x",
|
||||||
|
usa->sin6.sin6_addr.u.Word[0], usa->sin6.sin6_addr.u.Word[1], usa->sin6.sin6_addr.u.Word[2], usa->sin6.sin6_addr.u.Word[3],
|
||||||
|
usa->sin6.sin6_addr.u.Word[4], usa->sin6.sin6_addr.u.Word[5], usa->sin6.sin6_addr.u.Word[6], usa->sin6.sin6_addr.u.Word[7]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
|
inet_ntop(usa->sa.sa_family, usa->sa.sa_family == AF_INET ?
|
||||||
(void *) &usa->sin.sin_addr :
|
(void *) &usa->sin.sin_addr :
|
||||||
(void *) &usa->sin6.sin6_addr, buf, len);
|
(void *) &usa->sin6.sin6_addr, buf, len);
|
||||||
#elif defined(_WIN32)
|
|
||||||
/* Only Windoze Vista (and newer) have inet_ntop() */
|
|
||||||
strncpy(buf, inet_ntoa(usa->sin.sin_addr), len);
|
|
||||||
#else
|
|
||||||
inet_ntop(usa->sa.sa_family, (void *) &usa->sin.sin_addr, buf, len);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5185,7 +5191,11 @@ static int parse_port_string(const struct vec *vec, struct socket *so)
|
|||||||
{
|
{
|
||||||
unsigned int a, b, c, d, ch, len, port;
|
unsigned int a, b, c, d, ch, len, port;
|
||||||
#if defined(USE_IPV6)
|
#if defined(USE_IPV6)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
unsigned int e, f, g, h;
|
||||||
|
#else
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MacOS needs that. If we do not zero it, subsequent bind() will fail.
|
/* MacOS needs that. If we do not zero it, subsequent bind() will fail.
|
||||||
@@ -5199,10 +5209,21 @@ static int parse_port_string(const struct vec *vec, struct socket *so)
|
|||||||
so->lsa.sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
|
so->lsa.sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
|
||||||
so->lsa.sin.sin_port = htons((uint16_t) port);
|
so->lsa.sin.sin_port = htons((uint16_t) port);
|
||||||
#if defined(USE_IPV6)
|
#if defined(USE_IPV6)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
} else if (sscanf(vec->ptr, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d%n", &a, &b, &c, &d, &e, &f, &g, &h, &port, &len) == 9) {
|
||||||
|
#else
|
||||||
} else if (sscanf(vec->ptr, "[%49[^]]]:%d%n", buf, &port, &len) == 2 &&
|
} else if (sscanf(vec->ptr, "[%49[^]]]:%d%n", buf, &port, &len) == 2 &&
|
||||||
inet_pton(AF_INET6, buf, &so->lsa.sin6.sin6_addr)) {
|
inet_pton(AF_INET6, buf, &so->lsa.sin6.sin6_addr)) {
|
||||||
|
#endif
|
||||||
/* IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080 */
|
/* IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080 */
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = a;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = b;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = c;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = d;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = e;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = f;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = g;
|
||||||
|
so->lsa.sin6.sin6_addr.u.Word[0] = h;
|
||||||
so->lsa.sin6.sin6_family = AF_INET6;
|
so->lsa.sin6.sin6_family = AF_INET6;
|
||||||
so->lsa.sin6.sin6_port = htons((uint16_t) port);
|
so->lsa.sin6.sin6_port = htons((uint16_t) port);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -281,9 +281,13 @@ static int lsp_redirect(lua_State *L)
|
|||||||
static void prepare_lua_environment(struct mg_connection *conn, lua_State *L, const char *script_name)
|
static void prepare_lua_environment(struct mg_connection *conn, lua_State *L, const char *script_name)
|
||||||
{
|
{
|
||||||
const struct mg_request_info *ri = mg_get_request_info(conn);
|
const struct mg_request_info *ri = mg_get_request_info(conn);
|
||||||
extern void luaL_openlibs(lua_State *);
|
char src_addr[IP_ADDR_STR_LEN];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
extern void luaL_openlibs(lua_State *);
|
||||||
|
|
||||||
|
sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
|
||||||
|
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
#ifdef USE_LUA_SQLITE3
|
#ifdef USE_LUA_SQLITE3
|
||||||
{
|
{
|
||||||
@@ -326,7 +330,8 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L, co
|
|||||||
reg_string(L, "uri", ri->uri);
|
reg_string(L, "uri", ri->uri);
|
||||||
reg_string(L, "http_version", ri->http_version);
|
reg_string(L, "http_version", ri->http_version);
|
||||||
reg_string(L, "query_string", ri->query_string);
|
reg_string(L, "query_string", ri->query_string);
|
||||||
reg_int(L, "remote_ip", ri->remote_ip);
|
reg_int(L, "remote_ip", ri->remote_ip); /* remote_ip is deprecated, use remote_addr instead */
|
||||||
|
reg_string(L, "remote_addr", src_addr);
|
||||||
reg_int(L, "remote_port", ri->remote_port);
|
reg_int(L, "remote_port", ri->remote_port);
|
||||||
reg_int(L, "num_headers", ri->num_headers);
|
reg_int(L, "num_headers", ri->num_headers);
|
||||||
reg_int(L, "server_port", ntohs(conn->client.lsa.sin.sin_port));
|
reg_int(L, "server_port", ntohs(conn->client.lsa.sin.sin_port));
|
||||||
|
Reference in New Issue
Block a user