When we resolv hostname, we will append the domain name then we may
get question section mismatch error. After we get the DNS reply
we can remove the domain name again. This works well with one host
with only a A record, it may failed when the reply with many cnames
or additional records due to message compression error. But in a
local network we only resolv hostname will not meet these issues.
---
src/dnsproxy.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index 5c98af9..7a0c2d8 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -113,6 +113,7 @@ struct request_data {
gpointer resp;
gsize resplen;
struct listener_data *ifdata;
+ gboolean append_domain;
};
struct listener_data {
@@ -393,6 +394,7 @@ static int ns_resolv(struct server_data *server, struct
request_data *req,
if (err < 0)
return -EIO;
+ req->append_domain = TRUE;
req->numserv++;
}
@@ -428,6 +430,21 @@ static int forward_dns_reply(unsigned char *reply, int
reply_len, int protocol)
req->numresp++;
if (hdr->rcode == 0 || req->resp == NULL) {
+ if (req->append_domain == TRUE) {
+ unsigned char *ptr;
+ uint8_t len;
+ unsigned int remove_len;
+
+ ptr = reply + offset + sizeof(struct domain_hdr);
+ len = *ptr;
+ remove_len = strlen((const char *)ptr) - len - 1;
+
+ memmove(ptr + len + 1, ptr + len + remove_len + 1,
+ reply_len - (ptr - reply + remove_len));
+
+ reply_len = reply_len - remove_len;
+ }
+
g_free(req->resp);
req->resplen = 0;
@@ -1176,6 +1193,7 @@ static gboolean tcp_listener_event(GIOChannel *channel,
GIOCondition condition,
req->numserv = 0;
req->ifdata = (struct listener_data *) ifdata;
+ req->append_domain = FALSE;
request_list = g_slist_append(request_list, req);
for (list = server_list; list; list = list->next) {
@@ -1290,6 +1308,7 @@ static gboolean udp_listener_event(GIOChannel *channel,
GIOCondition condition,
req->numserv = 0;
req->ifdata = (struct listener_data *) ifdata;
req->timeout = g_timeout_add_seconds(5, request_timeout, req);
+ req->append_domain = FALSE;
request_list = g_slist_append(request_list, req);
return resolv(req, buf, query);
--
1.7.2.2
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman