Group PJ_DNS_SERVER

group PJ_DNS_SERVER

This contains a simple but fully working DNS server implementation, mostly for testing purposes. It supports serving various DNS resource records such as SRV, CNAME, A, and AAAA.

Typedefs

typedef struct pj_dns_server pj_dns_server

Opaque structure to hold DNS server instance.

Functions

pj_status_t pj_dns_server_create(pj_pool_factory *pf, pj_ioqueue_t *ioqueue, int af, unsigned port, unsigned flags, pj_dns_server **p_srv)

Create the DNS server instance. The instance will run immediately.

Parameters
  • pf – The pool factory to create memory pools.

  • ioqueue – Ioqueue instance where the server socket will be registered to.

  • af – Address family of the server socket (valid values are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).

  • port – The UDP port to listen.

  • flags – Flags, currently must be zero.

  • p_srv – Pointer to receive the DNS server instance.

Returns

PJ_SUCCESS if server has been created successfully, otherwise the function will return the appropriate error code.

pj_status_t pj_dns_server_destroy(pj_dns_server *srv)

Destroy DNS server instance.

Parameters

srv – The DNS server instance.

Returns

PJ_SUCCESS on success or the appropriate error code.

pj_status_t pj_dns_server_add_rec(pj_dns_server *srv, unsigned count, const pj_dns_parsed_rr rr[])

Add generic resource record entries to the server.

Parameters
  • srv – The DNS server instance.

  • count – Number of records to be added.

  • rr – Array of records to be added.

Returns

PJ_SUCCESS on success or the appropriate error code.

pj_status_t pj_dns_server_del_rec(pj_dns_server *srv, int dns_class, pj_dns_type type, const pj_str_t *name)

Remove the specified record from the server.

Parameters
  • srv – The DNS server instance.

  • dns_class – The resource’s DNS class. Valid value is PJ_DNS_CLASS_IN.

  • type – The resource type.

  • name – The resource name to be removed.

Returns

PJ_SUCCESS on success or the appropriate error code.