1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #17859 from benpicco/use_sock_tl_name2ep

treewide: use sock_tl_name2ep() class of functions where applicable
This commit is contained in:
benpicco 2022-03-29 12:31:51 +02:00 committed by GitHub
commit cdffc8f0ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 25 additions and 9 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}