10#include <sys/socket.h>
24#if defined IP_RECVDSTADDR
25#define DSTADDR_SOCKOPT IP_RECVDSTADDR
26#define DSTADDR_DATASIZE (CMSG_SPACE(sizeof(struct in6_addr)))
27#define dstaddr(x) (CMSG_DATA(x))
28#elif defined IPV6_PKTINFO
29#define DSTADDR_SOCKOPT IPV6_PKTINFO
30#define DSTADDR_DATASIZE (CMSG_SPACE(sizeof(struct in6_pktinfo)))
31#define dstaddr(x) (&(((struct in6_pktinfo *)(CMSG_DATA(x)))->ipi6_addr))
33#error "can't determine socket option"
78 int octet = *((*inpos)++);
93 if ((
octet & 0xC0) == 0xC0) {
97 int ref = ((
octet - 0xC0) << 8) + *((*inpos)++);
122 int c = *((*inpos)++);
167 *((*outpos)++) = (
offset >> 8) | 0xC0;
168 *((*outpos)++) =
offset & 0xFF;
189 *((*outpos)++) = typ >> 8;
190 *((*outpos)++) = typ & 0xFF;
192 *((*outpos)++) =
cls >> 8;
193 *((*outpos)++) =
cls & 0xFF;
195 *((*outpos)++) = (
ttl >> 24) & 0xFF;
196 *((*outpos)++) = (
ttl >> 16) & 0xFF;
197 *((*outpos)++) = (
ttl >> 8) & 0xFF;
198 *((*outpos)++) =
ttl & 0xFF;
225 for (
int i = 0; i < 4; i++) {
226 *((*outpos)++) = ip->
data.
v4[i];
254 for (
int i = 0; i < 16; i++) {
255 *((*outpos)++) = ip->
data.
v6[i];
337 *((*outpos)++) = (
serial >> 24) & 0xFF;
338 *((*outpos)++) = (
serial >> 16) & 0xFF;
339 *((*outpos)++) = (
serial >> 8) & 0xFF;
340 *((*outpos)++) =
serial & 0xFF;
341 *((*outpos)++) = (refresh >> 24) & 0xFF;
342 *((*outpos)++) = (refresh >> 16) & 0xFF;
343 *((*outpos)++) = (refresh >> 8) & 0xFF;
344 *((*outpos)++) = refresh & 0xFF;
345 *((*outpos)++) = (retry >> 24) & 0xFF;
346 *((*outpos)++) = (retry >> 16) & 0xFF;
347 *((*outpos)++) = (retry >> 8) & 0xFF;
348 *((*outpos)++) = retry & 0xFF;
349 *((*outpos)++) = (
expire >> 24) & 0xFF;
350 *((*outpos)++) = (
expire >> 16) & 0xFF;
351 *((*outpos)++) = (
expire >> 8) & 0xFF;
352 *((*outpos)++) =
expire & 0xFF;
353 *((*outpos)++) = (
minimum >> 24) & 0xFF;
354 *((*outpos)++) = (
minimum >> 16) & 0xFF;
355 *((*outpos)++) = (
minimum >> 8) & 0xFF;
356 *((*outpos)++) =
minimum & 0xFF;
388 if (
inbuf[2] & 128) {
395 if (((
inbuf[2] & 120) >> 3) != 0) {
513 GetTime(), 604800, 86400, 2592000, 604800);
530 if (addr[n].v == 4) {
533 opt->datattl, &addr[n]);
534 }
else if (addr[n].v == 6) {
537 opt->datattl, &addr[n]);
566 opt->mbox,
GetTime(), 604800, 86400, 2592000, 604800);
633 .iov_len =
sizeof(
inbuf),
643 msg.msg_control = &
cmsg;
644 msg.msg_controllen =
sizeof(
cmsg);
646 for (; 1; ++(
opt->nRequests)) {
666 msg.msg_iov[0].iov_base =
outbuf;
667 msg.msg_iov[0].iov_len =
ret;
669 msg.msg_iov[0].iov_base =
inbuf;
670 msg.msg_iov[0].iov_len =
sizeof(
inbuf);
static int write_record_ns(uint8_t **outpos, const uint8_t *outend, const char *name, int offset, dns_class cls, int ttl, const char *ns)
static ssize_t dnshandle(dns_opt_t *opt, const uint8_t *inbuf, size_t insize, uint8_t *outbuf)
ParseNameStatus parse_name(const uint8_t **inpos, const uint8_t *inend, const uint8_t *inbuf, char *buf, size_t bufsize)
int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, int offset)
static int write_record_aaaa(uint8_t **outpos, const uint8_t *outend, const char *name, int offset, dns_class cls, int ttl, const addr_t *ip)
int dnsserver(dns_opt_t *opt)
static int write_record_soa(uint8_t **outpos, const uint8_t *outend, const char *name, int offset, dns_class cls, int ttl, const char *mname, const char *rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum)
static int write_record(uint8_t **outpos, const uint8_t *outend, const char *name, int offset, dns_type typ, dns_class cls, int ttl)
static int write_record_a(uint8_t **outpos, const uint8_t *outend, const char *name, int offset, dns_class cls, int ttl, const addr_t *ip)
constexpr int MAX_LABEL_LENGTH
constexpr int MAX_QUERY_NAME_LENGTH
constexpr int MAX_QUERY_NAME_BUFFER_LENGTH
bool error(const char *fmt, const Args &...args)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
uint8_t data[DSTADDR_DATASIZE]