aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-05-29 12:38:26 +0200
committerMicael Karlberg <[email protected]>2019-07-08 16:53:40 +0200
commit86751fcc8665748a6bc8eeb5ab078f403d14107e (patch)
treedc8ba2cca39800281a76711ecc7dc29c95ada4de /erts/preloaded/src
parente6226c6741f336b4c0f2d5b4c930be2fcd9c3737 (diff)
downloadotp-86751fcc8665748a6bc8eeb5ab078f403d14107e.tar.gz
otp-86751fcc8665748a6bc8eeb5ab078f403d14107e.tar.bz2
otp-86751fcc8665748a6bc8eeb5ab078f403d14107e.zip
[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
Diffstat (limited to 'erts/preloaded/src')
-rw-r--r--erts/preloaded/src/socket.erl14
1 files changed, 9 insertions, 5 deletions
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().