Commit 4b1667a4 authored by Daniel Salzman's avatar Daniel Salzman

contrib: move utils as lookup and wire

parent 494b93af
......@@ -49,6 +49,7 @@ src/contrib/dnstap/writer.h
src/contrib/endian.h
src/contrib/getline.c
src/contrib/getline.h
src/contrib/lookup.h
src/contrib/net.c
src/contrib/net.h
src/contrib/openbsd/strlcat.c
......@@ -68,6 +69,7 @@ src/contrib/ucw/heap.c
src/contrib/ucw/heap.h
src/contrib/ucw/mempool.c
src/contrib/ucw/mempool.h
src/contrib/wire.h
src/contrib/wire_ctx.h
src/dnssec/Makefile.am
src/dnssec/contrib/gnutls_error.c
......@@ -384,8 +386,6 @@ src/libknot/internal/trie/hat-trie.c
src/libknot/internal/trie/hat-trie.h
src/libknot/internal/trie/murmurhash3.c
src/libknot/internal/trie/murmurhash3.h
src/libknot/internal/utils.c
src/libknot/internal/utils.h
src/libknot/libknot.h
src/libknot/packet/compr.c
src/libknot/packet/compr.h
......@@ -393,6 +393,7 @@ src/libknot/packet/pkt.c
src/libknot/packet/pkt.h
src/libknot/packet/rrset-wire.c
src/libknot/packet/rrset-wire.h
src/libknot/packet/wire.c
src/libknot/packet/wire.h
src/libknot/processing/layer.c
src/libknot/processing/layer.h
......@@ -409,6 +410,7 @@ src/libknot/rrset-dump.h
src/libknot/rrset.c
src/libknot/rrset.h
src/libknot/rrtype/aaaa.h
src/libknot/rrtype/dnskey.c
src/libknot/rrtype/dnskey.h
src/libknot/rrtype/naptr.c
src/libknot/rrtype/naptr.h
......@@ -420,7 +422,9 @@ src/libknot/rrtype/nsec3param.h
src/libknot/rrtype/opt.c
src/libknot/rrtype/opt.h
src/libknot/rrtype/rdname.h
src/libknot/rrtype/rrsig.c
src/libknot/rrtype/rrsig.h
src/libknot/rrtype/soa.c
src/libknot/rrtype/soa.h
src/libknot/rrtype/tsig.c
src/libknot/rrtype/tsig.h
......@@ -519,6 +523,7 @@ tests/hattrie.c
tests/hhash.c
tests/internal_mem.c
tests/journal.c
tests/lookup.c
tests/modules/online_sign.c
tests/namedb.c
tests/net.c
......@@ -538,7 +543,6 @@ tests/rrset_wire.c
tests/server.c
tests/test_conf.h
tests/tsig_key.c
tests/utils.c
tests/wire.c
tests/wire_ctx.c
tests/worker_pool.c
......
......@@ -28,11 +28,13 @@ nobase_libcontrib_la_HEADERS = \
contrib/base64.h \
contrib/endian.h \
contrib/getline.h \
contrib/lookup.h \
contrib/net.h \
contrib/print.h \
contrib/sockaddr.h \
contrib/string.h \
contrib/tolower.h \
contrib/wire.h \
contrib/wire_ctx.h \
contrib/openbsd/strlcat.h \
contrib/openbsd/strlcpy.h \
......@@ -89,8 +91,7 @@ nobase_libknot_internal_la_HEADERS = \
libknot/internal/namedb/namedb_lmdb.h \
libknot/internal/namedb/namedb_trie.h \
libknot/internal/trie/hat-trie.h \
libknot/internal/trie/murmurhash3.h \
libknot/internal/utils.h
libknot/internal/trie/murmurhash3.h
libknot_yparser_ladir = $(includedir)
nobase_libknot_yparser_la_HEADERS = \
......@@ -124,6 +125,7 @@ libknot_la_SOURCES = \
libknot/packet/compr.c \
libknot/packet/pkt.c \
libknot/packet/rrset-wire.c \
libknot/packet/wire.c \
libknot/processing/layer.c \
libknot/processing/overlay.c \
libknot/processing/requestor.c \
......@@ -131,10 +133,13 @@ libknot_la_SOURCES = \
libknot/rdataset.c \
libknot/rrset-dump.c \
libknot/rrset.c \
libknot/rrtype/dnskey.c \
libknot/rrtype/naptr.c \
libknot/rrtype/nsec3.c \
libknot/rrtype/nsec3param.c \
libknot/rrtype/opt.c \
libknot/rrtype/rrsig.c \
libknot/rrtype/soa.c \
libknot/rrtype/tsig.c \
libknot/tsig-op.c \
libknot/tsig.c \
......@@ -156,7 +161,6 @@ libknot_internal_la_SOURCES = \
libknot/internal/namedb/namedb_trie.c \
libknot/internal/trie/hat-trie.c \
libknot/internal/trie/murmurhash3.c \
libknot/internal/utils.c \
$(nobase_libknot_internal_la_HEADERS)
libcontrib_la_CPPFLAGS = $(AM_CPPFLAGS)
......
......@@ -13,18 +13,37 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief A general purpose lookup table.
*
* \addtogroup contrib
* @{
*/
#include <string.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#pragma once
#include "contrib/endian.h"
#include "libknot/internal/utils.h"
#include "libknot/internal/macros.h"
#include <string.h>
/*----------------------------------------------------------------------------*/
lookup_table_t *lookup_by_name(lookup_table_t *table, const char *name)
/*!
* \brief A general purpose lookup table.
*/
typedef struct lookup_table {
int id;
const char *name;
} lookup_table_t;
/*!
* \brief Looks up the given name in the lookup table.
*
* \param table Lookup table.
* \param name Name to look up.
*
* \return Item in the lookup table with the given name or NULL if no such is
* present.
*/
inline static const lookup_table_t *lookup_by_name(const lookup_table_t *table, const char *name)
{
if (table == NULL || name == NULL) {
return NULL;
......@@ -40,8 +59,16 @@ lookup_table_t *lookup_by_name(lookup_table_t *table, const char *name)
return NULL;
}
/*----------------------------------------------------------------------------*/
lookup_table_t *lookup_by_id(lookup_table_t *table, int id)
/*!
* \brief Looks up the given id in the lookup table.
*
* \param table Lookup table.
* \param id ID to look up.
*
* \return Item in the lookup table with the given id or NULL if no such is
* present.
*/
inline static const lookup_table_t *lookup_by_id(const lookup_table_t *table, int id)
{
if (table == NULL) {
return NULL;
......@@ -56,48 +83,3 @@ lookup_table_t *lookup_by_id(lookup_table_t *table, int id)
return NULL;
}
/*----------------------------------------------------------------------------*/
uint16_t wire_read_u16(const uint8_t *pos)
{
return be16toh(*(uint16_t *)pos);
}
uint32_t wire_read_u32(const uint8_t *pos)
{
return be32toh(*(uint32_t *)pos);
}
uint64_t wire_read_u48(const uint8_t *pos)
{
uint64_t input = 0;
memcpy((uint8_t *)&input + 1, pos, 6);
return be64toh(input) >> 8;
}
uint64_t wire_read_u64(const uint8_t *pos)
{
return be64toh(*(uint64_t *)pos);
}
void wire_write_u16(uint8_t *pos, uint16_t data)
{
*(uint16_t *)pos = htobe16(data);
}
void wire_write_u32(uint8_t *pos, uint32_t data)
{
*(uint32_t *)pos = htobe32(data);
}
void wire_write_u48(uint8_t *pos, uint64_t data)
{
uint64_t swapped = htobe64(data << 8);
memcpy(pos, (uint8_t *)&swapped + 1, 6);
}
void wire_write_u64(uint8_t *pos, uint64_t data)
{
*(uint64_t *)pos = htobe64(data);
}
/*!
* \file utils.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Various utilities.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
......@@ -23,48 +13,21 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string.h>
#include <stdint.h>
#include <stdio.h>
/*!
* \brief A general purpose lookup table.
*/
struct lookup_table {
int id;
const char *name;
};
typedef struct lookup_table lookup_table_t;
/*!
* \brief Looks up the given name in the lookup table.
* \file
*
* \param table Lookup table.
* \param name Name to look up.
* \brief Wire integer operations.
*
* \return Item in the lookup table with the given name or NULL if no such is
* present.
* \addtogroup contrib
* @{
*/
lookup_table_t *lookup_by_name(lookup_table_t *table, const char *name);
/*!
* \brief Looks up the given id in the lookup table.
*
* \param table Lookup table.
* \param id ID to look up.
*
* \return Item in the lookup table with the given id or NULL if no such is
* present.
*/
lookup_table_t *lookup_by_id(lookup_table_t *table, int id);
#pragma once
/*
* Writing / reading arbitrary data to / from wireformat.
*/
#include <stdint.h>
#include <string.h>
#include "contrib/endian.h"
/*!
* \brief Reads 2 bytes from the wireformat data.
......@@ -73,7 +36,10 @@ lookup_table_t *lookup_by_id(lookup_table_t *table, int id);
*
* \return The 2 bytes read, in host byte order.
*/
uint16_t wire_read_u16(const uint8_t *pos);
inline static uint16_t wire_read_u16(const uint8_t *pos)
{
return be16toh(*(uint16_t *)pos);
}
/*!
* \brief Reads 4 bytes from the wireformat data.
......@@ -82,7 +48,10 @@ uint16_t wire_read_u16(const uint8_t *pos);
*
* \return The 4 bytes read, in host byte order.
*/
uint32_t wire_read_u32(const uint8_t *pos);
inline static uint32_t wire_read_u32(const uint8_t *pos)
{
return be32toh(*(uint32_t *)pos);
}
/*!
* \brief Reads 6 bytes from the wireformat data.
......@@ -91,7 +60,12 @@ uint32_t wire_read_u32(const uint8_t *pos);
*
* \return The 6 bytes read, in host byte order.
*/
uint64_t wire_read_u48(const uint8_t *pos);
inline static uint64_t wire_read_u48(const uint8_t *pos)
{
uint64_t input = 0;
memcpy((uint8_t *)&input + 1, pos, 6);
return be64toh(input) >> 8;
}
/*!
* \brief Read 8 bytes from the wireformat data.
......@@ -100,7 +74,10 @@ uint64_t wire_read_u48(const uint8_t *pos);
*
* \return The 8 bytes read, in host byte order.
*/
uint64_t wire_read_u64(const uint8_t *pos);
inline static uint64_t wire_read_u64(const uint8_t *pos)
{
return be64toh(*(uint64_t *)pos);
}
/*!
* \brief Writes 2 bytes in wireformat.
......@@ -110,7 +87,10 @@ uint64_t wire_read_u64(const uint8_t *pos);
* \param pos Position where to put the 2 bytes.
* \param data Data to put.
*/
void wire_write_u16(uint8_t *pos, uint16_t data);
inline static void wire_write_u16(uint8_t *pos, uint16_t data)
{
*(uint16_t *)pos = htobe16(data);
}
/*!
* \brief Writes 4 bytes in wireformat.
......@@ -120,7 +100,10 @@ void wire_write_u16(uint8_t *pos, uint16_t data);
* \param pos Position where to put the 4 bytes.
* \param data Data to put.
*/
void wire_write_u32(uint8_t *pos, uint32_t data);
inline static void wire_write_u32(uint8_t *pos, uint32_t data)
{
*(uint32_t *)pos = htobe32(data);
}
/*!
* \brief Writes 6 bytes in wireformat.
......@@ -130,7 +113,11 @@ void wire_write_u32(uint8_t *pos, uint32_t data);
* \param pos Position where to put the 4 bytes.
* \param data Data to put.
*/
void wire_write_u48(uint8_t *pos, uint64_t data);
inline static void wire_write_u48(uint8_t *pos, uint64_t data)
{
uint64_t swapped = htobe64(data << 8);
memcpy(pos, (uint8_t *)&swapped + 1, 6);
}
/*!
* \brief Writes 8 bytes in wireformat.
......@@ -140,6 +127,9 @@ void wire_write_u48(uint8_t *pos, uint64_t data);
* \param pos Position where to put the 8 bytes.
* \param data Data to put.
*/
void wire_write_u64(uint8_t *pos, uint64_t data);
inline static void wire_write_u64(uint8_t *pos, uint64_t data)
{
*(uint64_t *)pos = htobe64(data);
}
/*! @} */
......@@ -26,6 +26,7 @@
#pragma once
#include "libknot/yparser/ypscheme.h"
#include "contrib/lookup.h"
#define C_ACL "\x03""acl"
#define C_ACTION "\x06""action"
......
......@@ -35,7 +35,6 @@
#include "knot/conf/scheme.h"
#include "knot/common/log.h"
#include "libknot/errcode.h"
#include "libknot/internal/utils.h"
#include "libknot/yparser/yptrafo.h"
#include "contrib/wire_ctx.h"
......
......@@ -35,6 +35,7 @@
#include "contrib/sockaddr.h"
#include "contrib/string.h"
#include "contrib/openbsd/strlcpy.h"
#include "contrib/wire.h"
#define KNOT_CTL_REALM "knot."
#define KNOT_CTL_REALM_EXT ("." KNOT_CTL_REALM)
......
......@@ -21,8 +21,8 @@
#include "knot/modules/rosedb.h"
#include "knot/nameserver/process_query.h"
#include "libknot/libknot.h"
#include "libknot/internal/utils.h"
#include "contrib/net.h"
#include "contrib/wire.h"
/* Module configuration scheme. */
#define MOD_DBDIR "\x05""dbdir"
......
......@@ -386,7 +386,7 @@ int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
AXFRIN_LOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -14,6 +14,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "knot/nameserver/capture.h"
#include "knot/server/tcp-handler.h"
#include "knot/server/udp-handler.h"
......
......@@ -26,7 +26,6 @@
#include "knot/zone/serial.h"
#include "libknot/libknot.h"
#include "libknot/descriptor.h"
#include "libknot/internal/utils.h"
#include "libknot/rrtype/soa.h"
#include "contrib/print.h"
#include "contrib/sockaddr.h"
......@@ -696,7 +695,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
IXFRIN_LOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -119,7 +119,7 @@ int notify_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
NOTIFY_RLOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -14,6 +14,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "libknot/libknot.h"
#include "knot/nameserver/nsec_proofs.h"
#include "knot/nameserver/process_query.h"
......
......@@ -567,8 +567,8 @@ bool process_query_acl_check(const knot_dname_t *zone_name, acl_action_t action,
if (!acl_allowed(&acl, action, query_source, &tsig)) {
char addr_str[SOCKADDR_STRLEN] = { 0 };
sockaddr_tostr(addr_str, sizeof(addr_str), query_source);
lookup_table_t *act = lookup_by_id((lookup_table_t *)acl_actions,
action);
const lookup_table_t *act = lookup_by_id((lookup_table_t *)acl_actions,
action);
char *key_name = knot_dname_to_str_alloc(tsig.name);
log_zone_debug(zone_name,
......
......@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
......
......@@ -22,6 +22,7 @@
#include "libknot/processing/requestor.h"
#include "libknot/yparser/yptrafo.h"
#include "contrib/ucw/mempool.h"
#include "contrib/wire.h"
#include "knot/common/log.h"
#include "knot/common/trim.h"
......
......@@ -14,11 +14,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libknot/rrtype/soa.h"
#include <assert.h>
#include "knot/zone/events/replan.h"
#include "knot/zone/events/handlers.h"
#include "knot/zone/zone.h"
#include "libknot/rrtype/soa.h"
#include "libknot/internal/macros.h"
/* -- Zone event replanning functions --------------------------------------- */
......
......@@ -29,6 +29,7 @@
#include "libknot/dnssec/rrset-sign.h"
#include "libknot/internal/mempattern.h"
#include "contrib/base32hex.h"
#include "contrib/wire.h"
static char *error_messages[(-ZC_ERR_UNKNOWN) + 1] = {
[-ZC_ERR_MISSING_SOA] =
......
......@@ -20,6 +20,7 @@
#include "knot/zone/timers.h"
#include "knot/zone/zonedb.h"
#include "contrib/string.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
/* ---- Knot-internal event code to db key lookup tables ------------------ - */
......
......@@ -22,7 +22,6 @@
#include "knot/zone/zone-diff.h"
#include "knot/zone/serial.h"
#include "libknot/descriptor.h"
#include "libknot/internal/utils.h"
#include "libknot/rrtype/soa.h"
struct zone_diff_param {
......
......@@ -37,7 +37,6 @@
#include "knot/nameserver/process_query.h"
#include "libknot/libknot.h"
#include "libknot/dname.h"
#include "libknot/internal/utils.h"
#include "contrib/string.h"
#include "libknot/rrtype/soa.h"
......
......@@ -15,10 +15,11 @@
*/
#include "libknot/codes.h"
#include "libknot/consts.h"
#include "contrib/lookup.h"
#include "libknot/internal/macros.h"
_public_
lookup_table_t knot_opcode_names[] = {
const lookup_table_t opcode_names[] = {
{ KNOT_OPCODE_QUERY, "QUERY" },
{ KNOT_OPCODE_IQUERY, "IQUERY" },
{ KNOT_OPCODE_STATUS, "STATUS" },
......@@ -26,9 +27,10 @@ lookup_table_t knot_opcode_names[] = {
{ KNOT_OPCODE_UPDATE, "UPDATE" },
{ 0, NULL }
};
_public_
lookup_table_t knot_rcode_names[] = {
const lookup_table_t *knot_opcode_names = opcode_names;
const lookup_table_t rcode_names[] = {
{ KNOT_RCODE_NOERROR, "NOERROR" },
{ KNOT_RCODE_FORMERR, "FORMERR" },
{ KNOT_RCODE_SERVFAIL, "SERVFAIL" },
......@@ -43,26 +45,29 @@ lookup_table_t knot_rcode_names[] = {
{ KNOT_RCODE_BADVERS, "BADVERS" },
{ 0, NULL }
};
_public_
lookup_table_t knot_tsig_err_names[] = {
const lookup_table_t *knot_rcode_names = rcode_names;
const lookup_table_t tsig_err_names[] = {
{ KNOT_TSIG_ERR_BADSIG, "BADSIG" },
{ KNOT_TSIG_ERR_BADKEY, "BADKEY" },
{ KNOT_TSIG_ERR_BADTIME, "BADTIME" },
{ KNOT_TSIG_ERR_BADTRUNC, "BADTRUNC" },
{ 0, NULL }
};
_public_
lookup_table_t knot_tkey_err_names[] = {
const lookup_table_t *knot_tsig_err_names = tsig_err_names;
const lookup_table_t tkey_err_names[] = {
{ KNOT_TKEY_ERR_BADMODE, "BADMODE" },
{ KNOT_TKEY_ERR_BADNAME, "BADNAME" },
{ KNOT_TKEY_ERR_BADALG, "BADALG" },
{ 0, NULL }
};
_public_
lookup_table_t knot_dnssec_alg_names[] = {
const lookup_table_t *knot_tkey_err_names = tkey_err_names;
const lookup_table_t dnssec_alg_names[] = {
{ KNOT_DNSSEC_ALG_RSAMD5, "RSAMD5" },
{ KNOT_DNSSEC_ALG_DH, "DH" },
{ KNOT_DNSSEC_ALG_DSA, "DSA" },
......@@ -76,3 +81,5 @@ lookup_table_t knot_dnssec_alg_names[] = {
{ KNOT_DNSSEC_ALG_ECDSAP384SHA384, "ECDSAP384SHA384" },
{ 0, NULL }
};
_public_
const lookup_table_t *knot_dnssec_alg_names = dnssec_alg_names;
......@@ -24,35 +24,31 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "libknot/consts.h"
#include "libknot/internal/utils.h"
struct lookup_table;
/*!
* \brief DNS operation code names.
*/
extern lookup_table_t knot_opcode_names[];
extern const struct lookup_table *knot_opcode_names;
/*!
* \brief DNS reply code names.
*/
extern lookup_table_t knot_rcode_names[];
extern const struct lookup_table *knot_rcode_names;
/*!
* \brief TSIG error names.
*/
extern lookup_table_t knot_tsig_err_names[];
extern const struct lookup_table *knot_tsig_err_names;
/*!
* \brief TKEY error names.
*/
extern lookup_table_t knot_tkey_err_names[];
extern const struct lookup_table *knot_tkey_err_names;
/*!
* \brief DNSSEC algorithm names.
*/
extern lookup_table_t knot_dnssec_alg_names[];
extern const struct lookup_table *knot_dnssec_alg_names;
/*! @} */
......@@ -27,7 +27,6 @@
#include "libknot/packet/wire.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/utils.h"
#include "contrib/tolower.h"
/*----------------------------------------------------------------------------*/
......
......@@ -26,6 +26,7 @@
#include "libknot/packet/wire.h"
#include "libknot/packet/rrset-wire.h"
#include "libknot/internal/macros.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
/*! \brief Packet RR array growth step. */
......
......@@ -30,6 +30,7 @@
#include "libknot/rrset.h"
#include "libknot/rrtype/naptr.h"
#include "libknot/internal/macros.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
#define RR_HEADER_SIZE 10
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "libknot/internal/macros.h"
#include "libknot/packet/wire.h"
#include "contrib/wire.h"
_public_
uint16_t knot_wire_get_id(const uint8_t *packet)
{
return wire_read_u16(packet + KNOT_WIRE_OFFSET_ID);
}
_public_
void knot_wire_set_id(uint8_t *packet, uint16_t id)
{
wire_write_u16(packet + KNOT_WIRE_OFFSET_ID, id);
}
_public_
uint16_t knot_wire_get_qdcount(const uint8_t *packet)
{
return wire_read_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT);
}
_public_
void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount)
{
wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT,