[PATCH] dns: handle incoming packets in the separate dns_recv() function

Antony Pavlov antonynpavlov at gmail.com
Tue Jun 30 14:32:54 PDT 2015


The separation of incoming packets handling makes it much easier
to run barebox dns client on top of picotcp network stack in the future.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 net/dns.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/dns.c b/net/dns.c
index 0a8ce8b..0e16ea2 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -116,9 +116,8 @@ static int dns_send(char *name)
 	return ret;
 }
 
-static void dns_handler(void *ctx, char *packet, unsigned len)
+static void dns_recv(struct header *header, unsigned len)
 {
-	struct header *header;
 	unsigned char *p, *e, *s;
 	u16 type;
 	int found, stop, dlen;
@@ -127,7 +126,6 @@ static void dns_handler(void *ctx, char *packet, unsigned len)
 	debug("%s\n", __func__);
 
 	/* We sent 1 query. We want to see more that 1 answer. */
-	header = (struct header *)net_eth_to_udp_payload(packet);
 	if (ntohs(header->nqueries) != 1)
 		return;
 
@@ -140,7 +138,7 @@ static void dns_handler(void *ctx, char *packet, unsigned len)
 
 	/* Skip host name */
 	s = &header->data[0];
-	e = packet + len;
+	e = ((uint8_t *)header) + len;
 	for (p = s; p < e && *p != '\0'; p++)
 		continue;
 
@@ -194,6 +192,13 @@ static void dns_handler(void *ctx, char *packet, unsigned len)
 	}
 }
 
+static void dns_handler(void *ctx, char *packet, unsigned len)
+{
+	(void)ctx;
+	dns_recv((struct header *)net_eth_to_udp_payload(packet),
+		net_eth_to_udplen(packet));
+}
+
 IPaddr_t resolv(char *host)
 {
 	IPaddr_t ip;
-- 
2.1.4




More information about the barebox mailing list