+static void
+send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
+ struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls;
+
+ unsigned short id = pdns->s.id;
+
+ if (query_states[id].valid != GNUNET_YES) return;
+ query_states[id].valid = GNUNET_NO;
+
+ GNUNET_assert(query_states[id].namelen == 74);
+
+ size_t len = sizeof(struct answer_packet) - 1 \
+ + sizeof(struct dns_static) \
+ + 74 /* this is the length of a reverse ipv6-lookup */ \
+ + sizeof(struct dns_query_line) \
+ + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
+ + sizeof(struct dns_record_line) - 1 \
+ - 2 /* We do not know the lenght of the answer yet*/ \
+ - 2 /* No idea why... */ ;
+
+ struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
+ memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
+
+ answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
+ answer->pkt.hdr.size = htons(len);
+ answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV;
+
+ answer->pkt.from = query_states[id].remote_ip;
+
+ answer->pkt.to = query_states[id].local_ip;
+ answer->pkt.dst_port = query_states[id].local_port;
+
+ struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;
+
+ dpkt->s.id = id;
+ dpkt->s.aa = 1;
+ dpkt->s.qr = 1;
+ dpkt->s.ra = 1;
+ dpkt->s.qdcount = htons(1);
+ dpkt->s.ancount = htons(1);
+
+ memcpy(dpkt->data, query_states[id].name, query_states[id].namelen);
+ GNUNET_free(query_states[id].name);
+
+ struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen));
+ dque->type = htons(12); /* PTR */
+ dque->class = htons(1); /* IN */
+
+ char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line));
+ memcpy(anname, (char[]){0xc0, 0x0c}, 2);
+
+ struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2);
+ drec_data->type = htons(12); /* AAAA */
+ drec_data->class = htons(1); /* IN */
+ drec_data->ttl = htonl(3600); /* FIXME: read from block */
+
+ /* Calculate at which offset in the packet the length of the name and the
+ * name, it is filled in by the daemon-vpn */
+ answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data_len)-(unsigned long)(&answer->pkt)));
+
+ GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer);
+
+ GNUNET_SERVER_notify_transmit_ready(query_states[id].client,
+ len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer,
+ query_states[id].client);
+
+ /*
+ * build
+ * complete dns-packet with empty name in the answer
+ * provide offsett of the name
+ */
+}
+
+/**
+ * Receive a block from the dht.
+ */
+static void
+receive_dht(void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *const *get_path,
+ const struct GNUNET_PeerIdentity *const *put_path,
+ enum GNUNET_BLOCK_Type type,
+ size_t size,
+ const void *data) {
+
+ unsigned short id = ((struct receive_dht_cls*)cls)->id;
+ struct GNUNET_DHT_GetHandle* handle = ((struct receive_dht_cls*)cls)->handle;
+ GNUNET_free(cls);
+
+ GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS);
+
+ /* If no query with this id is pending, ignore the block */
+ if (query_states[id].valid != GNUNET_YES) return;
+ query_states[id].valid = GNUNET_NO;
+
+ const struct GNUNET_DNS_Record* rec = data;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Got block of size %d, peer: %08x, desc: %08x\n",
+ size,
+ *((unsigned int*)&rec->peer),
+ *((unsigned int*)&rec->service_descriptor));
+
+ size_t len = sizeof(struct answer_packet) - 1 \
+ + sizeof(struct dns_static) \
+ + query_states[id].namelen \
+ + sizeof(struct dns_query_line) \
+ + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \
+ + sizeof(struct dns_record_line) - 1 \
+ + 16; /* To hold the IPv6-Address */
+
+ struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*));
+ memset(answer, 0, len + 2*sizeof(struct answer_packet_list*));
+
+ answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
+ answer->pkt.hdr.size = htons(len);
+ answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE;
+
+ GNUNET_CRYPTO_hash(&rec->peer,
+ sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &answer->pkt.service_descr.peer);
+
+ memcpy(&answer->pkt.service_descr.service_descriptor,
+ &rec->service_descriptor,
+ sizeof(GNUNET_HashCode));
+ memcpy(&answer->pkt.service_descr.service_type,
+ &rec->service_type,
+ sizeof(answer->pkt.service_descr.service_type));
+ memcpy(&answer->pkt.service_descr.ports, &rec->ports, sizeof(answer->pkt.service_descr.ports));
+
+ answer->pkt.from = query_states[id].remote_ip;
+
+ answer->pkt.to = query_states[id].local_ip;
+ answer->pkt.dst_port = query_states[id].local_port;
+
+ struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data;