Update SocketClient to support raw IP addresses

This commit is contained in:
Deon George 2024-05-21 21:07:11 +10:00
parent aaec5f8f4a
commit 72d68fa1ab

View File

@ -201,10 +201,16 @@ final class SocketClient {
$sort = collect(['AAAA','A']);
// We only look at AAAA/A records
$resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A))
->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; })
->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); });
if (filter_var($address,FILTER_VALIDATE_IP))
$resolved = collect([[
(($x=filter_var($address,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 'ipv6' : 'ip')=>$address,
'type'=>$x ? 'AAAA' : 'A'
]]);
else
// We only look at AAAA/A records
$resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A))
->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; })
->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); });
if (! $resolved->count())
throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address));