diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-06-01 15:02:08 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-06-07 10:39:48 +0300 |
commit | 729e062d89d4ead006fa837675ed2d0d2b803ae2 (patch) | |
tree | 74aab7df3a151089663093461cdd1ad10af5702f /src/dnsproxy.c | |
parent | 6ca02c55add42f4d25114c77de9ef020221e7ab8 (diff) | |
download | connman-729e062d89d4ead006fa837675ed2d0d2b803ae2.tar.gz connman-729e062d89d4ead006fa837675ed2d0d2b803ae2.tar.bz2 connman-729e062d89d4ead006fa837675ed2d0d2b803ae2.zip |
dnsproxy: Randomize the transaction id
Diffstat (limited to 'src/dnsproxy.c')
-rw-r--r-- | src/dnsproxy.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/dnsproxy.c b/src/dnsproxy.c index 49651a25..ea7a1222 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -24,6 +24,7 @@ #endif #include <errno.h> +#include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdint.h> @@ -183,10 +184,14 @@ static int cache_refcount; static GSList *server_list = NULL; static GSList *request_list = NULL; static GSList *request_pending_list = NULL; -static guint16 request_id = 0x0000; static GHashTable *listener_table = NULL; static time_t next_refresh; +static guint16 get_id() +{ + return random(); +} + static int protocol_offset(int protocol) { switch (protocol) { @@ -2383,13 +2388,9 @@ static gboolean tcp_listener_event(GIOChannel *channel, GIOCondition condition, req->client_sk = client_sk; req->protocol = IPPROTO_TCP; - request_id += 2; - if (request_id == 0x0000 || request_id == 0xffff) - request_id += 2; - req->srcid = buf[2] | (buf[3] << 8); - req->dstid = request_id; - req->altid = request_id + 1; + req->dstid = get_id(); + req->altid = get_id(); req->request_len = len; buf[2] = req->dstid & 0xff; @@ -2502,13 +2503,9 @@ static gboolean udp_listener_event(GIOChannel *channel, GIOCondition condition, req->client_sk = 0; req->protocol = IPPROTO_UDP; - request_id += 2; - if (request_id == 0x0000 || request_id == 0xffff) - request_id += 2; - req->srcid = buf[0] | (buf[1] << 8); - req->dstid = request_id; - req->altid = request_id + 1; + req->dstid = get_id(); + req->altid = get_id(); req->request_len = len; buf[0] = req->dstid & 0xff; @@ -2786,6 +2783,8 @@ int __connman_dnsproxy_init(void) DBG(""); + srandom(time(NULL)); + listener_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); err = __connman_dnsproxy_add_listener("lo"); |