From 86751fcc8665748a6bc8eeb5ab078f403d14107e Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 29 May 2019 12:38:26 +0200 Subject: [esock] Make it it work for IPv6 The nif code expects the socket address to be "complete", that is all fields must exist. This was not the case for a couple of functions, sendto, sendmsg and connect. What was mssing was a call to 'ensure_sockaddr'. Test: 1) Add a condition function to test if IPv6 is available and works. 2) Needed to adjust a test case (actually a common function used in several test cases) since the socket address data type has two optional fields, which we do not initiate (when sending), but the nif-code does fill in. OTP-15897 --- erts/preloaded/src/socket.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'erts/preloaded/src') diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index be94e3a867..910c8be294 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -1301,7 +1301,7 @@ connect(#socket{ref = SockRef}, #{family := Fam} = SockAddr, Timeout) ((Timeout =:= nowait) orelse (Timeout =:= infinity) orelse is_integer(Timeout)) -> TS = timestamp(Timeout), - case nif_connect(SockRef, SockAddr) of + case nif_connect(SockRef, ensure_sockaddr(SockAddr)) of ok -> %% Connected! ok; @@ -1620,7 +1620,7 @@ sendto(#socket{ref = SockRef}, Data, Dest, Flags, Timeout) (Timeout =:= infinity) orelse (is_integer(Timeout) andalso (Timeout > 0))) -> EFlags = enc_send_flags(Flags), - do_sendto(SockRef, Data, Dest, EFlags, Timeout); + do_sendto(SockRef, Data, ensure_sockaddr(Dest), EFlags, Timeout); sendto(#socket{ref = SockRef}, Data, #{family := Fam} = Dest, Flags, Timeout) when is_binary(Data) andalso ((Fam =:= inet) orelse (Fam =:= inet6) orelse (Fam =:= local)) andalso @@ -1629,7 +1629,7 @@ sendto(#socket{ref = SockRef}, Data, #{family := Fam} = Dest, Flags, Timeout) (Timeout =:= infinity) orelse (is_integer(Timeout) andalso (Timeout > 0))) -> EFlags = enc_send_flags(Flags), - do_sendto(SockRef, Data, Dest, EFlags, Timeout). + do_sendto(SockRef, Data, ensure_sockaddr(Dest), EFlags, Timeout). do_sendto(SockRef, Data, Dest, EFlags, Timeout) -> TS = timestamp(Timeout), @@ -1820,8 +1820,12 @@ do_sendmsg_rest([B|IOVec], Written) -> ensure_msghdr(#{ctrl := []} = M) -> ensure_msghdr(maps:remove(ctrl, M)); -ensure_msghdr(#{iov := IOV} = M) when is_list(IOV) andalso (IOV =/= []) -> - M#{iov := erlang:iolist_to_iovec(IOV)}; +ensure_msghdr(#{iov := IOV, addr := Addr} = M) + when is_list(IOV) andalso (IOV =/= []) -> + M#{iov => erlang:iolist_to_iovec(IOV), addr => ensure_sockaddr(Addr)}; +ensure_msghdr(#{iov := IOV} = M) + when is_list(IOV) andalso (IOV =/= []) -> + M#{iov => erlang:iolist_to_iovec(IOV)}; ensure_msghdr(_) -> einval(). -- cgit v1.2.3