Software /
code /
prosody
Comparison
net/resolvers/basic.lua @ 8775:ae7cf011e46a
net.resolvers.basic: Support IP address literals
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 02 May 2018 19:06:59 +0200 |
parent | 8531:601681acea73 |
child | 9496:4ac3103787cc |
comparison
equal
deleted
inserted
replaced
8774:cac4bd0d3335 | 8775:ae7cf011e46a |
---|---|
1 local adns = require "net.adns"; | 1 local adns = require "net.adns"; |
2 local inet_pton = require "util.net".pton; | |
2 | 3 |
3 local methods = {}; | 4 local methods = {}; |
4 local resolver_mt = { __index = methods }; | 5 local resolver_mt = { __index = methods }; |
5 | 6 |
6 -- Find the next target to connect to, and | 7 -- Find the next target to connect to, and |
21 local function ready() | 22 local function ready() |
22 n = n - 1; | 23 n = n - 1; |
23 if n > 0 then return; end | 24 if n > 0 then return; end |
24 self.targets = targets; | 25 self.targets = targets; |
25 self:next(cb); | 26 self:next(cb); |
27 end | |
28 | |
29 local is_ip = inet_pton(self.hostname); | |
30 if is_ip then | |
31 if #is_ip == 16 then | |
32 cb(self.conn_type.."6", self.hostname, self.port, self.extra); | |
33 elseif #is_ip == 4 then | |
34 cb(self.conn_type, self.hostname, self.port, self.extra); | |
35 end | |
36 return; | |
26 end | 37 end |
27 | 38 |
28 -- Resolve DNS to target list | 39 -- Resolve DNS to target list |
29 local dns_resolver = adns.resolver(); | 40 local dns_resolver = adns.resolver(); |
30 dns_resolver:lookup(function (answer) | 41 dns_resolver:lookup(function (answer) |