]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add host_lookup api call
authorBrian West <brian@freeswitch.org>
Fri, 28 Aug 2009 20:30:03 +0000 (20:30 +0000)
committerBrian West <brian@freeswitch.org>
Fri, 28 Aug 2009 20:30:03 +0000 (20:30 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14667 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_utils.c

index daa2f615acf85d4c3cc39f460e21cd15dbd474fa..3bac7c02c769a9833957bdad4a4754e8c5f7f744 100644 (file)
@@ -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);
 
 
 /*!
index 348f44f13719f82dcc859d8b059aba180db728f3..c0d04fa8c0707ea04624a92584ef48622abe7a3f 100644 (file)
@@ -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, "<mss>");
        SWITCH_ADD_API(commands_api_interface, "nat_map", "nat_map", nat_map_function, "[status|republish|reinit] | [add|del] <port> [tcp|udp] [static]");
+       SWITCH_ADD_API(commands_api_interface, "host_lookup", "host_lookup", host_lookup_function, "<hostname>");
 
        /* indicate that the module should continue to be loaded */
        return SWITCH_STATUS_NOUNLOAD;
index 2e1d6be3212a57d300563247c1c210996b3c1b7b..d75533339deee185ec7c19ee9222e6f457b16ecc 100644 (file)
@@ -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;