From b6c94d893237f4c339a1ad9ede7b809811001f77 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 24 Oct 2009 14:10:33 +0000 Subject: Remove usage of sock_any calls. * This allows us to properly handle complex addresses with things like %eth0 on the end, etc... * Also removes support for unix sockets, which didn't really make sense in an snmp context anyway. Not sure how that code was usable. --- tools/rrdbot-get.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c index c6be921..a2fd19b 100644 --- a/tools/rrdbot-get.c +++ b/tools/rrdbot-get.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,6 @@ #include "log.h" #include "server-mainloop.h" #include "snmp-engine.h" -#include "sock-any.h" #define DEFAULT_TIMEOUT 5000 /* Default timeout for SNMP response */ #define MAX_RETRIES 3 /* Number of SNMP packets we retry */ @@ -120,8 +120,9 @@ log_vmessage (int level, int erno, const char *msg, va_list va) static void parse_host (char *host) { - struct sockaddr_any addr; + struct addrinfo hints, *ai; char *x; + int r; /* Use the first of multiple hosts */ x = strchr (host, ','); @@ -130,11 +131,20 @@ parse_host (char *host) warnx ("only using the first host name: %s", host); } - if (sock_any_pton (host, &addr, SANY_OPT_DEFPORT(161) | SANY_OPT_DEFLOCAL) == -1) - err (1, "couldn't resolve host address: %s", host); + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_NUMERICSERV; + r = getaddrinfo (host, "161", &hints, &ai); + if (r != 0) + errx (1, "couldn't resolve host address: %s: %s", host, gai_strerror (r)); - if (sock_any_ntop (&addr, ctx.host, sizeof (ctx.host), 0) == -1) - err (1, "couldn't convert host address: %s", host); + r = getnameinfo (ai->ai_addr, ai->ai_addrlen, ctx.host, sizeof (ctx.host), + NULL, 0, NI_NUMERICSERV | NI_NUMERICHOST); + if (r != 0) + errx (1, "couldn't convert host address: %s: %s", host, gai_strerror (r)); + + freeaddrinfo (ai); } static void -- cgit v1.2.3