DNS: minimal query parse and A-record response
Functions
| Name | |
|---|---|
| int | n_dns_parse_query(const unsigned char * msg, size_t len, uint16_t * id_out, char * qname_out, size_t qname_sz, uint16_t * qtype_out) Parse the header id and the first question (QNAME + QTYPE) of a DNS message. |
| int | n_dns_build_a_response(const unsigned char * query, size_t qlen, uint32_t ipv4_be, uint32_t ttl, unsigned char * out, size_t outsz) Build a DNS response answering a query's first question with one A record. |
Defines
| Name | |
|---|---|
| N_DNS_TYPE_A DNS resource-record type A (IPv4 address). |
|
| N_DNS_QNAME_MAX Maximum decoded QNAME length, including the terminating NUL. |
Functions Documentation
function n_dns_parse_query
int n_dns_parse_query(
const unsigned char * msg,
size_t len,
uint16_t * id_out,
char * qname_out,
size_t qname_sz,
uint16_t * qtype_out
)
Parse the header id and the first question (QNAME + QTYPE) of a DNS message.
Parameters:
- msg The DNS message bytes. NULL returns -1.
- len The message length in bytes.
- id_out Out: the 16-bit transaction id, or NULL.
- qname_out Out: the decoded question name, or NULL.
- qname_sz Size of qname_out.
- qtype_out Out: the question type (QTYPE), or NULL.
Return: 0 on success, -1 on a malformed or truncated message.
The QNAME is written as a lowercase dot-separated string (no trailing dot). Name compression is rejected in the question (a query has none). Any out pointer may be NULL to skip it.
function n_dns_build_a_response
int n_dns_build_a_response(
const unsigned char * query,
size_t qlen,
uint32_t ipv4_be,
uint32_t ttl,
unsigned char * out,
size_t outsz
)
Build a DNS response answering a query's first question with one A record.
Parameters:
- query The received query bytes. NULL returns -1.
- qlen The query length in bytes.
- ipv4_be The answer IPv4 address, in network byte order.
- ttl The record time-to-live in seconds.
- out Output buffer for the response. NULL returns -1.
- outsz Size of
out.
Return: The response length in bytes, or -1 on a malformed query or too-small buffer.
Echoes the query header (with QR/AA/RA set and RCODE 0) and question, then appends a single A resource record pointing at ipv4_be. The address is taken in network byte order (as returned by inet_addr) and copied verbatim into the RDATA, so the helper is endianness-agnostic.
Macros Documentation
define N_DNS_TYPE_A
#define N_DNS_TYPE_A 1
DNS resource-record type A (IPv4 address).
define N_DNS_QNAME_MAX
#define N_DNS_QNAME_MAX 256
Maximum decoded QNAME length, including the terminating NUL.
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB