#include "list.h"
#include "hostport.h"
-static void freehostport(struct hostportres *hp) {
+void freehostport(struct hostportres *hp) {
if (hp) {
free(hp->host);
free(hp->port);
ipv6 = 1;
} else {
field = p;
- for (; *p && *p != ':' && *p != ' ' && *p != '\t' && *p != '\n'; p++);
+ for (; *p && *p != ':' && *p != '/' && *p != ' ' && *p != '\t' && *p != '\n'; p++);
}
if (field == p) {
debug(DBG_ERR, "missing host/address");
hp->host = stringcopy(field, p - field);
if (ipv6) {
p++;
- if (*p && *p != ':' && *p != ' ' && *p != '\t' && *p != '\n') {
+ if (*p && *p != ':' && *p != '/' && *p != ' ' && *p != '\t' && *p != '\n') {
debug(DBG_ERR, "unexpected character after ]");
return 0;
}
return 1;
}
-static struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok) {
+struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok) {
struct hostportres *hp;
char *slash, *s;
int plen;
hp->host = NULL;
}
- slash = hp->host ? strchr(hp->host, '/') : NULL;
+ slash = hostport ? strchr(hostport, '/') : NULL;
if (slash) {
if (!prefixok) {
debug(DBG_WARN, "newhostport: prefix not allowed here", hp->host);
goto errexit;
}
hp->prefixlen = plen;
- *slash = '\0';
} else
hp->prefixlen = 255;
return hp;
return NULL;
}
-static int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) {
+int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) {
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
return 0;
}
-int addhostport(struct list **hostports, char *hostport, char *portdefault, uint8_t prefixok) {
+int addhostport(struct list **hostports, char **hostport, char *portdefault, uint8_t prefixok) {
struct hostportres *hp;
+ int i;
- hp = newhostport(hostport, portdefault, prefixok);
- if (!hp)
- return 0;
- if (!*hostports)
+ if (!*hostports) {
*hostports = list_create();
- if (!*hostports || !list_push(*hostports, hp)) {
- freehostport(hp);
- debug(DBG_ERR, "addhostport: malloc failed");
- return 0;
+ if (!*hostports) {
+ debug(DBG_ERR, "addhostport: malloc failed");
+ return 0;
+ }
+ }
+
+ for (i = 0; hostport[i]; i++) {
+ hp = newhostport(hostport[i], portdefault, prefixok);
+ if (!hp)
+ return 0;
+ if (!list_push(*hostports, hp)) {
+ freehostport(hp);
+ debug(DBG_ERR, "addhostport: malloc failed");
+ return 0;
+ }
}
return 1;
}
for (entry = list_first(hostports); entry; entry = list_next(entry)) {
hp = (struct hostportres *)entry->data;
debug(DBG_WARN, "connecttcphostlist: trying to open TCP connection to %s port %s", hp->host, hp->port);
- if ((s = connecttcp(hp->addrinfo, src)) >= 0) {
+ if ((s = connecttcp(hp->addrinfo, src, list_count(hostports) > 1 ? 5 : 30)) >= 0) {
debug(DBG_WARN, "connecttcphostlist: TCP connection to %s port %s up", hp->host, hp->port);
return s;
}