+++ /dev/null
-/* Copyright (C) 2018 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/attribute.h"
-#include "libknot/packet/wire.h"
-#include "libknot/wire.h"
-
-_public_
-uint16_t knot_wire_get_id(const uint8_t *packet)
-{
- return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ID);
-}
-
-_public_
-void knot_wire_set_id(uint8_t *packet, uint16_t id)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ID, id);
-}
-
-_public_
-uint16_t knot_wire_get_qdcount(const uint8_t *packet)
-{
- return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT);
-}
-
-_public_
-void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, qdcount);
-}
-
-_public_
-void knot_wire_add_qdcount(uint8_t *packet, int16_t n)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT,
- knot_wire_get_qdcount(packet) + n);
-}
-
-_public_
-uint16_t knot_wire_get_ancount(const uint8_t *packet)
-{
- return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT);
-}
-
-_public_
-void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, ancount);
-}
-
-_public_
-void knot_wire_add_ancount(uint8_t *packet, int16_t n)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT,
- knot_wire_get_ancount(packet) + n);
-}
-
-_public_
-uint16_t knot_wire_get_nscount(const uint8_t *packet)
-{
- return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT);
-}
-
-_public_
-void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, nscount);
-}
-
-_public_
-void knot_wire_add_nscount(uint8_t *packet, int16_t n)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT,
- knot_wire_get_nscount(packet) + n);
-}
-
-_public_
-uint16_t knot_wire_get_arcount(const uint8_t *packet)
-{
- return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT);
-}
-
-_public_
-void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, arcount);
-}
-
-_public_
-void knot_wire_add_arcount(uint8_t *packet, int16_t n)
-{
- knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT,
- knot_wire_get_arcount(packet) + n);
-}
-
-_public_
-void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr)
-{
- knot_wire_write_u16(pos, ptr); // Write pointer offset.
- assert((pos[0] & KNOT_WIRE_PTR) == 0); // Check for maximal offset.
- pos[0] |= KNOT_WIRE_PTR; // Add pointer mark.
-}
-
-_public_
-uint16_t knot_wire_get_pointer(const uint8_t *pos)
-{
- assert(knot_wire_is_pointer(pos)); // Check pointer.
- return (knot_wire_read_u16(pos) - KNOT_WIRE_PTR_BASE); // Return offset.
-}
-
-/*! @} */
-/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/* Copyright (C) 2018 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
#pragma once
+#include <assert.h>
#include <stdint.h>
-#include <stdlib.h>
+
#include "libknot/attribute.h"
+#include "libknot/wire.h"
/*! \brief Offset of DNS header fields in wireformat. */
enum knot_wire_offsets {
*
* \return DNS packet ID.
*/
-uint16_t knot_wire_get_id(const uint8_t *packet);
+static inline uint16_t knot_wire_get_id(const uint8_t *packet)
+{
+ return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ID);
+}
/*!
* \brief Sets the ID to the wire format of the packet.
* \param packet Wire format of the packet.
* \param id DNS packet ID.
*/
-void knot_wire_set_id(uint8_t *packet, uint16_t id);
+static inline void knot_wire_set_id(uint8_t *packet, uint16_t id)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ID, id);
+}
/*!
* \brief Returns the first byte of flags from wire format of the packet.
*
* \return QDCOUNT (count of Question entries in the packet).
*/
-uint16_t knot_wire_get_qdcount(const uint8_t *packet);
+static inline uint16_t knot_wire_get_qdcount(const uint8_t *packet)
+{
+ return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT);
+}
/*!
* \brief Sets the QDCOUNT (count of Question entries) to wire format of the
* \param packet Wire format of the packet.
* \param qdcount QDCOUNT (count of Question entries in the packet).
*/
-void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount);
+static inline void knot_wire_set_qdcount(uint8_t *packet, uint16_t qdcount)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT, qdcount);
+}
/*!
* \brief Adds to QDCOUNT.
*/
-void knot_wire_add_qdcount(uint8_t *packet, int16_t n);
+static inline void knot_wire_add_qdcount(uint8_t *packet, int16_t n)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_QDCOUNT,
+ knot_wire_get_qdcount(packet) + n);
+}
/*!
* \brief Returns the ANCOUNT (count of Answer entries) from wire format of
*
* \return ANCOUNT (count of Answer entries in the packet).
*/
-uint16_t knot_wire_get_ancount(const uint8_t *packet);
+static inline uint16_t knot_wire_get_ancount(const uint8_t *packet)
+{
+ return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT);
+}
/*!
* \brief Sets the ANCOUNT (count of Answer entries) to wire format of the
* \param packet Wire format of the packet.
* \param ancount ANCOUNT (count of Answer entries in the packet).
*/
-void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount);
+static inline void knot_wire_set_ancount(uint8_t *packet, uint16_t ancount)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT, ancount);
+}
/*!
* \brief Adds to ANCOUNT.
*/
-void knot_wire_add_ancount(uint8_t *packet, int16_t n);
+static inline void knot_wire_add_ancount(uint8_t *packet, int16_t n)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ANCOUNT,
+ knot_wire_get_ancount(packet) + n);
+}
/*!
* \brief Returns the NSCOUNT (count of Authority entries) from wire format of
*
* \return NSCOUNT (count of Authority entries in the packet).
*/
-uint16_t knot_wire_get_nscount(const uint8_t *packet);
+static inline uint16_t knot_wire_get_nscount(const uint8_t *packet)
+{
+ return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT);
+}
/*!
* \brief Sets the NSCOUNT (count of Authority entries) to wire format of the
* \param packet Wire format of the packet.
* \param nscount NSCOUNT (count of Authority entries in the packet).
*/
-void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount);
+static inline void knot_wire_set_nscount(uint8_t *packet, uint16_t nscount)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT, nscount);
+}
/*!
* \brief Adds to NSCOUNT.
*/
-void knot_wire_add_nscount(uint8_t *packet, int16_t n);
+static inline void knot_wire_add_nscount(uint8_t *packet, int16_t n)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_NSCOUNT,
+ knot_wire_get_nscount(packet) + n);
+}
/*!
* \brief Returns the ARCOUNT (count of Additional entries) from wire format of
*
* \return ARCOUNT (count of Additional entries in the packet).
*/
-uint16_t knot_wire_get_arcount(const uint8_t *packet);
+static inline uint16_t knot_wire_get_arcount(const uint8_t *packet)
+{
+ return knot_wire_read_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT);
+}
/*!
* \brief Sets the ARCOUNT (count of Additional entries) to wire format of the
* \param packet Wire format of the packet.
* \param arcount ARCOUNT (count of Additional entries in the packet).
*/
-void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount);
+static inline void knot_wire_set_arcount(uint8_t *packet, uint16_t arcount)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT, arcount);
+}
/*!
* \brief Adds to ARCOUNT.
*/
-void knot_wire_add_arcount(uint8_t *packet, int16_t n);
+static inline void knot_wire_add_arcount(uint8_t *packet, int16_t n)
+{
+ knot_wire_write_u16(packet + KNOT_WIRE_OFFSET_ARCOUNT,
+ knot_wire_get_arcount(packet) + n);
+}
/*
* Packet header flags manipulation functions.
KNOT_WIRE_PTR_MAX = (uint16_t)0x3FFF
};
+static inline int knot_wire_is_pointer(const uint8_t *pos)
+{
+ return pos && ((pos[0] & KNOT_WIRE_PTR) == KNOT_WIRE_PTR);
+}
+
/*!
* \brief Creates a DNS packet pointer and stores it in wire format.
*
* \param ptr Relative position of the item to which the pointer should point in
* the wire format of the packet.
*/
-void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr);
-
-uint16_t knot_wire_get_pointer(const uint8_t *pos);
+static inline void knot_wire_put_pointer(uint8_t *pos, uint16_t ptr)
+{
+ knot_wire_write_u16(pos, ptr); // Write pointer offset.
+ assert((pos[0] & KNOT_WIRE_PTR) == 0); // Check for maximal offset.
+ pos[0] |= KNOT_WIRE_PTR; // Add pointer mark.
+}
-static inline int knot_wire_is_pointer(const uint8_t *pos)
+static inline uint16_t knot_wire_get_pointer(const uint8_t *pos)
{
- return pos && ((pos[0] & KNOT_WIRE_PTR) == KNOT_WIRE_PTR);
+ assert(knot_wire_is_pointer(pos)); // Check pointer.
+ return (knot_wire_read_u16(pos) - KNOT_WIRE_PTR_BASE); // Return offset.
}
_pure_ _mustcheck_