mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH] dns: handle incoming packets in the separate dns_recv() function
Date: Wed,  1 Jul 2015 00:32:54 +0300	[thread overview]
Message-ID: <1435699974-20530-1-git-send-email-antonynpavlov@gmail.com> (raw)

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


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

             reply	other threads:[~2015-06-30 21:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-30 21:32 Antony Pavlov [this message]
2015-07-01  5:34 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435699974-20530-1-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox