diff --git a/mongoose.c b/mongoose.c index 674733f6..0870bc34 100644 --- a/mongoose.c +++ b/mongoose.c @@ -279,7 +279,8 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data, mg_ntoa(&d->c->rem, buf, sizeof(buf)))); mg_connect_resolved(d->c); #if MG_ENABLE_IPV6 - } else if (dm.addr.is_ip6 == false && dm.name[0] != '\0') { + } else if (dm.addr.is_ip6 == false && dm.name[0] != '\0' && + c->mgr->use_dns6 == false) { struct mg_str x = mg_str(dm.name); mg_sendnsreq(d->c, &x, c->mgr->dnstimeout, &c->mgr->dns6, true); #endif @@ -374,7 +375,8 @@ void mg_resolve(struct mg_connection *c, const char *url) { mg_connect_resolved(c); } else { // host is not an IP, send DNS resolution request - mg_sendnsreq(c, &host, c->mgr->dnstimeout, &c->mgr->dns4, false); + struct mg_dns *dns = c->mgr->use_dns6 ? &c->mgr->dns6 : &c->mgr->dns4; + mg_sendnsreq(c, &host, c->mgr->dnstimeout, dns, c->mgr->use_dns6); } } diff --git a/mongoose.h b/mongoose.h index d04510e8..fd45defb 100644 --- a/mongoose.h +++ b/mongoose.h @@ -898,6 +898,7 @@ struct mg_mgr { struct mg_dns dns4; // DNS for IPv4 struct mg_dns dns6; // DNS for IPv6 int dnstimeout; // DNS resolve timeout in milliseconds + bool use_dns6; // Use DNS6 server by default, see #1532 unsigned long nextid; // Next connection ID void *userdata; // Arbitrary user data pointer uint16_t mqtt_id; // MQTT IDs for pub/sub diff --git a/src/dns.c b/src/dns.c index e08ecd49..b560c444 100644 --- a/src/dns.c +++ b/src/dns.c @@ -167,7 +167,8 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data, mg_ntoa(&d->c->rem, buf, sizeof(buf)))); mg_connect_resolved(d->c); #if MG_ENABLE_IPV6 - } else if (dm.addr.is_ip6 == false && dm.name[0] != '\0') { + } else if (dm.addr.is_ip6 == false && dm.name[0] != '\0' && + c->mgr->use_dns6 == false) { struct mg_str x = mg_str(dm.name); mg_sendnsreq(d->c, &x, c->mgr->dnstimeout, &c->mgr->dns6, true); #endif @@ -262,6 +263,7 @@ void mg_resolve(struct mg_connection *c, const char *url) { mg_connect_resolved(c); } else { // host is not an IP, send DNS resolution request - mg_sendnsreq(c, &host, c->mgr->dnstimeout, &c->mgr->dns4, false); + struct mg_dns *dns = c->mgr->use_dns6 ? &c->mgr->dns6 : &c->mgr->dns4; + mg_sendnsreq(c, &host, c->mgr->dnstimeout, dns, c->mgr->use_dns6); } } diff --git a/src/net.h b/src/net.h index 3171ce54..bdb23535 100644 --- a/src/net.h +++ b/src/net.h @@ -23,6 +23,7 @@ struct mg_mgr { struct mg_dns dns4; // DNS for IPv4 struct mg_dns dns6; // DNS for IPv6 int dnstimeout; // DNS resolve timeout in milliseconds + bool use_dns6; // Use DNS6 server by default, see #1532 unsigned long nextid; // Next connection ID void *userdata; // Arbitrary user data pointer uint16_t mqtt_id; // MQTT IDs for pub/sub