diff --git a/pkg/paho-mqtt/contrib/riot_iface.c b/pkg/paho-mqtt/contrib/riot_iface.c index 154ffb1e2e..3df9223c9d 100644 --- a/pkg/paho-mqtt/contrib/riot_iface.c +++ b/pkg/paho-mqtt/contrib/riot_iface.c @@ -22,6 +22,7 @@ #ifdef MODULE_IPV4_ADDR #include "net/ipv4/addr.h" #endif +#include "net/dns.h" #include "net/sock/tcp.h" #include "paho_mqtt.h" #include "MQTTClient.h" @@ -121,6 +122,12 @@ int NetworkConnect(Network *n, char *addr_ip, int port) int ret =-1; sock_tcp_ep_t remote = SOCK_IPV4_EP_ANY; + ret = dns_query(addr_ip, &remote.addr, AF_UNSPEC); + if (ret > 0) { + remote.port = port; + remote.family = ret == 4 ? AF_INET : AF_INET6; + } + if (IS_USED(MODULE_IPV4_ADDR) && (remote.port == 0) && ipv4_addr_from_str((ipv4_addr_t *)&remote.addr, addr_ip)) { remote.port = port;