send the dns-queries from daemon-vpn to service-dns
authorPhilipp Tölke <toelke@in.tum.de>
Tue, 7 Sep 2010 13:37:26 +0000 (13:37 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Tue, 7 Sep 2010 13:37:26 +0000 (13:37 +0000)
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-service-dns.c

index 8575345e024be0e09df4a0a1cdfe19d516d22380..72066844f05e3f6cda4ddd7f33bee2a0d543d379 100644 (file)
@@ -111,6 +111,16 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts
        GNUNET_SCHEDULER_add_read_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_from_helper, &helper_read, NULL);
 }
 
+size_t send_query(void* cls, size_t size, void* buf)
+{
+       struct query_packet* pkt = cls;
+       size_t len = ntohs(pkt->hdr.size);
+       memcpy(buf, cls, len);
+       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes.\n", len);
+       GNUNET_free(cls);
+       return len;
+}
+
 static void message_token(void *cls, void *client, const struct GNUNET_MessageHeader *message) {
        if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) return;
 
@@ -139,13 +149,16 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe
                struct ip_pkt *pkt = (struct ip_pkt*) message;
                struct ip_udp *udp = (struct ip_udp*) message;
                if (pkt->ip_hdr.proto == 0x11 && ntohl(udp->ip_hdr.dadr) == 0x0a0a0a02 && ntohs(udp->udp_hdr.dpt) == 53 ) {
-                       struct query_packet* query = alloca((sizeof query) + ntohs(udp->udp_hdr.len) - 7); /* 7 = 8 for the udp-header - 1 for the unsigned char data[1]; */
+                       size_t len = sizeof(struct query_packet*) + ntohs(udp->udp_hdr.len) - 7; /* 7 = 8 for the udp-header - 1 for the unsigned char data[1]; */
+                       struct query_packet* query = GNUNET_malloc(len);
                        query->hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS);
-                       query->hdr.size = htons((sizeof query) + ntohs(udp->udp_hdr.len) - 7);
+                       query->hdr.size = htons(len);
                        query->orig_to = pkt->ip_hdr.dadr;
                        query->orig_from = pkt->ip_hdr.sadr;
                        query->src_port = udp->udp_hdr.spt;
                        memcpy(query->data, udp->data, ntohs(udp->udp_hdr.len) - 8);
+                       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued sending\n");
+                       GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, query);
                }
        }
 
index 8abf19900b750a20c44398e39f0242f3c2492a58..e6508682c83ccc05558a353f2d7e2a0aeaad746c 100644 (file)
@@ -57,6 +57,9 @@ void unhijack(unsigned short port) {
 void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
 {
        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received query!\n");
+       struct query_packet* pkt = (struct query_packet*)message;
+
+       GNUNET_SERVER_receive_done(client, GNUNET_OK);
 }
 
 /**