This commit is contained in:
Sergio R. Caprile committed 2026-11-11 17:51:49 -03:00
1 parent d47cfa183d
commit 3a4f044e41
2 files changed
+6 -4

No files matched your search

+3 -2
View File
@@ -125,7 +125,7 @@ static struct mg_connection *start_modbus_request(struct mg_mgr *mgr,
} else { } else {
send16(c, 1); // TID. Use random? send16(c, 1); // TID. Use random?
send16(c, 0); // Protocol identifier: 0 (modbus) send16(c, 0); // Protocol identifier: 0 (modbus)
uint16_t *lp = (uint16_t *) &c->send.buf[c->send.len]; size_t lp = c->send.len;
send16(c, 0); // Length: to be set later send16(c, 0); // Length: to be set later
size_t len = c->send.len; size_t len = c->send.len;
@@ -151,7 +151,8 @@ static struct mg_connection *start_modbus_request(struct mg_mgr *mgr,
send8(c, 0); // Object ID: 0 (vendor name) send8(c, 0); // Object ID: 0 (vendor name)
} }
*lp = mg_htons((uint16_t) (c->send.len - len)); // Set length field uint16_t length = mg_htons((uint16_t) (c->send.len - len));
memcpy(c->send.buf + lp, &length, sizeof(length)); // Set length field
mg_hexdump(c->send.buf, c->send.len); mg_hexdump(c->send.buf, c->send.len);
MG_INFO(("%lu SENDING %lu", c->id, c->send.len)); MG_INFO(("%lu SENDING %lu", c->id, c->send.len));
+3 -2
View File
@@ -25,10 +25,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
c->is_hexdumping = 1; c->is_hexdumping = 1;
} else if (ev == MG_EV_READ) { } else if (ev == MG_EV_READ) {
struct mg_dns_rr rr; // Parse first question, offset 12 is header size struct mg_dns_rr rr; // Parse first question, offset 12 is header size
char buf[512];
size_t n = mg_dns_parse_rr(c->recv.buf, c->recv.len, 12, true, &rr); size_t n = mg_dns_parse_rr(c->recv.buf, c->recv.len, 12, true, &rr);
MG_INFO(("DNS request parsed, result=%d", (int) n)); MG_INFO(("DNS request parsed, result=%d", (int) n));
if (n > 0) { if (n > 0 &&
char buf[512]; n <= sizeof(buf) - sizeof(struct mg_dns_header) - sizeof(answer)) {
struct mg_dns_header *h = (struct mg_dns_header *) buf; struct mg_dns_header *h = (struct mg_dns_header *) buf;
memset(buf, 0, sizeof(buf)); // Clear the whole datagram memset(buf, 0, sizeof(buf)); // Clear the whole datagram
h->txnid = ((struct mg_dns_header *) c->recv.buf)->txnid; // Copy tnxid h->txnid = ((struct mg_dns_header *) c->recv.buf)->txnid; // Copy tnxid