![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Macros | |
| #define | N_DNS_QNAME_MAX 256 |
| Maximum decoded QNAME length, including the terminating NUL. | |
| #define | N_DNS_TYPE_A 1 |
| DNS resource-record type A (IPv4 address). | |
Functions | |
| 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. | |
| 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. | |
| #define N_DNS_QNAME_MAX 256 |
| #define N_DNS_TYPE_A 1 |
| 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.
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.
| 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. |
Definition at line 94 of file n_dns.c.
References N_DNS_HEADER_LEN, and n_dns_u16().
Referenced by test_build_response(), and test_errors().
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
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.
| 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. |
Definition at line 39 of file n_dns.c.
References N_DNS_HEADER_LEN, and n_dns_u16().
Referenced by test_build_response(), test_errors(), and test_parse().
Here is the call graph for this function:
Here is the caller graph for this function: