- 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 + sizeof (struct answer_packet_list) -
- sizeof (struct answer_packet));
-
- answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
- answer->pkt.hdr.size = htons (len);
- answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE;
- answer->client = query_states[id].client;
-
- 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));
-
- memcpy (answer->pkt.from, query_states[id].remote_ip,
- query_states[id].addrlen);
- memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
- answer->pkt.addrlen = query_states[id].addrlen;
-
- 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);
- query_states[id].name = NULL;
-
- struct dns_query_line *dque =
- (struct dns_query_line *) (dpkt->data + (query_states[id].namelen));
- dque->type = htons (28); /* AAAA */
- dque->class = htons (1); /* IN */
-
- char *anname =
- (char *) (dpkt->data + (query_states[id].namelen) +
- sizeof (struct dns_query_line));
- memcpy (anname, "\xc0\x0c", 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 (28); /* AAAA */
- drec_data->class = htons (1); /* IN */
-
- /* FIXME: read the TTL from block:
- * GNUNET_TIME_absolute_get_remaining(rec->expiration_time)
- *
- * But how to get the seconds out of this?
- */
- drec_data->ttl = htonl (3600);
- drec_data->data_len = htons (16);
-
- /* Calculate at which offset in the packet the IPv6-Address belongs, it is
- * filled in by the daemon-vpn */
- answer->pkt.addroffset =
- htons ((unsigned short) ((unsigned long) (&drec_data->data) -
- (unsigned long) (&answer->pkt)));
-
- GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
-
- if (server_notify == NULL)
- server_notify =
- GNUNET_SERVER_notify_transmit_ready (answer->client, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer, NULL);
-}