FS-5396 --resolve add gethost function to call gethostbyname as desired

Conflicts:
	src/mod/endpoints/mod_sofia/mod_sofia.c
This commit is contained in:
Anthony Minessale 2014-02-05 01:08:31 +05:00
parent e094f5dc70
commit dedc4d7e3e
2 changed files with 28 additions and 5 deletions

View File

@ -518,6 +518,29 @@ SWITCH_STANDARD_API(switchname_api_function)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_STANDARD_API(gethost_api_function)
{
struct sockaddr_in sa;
struct hostent *he;
const char *ip;
char buf[50] = "";
if (!zstr(cmd)) {
he = gethostbyname(cmd);
if (he) {
memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr));
ip = inet_ntop(AF_INET, &sa.sin_addr, buf, sizeof(buf));
stream->write_function(stream, "%s", ip);
return SWITCH_STATUS_SUCCESS;
}
}
stream->write_function(stream, "-ERR");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(shutdown_function) SWITCH_STANDARD_API(shutdown_function)
{ {
@ -6178,6 +6201,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "hostname", "Return the system hostname", hostname_api_function, ""); SWITCH_ADD_API(commands_api_interface, "hostname", "Return the system hostname", hostname_api_function, "");
SWITCH_ADD_API(commands_api_interface, "interface_ip", "Return the primary IP of an interface", interface_ip_function, INTERFACE_IP_SYNTAX); SWITCH_ADD_API(commands_api_interface, "interface_ip", "Return the primary IP of an interface", interface_ip_function, INTERFACE_IP_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "switchname", "Return the switch name", switchname_api_function, ""); SWITCH_ADD_API(commands_api_interface, "switchname", "Return the switch name", switchname_api_function, "");
SWITCH_ADD_API(commands_api_interface, "gethost", "gethostbyname", gethost_api_function, "");
SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]"); SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]");
SWITCH_ADD_API(commands_api_interface, "in_group", "Determine if a user is in a group", in_group_function, "<user>[@<domain>] <group_name>"); SWITCH_ADD_API(commands_api_interface, "in_group", "Determine if a user is in a group", in_group_function, "<user>[@<domain>] <group_name>");
SWITCH_ADD_API(commands_api_interface, "is_lan_addr", "See if an ip is a lan addr", lan_addr_function, "<ip>"); SWITCH_ADD_API(commands_api_interface, "is_lan_addr", "See if an ip is a lan addr", lan_addr_function, "<ip>");

View File

@ -5089,15 +5089,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!strchr(host, '.') || switch_true(switch_event_get_header(var_event, "sip_gethostbyname"))) { if (!strchr(host, '.') || switch_true(switch_event_get_header(var_event, "sip_gethostbyname"))) {
struct sockaddr_in sa; struct sockaddr_in sa;
struct hostent *he = gethostbyname(host); struct hostent *he = gethostbyname(host);
char *ip, *tmp; char buf[50] = "", *tmp;
const char *ip;
if (he) { if (he) {
memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr)); memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr));
ip = inet_ntoa(sa.sin_addr); ip = inet_ntop(AF_INET, &sa.sin_addr, buf, sizeof(buf));
tmp = switch_string_replace(dest, host, ip); 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); switch_channel_set_variable_printf(nchannel, "sip_route_uri", "sip:%s", tmp);
free(tmp); free(tmp);
} }