summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-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)
168 struct addrinfo hints; 168 struct addrinfo hints;
169 struct addrinfo *r, *res; 169 struct addrinfo *r, *res;
170 struct sockaddr_un su; 170 struct sockaddr_un su;
171 char port_str[6]; 171 char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
172 size_t len;
172 int socktype, result; 173 int socktype, result;
173 174
174 socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM; 175 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)
180 hints.ai_protocol = proto; 181 hints.ai_protocol = proto;
181 hints.ai_socktype = socktype; 182 hints.ai_socktype = socktype;
182 183
184 len = strlen (host_name);
185 /* check for an [IPv6] address (and strip the brackets) */
186 if (len >= 2 && host_name[0] == '[' && host_name[len - 1] == ']') {
187 host_name++;
188 len -= 2;
189 }
190 if (len >= sizeof(host))
191 return STATE_UNKNOWN;
192 memcpy (host, host_name, len);
193 host[len] = '\0';
183 snprintf (port_str, sizeof (port_str), "%d", port); 194 snprintf (port_str, sizeof (port_str), "%d", port);
184 result = getaddrinfo (host_name, port_str, &hints, &res); 195 result = getaddrinfo (host, port_str, &hints, &res);
185 196
186 if (result != 0) { 197 if (result != 0) {
187 printf ("%s\n", gai_strerror (result)); 198 printf ("%s\n", gai_strerror (result));