aboutsummaryrefslogtreecommitdiff
path: root/plugins/netutils.c
diff options
context:
space:
mode:
authorGravatar Holger Weiss <hweiss@users.sourceforge.net> 2008-01-07 02:04:17 +0000
committerGravatar Holger Weiss <hweiss@users.sourceforge.net> 2008-01-07 02:04:17 +0000
commitbf8ce4d2a28dc692c8947103522e9ccd23c21c10 (patch)
treebda394bfdad597e772d9f595b737eab44fbc5ff9 /plugins/netutils.c
parent59a2d41d63e3dd766ee9c8fcd6d086d88f6ac417 (diff)
downloadmonitoring-plugins-bf8ce4d2a28dc692c8947103522e9ccd23c21c10.tar.gz
Support "[IPv6]" address syntax.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1893 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/netutils.c')
-rw-r--r--plugins/netutils.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 7bf22543..09a73e45 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -168,7 +168,8 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
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;
@@ -180,8 +181,18 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
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));