mod_erlang_event: generate long node names the same as erlang does

Also, allow you to override the node name inference by passing a
nodename with an @ in it, eg. freeswitch@freeswitch.com
This commit is contained in:
Andrew Thompson 2010-08-17 02:32:37 -04:00
parent b0de3585ea
commit 9ad509c29a

View File

@ -33,6 +33,11 @@
*/
#include <switch.h>
#include <ei.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include "mod_erlang_event.h"
/* Stolen from code added to ei in R12B-5.
@ -340,6 +345,10 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(prefs.port);
if (strchr(prefs.nodename, '@')) {
/* we got a qualified node name, don't guess the host/domain */
snprintf(thisnodename, MAXNODELEN + 1, "%s", prefs.nodename);
} else {
#ifdef WIN32
if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#else
@ -356,9 +365,19 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
if ((off = strchr(thishostname, '.'))) {
*off = '\0';
}
} else {
if (!(_res.options & RES_INIT)) {
// init the resolver
res_init();
}
if (!zstr_buf(_res.dnsrch[0])) {
strncat(thishostname, ".", 1);
strncat(thishostname, _res.dnsrch[0], EI_MAXHOSTNAMELEN - strlen(thishostname));
}
}
snprintf(thisnodename, MAXNODELEN + 1, "%s@%s", prefs.nodename, thishostname);
}
snprintf(thisnodename, MAXNODELEN + 1, "%s@%s", prefs.nodename, thishostname);
/* init the ei stuff */
if (ei_connect_xinit(ec, thishostname, prefs.nodename, thisnodename, (Erl_IpAddr) (&server_addr.sin_addr.s_addr), prefs.cookie, 0) < 0) {