I sometimes try to read the ejabberd source to find answers to specific questions not answered elsewhere. I'll start to write about such things here, for future reference of myself and possibly others.
The question: does ejabberd use /etc/hosts
for hostname resolution in s2s? I've heard rumors of other Jabber servers not doing that. This might be useful for connecting an internal server with a non-resolvable hostname to a public server.
The short answer is yes: /etc/hosts
is consulted as with most other programs, notably ping
. Typing inet_db:res_option(lookup).
at the Erlang prompt gives [native,file], where "native" is the entry giving the expected result, with gethostbyname
and nsswitch.conf
and all that.
Some things in ejabberd_s2s_out.erl
seem funny. In open_socket
, get_addr_port
(the function doing SRV lookups) is called before the domain name is converted to ASCII by IDNA. It seems that this would give incorrect results if a server with non-ASCII hostname listens only on a nonstandard port.
Additionally, it seems that get_addr_port
will only get the first SRV entry, instead of taking into account weights and priorities used for load balancing and such. Then again, maybe not enough people are using those features for it to be worth implementing…