-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: support tcp binding ip:port or ip of ipv4 or ipv6 #2381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -867,7 +867,7 @@ ngx_http_lua_socket_tcp_bind(lua_State *L) | |
|
||
text = (u_char *) luaL_checklstring(L, 2, &len); | ||
|
||
local = ngx_http_lua_parse_addr(L, text, len); | ||
local = ngx_http_lua_parse_addr_port(L, text, len); | ||
if (local == NULL) { | ||
lua_pushnil(L); | ||
lua_pushfstring(L, "bad address"); | ||
|
@@ -3430,7 +3430,7 @@ ngx_http_lua_socket_tcp_handler(ngx_event_t *ev) | |
static ngx_int_t | ||
ngx_http_lua_socket_tcp_get_peer(ngx_peer_connection_t *pc, void *data) | ||
{ | ||
/* empty */ | ||
pc->type = SOCK_STREAM; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SOCK_STREAM is by Default |
||
return NGX_OK; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4555,4 +4555,59 @@ ngx_http_lua_parse_addr(lua_State *L, u_char *text, size_t len) | |
} | ||
|
||
|
||
ngx_addr_t * | ||
ngx_http_lua_parse_addr_port(lua_State *L, u_char *text, size_t len) | ||
{ | ||
u_char *p, *last; | ||
ngx_int_t port; | ||
ngx_addr_t *addr; | ||
size_t plen; | ||
|
||
addr = ngx_http_lua_parse_addr(L, text, len); | ||
if (addr != NULL) { | ||
return addr; | ||
} | ||
|
||
last = text + len; | ||
|
||
#if (NGX_HAVE_INET6) | ||
if (len && text[0] == '[') { | ||
p = ngx_strlchr(text, last, ']'); | ||
if (p == NULL || p == last - 1 || *++p != ':') { | ||
return NULL; | ||
} | ||
|
||
text++; | ||
len -= 2; | ||
} else | ||
#endif | ||
|
||
{ | ||
p = ngx_strlchr(text, last, ':'); | ||
if (p == NULL) { | ||
return NULL; | ||
} | ||
} | ||
|
||
p++; | ||
plen = last - p; | ||
|
||
port = ngx_atoi(p, plen); | ||
if (port < 1 || port > 65535) { | ||
return NULL; | ||
} | ||
|
||
len -= plen + 1; | ||
|
||
addr = ngx_http_lua_parse_addr(L, text, len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeated parsing of addr from above |
||
if (addr == NULL) { | ||
return NULL; | ||
} | ||
|
||
ngx_inet_set_port(addr->sockaddr, (in_port_t) port); | ||
|
||
return addr; | ||
} | ||
Comment on lines
+4602
to
+4610
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong indentation |
||
|
||
|
||
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add test cases