diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2020-05-19 22:55:12 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2020-05-19 22:55:12 +0200 |
commit | f19b975e8deaf3c0d943894142d5981791f07219 (patch) | |
tree | e4259b8b5c879a91d04393243e4313e1c081f3ea /src/misc.erl | |
parent | ejabberd_stun: Support IPv6 for TURN (diff) |
mod_stun_disco: Offer local IPv6 services
Also announce local STUN/TURN services listening on IPv6 sockets (unless
the 'offer_local_services' option is set to 'false').
Diffstat (limited to 'src/misc.erl')
-rw-r--r-- | src/misc.erl | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/misc.erl b/src/misc.erl index 9030be60..bb9d39d8 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -40,8 +40,8 @@ read_css/1, read_img/1, read_js/1, read_lua/1, try_url/1, intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0, is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4, - get_my_ip/0, parse_ip_mask/1, match_ip_mask/3, format_hosts_list/1, - format_cycle/1, delete_dir/1]). + get_my_v4_ip/0, get_my_v6_ip/0, parse_ip_mask/1, match_ip_mask/3, + format_hosts_list/1, format_cycle/1, delete_dir/1]). %% Deprecated functions -export([decode_base64/1, encode_base64/1]). @@ -509,14 +509,22 @@ format_exception(Level, Class, Reason, Stacktrace) -> end). -endif. --spec get_my_ip() -> inet:ip_address(). -get_my_ip() -> +-spec get_my_v4_ip() -> inet:ip4_address(). +get_my_v4_ip() -> {ok, MyHostName} = inet:gethostname(), case inet:getaddr(MyHostName, inet) of {ok, Addr} -> Addr; {error, _} -> {127, 0, 0, 1} end. +-spec get_my_v6_ip() -> inet:ip6_address(). +get_my_v6_ip() -> + {ok, MyHostName} = inet:gethostname(), + case inet:getaddr(MyHostName, inet6) of + {ok, Addr} -> Addr; + {error, _} -> {0, 0, 0, 0, 0, 0, 0, 1} + end. + -spec parse_ip_mask(binary()) -> {ok, {inet:ip4_address(), 0..32}} | {ok, {inet:ip6_address(), 0..128}} | error. |