summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 59a2d41)
raw | patch | inline | side by side (parent: 59a2d41)
author | Holger Weiss <hweiss@users.sourceforge.net> | |
Mon, 7 Jan 2008 02:04:17 +0000 (02:04 +0000) | ||
committer | Holger Weiss <hweiss@users.sourceforge.net> | |
Mon, 7 Jan 2008 02:04:17 +0000 (02:04 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1893 f882894a-f735-0410-b71e-b25c423dba1c
plugins/netutils.c | patch | blob | history |
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 7bf225437aaaf3f86a015b5692be00c710a86118..09a73e450447a58d47976e32f645d329190ac8bf 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
struct addrinfo hints;
struct addrinfo *r, *res;
struct sockaddr_un su;
- char port_str[6];
+ char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
+ size_t len;
int socktype, result;
socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
hints.ai_protocol = proto;
hints.ai_socktype = socktype;
+ len = strlen (host_name);
+ /* check for an [IPv6] address (and strip the brackets) */
+ if (len >= 2 && host_name[0] == '[' && host_name[len - 1] == ']') {
+ host_name++;
+ len -= 2;
+ }
+ if (len >= sizeof(host))
+ return STATE_UNKNOWN;
+ memcpy (host, host_name, len);
+ host[len] = '\0';
snprintf (port_str, sizeof (port_str), "%d", port);
- result = getaddrinfo (host_name, port_str, &hints, &res);
+ result = getaddrinfo (host, port_str, &hints, &res);
if (result != 0) {
printf ("%s\n", gai_strerror (result));