diff --git a/examples/asymcute_mqttsn/main.c b/examples/asymcute_mqttsn/main.c index a8793ccdaa..17c647fabe 100644 --- a/examples/asymcute_mqttsn/main.c +++ b/examples/asymcute_mqttsn/main.c @@ -246,7 +246,7 @@ static int _cmd_connect(int argc, char **argv) /* get sock ep */ sock_udp_ep_t ep; - if (sock_udp_str2ep(&ep, argv[2]) != 0) { + if (sock_udp_name2ep(&ep, argv[2]) != 0) { puts("error: unable to parse gateway address"); return 1; } diff --git a/examples/cord_epsim/main.c b/examples/cord_epsim/main.c index 582547f16d..4dd9b85dca 100644 --- a/examples/cord_epsim/main.c +++ b/examples/cord_epsim/main.c @@ -83,7 +83,7 @@ int main(void) /* parse RD address information */ sock_udp_ep_t rd_ep; - if (sock_udp_str2ep(&rd_ep, RD_ADDR) < 0) { + if (sock_udp_name2ep(&rd_ep, RD_ADDR) < 0) { puts("error: unable to parse RD address from RD_ADDR variable"); return 1; } diff --git a/examples/cord_lc/cord_lc_cli.c b/examples/cord_lc/cord_lc_cli.c index fa8d5ba7f9..53c60cd9d4 100644 --- a/examples/cord_lc/cord_lc_cli.c +++ b/examples/cord_lc/cord_lc_cli.c @@ -35,7 +35,7 @@ static unsigned rd_initialized = 0; static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) { ep->port = 0; - if (sock_udp_str2ep(ep, addr) < 0) { + if (sock_udp_name2ep(ep, addr) < 0) { return -1; } /* if netif not specified in addr */ diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index 2fce53ac4a..8f998a5a3d 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -263,7 +263,7 @@ int nanocoap_get_blockwise_url(const char *url, return -EINVAL; } - if (sock_udp_str2ep(&remote, hostport) < 0) { + if (sock_udp_name2ep(&remote, hostport) < 0) { DEBUG("nanocoap: invalid URL\n"); return -EINVAL; } diff --git a/sys/net/sock/sock_util.c b/sys/net/sock/sock_util.c index 3bd760c066..8225bfd691 100644 --- a/sys/net/sock/sock_util.c +++ b/sys/net/sock/sock_util.c @@ -265,6 +265,7 @@ int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str) } #if defined(MODULE_SOCK_DNS) + int family; char hostbuf[CONFIG_SOCK_HOSTPORT_MAXLEN]; const char *host; char *hostend = strchr(str, ':'); @@ -282,13 +283,28 @@ int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str) ep_out->port = atoi(hostend + 1);; } - switch (sock_dns_query(host, &ep_out->addr, AF_UNSPEC)) { + if (IS_ACTIVE(SOCK_HAS_IPV4) && IS_ACTIVE(SOCK_HAS_IPV6)) { + family = AF_UNSPEC; + } else if (IS_ACTIVE(SOCK_HAS_IPV4)) { + family = AF_INET; + } else if (IS_ACTIVE(SOCK_HAS_IPV6)) { + family = AF_INET6; + } else { + assert(0); + return -EINVAL; + } + + switch (sock_dns_query(host, &ep_out->addr, family)) { +#ifdef SOCK_HAS_IPV4 case 4: ep_out->family = AF_INET; return 0; +#endif +#ifdef SOCK_HAS_IPV6 case 16: ep_out->family = AF_INET6; return 0; +#endif default: return -EINVAL; } diff --git a/sys/shell/commands/sc_cord_ep.c b/sys/shell/commands/sc_cord_ep.c index 311bde110b..f4b1152590 100644 --- a/sys/shell/commands/sc_cord_ep.c +++ b/sys/shell/commands/sc_cord_ep.c @@ -30,7 +30,7 @@ static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) { ep->port = 0; - if (sock_udp_str2ep(ep, addr) < 0) { + if (sock_udp_name2ep(ep, addr) < 0) { return -1; } /* if netif not specified in addr */ diff --git a/tests/emcute/main.c b/tests/emcute/main.c index 022e207d98..9637dc5193 100644 --- a/tests/emcute/main.c +++ b/tests/emcute/main.c @@ -105,7 +105,7 @@ static int _con(int argc, char **argv) return 1; } - if (sock_udp_str2ep(&_gw, argv[1]) != 0) { + if (sock_udp_name2ep(&_gw, argv[1]) != 0) { puts("error: unable to parse gateway address"); _gw.port = 0; return 1; diff --git a/tests/lwip/tcp.c b/tests/lwip/tcp.c index 286447cd96..37b91b591c 100644 --- a/tests/lwip/tcp.c +++ b/tests/lwip/tcp.c @@ -131,7 +131,7 @@ static int tcp_connect(char *addr_str, char *local_port_str) } /* parse destination address */ - if (sock_tcp_str2ep(&dst, addr_str) < 0) { + if (sock_tcp_name2ep(&dst, addr_str) < 0) { puts("Error: unable to parse destination address"); return 1; } diff --git a/tests/lwip/udp.c b/tests/lwip/udp.c index efddf8dcf4..424d2a8512 100644 --- a/tests/lwip/udp.c +++ b/tests/lwip/udp.c @@ -99,7 +99,7 @@ static int udp_send(char *addr_str, char *data, unsigned int num, size_t data_len; /* parse destination address */ - if (sock_udp_str2ep(&dst, addr_str) < 0) { + if (sock_udp_name2ep(&dst, addr_str) < 0) { puts("Error: unable to parse destination address"); return 1; }