@@ -112,17 +112,17 @@ local function each_matching_record(pkt, name, type)
112112 return pkt :grep (params )
113113end
114114
115- local function dns_lookup (records , dns_resolver , host , query_type , filter_type , timeout )
115+ local function dns_lookup (records , dns_resolver , host , port , query_type , filter_type , timeout )
116116 local packet = dns_resolver :query (host , query_type , nil , timeout )
117117 if not packet then
118118 return
119119 end
120120 for rec in each_matching_record (packet , host , filter_type ) do
121121 local t = rec :type ()
122122 if t == cqueues_dns_record .AAAA then
123- records :add_v6 (rec :addr ())
123+ records :add_v6 (rec :addr (), port )
124124 elseif t == cqueues_dns_record .A then
125- records :add_v4 (rec :addr ())
125+ records :add_v4 (rec :addr (), port )
126126 end
127127 end
128128end
@@ -144,20 +144,22 @@ function records_mt:__len()
144144 return self .n
145145end
146146
147- function records_methods :add_v4 (addr )
147+ function records_methods :add_v4 (addr , port )
148148 local n = self .n + 1
149149 self [n ] = {
150150 family = cs .AF_INET ;
151151 addr = addr ;
152+ port = port ;
152153 }
153154 self .n = n
154155end
155156
156- function records_methods :add_v6 (addr )
157+ function records_methods :add_v6 (addr , port )
157158 local n = self .n + 1
158159 self [n ] = {
159160 family = cs .AF_INET6 ;
160161 addr = addr ;
162+ port = port ;
161163 }
162164 self .n = n
163165end
@@ -202,28 +204,29 @@ local function lookup_records(options, timeout)
202204 end
203205
204206 local host = options .host
207+ local port = options .port
205208
206209 local ipv4 = IPv4address :match (host )
207210 if ipv4 then
208- records :add_v4 (host )
211+ records :add_v4 (host , port )
209212 return records
210213 end
211214
212215 local ipv6 = IPv6addrz :match (host )
213216 if ipv6 then
214- records :add_v6 (host )
217+ records :add_v6 (host , port )
215218 return records
216219 end
217220
218221 local dns_resolver = options .dns_resolver or cqueues_dns .getpool ()
219222 if family == cs .AF_UNSPEC then
220223 local deadline = timeout and monotime ()+ timeout
221- dns_lookup (records , dns_resolver , host , cqueues_dns_record .AAAA , nil , timeout )
222- dns_lookup (records , dns_resolver , host , cqueues_dns_record .A , nil , deadline and deadline - monotime ())
224+ dns_lookup (records , dns_resolver , host , port , cqueues_dns_record .AAAA , nil , timeout )
225+ dns_lookup (records , dns_resolver , host , port , cqueues_dns_record .A , nil , deadline and deadline - monotime ())
223226 elseif family == cs .AF_INET then
224- dns_lookup (records , dns_resolver , host , cqueues_dns_record .A , cqueues_dns_record .A , timeout )
227+ dns_lookup (records , dns_resolver , host , port , cqueues_dns_record .A , cqueues_dns_record .A , timeout )
225228 elseif family == cs .AF_INET6 then
226- dns_lookup (records , dns_resolver , host , cqueues_dns_record .AAAA , cqueues_dns_record .AAAA , timeout )
229+ dns_lookup (records , dns_resolver , host , port , cqueues_dns_record .AAAA , cqueues_dns_record .AAAA , timeout )
227230 end
228231 return records
229232end
@@ -255,7 +258,7 @@ local function connect(options, timeout)
255258 local connect_params = {
256259 family = nil ;
257260 host = nil ;
258- port = options . port ;
261+ port = nil ;
259262 path = nil ;
260263 bind = bind ;
261264 sendname = false ;
@@ -269,6 +272,7 @@ local function connect(options, timeout)
269272 local rec = records [i ]
270273 connect_params .family = rec .family ;
271274 connect_params .host = rec .addr ;
275+ connect_params .port = rec .port ;
272276 connect_params .path = rec .path ;
273277 local s
274278 s , lasterr , lasterrno = ca .fileresult (cs .connect (connect_params ))
0 commit comments