From f28b26b8aa1f87344f352f1a9ca5fb59589d58cc Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 28 Aug 2009 20:30:03 +0000 Subject: [PATCH] add host_lookup api call git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14667 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 2 +- .../applications/mod_commands/mod_commands.c | 18 ++++++++++++++++++ src/switch_utils.c | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index daa2f615ac..3bac7c02c7 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -165,7 +165,7 @@ SWITCH_DECLARE(switch_status_t) switch_frame_free(switch_frame_t **frame); (switch_is_number(expr) && !atoi(expr)))) ? SWITCH_TRUE : SWITCH_FALSE) -SWITCH_DECLARE(switch_status_t) switch_resolve_host(char *host, char *buf, size_t buflen); +SWITCH_DECLARE(switch_status_t) switch_resolve_host(const char *host, char *buf, size_t buflen); /*! diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 348f44f137..c0d04fa8c0 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -45,6 +45,23 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown); SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown, NULL); +SWITCH_STANDARD_API(host_lookup_function) +{ + char host[256] = ""; + + if (switch_strlen_zero(cmd)) { + stream->write_function(stream, "%s", "parameter missing\n"); + } else { + if (switch_resolve_host(cmd, host, sizeof(host)) == SWITCH_STATUS_SUCCESS) { + stream->write_function(stream, "%s", host); + } else { + stream->write_function(stream, "%s", "!err!"); + } + } + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_STANDARD_API(nat_map_function) { int argc; @@ -3587,6 +3604,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX); SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, ""); SWITCH_ADD_API(commands_api_interface, "nat_map", "nat_map", nat_map_function, "[status|republish|reinit] | [add|del] [tcp|udp] [static]"); + SWITCH_ADD_API(commands_api_interface, "host_lookup", "host_lookup", host_lookup_function, ""); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_NOUNLOAD; diff --git a/src/switch_utils.c b/src/switch_utils.c index 2e1d6be321..d75533339d 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -867,7 +867,7 @@ static int get_netmask(struct sockaddr_in *me, int *mask) #endif -SWITCH_DECLARE(switch_status_t) switch_resolve_host(char *host, char *buf, size_t buflen) +SWITCH_DECLARE(switch_status_t) switch_resolve_host(const char *host, char *buf, size_t buflen) { struct addrinfo *ai;