Skip to content

Commit

Permalink
Bring this back.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 18, 2025
1 parent 3e6b7c2 commit 9d1690d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/core/io/srt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ let getaddrinfo ~(log : Log.t) ~prefer_address address port =
let open Posix_socket in
let hints = allocate_n Addrinfo.t ~count:1 in
hints |-> Addrinfo.ai_flags <-@ ni_numerichost;
(hints |-> Addrinfo.ai_family
<-@
match prefer_address with
| `System_default -> af_unspec
| `Ipv4 -> af_inet
| `Ipv6 -> af_inet6);
hints |-> Addrinfo.ai_family <-@ af_unspec;
hints |-> Addrinfo.ai_socktype <-@ sock_stream;
match getaddrinfo ~hints ~port:(`Int port) address with
| ptr when is_null !@ptr ->
Expand All @@ -89,7 +84,31 @@ let getaddrinfo ~(log : Log.t) ~prefer_address address port =
address port)
"srt"
| ptr ->
let sockaddr = !@ptr in
let first_address = !@ptr in
let sockaddr =
match prefer_address with
| `System_default -> first_address
| `Ipv4 ->
let rec f ptr cur =
let sockaddr = !@ptr in
if is_null sockaddr then cur
else (
match !@(sockaddr |-> Sockaddr.sa_family) with
| id when id = af_inet -> sockaddr
| _ -> f (ptr +@ 1) cur)
in
f ptr first_address
| `Ipv6 ->
let rec f ptr cur =
let sockaddr = !@ptr in
if is_null sockaddr then cur
else (
match !@(sockaddr |-> Sockaddr.sa_family) with
| id when id = af_inet6 -> sockaddr
| _ -> f (ptr +@ 1) cur)
in
f ptr first_address
in
if log#active 5 then
log#f 5 "Address %s:%n resolved to: %s" address port
(string_of_address (to_unix_sockaddr sockaddr));
Expand Down

0 comments on commit 9d1690d

Please sign in to comment.