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