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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux