[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1893] nagiosplug/trunk/plugins/netutils.c
hweiss at users.sourceforge.net
hweiss at users.sourceforge.net
Mon Jan 7 03:04:17 CET 2008
Revision: 1893
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1893&view=rev
Author: hweiss
Date: 2008-01-06 18:04:17 -0800 (Sun, 06 Jan 2008)
Log Message:
-----------
Support "[IPv6]" address syntax.
Modified Paths:
--------------
nagiosplug/trunk/plugins/netutils.c
Modified: nagiosplug/trunk/plugins/netutils.c
===================================================================
--- nagiosplug/trunk/plugins/netutils.c 2008-01-07 01:59:59 UTC (rev 1892)
+++ nagiosplug/trunk/plugins/netutils.c 2008-01-07 02:04:17 UTC (rev 1893)
@@ -168,7 +168,8 @@
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 @@
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));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list