From 51de7bc59bb05f965d493b03dd66ba22d126a753 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 16 Jun 2010 16:22:33 +0200 Subject: [PATCH] Remove magic constants from dns request parsing code --- plugins/dnsproxy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/dnsproxy.c b/plugins/dnsproxy.c index 5a77c5f..2cb2f41 100644 --- a/plugins/dnsproxy.c +++ b/plugins/dnsproxy.c @@ -401,6 +401,8 @@ static struct connman_notifier dnsproxy_notifier = { .offline_mode = dnsproxy_offline_mode, }; +static unsigned char opt_edns0_type[2] = { 0x00, 0x29 }; + static int parse_request(unsigned char *buf, int len, char *name, unsigned int size) { @@ -423,8 +425,8 @@ static int parse_request(unsigned char *buf, int len, memset(name, 0, size); - ptr = buf + 12; - remain = len - 12; + ptr = buf + sizeof(struct domain_hdr); + remain = len - sizeof(struct domain_hdr); while (remain > 0) { uint8_t len = *ptr; @@ -447,7 +449,7 @@ static int parse_request(unsigned char *buf, int len, } if (last_label && arcount && remain >= 9 && last_label[4] == 0 && - last_label[5] == 0 && last_label[6] == 0x29) { + !memcmp(last_label + 5, opt_edns0_type, 2)) { uint16_t edns0_bufsize; edns0_bufsize = last_label[7] << 8 | last_label[8]; -- 2.7.4