2 This file is part of GNUnet
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file dns/dnsparser.c
23 * @brief helper library to parse DNS packets.
24 * @author Philipp Toelke
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_dnsparser_lib.h"
32 GNUNET_NETWORK_STRUCT_BEGIN
34 /* FIXME: replace this one with the one from tcpip_tun.h!? */
36 * Head of a any DNS message.
38 struct GNUNET_TUN_DnsHeader
41 * Request/response ID. (NBO)
43 uint16_t id GNUNET_PACKED;
46 * Flags for the operation.
48 struct GNUNET_DNSPARSER_Flags flags;
51 * number of questions (NBO)
53 uint16_t query_count GNUNET_PACKED;
56 * number of answers (NBO)
58 uint16_t answer_rcount GNUNET_PACKED;
61 * number of authority-records (NBO)
63 uint16_t authority_rcount GNUNET_PACKED;
66 * number of additional records (NBO)
68 uint16_t additional_rcount GNUNET_PACKED;
78 * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
80 uint16_t type GNUNET_PACKED;
83 * Desired class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
85 uint16_t class GNUNET_PACKED;
90 * General DNS record prefix.
95 * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
97 uint16_t type GNUNET_PACKED;
100 * Record class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO)
102 uint16_t class GNUNET_PACKED;
105 * Expiration for the record (in seconds). (NBO)
107 uint32_t ttl GNUNET_PACKED;
110 * Number of bytes of data that follow. (NBO)
112 uint16_t data_len GNUNET_PACKED;
117 * Payload of DNS SOA record (header).
122 * The version number of the original copy of the zone. (NBO)
124 uint32_t serial GNUNET_PACKED;
127 * Time interval before the zone should be refreshed. (NBO)
129 uint32_t refresh GNUNET_PACKED;
132 * Time interval that should elapse before a failed refresh should
135 uint32_t retry GNUNET_PACKED;
138 * Time value that specifies the upper limit on the time interval
139 * that can elapse before the zone is no longer authoritative. (NBO)
141 uint32_t expire GNUNET_PACKED;
144 * The bit minimum TTL field that should be exported with any RR
145 * from this zone. (NBO)
147 uint32_t minimum GNUNET_PACKED;
152 * Payload of DNS SRV record (header).
158 * Preference for this entry (lower value is higher preference). Clients
159 * will contact hosts from the lowest-priority group first and fall back
160 * to higher priorities if the low-priority entries are unavailable. (NBO)
162 uint16_t prio GNUNET_PACKED;
165 * Relative weight for records with the same priority. Clients will use
166 * the hosts of the same (lowest) priority with a probability proportional
167 * to the weight given. (NBO)
169 uint16_t weight GNUNET_PACKED;
172 * TCP or UDP port of the service. (NBO)
174 uint16_t port GNUNET_PACKED;
176 /* followed by 'target' name */
179 GNUNET_NETWORK_STRUCT_END
183 * Parse name inside of a DNS query or record.
185 * @param udp_payload entire UDP payload
186 * @param udp_payload_length length of udp_payload
187 * @param off pointer to the offset of the name to parse in the udp_payload (to be
188 * incremented by the size of the name)
189 * @param depth current depth of our recursion (to prevent stack overflow)
190 * @return name as 0-terminated C string on success, NULL if the payload is malformed
193 parse_name (const char *udp_payload,
194 size_t udp_payload_length,
198 const uint8_t *input = (const uint8_t *) udp_payload;
205 ret = GNUNET_strdup ("");
208 if (*off >= udp_payload_length)
218 if (*off + 1 + len > udp_payload_length)
220 GNUNET_asprintf (&tmp,
224 &udp_payload[*off + 1]);
229 else if ((64 | 128) == (len & (64 | 128)) )
232 goto error; /* hard bound on stack to prevent "infinite" recursion, disallow! */
233 /* pointer to string */
234 if (*off + 1 > udp_payload_length)
236 xoff = ((len - (64 | 128)) << 8) + input[*off+1];
237 xstr = parse_name (udp_payload,
243 GNUNET_asprintf (&tmp,
250 if (strlen (ret) > udp_payload_length)
251 goto error; /* we are looping (building an infinite string) */
253 /* pointers always terminate names */
258 /* neither pointer nor inline string, not supported... */
263 ret[strlen(ret)-1] = '\0'; /* eat tailing '.' */
272 * Parse a DNS query entry.
274 * @param udp_payload entire UDP payload
275 * @param udp_payload_length length of udp_payload
276 * @param off pointer to the offset of the query to parse in the udp_payload (to be
277 * incremented by the size of the query)
278 * @param q where to write the query information
279 * @return GNUNET_OK on success, GNUNET_SYSERR if the query is malformed
282 parse_query (const char *udp_payload,
283 size_t udp_payload_length,
285 struct GNUNET_DNSPARSER_Query *q)
288 struct query_line ql;
290 name = parse_name (udp_payload,
294 return GNUNET_SYSERR;
296 if (*off + sizeof (struct query_line) > udp_payload_length)
297 return GNUNET_SYSERR;
298 memcpy (&ql, &udp_payload[*off], sizeof (ql));
300 q->type = ntohs (ql.type);
301 q->class = ntohs (ql.class);
307 * Parse a DNS record entry.
309 * @param udp_payload entire UDP payload
310 * @param udp_payload_length length of udp_payload
311 * @param off pointer to the offset of the record to parse in the udp_payload (to be
312 * incremented by the size of the record)
313 * @param r where to write the record information
314 * @return GNUNET_OK on success, GNUNET_SYSERR if the record is malformed
317 parse_record (const char *udp_payload,
318 size_t udp_payload_length,
320 struct GNUNET_DNSPARSER_Record *r)
323 struct record_line rl;
332 name = parse_name (udp_payload,
336 return GNUNET_SYSERR;
338 if (*off + sizeof (struct record_line) > udp_payload_length)
339 return GNUNET_SYSERR;
340 memcpy (&rl, &udp_payload[*off], sizeof (rl));
341 (*off) += sizeof (rl);
342 r->type = ntohs (rl.type);
343 r->class = ntohs (rl.class);
344 r->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
346 data_len = ntohs (rl.data_len);
347 if (*off + data_len > udp_payload_length)
348 return GNUNET_SYSERR;
351 case GNUNET_DNSPARSER_TYPE_NS:
352 case GNUNET_DNSPARSER_TYPE_CNAME:
353 case GNUNET_DNSPARSER_TYPE_PTR:
355 r->data.hostname = parse_name (udp_payload,
358 if ( (NULL == r->data.hostname) ||
359 (old_off + data_len != *off) )
360 return GNUNET_SYSERR;
362 case GNUNET_DNSPARSER_TYPE_SOA:
364 r->data.soa = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_SoaRecord));
365 r->data.soa->mname = parse_name (udp_payload,
368 r->data.soa->rname = parse_name (udp_payload,
371 if ( (NULL == r->data.soa->mname) ||
372 (NULL == r->data.soa->rname) ||
373 (*off + sizeof (struct soa_data) > udp_payload_length) )
374 return GNUNET_SYSERR;
375 memcpy (&soa, &udp_payload[*off], sizeof (struct soa_data));
376 r->data.soa->serial = ntohl (soa.serial);
377 r->data.soa->refresh = ntohl (soa.refresh);
378 r->data.soa->retry = ntohl (soa.retry);
379 r->data.soa->expire = ntohl (soa.expire);
380 r->data.soa->minimum_ttl = ntohl (soa.minimum);
381 (*off) += sizeof (struct soa_data);
382 if (old_off + data_len != *off)
383 return GNUNET_SYSERR;
385 case GNUNET_DNSPARSER_TYPE_MX:
387 if (*off + sizeof (uint16_t) > udp_payload_length)
388 return GNUNET_SYSERR;
389 memcpy (&mxpref, &udp_payload[*off], sizeof (uint16_t));
390 (*off) += sizeof (uint16_t);
391 r->data.mx = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_MxRecord));
392 r->data.mx->preference = ntohs (mxpref);
393 r->data.mx->mxhost = parse_name (udp_payload,
396 if (old_off + data_len != *off)
397 return GNUNET_SYSERR;
399 case GNUNET_DNSPARSER_TYPE_SRV:
401 return GNUNET_SYSERR; /* all valid srv names must start with "_" */
402 if (NULL == strstr (r->name, "._"))
403 return GNUNET_SYSERR; /* necessary string from "._$PROTO" not present */
405 if (*off + sizeof (struct srv_data) > udp_payload_length)
406 return GNUNET_SYSERR;
407 memcpy (&srv, &udp_payload[*off], sizeof (struct srv_data));
408 (*off) += sizeof (struct srv_data);
409 r->data.srv = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_SrvRecord));
410 r->data.srv->priority = ntohs (srv.prio);
411 r->data.srv->weight = ntohs (srv.weight);
412 r->data.srv->port = ntohs (srv.port);
413 /* parse 'data.hostname' into components, which are
414 "_$SERVICE._$PROTO.$DOMAIN_NAME" */
415 ndup = GNUNET_strdup (r->name);
416 tok = strtok (ndup, ".");
417 GNUNET_assert ('_' == *tok);
418 r->data.srv->service = GNUNET_strdup (&tok[1]);
419 tok = strtok (NULL, ".");
422 GNUNET_free (r->data.srv);
424 return GNUNET_SYSERR;
426 r->data.srv->proto = GNUNET_strdup (&tok[1]);
427 tok = strtok (NULL, ".");
430 GNUNET_free (r->data.srv);
432 return GNUNET_SYSERR;
434 r->data.srv->domain_name = GNUNET_strdup (tok);
436 r->data.srv->target = parse_name (udp_payload,
439 if (old_off + data_len != *off)
440 return GNUNET_SYSERR;
443 r->data.raw.data = GNUNET_malloc (data_len);
444 r->data.raw.data_len = data_len;
445 memcpy (r->data.raw.data, &udp_payload[*off], data_len);
454 * Parse a UDP payload of a DNS packet in to a nice struct for further
455 * processing and manipulation.
457 * @param udp_payload wire-format of the DNS packet
458 * @param udp_payload_length number of bytes in udp_payload
459 * @return NULL on error, otherwise the parsed packet
461 struct GNUNET_DNSPARSER_Packet *
462 GNUNET_DNSPARSER_parse (const char *udp_payload,
463 size_t udp_payload_length)
465 struct GNUNET_DNSPARSER_Packet *p;
466 const struct GNUNET_TUN_DnsHeader *dns;
471 if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader))
473 dns = (const struct GNUNET_TUN_DnsHeader *) udp_payload;
474 off = sizeof (struct GNUNET_TUN_DnsHeader);
475 p = GNUNET_malloc (sizeof (struct GNUNET_DNSPARSER_Packet));
476 p->flags = dns->flags;
478 n = ntohs (dns->query_count);
481 p->queries = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Query));
485 parse_query (udp_payload,
491 n = ntohs (dns->answer_rcount);
494 p->answers = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record));
498 parse_record (udp_payload,
504 n = ntohs (dns->authority_rcount);
507 p->authority_records = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record));
508 p->num_authority_records = n;
511 parse_record (udp_payload,
514 &p->authority_records[i]))
517 n = ntohs (dns->additional_rcount);
520 p->additional_records = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record));
521 p->num_additional_records = n;
524 parse_record (udp_payload,
527 &p->additional_records[i]))
532 GNUNET_DNSPARSER_free_packet (p);
538 * Free SOA information record.
540 * @param soa record to free
543 free_soa (struct GNUNET_DNSPARSER_SoaRecord *soa)
547 GNUNET_free_non_null (soa->mname);
548 GNUNET_free_non_null (soa->rname);
554 * Free SRV information record.
556 * @param srv record to free
559 free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv)
563 GNUNET_free_non_null (srv->target);
564 GNUNET_free_non_null (srv->domain_name);
565 GNUNET_free_non_null (srv->proto);
566 GNUNET_free_non_null (srv->service);
572 * Free MX information record.
574 * @param mx record to free
577 free_mx (struct GNUNET_DNSPARSER_MxRecord *mx)
581 GNUNET_free_non_null (mx->mxhost);
587 free_record (struct GNUNET_DNSPARSER_Record *r)
589 GNUNET_free_non_null (r->name);
592 case GNUNET_DNSPARSER_TYPE_MX:
593 free_mx (r->data.mx);
595 case GNUNET_DNSPARSER_TYPE_SOA:
596 free_soa (r->data.soa);
598 case GNUNET_DNSPARSER_TYPE_SRV:
599 free_srv (r->data.srv);
601 case GNUNET_DNSPARSER_TYPE_NS:
602 case GNUNET_DNSPARSER_TYPE_CNAME:
603 case GNUNET_DNSPARSER_TYPE_PTR:
604 GNUNET_free_non_null (r->data.hostname);
607 GNUNET_free_non_null (r->data.raw.data);
614 * Free memory taken by a packet.
616 * @param p packet to free
619 GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p)
623 for (i=0;i<p->num_queries;i++)
624 GNUNET_free_non_null (p->queries[i].name);
625 GNUNET_free_non_null (p->queries);
626 for (i=0;i<p->num_answers;i++)
627 free_record (&p->answers[i]);
628 GNUNET_free_non_null (p->answers);
629 for (i=0;i<p->num_authority_records;i++)
630 free_record (&p->authority_records[i]);
631 GNUNET_free_non_null (p->authority_records);
632 for (i=0;i<p->num_additional_records;i++)
633 free_record (&p->additional_records[i]);
634 GNUNET_free_non_null (p->additional_records);
639 /* ********************** DNS packet assembly code **************** */
643 * Add a DNS name to the UDP packet at the given location.
645 * @param dst where to write the name
646 * @param dst_len number of bytes in dst
647 * @param off pointer to offset where to write the name (increment by bytes used)
648 * must not be changed if there is an error
649 * @param name name to write
650 * @return GNUNET_SYSERR if 'name' is invalid
651 * GNUNET_NO if 'name' did not fit
652 * GNUNET_OK if 'name' was added to 'dst'
666 return GNUNET_SYSERR;
668 if (start + strlen (name) + 2 > dst_len)
673 dot = strchr (name, '.');
678 if ( (len >= 64) || (len == 0) )
679 return GNUNET_NO; /* segment too long or empty */
680 dst[pos++] = (char) (uint8_t) len;
681 memcpy (&dst[pos], name, len);
683 name += len + 1; /* also skip dot */
686 dst[pos++] = '\0'; /* terminator */
693 * Add a DNS query to the UDP packet at the given location.
695 * @param dst where to write the query
696 * @param dst_len number of bytes in dst
697 * @param off pointer to offset where to write the query (increment by bytes used)
698 * must not be changed if there is an error
699 * @param query query to write
700 * @return GNUNET_SYSERR if 'query' is invalid
701 * GNUNET_NO if 'query' did not fit
702 * GNUNET_OK if 'query' was added to 'dst'
705 add_query (char *dst,
708 const struct GNUNET_DNSPARSER_Query *query)
711 struct query_line ql;
713 ret = add_name (dst, dst_len - sizeof (struct query_line), off, query->name);
714 if (ret != GNUNET_OK)
716 ql.type = htons (query->type);
717 ql.class = htons (query->class);
718 memcpy (&dst[*off], &ql, sizeof (ql));
719 (*off) += sizeof (ql);
725 * Add an MX record to the UDP packet at the given location.
727 * @param dst where to write the mx record
728 * @param dst_len number of bytes in dst
729 * @param off pointer to offset where to write the mx information (increment by bytes used);
730 * can also change if there was an error
731 * @param mx mx information to write
732 * @return GNUNET_SYSERR if 'mx' is invalid
733 * GNUNET_NO if 'mx' did not fit
734 * GNUNET_OK if 'mx' was added to 'dst'
740 const struct GNUNET_DNSPARSER_MxRecord *mx)
744 if (*off + sizeof (uint16_t) > dst_len)
746 mxpref = htons (mx->preference);
747 memcpy (&dst[*off], &mxpref, sizeof (mxpref));
748 (*off) += sizeof (mxpref);
749 return add_name (dst, dst_len, off, mx->mxhost);
754 * Add an SOA record to the UDP packet at the given location.
756 * @param dst where to write the SOA record
757 * @param dst_len number of bytes in dst
758 * @param off pointer to offset where to write the SOA information (increment by bytes used)
759 * can also change if there was an error
760 * @param soa SOA information to write
761 * @return GNUNET_SYSERR if 'soa' is invalid
762 * GNUNET_NO if 'soa' did not fit
763 * GNUNET_OK if 'soa' was added to 'dst'
769 const struct GNUNET_DNSPARSER_SoaRecord *soa)
774 if ( (GNUNET_OK != (ret = add_name (dst,
778 (GNUNET_OK != (ret = add_name (dst,
783 if (*off + sizeof (struct soa_data) > dst_len)
785 sd.serial = htonl (soa->serial);
786 sd.refresh = htonl (soa->refresh);
787 sd.retry = htonl (soa->retry);
788 sd.expire = htonl (soa->expire);
789 sd.minimum = htonl (soa->minimum_ttl);
790 memcpy (&dst[*off], &sd, sizeof (sd));
791 (*off) += sizeof (sd);
797 * Add an SRV record to the UDP packet at the given location.
799 * @param dst where to write the SRV record
800 * @param dst_len number of bytes in dst
801 * @param off pointer to offset where to write the SRV information (increment by bytes used)
802 * can also change if there was an error
803 * @param srv SRV information to write
804 * @return GNUNET_SYSERR if 'srv' is invalid
805 * GNUNET_NO if 'srv' did not fit
806 * GNUNET_OK if 'srv' was added to 'dst'
812 const struct GNUNET_DNSPARSER_SrvRecord *srv)
817 if (*off + sizeof (struct srv_data) > dst_len)
819 sd.prio = htons (srv->priority);
820 sd.weight = htons (srv->weight);
821 sd.port = htons (srv->port);
822 memcpy (&dst[*off], &sd, sizeof (sd));
823 (*off) += sizeof (sd);
824 if (GNUNET_OK != (ret = add_name (dst,
834 * Add a DNS record to the UDP packet at the given location.
836 * @param dst where to write the query
837 * @param dst_len number of bytes in dst
838 * @param off pointer to offset where to write the query (increment by bytes used)
839 * must not be changed if there is an error
840 * @param record record to write
841 * @return GNUNET_SYSERR if 'record' is invalid
842 * GNUNET_NO if 'record' did not fit
843 * GNUNET_OK if 'record' was added to 'dst'
846 add_record (char *dst,
849 const struct GNUNET_DNSPARSER_Record *record)
854 struct record_line rl;
858 /* for SRV records, we can create the name from the details
859 of the record if needed */
861 if ( (GNUNET_DNSPARSER_TYPE_SRV == record->type) &&
863 GNUNET_asprintf (&name,
865 record->data.srv->service,
866 record->data.srv->proto,
867 record->data.srv->domain_name);
868 ret = add_name (dst, dst_len - sizeof (struct record_line), off, name);
869 if (name != record->name)
871 if (GNUNET_OK != ret)
873 /* '*off' is now the position where we will need to write the record line */
875 pos = *off + sizeof (struct record_line);
876 switch (record->type)
878 case GNUNET_DNSPARSER_TYPE_MX:
879 ret = add_mx (dst, dst_len, &pos, record->data.mx);
881 case GNUNET_DNSPARSER_TYPE_SOA:
882 ret = add_soa (dst, dst_len, &pos, record->data.soa);
884 case GNUNET_DNSPARSER_TYPE_NS:
885 case GNUNET_DNSPARSER_TYPE_CNAME:
886 case GNUNET_DNSPARSER_TYPE_PTR:
887 ret = add_name (dst, dst_len, &pos, record->data.hostname);
889 case GNUNET_DNSPARSER_TYPE_SRV:
890 ret = add_srv (dst, dst_len, &pos, record->data.srv);
893 if (pos + record->data.raw.data_len > dst_len)
898 memcpy (&dst[pos], record->data.raw.data, record->data.raw.data_len);
899 pos += record->data.raw.data_len;
903 if (GNUNET_OK != ret)
909 if (pos - (*off + sizeof (struct record_line)) > UINT16_MAX)
911 /* record data too long */
915 rl.type = htons (record->type);
916 rl.class = htons (record->class);
917 rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value / 1000); /* in seconds */
918 rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct record_line))));
919 memcpy (&dst[*off], &rl, sizeof (struct record_line));
926 * Given a DNS packet, generate the corresponding UDP payload.
927 * Note that we do not attempt to pack the strings with pointers
928 * as this would complicate the code and this is about being
929 * simple and secure, not fast, fancy and broken like bind.
931 * @param p packet to pack
932 * @param max maximum allowed size for the resulting UDP payload
933 * @param buf set to a buffer with the packed message
934 * @param buf_length set to the length of buf
935 * @return GNUNET_SYSERR if 'p' is invalid
936 * GNUNET_NO if 'p' was truncated (but there is still a result in 'buf')
937 * GNUNET_OK if 'p' was packed completely into '*buf'
940 GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
945 struct GNUNET_TUN_DnsHeader dns;
952 if ( (p->num_queries > UINT16_MAX) ||
953 (p->num_answers > UINT16_MAX) ||
954 (p->num_authority_records > UINT16_MAX) ||
955 (p->num_additional_records > UINT16_MAX) )
956 return GNUNET_SYSERR;
958 dns.flags = p->flags;
959 dns.query_count = htons (p->num_queries);
960 dns.answer_rcount = htons (p->num_answers);
961 dns.authority_rcount = htons (p->num_authority_records);
962 dns.additional_rcount = htons (p->num_additional_records);
964 off = sizeof (struct GNUNET_TUN_DnsHeader);
966 for (i=0;i<p->num_queries;i++)
968 ret = add_query (tmp, sizeof (tmp), &off, &p->queries[i]);
969 if (GNUNET_SYSERR == ret)
970 return GNUNET_SYSERR;
971 if (GNUNET_NO == ret)
973 dns.query_count = htons ((uint16_t) (i-1));
978 for (i=0;i<p->num_answers;i++)
980 ret = add_record (tmp, sizeof (tmp), &off, &p->answers[i]);
981 if (GNUNET_SYSERR == ret)
982 return GNUNET_SYSERR;
983 if (GNUNET_NO == ret)
985 dns.answer_rcount = htons ((uint16_t) (i-1));
990 for (i=0;i<p->num_authority_records;i++)
992 ret = add_record (tmp, sizeof (tmp), &off, &p->authority_records[i]);
993 if (GNUNET_SYSERR == ret)
994 return GNUNET_SYSERR;
995 if (GNUNET_NO == ret)
997 dns.authority_rcount = htons ((uint16_t) (i-1));
1002 for (i=0;i<p->num_additional_records;i++)
1004 ret = add_record (tmp, sizeof (tmp), &off, &p->additional_records[i]);
1005 if (GNUNET_SYSERR == ret)
1006 return GNUNET_SYSERR;
1007 if (GNUNET_NO == ret)
1009 dns.additional_rcount = htons (i-1);
1015 if (GNUNET_YES == trc)
1016 dns.flags.message_truncated = 1;
1017 memcpy (tmp, &dns, sizeof (struct GNUNET_TUN_DnsHeader));
1019 *buf = GNUNET_malloc (off);
1021 memcpy (*buf, tmp, off);
1022 if (GNUNET_YES == trc)
1027 /* end of dnsparser.c */