return 1;
}
- if (network_get_endpoint(&ep, endpoint, UNETD_GLOBAL_PEX_PORT, 0) < 0) {
+ if (network_get_endpoint(&ep, AF_UNSPEC, endpoint, UNETD_GLOBAL_PEX_PORT, 0) < 0) {
INFO("Invalid hostname/port %s\n", endpoint);
return 1;
}
ep = &peer->state.next_endpoint;
if (peer->endpoint &&
- network_get_endpoint(ep, peer->endpoint, peer->port,
+ network_get_endpoint(ep, AF_UNSPEC, peer->endpoint, peer->port,
peer->state.connect_attempt++))
continue;
if (!peer->endpoint || peer->dynamic)
continue;
- if (network_get_endpoint(&ep, peer->endpoint,
+ if (network_get_endpoint(&ep, AF_UNSPEC, peer->endpoint,
UNETD_GLOBAL_PEX_PORT, 0) < 0)
continue;
blobmsg_for_each_attr(cur, net->config.auth_connect, rem) {
union network_endpoint ep = {};
- if (network_get_endpoint(&ep, blobmsg_get_string(cur),
+ if (network_get_endpoint(&ep, AF_UNSPEC, blobmsg_get_string(cur),
UNETD_GLOBAL_PEX_PORT, 0) < 0)
continue;
return UBUS_STATUS_INVALID_ARGUMENT;
if ((cur = tb[CONNECT_ATTR_ADDRESS]) == NULL ||
- network_get_endpoint(&ep, blobmsg_get_string(cur), UNETD_GLOBAL_PEX_PORT, 0) < 0 ||
+ network_get_endpoint(&ep, AF_UNSPEC, blobmsg_get_string(cur), UNETD_GLOBAL_PEX_PORT, 0) < 0 ||
!ep.in.sin_port)
return UBUS_STATUS_INVALID_ARGUMENT;
#include "unetd.h"
-int network_get_endpoint(union network_endpoint *dest, const char *str,
+int network_get_endpoint(union network_endpoint *dest, int af, const char *str,
int default_port, int idx)
{
struct addrinfo hints = {
.ai_flags = AI_ADDRCONFIG,
- .ai_family = AF_UNSPEC,
+ .ai_family = af,
};
char *buf = strdup(str);
char *host = buf, *port;
memset(dest, 0, sizeof(*dest));
if (*host == '[') {
+ if (af == AF_INET)
+ goto out;
+
host++;
port = strchr(host, ']');
if (!port)
return !memcmp(a1, a2, len);
}
-int network_get_endpoint(union network_endpoint *dest, const char *str,
+int network_get_endpoint(union network_endpoint *dest, int af, const char *str,
int default_port, int idx);
int network_get_subnet(int af, union network_addr *addr, int *mask,
const char *str);