diff --git a/src/otpbp_inet.erl b/src/otpbp_inet.erl index 9d8b17f8..8ec8382b 100644 --- a/src/otpbp_inet.erl +++ b/src/otpbp_inet.erl @@ -4,6 +4,11 @@ % OTP 21.0 -export([ipv4_mapped_ipv6_address/1]). -endif. +-ifndef(HAVE_inet__ensure_sockaddr_1). +% OTP 24.0 +-export([ensure_sockaddr/1]). +-compile({parse_transform, otpbp_pt}). +-endif. -ifndef(HAVE_inet__info_1). % OTP 24.0 -export([info/1]). @@ -17,6 +22,15 @@ ipv4_mapped_ipv6_address({D1, D2, D3, D4, D5, D6, D7, D8}) {D7 bsr 8, D7 band 16#FF, D8 bsr 8, D8 band 16#FF}. -endif. +-ifndef(HAVE_inet__ensure_sockaddr_1). +ensure_sockaddr(SockAddr) -> + try + prim_socket:enc_sockaddr(SockAddr) + catch + throw:{invalid, Invalid}:Stacktrace -> erlang:raise(error, {invalid, Invalid}, Stacktrace) + end. +-endif. + -ifndef(HAVE_inet__info_1). info({'$inet', GenSocketMod, _} = Socket) when is_atom(GenSocketMod) -> GenSocketMod:info(Socket); info(Socket) -> diff --git a/src/otpbp_pt.erl b/src/otpbp_pt.erl index 12555862..07b0ab23 100644 --- a/src/otpbp_pt.erl +++ b/src/otpbp_pt.erl @@ -140,7 +140,7 @@ {{geb_sctp, [connect, connect_init], 3}, otpbp_gen_sctp}, {{gen_server, start_monitor, [3, 4]}, otpbp_gen_server}, {{gen_statem, enter_loop, 4}, otpbp_gen_statem}, - {{inet, [info, ipv4_mapped_ipv6_address], 1}, otpbp_inet}, + {{inet, [ensure_sockaddr, info, ipv4_mapped_ipv6_address], 1}, otpbp_inet}, {{io_lib, format, 3}, otpbp_io_lib}, {{io_lib, fwrite, 3}, {otpbp_io_lib, format}}, {{io_lib, limit_term, 2}, otpbp_io_lib},