aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2010-10-14 16:56:43 +0200
committerRaimo Niskanen <[email protected]>2010-11-09 12:14:57 +0100
commitce4c78512fccda58e75c4846ced1c3a4e10d7454 (patch)
tree91249b26f7b2c6e2d3962a019e2d74a9d9451c89 /erts/preloaded
parentff7a4dbd6881e2434ed2619df541c113281cf0a0 (diff)
downloadotp-ce4c78512fccda58e75c4846ced1c3a4e10d7454.tar.gz
otp-ce4c78512fccda58e75c4846ced1c3a4e10d7454.tar.bz2
otp-ce4c78512fccda58e75c4846ced1c3a4e10d7454.zip
Implement inet:getifaddrs/0 on Windows
Diffstat (limited to 'erts/preloaded')
-rw-r--r--erts/preloaded/ebin/prim_inet.beambin64188 -> 65184 bytes
-rw-r--r--erts/preloaded/src/prim_inet.erl39
2 files changed, 32 insertions, 7 deletions
diff --git a/erts/preloaded/ebin/prim_inet.beam b/erts/preloaded/ebin/prim_inet.beam
index 8f0b1e3faa..3f53f35273 100644
--- a/erts/preloaded/ebin/prim_inet.beam
+++ b/erts/preloaded/ebin/prim_inet.beam
Binary files differ
diff --git a/erts/preloaded/src/prim_inet.erl b/erts/preloaded/src/prim_inet.erl
index 00ce26dfb3..446656e45f 100644
--- a/erts/preloaded/src/prim_inet.erl
+++ b/erts/preloaded/src/prim_inet.erl
@@ -658,7 +658,7 @@ getifaddrs(S) when is_port(S) ->
{error,enotsup} ->
case getiflist(S) of
{ok, IFs} ->
- getifaddrs_ifget(S, IFs);
+ {ok, getifaddrs_ifget(S, IFs)};
Err1 -> Err1
end;
Err2 -> Err2
@@ -674,14 +674,18 @@ comp_ifaddrs([{If,Opts}|IfOpts], T) ->
false ->
OptSet = comp_ifaddrs_add(ktree_empty(), Opts),
comp_ifaddrs(IfOpts, ktree_insert(If, OptSet, T))
- end;
+ end;
comp_ifaddrs([], T) ->
[{If,ktree_keys(ktree_get(If, T))} || If <- ktree_keys(T)].
comp_ifaddrs_add(OptSet, [Opt|Opts]) ->
case ktree_is_defined(Opt, OptSet) of
- true -> comp_ifaddrs_add(OptSet, Opts);
- false -> comp_ifaddrs_add(ktree_insert(Opt, undefined, OptSet), Opts)
+ true
+ when element(1, Opt) =:= flags;
+ element(1, Opt) =:= hwaddr ->
+ comp_ifaddrs_add(OptSet, Opts);
+ _ ->
+ comp_ifaddrs_add(ktree_insert(Opt, undefined, OptSet), Opts)
end;
comp_ifaddrs_add(OptSet, []) -> OptSet.
@@ -2018,9 +2022,9 @@ build_ifaddrs(Cs) ->
build_ifaddrs([], []) ->
[];
build_ifaddrs([0|Cs], Acc) ->
- Name = rev(Acc),
+ Name = utf8_to_characters(rev(Acc)),
{Opts,Rest} = build_ifaddrs_opts(Cs, []),
- [{Name,rev(Opts)}|build_ifaddrs(Rest)];
+ [{Name,Opts}|build_ifaddrs(Rest)];
build_ifaddrs([C|Cs], Acc) ->
build_ifaddrs(Cs, [C|Acc]).
@@ -2029,7 +2033,7 @@ build_ifaddrs_opts([0|Cs], Acc) ->
build_ifaddrs_opts([C|Cs]=CCs, Acc) ->
case dec_ifopt(C) of
undefined ->
- erlang:error([CCs,Acc]);
+ erlang:error(badarg, [CCs,Acc]);
Opt ->
Type = type_ifopt(Opt),
{Val,Rest} = dec_value(Type, Cs),
@@ -2112,6 +2116,27 @@ tree({K0,V0,L,R}, K, Op, H) ->
+utf8_to_characters([]) -> [];
+utf8_to_characters([B|Bs]=Arg) when (B band 16#FF) =:= B ->
+ if 16#F8 =< B ->
+ erlang:error(badarg, [Arg]);
+ 16#F0 =< B ->
+ utf8_to_characters(Bs, B band 16#07, 3);
+ 16#E0 =< B ->
+ utf8_to_characters(Bs, B band 16#0F, 2);
+ 16#C0 =< B ->
+ utf8_to_characters(Bs, B band 16#1F, 1);
+ 16#80 =< B ->
+ erlang:error(badarg, [Arg]);
+ true ->
+ [B|utf8_to_characters(Bs)]
+ end.
+%%
+utf8_to_characters(Bs, U, 0) ->
+ [U|utf8_to_characters(Bs)];
+utf8_to_characters([B|Bs], U, N) when ((B band 16#3F) bor 16#80) =:= B ->
+ utf8_to_characters(Bs, (U bsl 6) bor (B band 16#3F), N-1).
+
ip_to_bytes(IP) when tuple_size(IP) =:= 4 -> ip4_to_bytes(IP);
ip_to_bytes(IP) when tuple_size(IP) =:= 8 -> ip6_to_bytes(IP).