FreeSWITCH的sip_gethostbyname=true

cat /etc/hosts

192.168.1.100  ivr
192.168.1.100  node007.com

  • originate sofia/internal/1111@ivr &echo

可以呼出,没包含'.'

不可以呼出,包含'.',但ip_gethostbyname为false(默认值)

加了通道变量就可以呼出

测试的fs版本是1.10.9和1.10.10

对应的源码如下:

// mod_sofia.c

if (!strchr(host, '.') || switch_true(switch_event_get_header(var_event, "sip_gethostbyname"))) {
	struct sockaddr_in sa;
	struct hostent *he = gethostbyname(host);
	char buf[50] = "", *tmp;
	const char *ip;

	if (he) {
		memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr));
		ip = switch_inet_ntop(AF_INET, &sa.sin_addr, buf, sizeof(buf));
		tmp = switch_string_replace(dest, host, ip);
		//host = switch_core_session_strdup(nsession, ip);
		//dest = switch_core_session_strdup(nsession, tmp);
		switch_channel_set_variable_printf(nchannel, "sip_route_uri", "sip:%s", tmp);
		free(tmp);
	}
}

当然,dns解析域名,更好,这是正解

至于Kamailio,如果想让/etc/hosts生效,这样设置即可:

dns_use_search_list=yes
use_dns_cache=no

你可能感兴趣的:(FreeSWITCH,FreeSWITCH,主机的hosts)