2020-12-05 19:26:32 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
#include "str.h"
|
|
|
|
|
2020-12-22 17:44:59 +08:00
|
|
|
// Mongoose sends DNS queries that contain only one question:
|
|
|
|
// either A (IPv4) or AAAA (IPv6) address lookup.
|
|
|
|
// Therefore, we expect zero or one answer.
|
|
|
|
// If `resolved` is true, then `addr` contains resolved IPv4 or IPV6 address.
|
2020-12-05 19:26:32 +08:00
|
|
|
struct mg_dns_message {
|
2020-12-22 17:44:59 +08:00
|
|
|
uint16_t txnid; // Transaction ID
|
|
|
|
bool resolved; // Resolve successful, addr is set
|
|
|
|
struct mg_addr addr; // Resolved address
|
|
|
|
char name[256]; // Host name
|
2020-12-05 19:26:32 +08:00
|
|
|
};
|
|
|
|
|
2020-12-28 13:25:29 +08:00
|
|
|
struct mg_dns_header {
|
|
|
|
uint16_t txnid; // Transaction ID
|
|
|
|
uint16_t flags;
|
|
|
|
uint16_t num_questions;
|
|
|
|
uint16_t num_answers;
|
|
|
|
uint16_t num_authority_prs;
|
|
|
|
uint16_t num_other_prs;
|
|
|
|
};
|
|
|
|
|
|
|
|
// DNS resource record
|
|
|
|
struct mg_dns_rr {
|
|
|
|
uint16_t nlen; // Name or pointer length
|
|
|
|
uint16_t atype; // Address type
|
|
|
|
uint16_t aclass; // Address class
|
|
|
|
uint16_t alen; // Address length
|
|
|
|
};
|
|
|
|
|
2022-01-07 23:00:10 +08:00
|
|
|
void mg_resolve(struct mg_connection *, const char *url);
|
2020-12-22 17:44:59 +08:00
|
|
|
void mg_resolve_cancel(struct mg_connection *);
|
2020-12-21 00:55:33 +08:00
|
|
|
bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *);
|
2020-12-28 13:25:29 +08:00
|
|
|
size_t mg_dns_parse_rr(const uint8_t *buf, size_t len, size_t ofs,
|
|
|
|
bool is_question, struct mg_dns_rr *);
|