Software /
code /
prosody
Comparison
net/server_event.lua @ 9473:5fdda751333a
net.server: Require IP address as argument to addclient (no DNS names)
The net.connect API should be used to resolve DNS names first
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 11 Oct 2018 15:48:30 +0200 |
parent | 9387:33e52f727f0f |
child | 9495:89e05b118f6e |
comparison
equal
deleted
inserted
replaced
9472:ea40fe484c38 | 9473:5fdda751333a |
---|---|
48 local coroutine_yield = coroutine.yield | 48 local coroutine_yield = coroutine.yield |
49 | 49 |
50 local has_luasec, ssl = pcall ( require , "ssl" ) | 50 local has_luasec, ssl = pcall ( require , "ssl" ) |
51 local socket = require "socket" | 51 local socket = require "socket" |
52 local levent = require "luaevent.core" | 52 local levent = require "luaevent.core" |
53 local inet = require "util.net"; | |
54 local inet_pton = inet.pton; | |
53 | 55 |
54 local socket_gettime = socket.gettime | 56 local socket_gettime = socket.gettime |
55 local getaddrinfo = socket.dns.getaddrinfo | |
56 | 57 |
57 local log = require ("util.logger").init("socket") | 58 local log = require ("util.logger").init("socket") |
58 | 59 |
59 local function debug(...) | 60 local function debug(...) |
60 return log("debug", ("%s "):rep(select('#', ...)), ...) | 61 return log("debug", ("%s "):rep(select('#', ...)), ...) |
726 if sslctx and not has_luasec then | 727 if sslctx and not has_luasec then |
727 debug "need luasec, but not available" | 728 debug "need luasec, but not available" |
728 return nil, "luasec not found" | 729 return nil, "luasec not found" |
729 end | 730 end |
730 if not typ then | 731 if not typ then |
731 local addrinfo, err = getaddrinfo(addr) | 732 local n = inet_pton(addr); |
732 if not addrinfo then return nil, err end | 733 if not n then return nil, "invalid-ip"; end |
733 if addrinfo[1] and addrinfo[1].family == "inet6" then | 734 if #n == 16 then |
734 typ = "tcp6" | 735 typ = "tcp6"; |
735 else | 736 elseif #n == 4 then |
736 typ = "tcp" | 737 typ = "tcp4"; |
737 end | 738 end |
738 end | 739 end |
739 local create = socket[typ] | 740 local create = socket[typ] or socket.tcp; |
740 if type( create ) ~= "function" then | 741 if type( create ) ~= "function" then |
741 return nil, "invalid socket type" | 742 return nil, "invalid socket type" |
742 end | 743 end |
743 local client, err = create() -- creating new socket | 744 local client, err = create() -- creating new socket |
744 if not client then | 745 if not client then |