diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-09-24 20:48:33 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-09-24 20:48:33 +0200 |
commit | 17b2c99a8bbc4f760114e7b7fa2e0a15570e288d (patch) | |
tree | 683f8dac5bd6f334e02a0705c7749afa307cd9bd /plugins | |
parent | 6589d555200e06835d5a8eb38fb87dc1b9ae6bf1 (diff) | |
download | connman-17b2c99a8bbc4f760114e7b7fa2e0a15570e288d.tar.gz connman-17b2c99a8bbc4f760114e7b7fa2e0a15570e288d.tar.bz2 connman-17b2c99a8bbc4f760114e7b7fa2e0a15570e288d.zip |
Define protocol_offset() for DNS transport layer offset
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/dnsproxy.c | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/plugins/dnsproxy.c b/plugins/dnsproxy.c index ac184900..ca58df5d 100644 --- a/plugins/dnsproxy.c +++ b/plugins/dnsproxy.c @@ -116,6 +116,21 @@ static guint udp_listener_watch = 0; static GIOChannel *tcp_listener_channel = NULL; static guint tcp_listener_watch = 0; +static int protocol_offset(int protocol) +{ + switch (protocol) { + case IPPROTO_UDP: + return 0; + + case IPPROTO_TCP: + return 2; + + default: + return -EINVAL; + } + +} + static struct request_data *find_request(guint16 id) { GSList *list; @@ -167,22 +182,12 @@ static void send_response(int sk, unsigned char *buf, int len, int protocol) { struct domain_hdr *hdr; - int err, offset; + int err, offset = protocol_offset(protocol); DBG(""); - switch (protocol) { - case IPPROTO_UDP: - offset = 0; - break; - - case IPPROTO_TCP: - offset = 2; - break; - - default: + if (offset < 0) return; - } if (len < 12) return; @@ -350,21 +355,10 @@ static int forward_dns_reply(unsigned char *reply, int reply_len, int protocol) { struct domain_hdr *hdr; struct request_data *req; - unsigned char offset; - int dns_id, sk, err; + int dns_id, sk, err, offset = protocol_offset(protocol); - switch (protocol) { - case IPPROTO_UDP: - offset = 0; - break; - - case IPPROTO_TCP: - offset = 2; - break; - - default: - return -EINVAL; - } + if (offset < 0) + return offset; hdr = (void *)(reply + offset); dns_id = reply[offset] | reply[offset + 1] << 8; |