aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/inet_udp.erl
diff options
context:
space:
mode:
authorSerge Aleynikov <[email protected]>2015-12-30 13:29:34 -0500
committerSerge Aleynikov <[email protected]>2016-01-12 11:18:12 -0500
commite293ad1b08b2f937555a102e6f3b4336574773c8 (patch)
treeb2eb8a92e8386e9d9589503929b2cf8afac13068 /lib/kernel/src/inet_udp.erl
parent1237669f7c59714f0c27d3df748241dfd655c0be (diff)
downloadotp-e293ad1b08b2f937555a102e6f3b4336574773c8.tar.gz
otp-e293ad1b08b2f937555a102e6f3b4336574773c8.tar.bz2
otp-e293ad1b08b2f937555a102e6f3b4336574773c8.zip
Assign externally open fd to gen_tcp (UDS support)
When a AF_LOCAL file descriptor is created externally (e.g. Unix Domain Socket) and passed to `gen_tcp:listen(0, [{fd, FD}])`, the implementation incorrectly assigned the address family to be equal to `inet`, which in the inet_drv driver translated to AF_INET instead of AF_LOCAL (or AF_UNIX), and an `einval` error code was returned. This patch fixes this problem such that the file descriptors of the `local` address family are supported in the inet:fdopen/5, gen_tcp:connect/3, gen_tcp:listen/2, gen_udp:open/2 calls
Diffstat (limited to 'lib/kernel/src/inet_udp.erl')
-rw-r--r--lib/kernel/src/inet_udp.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/kernel/src/inet_udp.erl b/lib/kernel/src/inet_udp.erl
index 5b2e5120c9..74b2874d5b 100644
--- a/lib/kernel/src/inet_udp.erl
+++ b/lib/kernel/src/inet_udp.erl
@@ -52,8 +52,9 @@ open(Port, Opts) ->
{ok, #udp_opts{fd=Fd,
ifaddr=BAddr={A,B,C,D},
port=BPort,
+ family=Family,
opts=SockOpts}} when ?ip(A,B,C,D), ?port(BPort) ->
- inet:open(Fd,BAddr,BPort,SockOpts,udp,inet,dgram,?MODULE);
+ inet:open(Fd,BAddr,BPort,SockOpts,udp,Family,dgram,?MODULE);
{ok, _} -> exit(badarg)
end.
@@ -92,9 +93,12 @@ controlling_process(Socket, NewOwner) ->
%% Create a port/socket from a file descriptor
%%
fdopen(Fd, Opts) ->
+ fdopen(Fd, inet:getfamily(Opts), Opts).
+
+fdopen(Fd, Family, Opts) ->
inet:fdopen(Fd,
optuniquify([{recbuf, ?RECBUF} | Opts]),
- udp, inet, dgram, ?MODULE).
+ udp, Family, dgram, ?MODULE).
%% Remove all duplicate options from an option list.