Commit 1eaabdd8 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Marko Mikulicic

s/dmg/dns/g

    PUBLISHED_FROM=96dc8b0b4001f2206749a401c615f043fc5f6131
parent dcd4e660
...@@ -61,7 +61,7 @@ static uint8_t board_ip[] = {192, 168, 10, 177}; ...@@ -61,7 +61,7 @@ static uint8_t board_ip[] = {192, 168, 10, 177};
#ifdef WIFI_CC3000 #ifdef WIFI_CC3000
static uint8_t subnet_mask[] = {255, 255, 255, 0}; static uint8_t subnet_mask[] = {255, 255, 255, 0};
static uint8_t gateway[] = {192, 168, 10, 254}; static uint8_t gateway[] = {192, 168, 10, 254};
static uint8_t dmg_ip[] = {192, 168, 10, 254}; static uint8_t dns_ip[] = {192, 168, 10, 254};
static const char *wlan_ssid = "mynetwork"; static const char *wlan_ssid = "mynetwork";
static const char *wlan_pwd = "mypassword"; static const char *wlan_pwd = "mypassword";
...@@ -117,7 +117,7 @@ void setup() ...@@ -117,7 +117,7 @@ void setup()
avr_netinit(board_mac, board_ip); avr_netinit(board_mac, board_ip);
#elif defined(WIFI_CC3000) #elif defined(WIFI_CC3000)
if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip), if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip),
IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dmg_ip)) != 0) { IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dns_ip)) != 0) {
Serial.println("Initialization error, check network settings"); Serial.println("Initialization error, check network settings");
return; return;
}; };
......
...@@ -59,7 +59,7 @@ static uint8_t board_ip[] = {192, 168, 10, 8}; ...@@ -59,7 +59,7 @@ static uint8_t board_ip[] = {192, 168, 10, 8};
#ifdef WIFI_CC3000 #ifdef WIFI_CC3000
static uint8_t subnet_mask[] = {255, 255, 255, 0}; static uint8_t subnet_mask[] = {255, 255, 255, 0};
static uint8_t gateway[] = {192, 168, 10, 254}; static uint8_t gateway[] = {192, 168, 10, 254};
static uint8_t dmg_ip[] = {192, 168, 10, 254}; static uint8_t dns_ip[] = {192, 168, 10, 254};
static const char *wlan_ssid = "mynetwork"; static const char *wlan_ssid = "mynetwork";
static const char *wlan_pwd = "mypassword"; static const char *wlan_pwd = "mypassword";
...@@ -116,7 +116,7 @@ void setup() { ...@@ -116,7 +116,7 @@ void setup() {
avr_netinit(board_mac, board_ip); avr_netinit(board_mac, board_ip);
#elif defined(WIFI_CC3000) #elif defined(WIFI_CC3000)
if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip), if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip),
IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dmg_ip)) != 0) { IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dns_ip)) != 0) {
Serial.println("Initialization error, check network settings"); Serial.println("Initialization error, check network settings");
return; return;
}; };
......
...@@ -17,20 +17,20 @@ static in_addr_t s_our_ip_addr; ...@@ -17,20 +17,20 @@ static in_addr_t s_our_ip_addr;
static const char *s_listening_addr = "udp://:5533"; static const char *s_listening_addr = "udp://:5533";
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct mg_dmg_message *msg; struct mg_dns_message *msg;
struct mg_dmg_resource_record *rr; struct mg_dns_resource_record *rr;
struct mg_dmg_reply reply; struct mg_dns_reply reply;
int i; int i;
switch (ev) { switch (ev) {
case MG_DNS_MESSAGE: case MG_DNS_MESSAGE:
msg = (struct mg_dmg_message *) ev_data; msg = (struct mg_dns_message *) ev_data;
reply = mg_dmg_create_reply(&nc->send_mbuf, msg); reply = mg_dns_create_reply(&nc->send_mbuf, msg);
for (i = 0; i < msg->num_questions; i++) { for (i = 0; i < msg->num_questions; i++) {
rr = &msg->questions[i]; rr = &msg->questions[i];
if (rr->rtype == MG_DNS_A_RECORD) { if (rr->rtype == MG_DNS_A_RECORD) {
mg_dmg_reply_record(&reply, rr, NULL, rr->rtype, 3600, mg_dns_reply_record(&reply, rr, NULL, rr->rtype, 3600,
&s_our_ip_addr, 4); &s_our_ip_addr, 4);
} }
} }
...@@ -42,7 +42,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -42,7 +42,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
* See http://goo.gl/QWvufr for a distinction between NXDOMAIN and NODATA. * See http://goo.gl/QWvufr for a distinction between NXDOMAIN and NODATA.
*/ */
mg_dmg_send_reply(nc, &reply); mg_dns_send_reply(nc, &reply);
break; break;
} }
} }
......
This diff is collapsed.
...@@ -2139,35 +2139,35 @@ extern "C" { ...@@ -2139,35 +2139,35 @@ extern "C" {
#define MG_DNS_MESSAGE 100 /* High-level DNS message event */ #define MG_DNS_MESSAGE 100 /* High-level DNS message event */
enum mg_dmg_resource_record_kind { enum mg_dns_resource_record_kind {
MG_DNS_INVALID_RECORD = 0, MG_DNS_INVALID_RECORD = 0,
MG_DNS_QUESTION, MG_DNS_QUESTION,
MG_DNS_ANSWER MG_DNS_ANSWER
}; };
/* DNS resource record. */ /* DNS resource record. */
struct mg_dmg_resource_record { struct mg_dns_resource_record {
struct mg_str name; /* buffer with compressed name */ struct mg_str name; /* buffer with compressed name */
int rtype; int rtype;
int rclass; int rclass;
int ttl; int ttl;
enum mg_dmg_resource_record_kind kind; enum mg_dns_resource_record_kind kind;
struct mg_str rdata; /* protocol data (can be a compressed name) */ struct mg_str rdata; /* protocol data (can be a compressed name) */
}; };
/* DNS message (request and response). */ /* DNS message (request and response). */
struct mg_dmg_message { struct mg_dns_message {
struct mg_str pkt; /* packet body */ struct mg_str pkt; /* packet body */
uint16_t flags; uint16_t flags;
uint16_t transaction_id; uint16_t transaction_id;
int num_questions; int num_questions;
int num_answers; int num_answers;
struct mg_dmg_resource_record questions[MG_MAX_DNS_QUESTIONS]; struct mg_dns_resource_record questions[MG_MAX_DNS_QUESTIONS];
struct mg_dmg_resource_record answers[MG_MAX_DNS_ANSWERS]; struct mg_dns_resource_record answers[MG_MAX_DNS_ANSWERS];
}; };
struct mg_dmg_resource_record *mg_dmg_next_record( struct mg_dns_resource_record *mg_dns_next_record(
struct mg_dmg_message *, int, struct mg_dmg_resource_record *); struct mg_dns_message *, int, struct mg_dns_resource_record *);
/* /*
* Parse the record data from a DNS resource record. * Parse the record data from a DNS resource record.
...@@ -2180,20 +2180,20 @@ struct mg_dmg_resource_record *mg_dmg_next_record( ...@@ -2180,20 +2180,20 @@ struct mg_dmg_resource_record *mg_dmg_next_record(
* *
* TODO(mkm): MX * TODO(mkm): MX
*/ */
int mg_dmg_parse_record_data(struct mg_dmg_message *, int mg_dns_parse_record_data(struct mg_dns_message *,
struct mg_dmg_resource_record *, void *, size_t); struct mg_dns_resource_record *, void *, size_t);
/* /*
* Send a DNS query to the remote end. * Send a DNS query to the remote end.
*/ */
void mg_send_dmg_query(struct mg_connection *, const char *, int); void mg_send_dns_query(struct mg_connection *, const char *, int);
/* /*
* Insert a DNS header to an IO buffer. * Insert a DNS header to an IO buffer.
* *
* Return number of bytes inserted. * Return number of bytes inserted.
*/ */
int mg_dmg_insert_header(struct mbuf *, size_t, struct mg_dmg_message *); int mg_dns_insert_header(struct mbuf *, size_t, struct mg_dns_message *);
/* /*
* Append already encoded body from an existing message. * Append already encoded body from an existing message.
...@@ -2203,7 +2203,7 @@ int mg_dmg_insert_header(struct mbuf *, size_t, struct mg_dmg_message *); ...@@ -2203,7 +2203,7 @@ int mg_dmg_insert_header(struct mbuf *, size_t, struct mg_dmg_message *);
* *
* Return number of appened bytes. * Return number of appened bytes.
*/ */
int mg_dmg_copy_body(struct mbuf *, struct mg_dmg_message *); int mg_dns_copy_body(struct mbuf *, struct mg_dns_message *);
/* /*
* Encode and append a DNS resource record to an IO buffer. * Encode and append a DNS resource record to an IO buffer.
...@@ -2221,11 +2221,11 @@ int mg_dmg_copy_body(struct mbuf *, struct mg_dmg_message *); ...@@ -2221,11 +2221,11 @@ int mg_dmg_copy_body(struct mbuf *, struct mg_dmg_message *);
* *
* Return the number of bytes appened or -1 in case of error. * Return the number of bytes appened or -1 in case of error.
*/ */
int mg_dmg_encode_record(struct mbuf *, struct mg_dmg_resource_record *, int mg_dns_encode_record(struct mbuf *, struct mg_dns_resource_record *,
const char *, size_t, const void *, size_t); const char *, size_t, const void *, size_t);
/* Low-level: parses a DNS response. */ /* Low-level: parses a DNS response. */
int mg_parse_dns(const char *, int, struct mg_dmg_message *); int mg_parse_dns(const char *, int, struct mg_dns_message *);
/* /*
* Uncompress a DNS compressed name. * Uncompress a DNS compressed name.
...@@ -2240,7 +2240,7 @@ int mg_parse_dns(const char *, int, struct mg_dmg_message *); ...@@ -2240,7 +2240,7 @@ int mg_parse_dns(const char *, int, struct mg_dmg_message *);
* If `dst_len` is 0 `dst` can be NULL. * If `dst_len` is 0 `dst` can be NULL.
* Return the uncompressed name length. * Return the uncompressed name length.
*/ */
size_t mg_dmg_uncompress_name(struct mg_dmg_message *, struct mg_str *, char *, size_t mg_dns_uncompress_name(struct mg_dns_message *, struct mg_str *, char *,
int); int);
/* /*
...@@ -2249,10 +2249,10 @@ size_t mg_dmg_uncompress_name(struct mg_dmg_message *, struct mg_str *, char *, ...@@ -2249,10 +2249,10 @@ size_t mg_dmg_uncompress_name(struct mg_dmg_message *, struct mg_str *, char *,
* DNS event handler parses incoming UDP packets, treating them as DNS * DNS event handler parses incoming UDP packets, treating them as DNS
* requests. If incoming packet gets successfully parsed by the DNS event * requests. If incoming packet gets successfully parsed by the DNS event
* handler, a user event handler will receive `MG_DNS_REQUEST` event, with * handler, a user event handler will receive `MG_DNS_REQUEST` event, with
* `ev_data` pointing to the parsed `struct mg_dmg_message`. * `ev_data` pointing to the parsed `struct mg_dns_message`.
* *
* See * See
* https://github.com/cesanta/mongoose/tree/master/examples/captive_dmg_server[captive_dmg_server] * https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server[captive_dns_server]
* example on how to handle DNS request and send DNS reply. * example on how to handle DNS request and send DNS reply.
*/ */
void mg_set_protocol_dns(struct mg_connection *); void mg_set_protocol_dns(struct mg_connection *);
...@@ -2284,8 +2284,8 @@ extern "C" { ...@@ -2284,8 +2284,8 @@ extern "C" {
#define MG_DNS_SERVER_DEFAULT_TTL 3600 #define MG_DNS_SERVER_DEFAULT_TTL 3600
struct mg_dmg_reply { struct mg_dns_reply {
struct mg_dmg_message *msg; struct mg_dns_message *msg;
struct mbuf *io; struct mbuf *io;
size_t start; size_t start;
}; };
...@@ -2298,10 +2298,10 @@ struct mg_dmg_reply { ...@@ -2298,10 +2298,10 @@ struct mg_dmg_reply {
* "reply + recursion allowed" will be added to the message flags and * "reply + recursion allowed" will be added to the message flags and
* message's num_answers will be set to 0. * message's num_answers will be set to 0.
* *
* Answer records can be appended with `mg_dmg_send_reply` or by lower * Answer records can be appended with `mg_dns_send_reply` or by lower
* level function defined in the DNS API. * level function defined in the DNS API.
* *
* In order to send the reply use `mg_dmg_send_reply`. * In order to send the reply use `mg_dns_send_reply`.
* It's possible to use a connection's send buffer as reply buffers, * It's possible to use a connection's send buffer as reply buffers,
* and it will work for both UDP and TCP connections. * and it will work for both UDP and TCP connections.
* *
...@@ -2309,17 +2309,17 @@ struct mg_dmg_reply { ...@@ -2309,17 +2309,17 @@ struct mg_dmg_reply {
* *
* [source,c] * [source,c]
* ----- * -----
* reply = mg_dmg_create_reply(&nc->send_mbuf, msg); * reply = mg_dns_create_reply(&nc->send_mbuf, msg);
* for (i = 0; i < msg->num_questions; i++) { * for (i = 0; i < msg->num_questions; i++) {
* rr = &msg->questions[i]; * rr = &msg->questions[i];
* if (rr->rtype == MG_DNS_A_RECORD) { * if (rr->rtype == MG_DNS_A_RECORD) {
* mg_dmg_reply_record(&reply, rr, 3600, &dummy_ip_addr, 4); * mg_dns_reply_record(&reply, rr, 3600, &dummy_ip_addr, 4);
* } * }
* } * }
* mg_dmg_send_reply(nc, &reply); * mg_dns_send_reply(nc, &reply);
* ----- * -----
*/ */
struct mg_dmg_reply mg_dmg_create_reply(struct mbuf *, struct mg_dmg_message *); struct mg_dns_reply mg_dns_create_reply(struct mbuf *, struct mg_dns_message *);
/* /*
* Append a DNS reply record to the IO buffer and to the DNS message. * Append a DNS reply record to the IO buffer and to the DNS message.
...@@ -2329,7 +2329,7 @@ struct mg_dmg_reply mg_dmg_create_reply(struct mbuf *, struct mg_dmg_message *); ...@@ -2329,7 +2329,7 @@ struct mg_dmg_reply mg_dmg_create_reply(struct mbuf *, struct mg_dmg_message *);
* *
* Returns -1 on error. * Returns -1 on error.
*/ */
int mg_dmg_reply_record(struct mg_dmg_reply *, struct mg_dmg_resource_record *, int mg_dns_reply_record(struct mg_dns_reply *, struct mg_dns_resource_record *,
const char *, int, int, const void *, size_t); const char *, int, int, const void *, size_t);
/* /*
...@@ -2338,13 +2338,13 @@ int mg_dmg_reply_record(struct mg_dmg_reply *, struct mg_dmg_resource_record *, ...@@ -2338,13 +2338,13 @@ int mg_dmg_reply_record(struct mg_dmg_reply *, struct mg_dmg_resource_record *,
* The DNS data is stored in an IO buffer pointed by reply structure in `r`. * The DNS data is stored in an IO buffer pointed by reply structure in `r`.
* This function mutates the content of that buffer in order to ensure that * This function mutates the content of that buffer in order to ensure that
* the DNS header reflects size and flags of the mssage, that might have been * the DNS header reflects size and flags of the mssage, that might have been
* updated either with `mg_dmg_reply_record` or by direct manipulation of * updated either with `mg_dns_reply_record` or by direct manipulation of
* `r->message`. * `r->message`.
* *
* Once sent, the IO buffer will be trimmed unless the reply IO buffer * Once sent, the IO buffer will be trimmed unless the reply IO buffer
* is the connection's send buffer and the connection is not in UDP mode. * is the connection's send buffer and the connection is not in UDP mode.
*/ */
int mg_dmg_send_reply(struct mg_connection *, struct mg_dmg_reply *); int mg_dns_send_reply(struct mg_connection *, struct mg_dns_reply *);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -2369,7 +2369,7 @@ int mg_dmg_send_reply(struct mg_connection *, struct mg_dmg_reply *); ...@@ -2369,7 +2369,7 @@ int mg_dmg_send_reply(struct mg_connection *, struct mg_dmg_reply *);
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef void (*mg_resolve_callback_t)(struct mg_dmg_message *, void *); typedef void (*mg_resolve_callback_t)(struct mg_dns_message *, void *);
/* Options for `mg_resolve_async_opt`. */ /* Options for `mg_resolve_async_opt`. */
struct mg_resolve_async_opts { struct mg_resolve_async_opts {
...@@ -2395,14 +2395,14 @@ int mg_resolve_async(struct mg_mgr *, const char *, int, mg_resolve_callback_t, ...@@ -2395,14 +2395,14 @@ int mg_resolve_async(struct mg_mgr *, const char *, int, mg_resolve_callback_t,
* will receive a NULL `msg`. * will receive a NULL `msg`.
* *
* The DNS answers can be extracted with `mg_next_record` and * The DNS answers can be extracted with `mg_next_record` and
* `mg_dmg_parse_record_data`: * `mg_dns_parse_record_data`:
* *
* [source,c] * [source,c]
* ---- * ----
* struct in_addr ina; * struct in_addr ina;
* struct mg_dmg_resource_record *rr = mg_next_record(msg, MG_DNS_A_RECORD, * struct mg_dns_resource_record *rr = mg_next_record(msg, MG_DNS_A_RECORD,
* NULL); * NULL);
* mg_dmg_parse_record_data(msg, rr, &ina, sizeof(ina)); * mg_dns_parse_record_data(msg, rr, &ina, sizeof(ina));
* ---- * ----
*/ */
int mg_resolve_async_opt(struct mg_mgr *, const char *, int, int mg_resolve_async_opt(struct mg_mgr *, const char *, int,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment