#endif
#include <errno.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
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) {
* name. In this case we end up in this branch.
*/
if (domain_len > 0) {
- memcpy(ptr + host_len + 1,
+ /*
+ * Note that we must use memmove() here,
+ * because the memory areas can overlap.
+ */
+ memmove(ptr + host_len + 1,
ptr + host_len + domain_len + 1,
reply_len - (ptr - reply + domain_len));
g_io_channel_unref(server->channel);
if (server->protocol == IPPROTO_UDP)
- connman_info("Removing DNS server %s", server->server);
+ DBG("Removing DNS server %s", server->server);
g_free(server->incoming_reply);
g_free(server->server);
if (protocol == IPPROTO_UDP) {
/* Enable new servers by default */
data->enabled = TRUE;
- connman_info("Adding DNS server %s", data->server);
+ DBG("Adding DNS server %s", data->server);
server_list = g_slist_append(server_list, data);
struct server_data *data = list->data;
if (enabled == FALSE) {
- connman_info("Enabling DNS server %s", data->server);
+ DBG("Enabling DNS server %s", data->server);
data->enabled = TRUE;
cache_invalidate();
cache_refresh();
} else {
- connman_info("Disabling DNS server %s", data->server);
+ DBG("Disabling DNS server %s", data->server);
data->enabled = FALSE;
cache_invalidate();
}
struct server_data *data = list->data;
if (g_strcmp0(data->interface, interface) == 0) {
- connman_info("Enabling DNS server %s", data->server);
+ DBG("Enabling DNS server %s", data->server);
data->enabled = TRUE;
} else {
- connman_info("Disabling DNS server %s", data->server);
+ DBG("Disabling DNS server %s", data->server);
data->enabled = FALSE;
}
}
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;
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;
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");