mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-27 04:48:21 +01:00
Adapt socket.bind() to create a IPv4 or IPv6 depending on the address given
This commit is contained in:
parent
5065a2585c
commit
4df1618aab
@ -29,7 +29,15 @@ function connect(address, port, laddress, lport)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function bind(host, port, backlog)
|
function bind(host, port, backlog)
|
||||||
local sock, err = socket.tcp()
|
if host == "*" then host = "0.0.0.0" end
|
||||||
|
local addrinfo, err = socket.dns.getaddrinfo(host);
|
||||||
|
if not addrinfo then return nil, err end
|
||||||
|
local sock, err;
|
||||||
|
if addrinfo[1].family == "inet" then
|
||||||
|
sock, err = socket.tcp()
|
||||||
|
else
|
||||||
|
sock, err = socket.tcp6()
|
||||||
|
end
|
||||||
if not sock then return nil, err end
|
if not sock then return nil, err end
|
||||||
sock:setoption("reuseaddr", true)
|
sock:setoption("reuseaddr", true)
|
||||||
local res, err = sock:bind(host, port)
|
local res, err = sock:bind(host, port)
|
||||||
|
Loading…
Reference in New Issue
Block a user