mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 03:58:21 +01:00
Fix. setsockname fails with "*" as host.
Add. test_bind.lua
This commit is contained in:
parent
56dbda39ed
commit
e54f78c61c
@ -478,6 +478,9 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv,
|
|||||||
struct addrinfo *iterator = NULL, *resolved = NULL;
|
struct addrinfo *iterator = NULL, *resolved = NULL;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
t_socket sock = *ps;
|
t_socket sock = *ps;
|
||||||
|
/* translate luasocket special values to C */
|
||||||
|
if (strcmp(address, "*") == 0) address = NULL;
|
||||||
|
if (!serv) serv = "0";
|
||||||
/* try resolving */
|
/* try resolving */
|
||||||
err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved));
|
err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved));
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -222,7 +222,6 @@ static int meth_bind(lua_State *L)
|
|||||||
bindhints.ai_socktype = SOCK_STREAM;
|
bindhints.ai_socktype = SOCK_STREAM;
|
||||||
bindhints.ai_family = tcp->family;
|
bindhints.ai_family = tcp->family;
|
||||||
bindhints.ai_flags = AI_PASSIVE;
|
bindhints.ai_flags = AI_PASSIVE;
|
||||||
address = strcmp(address, "*")? address: NULL;
|
|
||||||
err = inet_trybind(&tcp->sock, address, port, &bindhints);
|
err = inet_trybind(&tcp->sock, address, port, &bindhints);
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
6
test/test_bind.lua
Normal file
6
test/test_bind.lua
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
local socket = require "socket"
|
||||||
|
local u = socket.udp() assert(u:setsockname("*", 5088)) u:close()
|
||||||
|
local u = socket.udp() assert(u:setsockname("*", 0)) u:close()
|
||||||
|
local t = socket.tcp() assert(t:bind("*", 5088)) t:close()
|
||||||
|
local t = socket.tcp() assert(t:bind("*", 0)) t:close()
|
||||||
|
print("done!")
|
Loading…
Reference in New Issue
Block a user