Merge branch 'collectd-5.4' into collectd-5.5
[collectd.git] / src / tokyotyrant.c
index 26366c9..f04a5fc 100644 (file)
 #include "plugin.h"
 #include "common.h"
 #include "utils_cache.h"
-#include "utils_parse_option.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
 
 #include <tcrdb.h>
 
@@ -46,56 +41,6 @@ static char *config_port = NULL;
 
 static TCRDB *rdb = NULL;
 
-static int parse_service_name (const char *service_name)
-{
-       struct addrinfo *ai_list;
-       struct addrinfo *ai_ptr;
-       struct addrinfo ai_hints;
-       int status;
-       int service_number;
-
-       ai_list = NULL;
-       memset (&ai_hints, 0, sizeof (ai_hints));
-       ai_hints.ai_family = AF_UNSPEC;
-
-       status = getaddrinfo (/* node = */ NULL, service_name,
-                       &ai_hints, &ai_list);
-       if (status != 0)
-       {
-               ERROR ("tokyotyrant plugin: getaddrinfo failed: %s",
-                               gai_strerror (status));
-               return (-1);
-       }
-
-       service_number = -1;
-       for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
-       {
-               if (ai_ptr->ai_family == AF_INET)
-               {
-                       struct sockaddr_in *sa;
-
-                       sa = (void *) ai_ptr->ai_addr;
-                       service_number = (int) ntohs (sa->sin_port);
-               }
-               else if (ai_ptr->ai_family == AF_INET6)
-               {
-                       struct sockaddr_in6 *sa;
-
-                       sa = (void *) ai_ptr->ai_addr;
-                       service_number = (int) ntohs (sa->sin6_port);
-               }
-
-               if ((service_number > 0) && (service_number <= 65535))
-                       break;
-       }
-
-       freeaddrinfo (ai_list);
-
-       if ((service_number > 0) && (service_number <= 65535))
-               return (service_number);
-       return (-1);
-} /* int parse_service_name */
-
 static int tt_config (const char *key, const char *value)
 {
        if (strcasecmp ("Host", key) == 0)
@@ -133,7 +78,7 @@ static int tt_config (const char *key, const char *value)
        return (0);
 }
 
-static void printerr()
+static void printerr (void)
 {
        int ecode = tcrdbecode(rdb);
        ERROR ("tokyotyrant plugin: error: %d, %s",
@@ -171,7 +116,7 @@ static void tt_open_db (void)
 
        if (config_port != NULL)
        {
-               port = parse_service_name (config_port);
+               port = service_name_to_port_number (config_port);
                if (port <= 0)
                        return;
        }