[erlang-questions] IPv6

Per Hedeland per@REDACTED
Mon Mar 30 14:19:20 CEST 2009


Per Hedeland <per@REDACTED> wrote:
>
>Is there some good reason for gen_tcp/gen_udp not auto-recognizing an
>8-tuple as an IPv6 address?

And if there isn't, perhaps the trivial patches below could be
considered for inclusion?

--Per

--- otp_src_R13A/lib/kernel/src/gen_tcp.erl.ORIG	2009-03-12 13:19:00.000000000 +0100
+++ otp_src_R13A/lib/kernel/src/gen_tcp.erl	2009-03-27 17:59:12.000000000 +0100
@@ -46,7 +46,7 @@
     end.
 
 connect1(Address,Port,Opts,Timer) ->
-    Mod = mod(Opts),
+    Mod = mod(Opts ++ [{ip, Address}]),
     case Mod:getaddrs(Address,Timer) of
 	{ok,IPs} ->
 	    case Mod:getserv(Port) of
@@ -179,13 +179,17 @@
 %% Get the tcp_module
 mod() -> inet_db:tcp_module().
 
-%% Get the tcp_module, but option tcp_module|inet|inet6 overrides
+%% Get the tcp_module, but option tcp_module|inet|inet6|{ip,tuple()} overrides
 mod([{tcp_module,Mod}|_]) ->
     Mod;
 mod([inet|_]) ->
     inet_tcp;
 mod([inet6|_]) ->
     inet6_tcp;
+mod([{ip, {_,_,_,_}}|_]) ->
+    inet_tcp;
+mod([{ip, {_,_,_,_,_,_,_,_}}|_]) ->
+    inet6_tcp;
 mod([_|Opts]) ->
     mod(Opts);
 mod([]) ->
--- otp_src_R13A/lib/kernel/src/gen_udp.erl.ORIG	2009-03-12 13:19:00.000000000 +0100
+++ otp_src_R13A/lib/kernel/src/gen_udp.erl	2009-03-27 18:05:02.000000000 +0100
@@ -104,13 +104,17 @@
 %% Get the udp_module
 mod() -> inet_db:udp_module().
 
-%% Get the udp_module, but option udp_module|inet|inet6 overrides
+%% Get the udp_module, but option tcp_module|inet|inet6|{ip,tuple()} overrides
 mod([{udp_module,Mod}|_]) ->
     Mod;
 mod([inet|_]) ->
     inet_udp;
 mod([inet6|_]) ->
     inet6_udp;
+mod([{ip, {_,_,_,_}}|_]) ->
+    inet_udp;
+mod([{ip, {_,_,_,_,_,_,_,_}}|_]) ->
+    inet6_udp;
 mod([_|Opts]) ->
     mod(Opts);
 mod([]) ->



Original message----------------------------------------------------
>From: Per Hedeland <per@REDACTED>
>To: erlang-questions@REDACTED
>Subject: [erlang-questions] IPv6
>
>Hi,
>
>Is there some good reason for gen_tcp/gen_udp not auto-recognizing an
>8-tuple as an IPv6 address? gen_tcp:listen/2 and gen_udp:open/2 don't
>even fail if you give them one w/o explicit 'inet6' option, but (OS
>stack permitting) interprets "the first 4 bytes" as an IPv4 address -
>shocking behaviour for an Erlang module!
>
>Erlang R13A (erts-5.7) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]
>Eshell V5.7  (abort with ^G)
>1> gen_tcp:listen(1234, [{ip,{1,43981,4660,0,0,0,0,5}}]).
>{ok,#Port<0.439>}
>2> gen_udp:open(1234, [{ip,{1,43981,4660,0,0,0,0,5}}]).  
>{ok,#Port<0.449>}
>
>$ netstat -an | grep 1234
>tcp        0      0 0.1.171.205:1234            0.0.0.0:*       LISTEN
>udp        0      0 0.1.171.205:1234            0.0.0.0:*  
>
>'inet' may be a reasonable default (though it isn't actually documented
>as such as far as I can see), but blindly "applying" it in the face of
>obvious evidence to the contrary can't be right. gen_tcp:connect/3 and
>gen_udp:send/4 also have "interesting" behaviour:
>
>4> gen_tcp:connect({1,43981,4660,0,0,0,0,5}, 1234, []).
>{error,nxdomain}
>5> gen_udp:send(S, {1,43981,4660,0,0,0,0,5}, 1234, <<"hello">>).
>{error,nxdomain}
>
>Yeah, I can imagine that the name server had trouble finding that
>"domain"... (no, it didn't actually try a DNS lookup).
>
>--Per Hedeland
>_______________________________________________
>erlang-questions mailing list
>erlang-questions@REDACTED
>http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list