Compare commits

..
1 Commits
Author SHA1 Message Date
Sergio R. Caprile ee338b7bba fix recvfrom in IPv6 2026-11-16 16:00:56 -03:00
3 changed files with 8 additions and 10 deletions

No files matched your search

+4 -5
View File
@@ -2146,13 +2146,12 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
dm->txnid = mg_ntohs(h->txnid);
is_response = mg_ntohs(h->flags) & 0x8000;
for (i = 0; i < mg_ntohs(h->num_questions); i++) { // advance past queries
for (i = 0; i < mg_ntohs(h->num_questions); i++) {
if ((n = mg_dns_parse_rr(buf, len, ofs, true, &rr)) == 0) return false;
// MG_INFO(("Q %lu %lu %hu/%hu", ofs, n, rr.atype, rr.aclass));
dm->addr.is_ip6 = (rr.atype == MG_DNS_RTYPE_AAAA);
mg_dns_parse_name(buf, len, ofs, dm->name, sizeof(dm->name));
ofs += n;
} // on unresolved responses, we got the name and query type, at least
}
if (!is_response) {
// For queries, there is no need to parse the answers. In this way,
@@ -16401,9 +16400,9 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) {
long n = 0;
if (c->is_udp) {
union usa usa;
socklen_t slen = tousa(&c->rem, &usa);
socklen_t slen = sizeof(usa);
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
if (n > 0) tomgaddr(&usa, &c->rem, slen != sizeof(usa.sin));
if (n > 0) tomgaddr(&usa, &c->rem, usa.sa.sa_family == AF_INET6);
} else {
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
}
+2 -3
View File
@@ -136,13 +136,12 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
dm->txnid = mg_ntohs(h->txnid);
is_response = mg_ntohs(h->flags) & 0x8000;
for (i = 0; i < mg_ntohs(h->num_questions); i++) { // advance past queries
for (i = 0; i < mg_ntohs(h->num_questions); i++) {
if ((n = mg_dns_parse_rr(buf, len, ofs, true, &rr)) == 0) return false;
// MG_INFO(("Q %lu %lu %hu/%hu", ofs, n, rr.atype, rr.aclass));
dm->addr.is_ip6 = (rr.atype == MG_DNS_RTYPE_AAAA);
mg_dns_parse_name(buf, len, ofs, dm->name, sizeof(dm->name));
ofs += n;
} // on unresolved responses, we got the name and query type, at least
}
if (!is_response) {
// For queries, there is no need to parse the answers. In this way,
+2 -2
View File
@@ -297,9 +297,9 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) {
long n = 0;
if (c->is_udp) {
union usa usa;
socklen_t slen = tousa(&c->rem, &usa);
socklen_t slen = sizeof(usa);
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
if (n > 0) tomgaddr(&usa, &c->rem, slen != sizeof(usa.sin));
if (n > 0) tomgaddr(&usa, &c->rem, usa.sa.sa_family == AF_INET6);
} else {
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
}