Retro Rocket Kernel
BASIC-Powered Operating System
dns.h File Reference
#include "kernel.h"

Data Structures

struct  ResourceRecord
 
struct  dns_header
 
struct  dns_request_t
 
struct  resource_record
 
struct  dns_result_t
 

Macros

#define DN_COMP_BITMASK   0xC000
 
#define ERROR_MASK   0x10000
 
#define FLAGS_MASK_RD   0x01 /* Recursive */
 
#define FLAGS_MASK_TC   0x02
 
#define FLAGS_MASK_AA   0x04 /* Authoritative */
 
#define FLAGS_MASK_OPCODE   0x78
 
#define FLAGS_MASK_QR   0x80
 
#define FLAGS_MASK_RCODE   0x0F /* Request */
 
#define FLAGS_MASK_Z   0x70
 
#define FLAGS_MASK_RA   0x80
 
#define DNS_DST_PORT   53
 

Typedefs

typedef void(* dns_reply_callback_a) (uint32_t result, const char *hostname, uint16_t reply_id)
 
typedef void(* dns_reply_callback_aaaa) (uint8_t *result, const char *hostname, uint16_t reply_id)
 
typedef void(* dns_reply_callback_ptr) (const char *const result, const uint32_t ip, uint16_t reply_id)
 

Enumerations

enum  query_type_t {
  DNS_QUERY_NONE = 0 , DNS_QUERY_A = 1 , DNS_QUERY_CNAME = 5 , DNS_QUERY_PTR = 12 ,
  DNS_QUERY_AAAA = 28 , DNS_QUERY_PTR4 = 0xFFFD , DNS_QUERY_PTR6 = 0xFFFE
}
 

Functions

struct dns_header __attribute__ ((packed)) dns_header_t
 
uint32_t dns_lookup_host (uint32_t resolver_ip, const char *hostname, uint32_t timeout)
 Look up an IPV4 hostname to IP address, with timeout. More...
 
uint16_t dns_lookup_host_async (uint32_t resolver_ip, const char *hostname, uint32_t timeout, dns_reply_callback_a callback)
 Look up an IPV4 hostname to IP address, with timeout. More...
 
void init_dns ()
 Initialise DNS protocol. This binds a UDP port for use with replies. More...
 

Variables

uint16_t id
 
uint8_t flags1
 
uint8_t flags2
 
uint16_t qdcount
 
uint16_t ancount
 
uint16_t nscount
 
uint16_t arcount
 
uint8_t payload [512]
 
uint16_t type
 
uint16_t rr_class
 
uint32_t ttl
 
uint16_t rdlength
 
struct dns_result_t __attribute__
 

Detailed Description

Author
Craig Edwards (craig.nosp@m.edwa.nosp@m.rds@b.nosp@m.rain.nosp@m.box.c.nosp@m.c)

Macro Definition Documentation

◆ DN_COMP_BITMASK

#define DN_COMP_BITMASK   0xC000

◆ DNS_DST_PORT

#define DNS_DST_PORT   53

◆ ERROR_MASK

#define ERROR_MASK   0x10000

◆ FLAGS_MASK_AA

#define FLAGS_MASK_AA   0x04 /* Authoritative */

◆ FLAGS_MASK_OPCODE

#define FLAGS_MASK_OPCODE   0x78

◆ FLAGS_MASK_QR

#define FLAGS_MASK_QR   0x80

◆ FLAGS_MASK_RA

#define FLAGS_MASK_RA   0x80

◆ FLAGS_MASK_RCODE

#define FLAGS_MASK_RCODE   0x0F /* Request */

◆ FLAGS_MASK_RD

#define FLAGS_MASK_RD   0x01 /* Recursive */

◆ FLAGS_MASK_TC

#define FLAGS_MASK_TC   0x02

◆ FLAGS_MASK_Z

#define FLAGS_MASK_Z   0x70

Typedef Documentation

◆ dns_reply_callback_a

typedef void(* dns_reply_callback_a) (uint32_t result, const char *hostname, uint16_t reply_id)

◆ dns_reply_callback_aaaa

typedef void(* dns_reply_callback_aaaa) (uint8_t *result, const char *hostname, uint16_t reply_id)

◆ dns_reply_callback_ptr

typedef void(* dns_reply_callback_ptr) (const char *const result, const uint32_t ip, uint16_t reply_id)

Enumeration Type Documentation

◆ query_type_t

Enumerator
DNS_QUERY_NONE 

Uninitialized Query

DNS_QUERY_A 

'A' record: an ipv4 address

DNS_QUERY_CNAME 

'CNAME' record: An alias

DNS_QUERY_PTR 

'PTR' record: a hostname

DNS_QUERY_AAAA 

'AAAA' record: an ipv6 address

DNS_QUERY_PTR4 

Force 'PTR' to use IPV4 scemantics

DNS_QUERY_PTR6 

Force 'PTR' to use IPV6 scemantics

Function Documentation

◆ __attribute__()

struct dns_header __attribute__ ( (packed)  )

Represents a dns request/reply header, and its payload as opaque data.

◆ dns_lookup_host()

uint32_t dns_lookup_host ( uint32_t  resolver_ip,
const char *  hostname,
uint32_t  timeout 
)

Look up an IPV4 hostname to IP address, with timeout.

Note
This function is synchronous! It will block until a suitable DNS request has been obtained from the DNS server you specify, or a timeout is reached.
Parameters
resolver_ipThe IP of the resolver to use, in network byte order
hostnameHost address to resolve
timeoutTimeout in seconds
Returns
uint32_t Resolved IP address. On error or timeout, the return value is 0, which translates to 0.0.0.0.

◆ dns_lookup_host_async()

uint16_t dns_lookup_host_async ( uint32_t  resolver_ip,
const char *  hostname,
uint32_t  timeout,
dns_reply_callback_a  callback 
)

Look up an IPV4 hostname to IP address, with timeout.

Note
This function is asynchronous. It will return the ID of the request, and will call the callback once the request has completed.
Parameters
resolver_ipThe IP of the resolver to use, in network byte order
hostnameHost address to resolve
timeoutTimeout in seconds
dns_reply_callback_aCallback to receive the resolved IP address. If an error occured during resolution, the received IP address will be 0, which is a representation of 0.0.0.0.
Returns
uint16_t Request ID that was submitted, or 0 on error

◆ init_dns()

void init_dns ( )

Initialise DNS protocol. This binds a UDP port for use with replies.

Variable Documentation

◆ __attribute__

◆ ancount

uint16_t ancount

◆ arcount

uint16_t arcount

◆ flags1

uint8_t flags1

◆ flags2

uint8_t flags2

◆ id

uint16_t id

◆ nscount

uint16_t nscount

◆ payload

uint8_t payload[512]

◆ qdcount

uint16_t qdcount

◆ rdlength

uint16_t rdlength

◆ rr_class

uint16_t rr_class

◆ ttl

uint32_t ttl

◆ type

uint8_t type