Skip to content

Commit

Permalink
otpbp_inet: add ensure_sockaddr/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledest committed Oct 25, 2023
1 parent 7916502 commit acadf67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/otpbp_inet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand All @@ -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) ->
Expand Down
2 changes: 1 addition & 1 deletion src/otpbp_pt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit acadf67

Please sign in to comment.