@@ -112,17 +112,17 @@ local function each_matching_record(pkt, name, type)
112
112
return pkt :grep (params )
113
113
end
114
114
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 )
116
116
local packet = dns_resolver :query (host , query_type , nil , timeout )
117
117
if not packet then
118
118
return
119
119
end
120
120
for rec in each_matching_record (packet , host , filter_type ) do
121
121
local t = rec :type ()
122
122
if t == cqueues_dns_record .AAAA then
123
- records :add_v6 (rec :addr ())
123
+ records :add_v6 (rec :addr (), port )
124
124
elseif t == cqueues_dns_record .A then
125
- records :add_v4 (rec :addr ())
125
+ records :add_v4 (rec :addr (), port )
126
126
end
127
127
end
128
128
end
@@ -144,20 +144,22 @@ function records_mt:__len()
144
144
return self .n
145
145
end
146
146
147
- function records_methods :add_v4 (addr )
147
+ function records_methods :add_v4 (addr , port )
148
148
local n = self .n + 1
149
149
self [n ] = {
150
150
family = cs .AF_INET ;
151
151
addr = addr ;
152
+ port = port ;
152
153
}
153
154
self .n = n
154
155
end
155
156
156
- function records_methods :add_v6 (addr )
157
+ function records_methods :add_v6 (addr , port )
157
158
local n = self .n + 1
158
159
self [n ] = {
159
160
family = cs .AF_INET6 ;
160
161
addr = addr ;
162
+ port = port ;
161
163
}
162
164
self .n = n
163
165
end
@@ -202,28 +204,29 @@ local function lookup_records(options, timeout)
202
204
end
203
205
204
206
local host = options .host
207
+ local port = options .port
205
208
206
209
local ipv4 = IPv4address :match (host )
207
210
if ipv4 then
208
- records :add_v4 (host )
211
+ records :add_v4 (host , port )
209
212
return records
210
213
end
211
214
212
215
local ipv6 = IPv6addrz :match (host )
213
216
if ipv6 then
214
- records :add_v6 (host )
217
+ records :add_v6 (host , port )
215
218
return records
216
219
end
217
220
218
221
local dns_resolver = options .dns_resolver or cqueues_dns .getpool ()
219
222
if family == cs .AF_UNSPEC then
220
223
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 ())
223
226
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 )
225
228
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 )
227
230
end
228
231
return records
229
232
end
@@ -255,7 +258,7 @@ local function connect(options, timeout)
255
258
local connect_params = {
256
259
family = nil ;
257
260
host = nil ;
258
- port = options . port ;
261
+ port = nil ;
259
262
path = nil ;
260
263
bind = bind ;
261
264
sendname = false ;
@@ -269,6 +272,7 @@ local function connect(options, timeout)
269
272
local rec = records [i ]
270
273
connect_params .family = rec .family ;
271
274
connect_params .host = rec .addr ;
275
+ connect_params .port = rec .port ;
272
276
connect_params .path = rec .path ;
273
277
local s
274
278
s , lasterr , lasterrno = ca .fileresult (cs .connect (connect_params ))
0 commit comments