uint8_t dname[KNOT_DNAME_MAXLEN];
knot_dname_from_str(dname, lua_tostring(L, 2), sizeof(dname));
if (!knot_dname_is_equal(knot_pkt_qname(pkt), dname)) {
- uint8_t header[KNOT_WIRE_HEADER_SIZE];
- memcpy(header, pkt->wire, sizeof(header));
- knot_pkt_clear(pkt);
- memcpy(pkt->wire, header, sizeof(header));
- size_t max_size = pkt->max_size;
+ KR_PKT_RECYCLE(pkt);
knot_pkt_put_question(pkt, dname, lua_tointeger(L, 3), lua_tointeger(L, 4));
pkt->parsed = pkt->size;
- pkt->max_size = max_size;
}
return 0;
}
/* Update packet question */
if (!knot_dname_is_equal(knot_pkt_qname(pkt), name)) {
- uint8_t header[KNOT_WIRE_HEADER_SIZE];
- memcpy(header, pkt->wire, sizeof(header));
- knot_pkt_clear(pkt);
- memcpy(pkt->wire, header, sizeof(header));
+ KR_PKT_RECYCLE(pkt);
knot_pkt_put_question(pkt, qry->sname, qry->sclass, qry->stype);
}
* Defines.
*/
+/** @internal Fast packet reset. */
+#define KR_PKT_RECYCLE(pkt) do { \
+ (pkt)->parsed = (pkt)->size = KNOT_WIRE_HEADER_SIZE; \
+ knot_pkt_parse_question((pkt)); \
+} while (0)
+
/** Concatenate N strings. */
char* kr_strcatdup(unsigned n, ...);