Skip to content

Commit c20ccc4

Browse files
Merge pull request #8440 from rabbitmq/rabbitmq-server-8415
rabbit_networking:ranch_ref/1: use the user-provided IP address/interface
2 parents e6a678b + 07a6926 commit c20ccc4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

deps/rabbit/src/rabbit_networking.erl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,24 @@ ranch_ref(#listener{port = Port}) ->
223223
{acceptor, IPAddress, Port};
224224
ranch_ref(Listener) when is_list(Listener) ->
225225
Port = rabbit_misc:pget(port, Listener),
226-
[{IPAddress, Port, _Family} | _] = tcp_listener_addresses(Port),
226+
IPAddress = case rabbit_misc:pget(ip, Listener) of
227+
undefined ->
228+
[{Value, _Port, _Family} | _] = tcp_listener_addresses(Port),
229+
Value;
230+
Value when is_list(Value) ->
231+
%% since we only use this function to parse the address, only one result should
232+
%% be returned
233+
[{Parsed, _Family} | _] = gethostaddr(Value, auto),
234+
Parsed;
235+
Value when is_binary(Value) ->
236+
Str = rabbit_data_coercion:to_list(Value),
237+
%% since we only use this function to parse the address, only one result should
238+
%% be returned
239+
[{Parsed, _Family} | _] = gethostaddr(Str, auto),
240+
Parsed;
241+
Value when is_tuple(Value) ->
242+
Value
243+
end,
227244
{acceptor, IPAddress, Port};
228245
ranch_ref(undefined) ->
229246
undefined.
@@ -692,6 +709,7 @@ getaddr(Host, Family) ->
692709
{error, _} -> gethostaddr(Host, Family)
693710
end.
694711

712+
-spec gethostaddr(string(), inet:address_family() | 'auto') -> [{inet:ip_address(), inet:address_family()}].
695713
gethostaddr(Host, auto) ->
696714
Lookups = [{Family, inet:getaddr(Host, Family)} || Family <- [inet, inet6]],
697715
case [{IP, Family} || {Family, {ok, IP}} <- Lookups] of

0 commit comments

Comments
 (0)