From 4df1618aaba49a35d5a262970b3f4773dcd0ee25 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 14 Jun 2011 02:04:37 +0200 Subject: [PATCH] Adapt socket.bind() to create a IPv4 or IPv6 depending on the address given --- src/socket.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/socket.lua b/src/socket.lua index 211adcd..7a77fbc 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -29,7 +29,15 @@ function connect(address, port, laddress, lport) end 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 sock:setoption("reuseaddr", true) local res, err = sock:bind(host, port)