File syn_dns.c¶
Go to the source code of this file
UDP DNS resolver and mDNS responder implementation.
#include "../port/syn_port_system.h"#include "../util/syn_assert.h"#include "../util/syn_pack.h"#include "syn_dns.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| SYN_PT_Status | syn_dns_resolve_task (SYN_PT * pt, SYN_Task * task) Cooperative task for resolving a hostname via DNS. |
| SYN_Status | syn_mdns_init (SYN_Mdns * mdns, const char * hostname, const uint8_t ip) Initialize the mDNS responder. |
| SYN_PT_Status | syn_mdns_task (SYN_PT * pt, SYN_Task * task) Cooperative task for responding to local mDNS queries. |
Public Static Functions¶
| Type | Name |
|---|---|
| size_t | encode_qname (uint8_t * dest, const char * src) Encode a hostname as a DNS QNAME (label-length format). |
| bool | match_qname_local (const uint8_t * buf, size_t buf_len, size_t * pos, const char * hostname) Check if QNAME matches hostname.local. |
| bool | parse_qname (const uint8_t * buf, size_t buf_len, size_t * pos) Skip a QNAME in a DNS packet (handles compression pointers). |
| SYN_Status | parse_response (const uint8_t * buf, size_t rx_len, SYN_SockAddr * addr_out, uint16_t expected_txid) Parse a DNS response packet to extract the resolved IP. |
Public Functions Documentation¶
function syn_dns_resolve_task¶
Cooperative task for resolving a hostname via DNS.
Register this as a SYN_TaskFunc with user_data pointing to a SYN_DnsResolver instance. The task runs non-blocking UDP queries, yielding via PT_YIELD until resolution completes or times out.
Parameters:
ptProtothread pointer.taskTask structure whose user_data points to a SYN_DnsResolver.
Returns:
PT_WAITING while running, PT_EXITED when done, or PT_ENDED on early exit.
function syn_mdns_init¶
Initialize the mDNS responder.
Parameters:
mdnsmDNS instance.hostnameHostname to respond to (without .local suffix).ipIPv4 address to advertise.
Returns:
SYN_OK on success.
function syn_mdns_task¶
Cooperative task for responding to local mDNS queries.
Parameters:
ptProtothread pointer.taskTask structure whose user_data points to a SYN_Mdns.
Returns:
PT_WAITING while running, PT_EXITED when done.
Public Static Functions Documentation¶
function encode_qname¶
Encode a hostname as a DNS QNAME (label-length format).
Parameters:
dest[out] Destination buffer.srcDot-separated hostname.
Returns:
Total bytes written.
function match_qname_local¶
Check if QNAME matches hostname.local.
static bool match_qname_local (
const uint8_t * buf,
size_t buf_len,
size_t * pos,
const char * hostname
)
Parameters:
bufPacket buffer.buf_lenBuffer length.pos[in/out] Parse position.hostnameExpected hostname.
Returns:
true if match.
function parse_qname¶
Skip a QNAME in a DNS packet (handles compression pointers).
Parameters:
bufPacket buffer.buf_lenBuffer length.pos[in/out] Current parse position.
Returns:
true on success.
function parse_response¶
Parse a DNS response packet to extract the resolved IP.
static SYN_Status parse_response (
const uint8_t * buf,
size_t rx_len,
SYN_SockAddr * addr_out,
uint16_t expected_txid
)
Checks transaction ID, question count, and pulls the first IPv4 A record.
Parameters:
bufReceived UDP packet buffer.rx_lenReceived packet length.addr_out[out] Output structure for resolved IPv4 address.expected_txidTransaction ID to verify.
Returns:
SYN_OK on success, SYN_ERROR on format/parsing error.
The documentation for this class was generated from the following file src/syntropic/net/syn_dns.c