From 2921864cf366297e21888813ec8771830959e766 Mon Sep 17 00:00:00 2001 From: Led Date: Wed, 25 Oct 2023 18:58:13 +0300 Subject: [PATCH] otpbp_inet: add ensure_sockaddr/1 --- src/otpbp_inet.erl | 14 ++++++++++++++ src/otpbp_pt.erl | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) 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 3d03cb87..323ac118 100644 --- a/src/otpbp_pt.erl +++ b/src/otpbp_pt.erl @@ -139,7 +139,7 @@ {{gen_event, start_monitor, [0, 1, 2]}, otpbp_gen_event}, {{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},