GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions
DNS parser library

Helper library to parse DNS packets. More...

Data Structures

struct  GNUNET_DNSPARSER_Query
 A DNS query. More...
 
struct  GNUNET_DNSPARSER_MxRecord
 Information from MX records (RFC 1035). More...
 
struct  GNUNET_DNSPARSER_SrvRecord
 Information from SRV records (RFC 2782). More...
 
struct  GNUNET_DNSPARSER_CertRecord
 Information from CERT records (RFC 4034). More...
 
struct  GNUNET_DNSPARSER_SoaRecord
 Information from SOA records (RFC 1035). More...
 
struct  GNUNET_DNSPARSER_CaaRecord
 Information from CAA records (RFC 6844). More...
 
struct  GNUNET_DNSPARSER_RawRecord
 Binary record information (unparsed). More...
 
struct  GNUNET_DNSPARSER_Record
 A DNS response record. More...
 
struct  GNUNET_DNSPARSER_Packet
 Easy-to-process, parsed version of a DNS packet. More...
 

Macros

#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH   63
 Maximum length of a label in DNS. More...
 
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH   253
 Maximum length of a name in DNS. More...
 
#define GNUNET_DNSPARSER_TYPE_ANY   0
 A few common DNS types. More...
 
#define GNUNET_DNSPARSER_TYPE_A   1
 
#define GNUNET_DNSPARSER_TYPE_NS   2
 
#define GNUNET_DNSPARSER_TYPE_CNAME   5
 
#define GNUNET_DNSPARSER_TYPE_SOA   6
 
#define GNUNET_DNSPARSER_TYPE_PTR   12
 
#define GNUNET_DNSPARSER_TYPE_MX   15
 
#define GNUNET_DNSPARSER_TYPE_TXT   16
 
#define GNUNET_DNSPARSER_TYPE_RP   17
 
#define GNUNET_DNSPARSER_TYPE_AFSDB   18
 
#define GNUNET_DNSPARSER_TYPE_SIG   24
 
#define GNUNET_DNSPARSER_TYPE_KEY   25
 
#define GNUNET_DNSPARSER_TYPE_AAAA   28
 
#define GNUNET_DNSPARSER_TYPE_LOC   29
 
#define GNUNET_DNSPARSER_TYPE_SRV   33
 
#define GNUNET_DNSPARSER_TYPE_NAPTR   35
 
#define GNUNET_DNSPARSER_TYPE_KX   36
 
#define GNUNET_DNSPARSER_TYPE_CERT   37
 
#define GNUNET_DNSPARSER_TYPE_DNAME   39
 
#define GNUNET_DNSPARSER_TYPE_APL   42
 
#define GNUNET_DNSPARSER_TYPE_DS   43
 
#define GNUNET_DNSPARSER_TYPE_SSHFP   44
 
#define GNUNET_DNSPARSER_TYPE_IPSECKEY   45
 
#define GNUNET_DNSPARSER_TYPE_RRSIG   46
 
#define GNUNET_DNSPARSER_TYPE_NSEC   47
 
#define GNUNET_DNSPARSER_TYPE_DNSKEY   48
 
#define GNUNET_DNSPARSER_TYPE_DHCID   49
 
#define GNUNET_DNSPARSER_TYPE_NSEC3   50
 
#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM   51
 
#define GNUNET_DNSPARSER_TYPE_TLSA   52
 
#define GNUNET_DNSPARSER_TYPE_HIP   55
 
#define GNUNET_DNSPARSER_TYPE_CDS   59
 
#define GNUNET_DNSPARSER_TYPE_CDNSKEY   60
 
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY   61
 
#define GNUNET_DNSPARSER_TYPE_TKEY   249
 
#define GNUNET_DNSPARSER_TYPE_TSIG   250
 
#define GNUNET_DNSPARSER_TYPE_ALL   255
 
#define GNUNET_DNSPARSER_TYPE_URI   256
 
#define GNUNET_DNSPARSER_TYPE_CAA   257
 
#define GNUNET_DNSPARSER_TYPE_TA   32768
 

Enumerations

enum  GNUNET_DNSPARSER_CertType {
  GNUNET_DNSPARSER_CERTTYPE_RESERVED = 0, GNUNET_DNSPARSER_CERTTYPE_PKIX = 1, GNUNET_DNSPARSER_CERTTYPE_SKPI = 2, GNUNET_DNSPARSER_CERTTYPE_PGP = 3,
  GNUNET_DNSPARSER_CERTTYPE_IPKIX = 4, GNUNET_DNSPARSER_CERTTYPE_ISKPI = 5, GNUNET_DNSPARSER_CERTTYPE_IPGP = 6, GNUNET_DNSPARSER_CERTTYPE_ACPKIX = 7,
  GNUNET_DNSPARSER_CERTTYPE_IACKPIX = 8
}
 DNS CERT types as defined in RFC 4398. More...
 
enum  GNUNET_DNSPARSER_CertAlgorithm {
  GNUNET_DNSPARSER_CERTALGO_UNDEFINED = 0, GNUNET_DNSPARSER_CERTALGO_RSAMD5 = 1, GNUNET_DNSPARSER_CERTALGO_DH = 2, GNUNET_DNSPARSER_CERTALGO_DSASHA = 3,
  GNUNET_DNSPARSER_CERTALGO_RSRVD4 = 4, GNUNET_DNSPARSER_CERTALGO_RSASHA = 5, GNUNET_DNSPARSER_CERTALGO_DSANSEC3 = 6, GNUNET_DNSPARSER_CERTALGO_RSANSEC3 = 7,
  GNUNET_DNSPARSER_CERTALGO_RSASHA256 = 8, GNUNET_DNSPARSER_CERTALGO_RSRVD9 = 9, GNUNET_DNSPARSER_CERTALGO_RSASHA512 = 10, GNUNET_DNSPARSER_CERTALGO_GOST_R34 = 12,
  GNUNET_DNSPARSER_CERTALGO_ECDSA_P256SHA256 = 13, GNUNET_DNSPARSER_CERTALGO_ECDSA_P384SHA384 = 14
}
 DNSCERT algorithms as defined in http://www.iana.org/assignments/ dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml, under dns-sec-alg-numbers-1. More...
 

Functions

int GNUNET_DNSPARSER_check_label (const char *label)
 Check if a label in UTF-8 format can be coded into valid IDNA. More...
 
int GNUNET_DNSPARSER_check_name (const char *name)
 Check if a hostname in UTF-8 format can be coded into valid IDNA. More...
 
struct GNUNET_DNSPARSER_PacketGNUNET_DNSPARSER_parse (const char *udp_payload, size_t udp_payload_length)
 Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation. More...
 
void GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p)
 Free memory taken by a packet. More...
 
int GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
 Given a DNS packet p, generate the corresponding UDP payload. More...
 
int GNUNET_DNSPARSER_builder_add_name (char *dst, size_t dst_len, size_t *off, const char *name)
 Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as necessary. More...
 
int GNUNET_DNSPARSER_builder_add_query (char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Query *query)
 Add a DNS query to the UDP packet at the given location. More...
 
int GNUNET_DNSPARSER_builder_add_mx (char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_MxRecord *mx)
 Add an MX record to the UDP packet at the given location. More...
 
int GNUNET_DNSPARSER_builder_add_soa (char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SoaRecord *soa)
 Add an SOA record to the UDP packet at the given location. More...
 
int GNUNET_DNSPARSER_builder_add_cert (char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_CertRecord *cert)
 Add CERT record to the UDP packet at the given location. More...
 
int GNUNET_DNSPARSER_builder_add_srv (char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SrvRecord *srv)
 Add an SRV record to the UDP packet at the given location. More...
 
int GNUNET_DNSPARSER_parse_record (const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Record *r)
 Parse a DNS record entry. More...
 
char * GNUNET_DNSPARSER_parse_name (const char *udp_payload, size_t udp_payload_length, size_t *off)
 Parse name inside of a DNS query or record. More...
 
int GNUNET_DNSPARSER_parse_query (const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Query *q)
 Parse a DNS query entry. More...
 
struct GNUNET_DNSPARSER_SoaRecordGNUNET_DNSPARSER_parse_soa (const char *udp_payload, size_t udp_payload_length, size_t *off)
 Parse a DNS SOA record. More...
 
struct GNUNET_DNSPARSER_CertRecordGNUNET_DNSPARSER_parse_cert (const char *udp_payload, size_t udp_payload_length, size_t *off)
 Parse a DNS CERT record. More...
 
struct GNUNET_DNSPARSER_MxRecordGNUNET_DNSPARSER_parse_mx (const char *udp_payload, size_t udp_payload_length, size_t *off)
 Parse a DNS MX record. More...
 
struct GNUNET_DNSPARSER_SrvRecordGNUNET_DNSPARSER_parse_srv (const char *udp_payload, size_t udp_payload_length, size_t *off)
 Parse a DNS SRV record. More...
 
struct GNUNET_DNSPARSER_RecordGNUNET_DNSPARSER_duplicate_record (const struct GNUNET_DNSPARSER_Record *r)
 Duplicate (deep-copy) the given DNS record. More...
 
struct GNUNET_DNSPARSER_SoaRecordGNUNET_DNSPARSER_duplicate_soa_record (const struct GNUNET_DNSPARSER_SoaRecord *r)
 Duplicate (deep-copy) the given DNS record. More...
 
struct GNUNET_DNSPARSER_CertRecordGNUNET_DNSPARSER_duplicate_cert_record (const struct GNUNET_DNSPARSER_CertRecord *r)
 Duplicate (deep-copy) the given DNS record. More...
 
struct GNUNET_DNSPARSER_MxRecordGNUNET_DNSPARSER_duplicate_mx_record (const struct GNUNET_DNSPARSER_MxRecord *r)
 Duplicate (deep-copy) the given DNS record. More...
 
struct GNUNET_DNSPARSER_SrvRecordGNUNET_DNSPARSER_duplicate_srv_record (const struct GNUNET_DNSPARSER_SrvRecord *r)
 Duplicate (deep-copy) the given DNS record. More...
 
void GNUNET_DNSPARSER_free_record (struct GNUNET_DNSPARSER_Record *r)
 Free the given DNS record. More...
 
void GNUNET_DNSPARSER_free_mx (struct GNUNET_DNSPARSER_MxRecord *mx)
 Free MX information record. More...
 
void GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv)
 Free SRV information record. More...
 
void GNUNET_DNSPARSER_free_soa (struct GNUNET_DNSPARSER_SoaRecord *soa)
 Free SOA information record. More...
 
void GNUNET_DNSPARSER_free_cert (struct GNUNET_DNSPARSER_CertRecord *cert)
 Free CERT information record. More...
 
char * GNUNET_DNSPARSER_bin_to_hex (const void *data, size_t data_size)
 Convert a block of binary data to HEX. More...
 
size_t GNUNET_DNSPARSER_hex_to_bin (const char *hex, void *data)
 Convert a HEX string to block of binary data. More...
 

Detailed Description

Helper library to parse DNS packets.

Macro Definition Documentation

◆ GNUNET_DNSPARSER_MAX_LABEL_LENGTH

#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH   63

Maximum length of a label in DNS.

Definition at line 40 of file gnunet_dnsparser_lib.h.

◆ GNUNET_DNSPARSER_MAX_NAME_LENGTH

#define GNUNET_DNSPARSER_MAX_NAME_LENGTH   253

Maximum length of a name in DNS.

Definition at line 45 of file gnunet_dnsparser_lib.h.

Referenced by check_lookup(), check_ssl_certificate(), handle_lookup(), and recursive_gns2dns_resolution().

◆ GNUNET_DNSPARSER_TYPE_ANY

#define GNUNET_DNSPARSER_TYPE_ANY   0

A few common DNS types.

Definition at line 51 of file gnunet_dnsparser_lib.h.

◆ GNUNET_DNSPARSER_TYPE_A

#define GNUNET_DNSPARSER_TYPE_A   1

◆ GNUNET_DNSPARSER_TYPE_NS

#define GNUNET_DNSPARSER_TYPE_NS   2

◆ GNUNET_DNSPARSER_TYPE_CNAME

#define GNUNET_DNSPARSER_TYPE_CNAME   5

◆ GNUNET_DNSPARSER_TYPE_SOA

#define GNUNET_DNSPARSER_TYPE_SOA   6

◆ GNUNET_DNSPARSER_TYPE_PTR

#define GNUNET_DNSPARSER_TYPE_PTR   12

◆ GNUNET_DNSPARSER_TYPE_MX

#define GNUNET_DNSPARSER_TYPE_MX   15

◆ GNUNET_DNSPARSER_TYPE_TXT

#define GNUNET_DNSPARSER_TYPE_TXT   16

◆ GNUNET_DNSPARSER_TYPE_RP

#define GNUNET_DNSPARSER_TYPE_RP   17

Definition at line 59 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_AFSDB

#define GNUNET_DNSPARSER_TYPE_AFSDB   18

Definition at line 60 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_SIG

#define GNUNET_DNSPARSER_TYPE_SIG   24

Definition at line 61 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_KEY

#define GNUNET_DNSPARSER_TYPE_KEY   25

Definition at line 62 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_AAAA

#define GNUNET_DNSPARSER_TYPE_AAAA   28

◆ GNUNET_DNSPARSER_TYPE_LOC

#define GNUNET_DNSPARSER_TYPE_LOC   29

Definition at line 64 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_SRV

#define GNUNET_DNSPARSER_TYPE_SRV   33

◆ GNUNET_DNSPARSER_TYPE_NAPTR

#define GNUNET_DNSPARSER_TYPE_NAPTR   35

Definition at line 66 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_KX

#define GNUNET_DNSPARSER_TYPE_KX   36

Definition at line 67 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_CERT

#define GNUNET_DNSPARSER_TYPE_CERT   37

◆ GNUNET_DNSPARSER_TYPE_DNAME

#define GNUNET_DNSPARSER_TYPE_DNAME   39

Definition at line 69 of file gnunet_dnsparser_lib.h.

Referenced by GNUNET_DNSPARSER_parse_record(), and process_record().

◆ GNUNET_DNSPARSER_TYPE_APL

#define GNUNET_DNSPARSER_TYPE_APL   42

Definition at line 70 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_DS

#define GNUNET_DNSPARSER_TYPE_DS   43

Definition at line 71 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_SSHFP

#define GNUNET_DNSPARSER_TYPE_SSHFP   44

Definition at line 72 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_IPSECKEY

#define GNUNET_DNSPARSER_TYPE_IPSECKEY   45

Definition at line 73 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_RRSIG

#define GNUNET_DNSPARSER_TYPE_RRSIG   46

Definition at line 74 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_NSEC

#define GNUNET_DNSPARSER_TYPE_NSEC   47

Definition at line 75 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_DNSKEY

#define GNUNET_DNSPARSER_TYPE_DNSKEY   48

Definition at line 76 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_DHCID

#define GNUNET_DNSPARSER_TYPE_DHCID   49

Definition at line 77 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_NSEC3

#define GNUNET_DNSPARSER_TYPE_NSEC3   50

Definition at line 78 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_NSEC3PARAM

#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM   51

Definition at line 79 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_TLSA

#define GNUNET_DNSPARSER_TYPE_TLSA   52

◆ GNUNET_DNSPARSER_TYPE_HIP

#define GNUNET_DNSPARSER_TYPE_HIP   55

Definition at line 81 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_CDS

#define GNUNET_DNSPARSER_TYPE_CDS   59

Definition at line 82 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_CDNSKEY

#define GNUNET_DNSPARSER_TYPE_CDNSKEY   60

Definition at line 83 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_OPENPGPKEY

#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY   61

Definition at line 84 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_TKEY

#define GNUNET_DNSPARSER_TYPE_TKEY   249

Definition at line 85 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_TSIG

#define GNUNET_DNSPARSER_TYPE_TSIG   250

Definition at line 86 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_ALL

#define GNUNET_DNSPARSER_TYPE_ALL   255

◆ GNUNET_DNSPARSER_TYPE_URI

#define GNUNET_DNSPARSER_TYPE_URI   256

Definition at line 88 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

◆ GNUNET_DNSPARSER_TYPE_CAA

#define GNUNET_DNSPARSER_TYPE_CAA   257

Definition at line 89 of file gnunet_dnsparser_lib.h.

Referenced by dns_string_to_value(), and dns_value_to_string().

◆ GNUNET_DNSPARSER_TYPE_TA

#define GNUNET_DNSPARSER_TYPE_TA   32768

Definition at line 90 of file gnunet_dnsparser_lib.h.

Referenced by process_record().

Enumeration Type Documentation

◆ GNUNET_DNSPARSER_CertType

DNS CERT types as defined in RFC 4398.

Enumerator
GNUNET_DNSPARSER_CERTTYPE_RESERVED 

Reserved value.

GNUNET_DNSPARSER_CERTTYPE_PKIX 

An x509 PKIX certificate.

GNUNET_DNSPARSER_CERTTYPE_SKPI 

A SKPI certificate.

GNUNET_DNSPARSER_CERTTYPE_PGP 

A PGP certificate.

GNUNET_DNSPARSER_CERTTYPE_IPKIX 

An x509 PKIX cert URL.

GNUNET_DNSPARSER_CERTTYPE_ISKPI 

A SKPI cert URL.

GNUNET_DNSPARSER_CERTTYPE_IPGP 

A PGP cert fingerprint and URL.

GNUNET_DNSPARSER_CERTTYPE_ACPKIX 

An attribute Certificate.

GNUNET_DNSPARSER_CERTTYPE_IACKPIX 

An attribute cert URL.

Definition at line 183 of file gnunet_dnsparser_lib.h.

◆ GNUNET_DNSPARSER_CertAlgorithm

DNSCERT algorithms as defined in http://www.iana.org/assignments/ dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml, under dns-sec-alg-numbers-1.

Enumerator
GNUNET_DNSPARSER_CERTALGO_UNDEFINED 

No defined.

GNUNET_DNSPARSER_CERTALGO_RSAMD5 

RSA/MD5.

GNUNET_DNSPARSER_CERTALGO_DH 

Diffie-Hellman.

GNUNET_DNSPARSER_CERTALGO_DSASHA 

DSA/SHA1.

GNUNET_DNSPARSER_CERTALGO_RSRVD4 

Reserved.

GNUNET_DNSPARSER_CERTALGO_RSASHA 

RSA/SHA1.

GNUNET_DNSPARSER_CERTALGO_DSANSEC3 

DSA/NSEC3/SHA.

GNUNET_DNSPARSER_CERTALGO_RSANSEC3 

RSA/NSEC3/SHA.

GNUNET_DNSPARSER_CERTALGO_RSASHA256 

RSA/SHA256.

GNUNET_DNSPARSER_CERTALGO_RSRVD9 

Reserved.

GNUNET_DNSPARSER_CERTALGO_RSASHA512 

RSA/SHA512.

GNUNET_DNSPARSER_CERTALGO_GOST_R34 

GOST R 34.10-2001.

GNUNET_DNSPARSER_CERTALGO_ECDSA_P256SHA256 

ECDSA Curve P-256/SHA256.

GNUNET_DNSPARSER_CERTALGO_ECDSA_P384SHA384 

ECDSA Curve P-384/SHA384.

Definition at line 236 of file gnunet_dnsparser_lib.h.

237 {
242 
247 
252 
257 
262 
267 
272 
277 
282 
287 
292 
297 
302 
307 
308 };

Function Documentation

◆ GNUNET_DNSPARSER_check_label()

int GNUNET_DNSPARSER_check_label ( const char *  label)

Check if a label in UTF-8 format can be coded into valid IDNA.

This can fail if the ASCII-conversion becomes longer than 63 characters.

Parameters
labellabel to check (UTF-8 string)
Returns
GNUNET_OK if the label can be converted to IDNA, GNUNET_SYSERR if the label is not valid for DNS names

Definition at line 56 of file dnsparser.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_DNSPARSER_check_name().

57 {
58  char *output;
59  size_t slen;
60 
61  if (NULL != strchr (label, '.'))
62  return GNUNET_SYSERR; /* not a label! Did you mean GNUNET_DNSPARSER_check_name? */
63  if (0 == strcmp (label, "@")) /* '@' is reserved for the empty label, see #GNUNET_GNS_EMPTY_LABEL_AT */
64  return GNUNET_SYSERR;
65  if (IDNA_SUCCESS != idna_to_ascii_8z (label, &output, IDNA_ALLOW_UNASSIGNED))
66  return GNUNET_SYSERR;
67  slen = strlen (output);
68 #if WINDOWS
69  idn_free (output);
70 #else
71  free (output);
72 #endif
73  return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK;
74 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_check_name()

int GNUNET_DNSPARSER_check_name ( const char *  name)

Check if a hostname in UTF-8 format can be coded into valid IDNA.

This can fail if a label becomes longer than 63 characters or if the entire name exceeds 253 characters.

Parameters
namename to check (UTF-8 string)
Returns
GNUNET_OK if the label can be converted to IDNA, GNUNET_SYSERR if the label is not valid for DNS names

Check if a hostname in UTF-8 format can be coded into valid IDNA.

This can fail if the ASCII-conversion becomes longer than 253 characters.

Parameters
namename to check (UTF-8 string)
Returns
GNUNET_OK if the label can be converted to IDNA, GNUNET_SYSERR if the label is not valid for DNS names

Definition at line 86 of file dnsparser.c.

References GNUNET_DNSPARSER_check_label(), GNUNET_free, GNUNET_OK, GNUNET_strdup, and GNUNET_SYSERR.

Referenced by queue(), and run().

87 {
88  char *ldup;
89  char *output;
90  size_t slen;
91  char *tok;
92 
93  ldup = GNUNET_strdup (name);
94  for (tok = strtok (ldup, "."); NULL != tok; tok = strtok (NULL, "."))
96  {
97  GNUNET_free (ldup);
98  return GNUNET_SYSERR;
99  }
100  GNUNET_free (ldup);
101  if (IDNA_SUCCESS != idna_to_ascii_8z (name, &output, IDNA_ALLOW_UNASSIGNED))
102  return GNUNET_SYSERR;
103  slen = strlen (output);
104 #if WINDOWS
105  idn_free (output);
106 #else
107  free (output);
108 #endif
109  return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK;
110 }
int GNUNET_DNSPARSER_check_label(const char *label)
Check if a label in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:56
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse()

struct GNUNET_DNSPARSER_Packet* GNUNET_DNSPARSER_parse ( const char *  udp_payload,
size_t  udp_payload_length 
)

Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.

Parameters
udp_payloadwire-format of the DNS packet
udp_payload_lengthnumber of bytes in udp_payload
Returns
NULL on error, otherwise the parsed packet

Definition at line 662 of file dnsparser.c.

References GNUNET_TUN_DnsHeader::additional_rcount, GNUNET_DNSPARSER_Packet::additional_records, GNUNET_TUN_DnsHeader::answer_rcount, GNUNET_DNSPARSER_Packet::answers, GNUNET_TUN_DnsHeader::authority_rcount, GNUNET_DNSPARSER_Packet::authority_records, GNUNET_TUN_DnsHeader::flags, GNUNET_DNSPARSER_Packet::flags, GNUNET_break_op, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse_query(), GNUNET_DNSPARSER_parse_record(), GNUNET_new, GNUNET_new_array, GNUNET_OK, GNUNET_TUN_DnsHeader::id, GNUNET_DNSPARSER_Packet::id, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, GNUNET_DNSPARSER_Packet::num_queries, p, GNUNET_DNSPARSER_Packet::queries, and GNUNET_TUN_DnsHeader::query_count.

Referenced by display_request(), dns_post_request_handler(), dns_result_parser(), dns_result_processor(), handle_dns_request(), handle_request(), handle_resolve_result(), modify_request(), and process_result().

663 {
664  struct GNUNET_DNSPARSER_Packet *p;
665  const struct GNUNET_TUN_DnsHeader *dns;
666  size_t off;
667  unsigned int n;
668 
669  if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader))
670  return NULL;
671  dns = (const struct GNUNET_TUN_DnsHeader *) udp_payload;
672  off = sizeof (struct GNUNET_TUN_DnsHeader);
673  p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
674  p->flags = dns->flags;
675  p->id = dns->id;
676  n = ntohs (dns->query_count);
677  if (n > 0)
678  {
680  p->num_queries = n;
681  for (unsigned int i = 0; i < n; i++)
682  if (GNUNET_OK != GNUNET_DNSPARSER_parse_query (udp_payload,
683  udp_payload_length,
684  &off,
685  &p->queries[i]))
686  goto error;
687  }
688  n = ntohs (dns->answer_rcount);
689  if (n > 0)
690  {
692  p->num_answers = n;
693  for (unsigned int i = 0; i < n; i++)
694  if (GNUNET_OK != GNUNET_DNSPARSER_parse_record (udp_payload,
695  udp_payload_length,
696  &off,
697  &p->answers[i]))
698  goto error;
699  }
700  n = ntohs (dns->authority_rcount);
701  if (n > 0)
702  {
704  p->num_authority_records = n;
705  for (unsigned int i = 0; i < n; i++)
706  if (GNUNET_OK != GNUNET_DNSPARSER_parse_record (udp_payload,
707  udp_payload_length,
708  &off,
709  &p->authority_records[i]))
710  goto error;
711  }
712  n = ntohs (dns->additional_rcount);
713  if (n > 0)
714  {
715  p->additional_records =
717  p->num_additional_records = n;
718  for (unsigned int i = 0; i < n; i++)
719  {
720  if (GNUNET_OK !=
721  GNUNET_DNSPARSER_parse_record (udp_payload,
722  udp_payload_length,
723  &off,
724  &p->additional_records[i]))
725  goto error;
726  }
727  }
728  return p;
729 error:
730  GNUNET_break_op (0);
732  return NULL;
733 }
struct GNUNET_TUN_DnsFlags flags
Flags.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
int GNUNET_DNSPARSER_parse_record(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Record *r)
Parse a DNS record entry.
Definition: dnsparser.c:569
uint16_t id
DNS ID (to match replies to requests).
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:854
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
uint16_t id
Unique identifier for the request/response.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
A DNS response record.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
int GNUNET_DNSPARSER_parse_query(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Query *q)
Parse a DNS query entry.
Definition: dnsparser.c:363
uint16_t query_count
Number of queries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
uint16_t authority_rcount
Number of authoritative answers.
uint16_t answer_rcount
Number of answers.
Easy-to-process, parsed version of a DNS packet.
uint16_t additional_rcount
Number of additional records.
unsigned int num_queries
Number of queries in the packet.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_packet()

void GNUNET_DNSPARSER_free_packet ( struct GNUNET_DNSPARSER_Packet p)

Free memory taken by a packet.

Parameters
ppacket to free

Definition at line 854 of file dnsparser.c.

References GNUNET_DNSPARSER_Packet::additional_records, GNUNET_DNSPARSER_Packet::answers, GNUNET_DNSPARSER_Packet::authority_records, GNUNET_DNSPARSER_free_record(), GNUNET_free, GNUNET_free_non_null, GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, GNUNET_DNSPARSER_Packet::num_queries, and GNUNET_DNSPARSER_Packet::queries.

Referenced by display_request(), dns_post_request_handler(), dns_result_parser(), do_timeout(), finish_request(), GNS_interceptor_done(), GNUNET_DNSPARSER_parse(), handle_dns_request(), handle_request(), handle_resolve_result(), modify_request(), process_result(), recursive_dns_resolution(), reply_to_dns(), result_processor(), send_response(), and vpn_allocation_callback().

855 {
856  for (unsigned int i = 0; i < p->num_queries; i++)
859  for (unsigned int i = 0; i < p->num_answers; i++)
862  for (unsigned int i = 0; i < p->num_authority_records; i++)
865  for (unsigned int i = 0; i < p->num_additional_records; i++)
868  GNUNET_free (p);
869 }
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
Definition: dnsparser.c:180
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
char * name
Name of the record that the query is for (0-terminated).
unsigned int num_queries
Number of queries in the packet.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_pack()

int GNUNET_DNSPARSER_pack ( const struct GNUNET_DNSPARSER_Packet p,
uint16_t  max,
char **  buf,
size_t *  buf_length 
)

Given a DNS packet p, generate the corresponding UDP payload.

Note that we do not attempt to pack the strings with pointers as this would complicate the code and this is about being simple and secure, not fast, fancy and broken like bind.

Parameters
ppacket to pack
maxmaximum allowed size for the resulting UDP payload
bufset to a buffer with the packed message
buf_lengthset to the length of buf
Returns
GNUNET_SYSERR if p is invalid GNUNET_NO if p was truncated (but there is still a result in buf) GNUNET_OK if p was packed completely into buf

Definition at line 1259 of file dnsparser.c.

References add_record(), GNUNET_TUN_DnsHeader::additional_rcount, GNUNET_DNSPARSER_Packet::additional_records, GNUNET_TUN_DnsHeader::answer_rcount, GNUNET_DNSPARSER_Packet::answers, GNUNET_TUN_DnsHeader::authority_rcount, GNUNET_DNSPARSER_Packet::authority_records, GNUNET_TUN_DnsHeader::flags, GNUNET_DNSPARSER_Packet::flags, GNUNET_DNSPARSER_builder_add_query(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_TUN_DnsHeader::id, GNUNET_DNSPARSER_Packet::id, GNUNET_TUN_DnsFlags::message_truncated, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, GNUNET_DNSPARSER_Packet::num_queries, GNUNET_DNSPARSER_Packet::queries, GNUNET_TUN_DnsHeader::query_count, and ret.

Referenced by build_dns_query(), finish_request(), modify_request(), pack(), queue(), recursive_dns_resolution(), reply_to_dns(), and send_response().

1263 {
1264  struct GNUNET_TUN_DnsHeader dns;
1265  size_t off;
1266  char tmp[max];
1267  int ret;
1268  int trc;
1269 
1270  if ((p->num_queries > UINT16_MAX) || (p->num_answers > UINT16_MAX) ||
1271  (p->num_authority_records > UINT16_MAX) ||
1272  (p->num_additional_records > UINT16_MAX))
1273  return GNUNET_SYSERR;
1274  dns.id = p->id;
1275  dns.flags = p->flags;
1276  dns.query_count = htons (p->num_queries);
1277  dns.answer_rcount = htons (p->num_answers);
1278  dns.authority_rcount = htons (p->num_authority_records);
1279  dns.additional_rcount = htons (p->num_additional_records);
1280 
1281  off = sizeof (struct GNUNET_TUN_DnsHeader);
1282  trc = GNUNET_NO;
1283  for (unsigned int i = 0; i < p->num_queries; i++)
1284  {
1286  sizeof (tmp),
1287  &off,
1288  &p->queries[i]);
1289  if (GNUNET_SYSERR == ret)
1290  return GNUNET_SYSERR;
1291  if (GNUNET_NO == ret)
1292  {
1293  dns.query_count = htons ((uint16_t) (i - 1));
1294  trc = GNUNET_YES;
1295  break;
1296  }
1297  }
1298  for (unsigned int i = 0; i < p->num_answers; i++)
1299  {
1300  ret = add_record (tmp, sizeof (tmp), &off, &p->answers[i]);
1301  if (GNUNET_SYSERR == ret)
1302  return GNUNET_SYSERR;
1303  if (GNUNET_NO == ret)
1304  {
1305  dns.answer_rcount = htons ((uint16_t) (i - 1));
1306  trc = GNUNET_YES;
1307  break;
1308  }
1309  }
1310  for (unsigned int i = 0; i < p->num_authority_records; i++)
1311  {
1312  ret = add_record (tmp, sizeof (tmp), &off, &p->authority_records[i]);
1313  if (GNUNET_SYSERR == ret)
1314  return GNUNET_SYSERR;
1315  if (GNUNET_NO == ret)
1316  {
1317  dns.authority_rcount = htons ((uint16_t) (i - 1));
1318  trc = GNUNET_YES;
1319  break;
1320  }
1321  }
1322  for (unsigned int i = 0; i < p->num_additional_records; i++)
1323  {
1324  ret = add_record (tmp, sizeof (tmp), &off, &p->additional_records[i]);
1325  if (GNUNET_SYSERR == ret)
1326  return GNUNET_SYSERR;
1327  if (GNUNET_NO == ret)
1328  {
1329  dns.additional_rcount = htons (i - 1);
1330  trc = GNUNET_YES;
1331  break;
1332  }
1333  }
1334 
1335  if (GNUNET_YES == trc)
1336  dns.flags.message_truncated = 1;
1337  GNUNET_memcpy (tmp, &dns, sizeof (struct GNUNET_TUN_DnsHeader));
1338 
1339  *buf = GNUNET_malloc (off);
1340  *buf_length = off;
1341  GNUNET_memcpy (*buf, tmp, off);
1342  if (GNUNET_YES == trc)
1343  return GNUNET_NO;
1344  return GNUNET_OK;
1345 }
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
static int add_record(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Record *record)
Add a DNS record to the UDP packet at the given location.
Definition: dnsparser.c:1161
uint16_t id
DNS ID (to match replies to requests).
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
static int ret
Final status code.
Definition: gnunet-arm.c:89
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
#define GNUNET_memcpy(dst, src, n)
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
static char buf[2048]
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
unsigned int num_queries
Number of queries in the packet.
int GNUNET_DNSPARSER_builder_add_query(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Query *query)
Add a DNS query to the UDP packet at the given location.
Definition: dnsparser.c:971
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_name()

int GNUNET_DNSPARSER_builder_add_name ( char *  dst,
size_t  dst_len,
size_t *  off,
const char *  name 
)

Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as necessary.

Parameters
dstwhere to write the name (UDP packet)
dst_lennumber of bytes in dst
offpointer to offset where to write the name (increment by bytes used) must not be changed if there is an error
namename to write
Returns
GNUNET_SYSERR if name is invalid GNUNET_NO if name did not fit GNUNET_OK if name was added to dst

Definition at line 889 of file dnsparser.c.

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, len, and start.

Referenced by add_record(), check_for_glue(), dns_result_parser(), dns_string_to_value(), gns_string_to_value(), GNUNET_DNSPARSER_builder_add_mx(), GNUNET_DNSPARSER_builder_add_query(), GNUNET_DNSPARSER_builder_add_soa(), GNUNET_DNSPARSER_builder_add_srv(), handle_gns_resolution_result(), and process_record().

893 {
894  const char *dot;
895  const char *idna_name;
896  char *idna_start;
897  size_t start;
898  size_t pos;
899  size_t len;
900  Idna_rc rc;
901 
902  if (NULL == name)
903  return GNUNET_SYSERR;
904 
905  if (IDNA_SUCCESS !=
906  (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED)))
907  {
909  _ (
910  "Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
911  name,
912  idna_strerror (rc));
913  return GNUNET_NO;
914  }
915  idna_name = idna_start;
916  start = *off;
917  if (start + strlen (idna_name) + 2 > dst_len)
918  goto fail;
919  pos = start;
920  do
921  {
922  dot = strchr (idna_name, '.');
923  if (NULL == dot)
924  len = strlen (idna_name);
925  else
926  len = dot - idna_name;
927  if ((len >= 64) || (0 == len))
928  {
930  "Invalid DNS name `%s': label with %u characters encountered\n",
931  name,
932  (unsigned int) len);
933  goto fail; /* label too long or empty */
934  }
935  dst[pos++] = (char) (uint8_t) len;
936  GNUNET_memcpy (&dst[pos], idna_name, len);
937  pos += len;
938  idna_name += len + 1; /* also skip dot */
939  } while (NULL != dot);
940  dst[pos++] = '\0'; /* terminator */
941  *off = pos;
942 #if WINDOWS
943  idn_free (idna_start);
944 #else
945  free (idna_start);
946 #endif
947  return GNUNET_OK;
948 fail:
949 #if WINDOWS
950  idn_free (idna_start);
951 #else
952  free (idna_start);
953 #endif
954  return GNUNET_NO;
955 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name
#define GNUNET_log(kind,...)
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_query()

int GNUNET_DNSPARSER_builder_add_query ( char *  dst,
size_t  dst_len,
size_t *  off,
const struct GNUNET_DNSPARSER_Query query 
)

Add a DNS query to the UDP packet at the given location.

Parameters
dstwhere to write the query
dst_lennumber of bytes in dst
offpointer to offset where to write the query (increment by bytes used) must not be changed if there is an error
queryquery to write
Returns
GNUNET_SYSERR if query is invalid GNUNET_NO if query did not fit GNUNET_OK if query was added to dst

Definition at line 971 of file dnsparser.c.

References GNUNET_DNSPARSER_Query::dns_traffic_class, GNUNET_TUN_DnsQueryLine::dns_traffic_class, GNUNET_DNSPARSER_builder_add_name(), GNUNET_memcpy, GNUNET_OK, GNUNET_DNSPARSER_Query::name, ret, GNUNET_DNSPARSER_Query::type, and GNUNET_TUN_DnsQueryLine::type.

Referenced by GNUNET_DNSPARSER_pack().

975 {
976  int ret;
977  struct GNUNET_TUN_DnsQueryLine ql;
978 
980  dst_len -
981  sizeof (
982  struct GNUNET_TUN_DnsQueryLine),
983  off,
984  query->name);
985  if (ret != GNUNET_OK)
986  return ret;
987  ql.type = htons (query->type);
988  ql.dns_traffic_class = htons (query->dns_traffic_class);
989  GNUNET_memcpy (&dst[*off], &ql, sizeof (ql));
990  (*off) += sizeof (ql);
991  return GNUNET_OK;
992 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
DNS query prefix.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
#define GNUNET_memcpy(dst, src, n)
char * name
Name of the record that the query is for (0-terminated).
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_mx()

int GNUNET_DNSPARSER_builder_add_mx ( char *  dst,
size_t  dst_len,
size_t *  off,
const struct GNUNET_DNSPARSER_MxRecord mx 
)

Add an MX record to the UDP packet at the given location.

Parameters
dstwhere to write the mx record
dst_lennumber of bytes in dst
offpointer to offset where to write the mx information (increment by bytes used); can also change if there was an error
mxmx information to write
Returns
GNUNET_SYSERR if mx is invalid GNUNET_NO if mx did not fit GNUNET_OK if mx was added to dst

Definition at line 1008 of file dnsparser.c.

References GNUNET_DNSPARSER_builder_add_name(), GNUNET_memcpy, GNUNET_NO, GNUNET_DNSPARSER_MxRecord::mxhost, and GNUNET_DNSPARSER_MxRecord::preference.

Referenced by add_record(), dns_result_parser(), dns_string_to_value(), handle_gns_resolution_result(), and process_record().

1012 {
1013  uint16_t mxpref;
1014 
1015  if (*off + sizeof (uint16_t) > dst_len)
1016  return GNUNET_NO;
1017  mxpref = htons (mx->preference);
1018  GNUNET_memcpy (&dst[*off], &mxpref, sizeof (mxpref));
1019  (*off) += sizeof (mxpref);
1020  return GNUNET_DNSPARSER_builder_add_name (dst, dst_len, off, mx->mxhost);
1021 }
char * mxhost
Name of the mail server.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_memcpy(dst, src, n)
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
uint16_t preference
Preference for this entry (lower value is higher preference).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_soa()

int GNUNET_DNSPARSER_builder_add_soa ( char *  dst,
size_t  dst_len,
size_t *  off,
const struct GNUNET_DNSPARSER_SoaRecord soa 
)

Add an SOA record to the UDP packet at the given location.

Parameters
dstwhere to write the SOA record
dst_lennumber of bytes in dst
offpointer to offset where to write the SOA information (increment by bytes used) can also change if there was an error
soaSOA information to write
Returns
GNUNET_SYSERR if soa is invalid GNUNET_NO if soa did not fit GNUNET_OK if soa was added to dst

Definition at line 1084 of file dnsparser.c.

References GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_TUN_DnsSoaRecord::expire, GNUNET_DNSPARSER_builder_add_name(), GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_TUN_DnsSoaRecord::minimum, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_SoaRecord::refresh, GNUNET_TUN_DnsSoaRecord::refresh, ret, GNUNET_DNSPARSER_SoaRecord::retry, GNUNET_TUN_DnsSoaRecord::retry, GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_DNSPARSER_SoaRecord::serial, and GNUNET_TUN_DnsSoaRecord::serial.

Referenced by add_record(), dns_result_parser(), dns_string_to_value(), handle_gns_resolution_result(), and process_record().

1088 {
1089  struct GNUNET_TUN_DnsSoaRecord sd;
1090  int ret;
1091 
1092  if ((GNUNET_OK !=
1093  (ret =
1094  GNUNET_DNSPARSER_builder_add_name (dst, dst_len, off, soa->mname))) ||
1095  (GNUNET_OK !=
1096  (ret =
1097  GNUNET_DNSPARSER_builder_add_name (dst, dst_len, off, soa->rname))))
1098  return ret;
1099  if (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > dst_len)
1100  return GNUNET_NO;
1101  sd.serial = htonl (soa->serial);
1102  sd.refresh = htonl (soa->refresh);
1103  sd.retry = htonl (soa->retry);
1104  sd.expire = htonl (soa->expire);
1105  sd.minimum = htonl (soa->minimum_ttl);
1106  GNUNET_memcpy (&dst[*off], &sd, sizeof (sd));
1107  (*off) += sizeof (sd);
1108  return GNUNET_OK;
1109 }
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
uint32_t refresh
Time interval before the zone should be refreshed.
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t serial
The version number of the original copy of the zone.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
#define GNUNET_memcpy(dst, src, n)
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
Payload of DNS SOA record (header).
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_cert()

int GNUNET_DNSPARSER_builder_add_cert ( char *  dst,
size_t  dst_len,
size_t *  off,
const struct GNUNET_DNSPARSER_CertRecord cert 
)

Add CERT record to the UDP packet at the given location.

Parameters
dstwhere to write the CERT record
dst_lennumber of bytes in dst
offpointer to offset where to write the CERT information (increment by bytes used) can also change if there was an error
certCERT information to write
Returns
GNUNET_SYSERR if soa is invalid GNUNET_NO if soa did not fit GNUNET_OK if soa was added to dst

Add CERT record to the UDP packet at the given location.

Parameters
dstwhere to write the CERT record
dst_lennumber of bytes in dst
offpointer to offset where to write the CERT information (increment by bytes used); can also change if there was an error
certCERT information to write
Returns
GNUNET_SYSERR if cert is invalid GNUNET_NO if cert did not fit GNUNET_OK if cert was added to dst

Definition at line 1037 of file dnsparser.c.

References GNUNET_DNSPARSER_CertRecord::algorithm, GNUNET_TUN_DnsCertRecord::algorithm, GNUNET_DNSPARSER_CertRecord::cert_tag, GNUNET_TUN_DnsCertRecord::cert_tag, GNUNET_DNSPARSER_CertRecord::cert_type, GNUNET_TUN_DnsCertRecord::cert_type, GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_DNSPARSER_CertRecord::certificate_size, GNUNET_break, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, and GNUNET_SYSERR.

Referenced by add_record(), dns_string_to_value(), and process_record().

1042 {
1043  struct GNUNET_TUN_DnsCertRecord dcert;
1044 
1045 #ifdef __clang__
1046 #pragma clang diagnostic push
1047 #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
1048 #endif
1049  if ((cert->cert_type > UINT16_MAX) || (cert->algorithm > UINT8_MAX))
1050  {
1051  GNUNET_break (0);
1052  return GNUNET_SYSERR;
1053  }
1054 #ifdef __clang__
1055 #pragma clang diagnostic pop
1056 #endif
1057  if (*off + sizeof (struct GNUNET_TUN_DnsCertRecord) + cert->certificate_size >
1058  dst_len)
1059  return GNUNET_NO;
1060  dcert.cert_type = htons ((uint16_t) cert->cert_type);
1061  dcert.cert_tag = htons ((uint16_t) cert->cert_tag);
1062  dcert.algorithm = (uint8_t) cert->algorithm;
1063  GNUNET_memcpy (&dst[*off], &dcert, sizeof (dcert));
1064  (*off) += sizeof (dcert);
1065  GNUNET_memcpy (&dst[*off], cert->certificate_data, cert->certificate_size);
1066  (*off) += cert->certificate_size;
1067  return GNUNET_OK;
1068 }
enum GNUNET_DNSPARSER_CertAlgorithm algorithm
Algorithm.
enum GNUNET_DNSPARSER_CertType cert_type
Certificate type.
uint16_t cert_tag
Certificate KeyTag.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Payload of DNS CERT record.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
size_t certificate_size
Number of bytes in certificate_data.
char * certificate_data
Data of the certificate.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_builder_add_srv()

int GNUNET_DNSPARSER_builder_add_srv ( char *  dst,
size_t  dst_len,
size_t *  off,
const struct GNUNET_DNSPARSER_SrvRecord srv 
)

Add an SRV record to the UDP packet at the given location.

Parameters
dstwhere to write the SRV record
dst_lennumber of bytes in dst
offpointer to offset where to write the SRV information (increment by bytes used) can also change if there was an error
srvSRV information to write
Returns
GNUNET_SYSERR if srv is invalid GNUNET_NO if srv did not fit GNUNET_OK if srv was added to dst

Definition at line 1125 of file dnsparser.c.

References GNUNET_DNSPARSER_builder_add_name(), GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_TUN_DnsSrvRecord::port, GNUNET_TUN_DnsSrvRecord::prio, GNUNET_DNSPARSER_SrvRecord::priority, ret, GNUNET_DNSPARSER_SrvRecord::target, GNUNET_DNSPARSER_SrvRecord::weight, and GNUNET_TUN_DnsSrvRecord::weight.

Referenced by add_record(), dns_result_parser(), dns_string_to_value(), handle_gns_resolution_result(), and process_record().

1129 {
1130  struct GNUNET_TUN_DnsSrvRecord sd;
1131  int ret;
1132 
1133  if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > dst_len)
1134  return GNUNET_NO;
1135  sd.prio = htons (srv->priority);
1136  sd.weight = htons (srv->weight);
1137  sd.port = htons (srv->port);
1138  GNUNET_memcpy (&dst[*off], &sd, sizeof (sd));
1139  (*off) += sizeof (sd);
1140  if (GNUNET_OK !=
1141  (ret =
1142  GNUNET_DNSPARSER_builder_add_name (dst, dst_len, off, srv->target)))
1143  return ret;
1144  return GNUNET_OK;
1145 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_memcpy(dst, src, n)
uint16_t port
TCP or UDP port of the service.
char * target
Hostname offering the service.
Payload of DNS SRV record (header).
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
Definition: dnsparser.c:889
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_record()

int GNUNET_DNSPARSER_parse_record ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off,
struct GNUNET_DNSPARSER_Record r 
)

Parse a DNS record entry.

Parameters
udp_payloadentire UDP payload
udp_payload_lengthlength of udp_payload
offpointer to the offset of the record to parse in the udp_payload (to be incremented by the size of the record)
rwhere to write the record information
Returns
GNUNET_OK on success, GNUNET_SYSERR if the record is malformed

Definition at line 569 of file dnsparser.c.

References GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_RawRecord::data_len, GNUNET_TUN_DnsRecordLine::data_len, GNUNET_DNSPARSER_Record::dns_traffic_class, GNUNET_TUN_DnsRecordLine::dns_traffic_class, GNUNET_DNSPARSER_Record::expiration_time, GNUNET_break_op, GNUNET_DNSPARSER_parse_mx(), GNUNET_DNSPARSER_parse_name(), GNUNET_DNSPARSER_parse_soa(), GNUNET_DNSPARSER_parse_srv(), GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_DNAME, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_SECONDS, GNUNET_DNSPARSER_Record::hostname, GNUNET_DNSPARSER_Record::mx, name, GNUNET_DNSPARSER_Record::name, GNUNET_DNSPARSER_Record::raw, GNUNET_DNSPARSER_Record::soa, GNUNET_DNSPARSER_Record::srv, GNUNET_TUN_DnsRecordLine::ttl, GNUNET_DNSPARSER_Record::type, and GNUNET_TUN_DnsRecordLine::type.

Referenced by GNUNET_DNSPARSER_parse().

573 {
574  char *name;
575  struct GNUNET_TUN_DnsRecordLine rl;
576  size_t old_off;
577  uint16_t data_len;
578 
579  name = GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
580  if (NULL == name)
581  {
582  GNUNET_break_op (0);
583  return GNUNET_SYSERR;
584  }
585  r->name = name;
586  if (*off + sizeof (struct GNUNET_TUN_DnsRecordLine) > udp_payload_length)
587  {
588  GNUNET_break_op (0);
589  return GNUNET_SYSERR;
590  }
591  GNUNET_memcpy (&rl, &udp_payload[*off], sizeof (rl));
592  (*off) += sizeof (rl);
593  r->type = ntohs (rl.type);
594  r->dns_traffic_class = ntohs (rl.dns_traffic_class);
597  data_len = ntohs (rl.data_len);
598  if (*off + data_len > udp_payload_length)
599  {
600  GNUNET_break_op (0);
601  return GNUNET_SYSERR;
602  }
603  old_off = *off;
604  switch (r->type)
605  {
610  r->data.hostname =
611  GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
612  if ((NULL == r->data.hostname) || (old_off + data_len != *off))
613  return GNUNET_SYSERR;
614  return GNUNET_OK;
616  r->data.soa =
617  GNUNET_DNSPARSER_parse_soa (udp_payload, udp_payload_length, off);
618  if ((NULL == r->data.soa) || (old_off + data_len != *off))
619  {
620  GNUNET_break_op (0);
621  return GNUNET_SYSERR;
622  }
623  return GNUNET_OK;
625  r->data.mx =
626  GNUNET_DNSPARSER_parse_mx (udp_payload, udp_payload_length, off);
627  if ((NULL == r->data.mx) || (old_off + data_len != *off))
628  {
629  GNUNET_break_op (0);
630  return GNUNET_SYSERR;
631  }
632  return GNUNET_OK;
634  r->data.srv =
635  GNUNET_DNSPARSER_parse_srv (udp_payload, udp_payload_length, off);
636  if ((NULL == r->data.srv) || (old_off + data_len != *off))
637  {
638  GNUNET_break_op (0);
639  return GNUNET_SYSERR;
640  }
641  return GNUNET_OK;
642  default:
643  r->data.raw.data = GNUNET_malloc (data_len);
644  r->data.raw.data_len = data_len;
645  GNUNET_memcpy (r->data.raw.data, &udp_payload[*off], data_len);
646  break;
647  }
648  (*off) += data_len;
649  return GNUNET_OK;
650 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:344
#define GNUNET_DNSPARSER_TYPE_CNAME
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_parse_soa(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SOA record.
Definition: dnsparser.c:401
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_DNSPARSER_TYPE_MX
General DNS record prefix.
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_SOA
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_DNSPARSER_TYPE_DNAME
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_parse_srv(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SRV record.
Definition: dnsparser.c:487
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_parse_mx(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS MX record.
Definition: dnsparser.c:446
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
size_t data_len
Number of bytes in data.
void * data
Binary record data.
const char * name
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
uint16_t data_len
Number of bytes of data that follow.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
#define GNUNET_DNSPARSER_TYPE_NS
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
#define GNUNET_DNSPARSER_TYPE_SRV
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_name()

char* GNUNET_DNSPARSER_parse_name ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off 
)

Parse name inside of a DNS query or record.

Parameters
udp_payloadentire UDP payload
udp_payload_lengthlength of udp_payload
offpointer to the offset of the name to parse in the udp_payload (to be incremented by the size of the name)
Returns
name as 0-terminated C string on success, NULL if the payload is malformed

Definition at line 344 of file dnsparser.c.

References parse_name().

Referenced by dns_value_to_string(), gns_value_to_string(), GNUNET_DNSPARSER_parse_mx(), GNUNET_DNSPARSER_parse_query(), GNUNET_DNSPARSER_parse_record(), GNUNET_DNSPARSER_parse_soa(), GNUNET_DNSPARSER_parse_srv(), handle_gns_resolution_result(), recursive_cname_resolution(), recursive_gns2dns_resolution(), and reply_to_dns().

347 {
348  return parse_name (udp_payload, udp_payload_length, off, 0);
349 }
static char * parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off, unsigned int depth)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:220
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_query()

int GNUNET_DNSPARSER_parse_query ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off,
struct GNUNET_DNSPARSER_Query q 
)

Parse a DNS query entry.

Parameters
udp_payloadentire UDP payload
udp_payload_lengthlength of udp_payload
offpointer to the offset of the query to parse in the udp_payload (to be incremented by the size of the query)
qwhere to write the query information
Returns
GNUNET_OK on success, GNUNET_SYSERR if the query is malformed

Definition at line 363 of file dnsparser.c.

References GNUNET_DNSPARSER_Query::dns_traffic_class, GNUNET_TUN_DnsQueryLine::dns_traffic_class, GNUNET_break_op, GNUNET_DNSPARSER_parse_name(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_DNSPARSER_Query::name, name, GNUNET_DNSPARSER_Query::type, and GNUNET_TUN_DnsQueryLine::type.

Referenced by GNUNET_DNSPARSER_parse().

367 {
368  char *name;
369  struct GNUNET_TUN_DnsQueryLine ql;
370 
371  name = GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
372  if (NULL == name)
373  {
374  GNUNET_break_op (0);
375  return GNUNET_SYSERR;
376  }
377  q->name = name;
378  if (*off + sizeof (struct GNUNET_TUN_DnsQueryLine) > udp_payload_length)
379  {
380  GNUNET_break_op (0);
381  return GNUNET_SYSERR;
382  }
383  GNUNET_memcpy (&ql, &udp_payload[*off], sizeof (ql));
384  *off += sizeof (ql);
385  q->type = ntohs (ql.type);
386  q->dns_traffic_class = ntohs (ql.dns_traffic_class);
387  return GNUNET_OK;
388 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:344
DNS query prefix.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name
char * name
Name of the record that the query is for (0-terminated).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_soa()

struct GNUNET_DNSPARSER_SoaRecord* GNUNET_DNSPARSER_parse_soa ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off 
)

Parse a DNS SOA record.

Parameters
udp_payloadreference to UDP packet
udp_payload_lengthlength of udp_payload
offpointer to the offset of the query to parse in the SOA record (to be incremented by the size of the record), unchanged on error
Returns
the parsed SOA record, NULL on error

Definition at line 401 of file dnsparser.c.

References GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_TUN_DnsSoaRecord::expire, GNUNET_break_op, GNUNET_DNSPARSER_free_soa(), GNUNET_DNSPARSER_parse_name(), GNUNET_memcpy, GNUNET_new, GNUNET_TUN_DnsSoaRecord::minimum, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_SoaRecord::refresh, GNUNET_TUN_DnsSoaRecord::refresh, GNUNET_DNSPARSER_SoaRecord::retry, GNUNET_TUN_DnsSoaRecord::retry, GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_DNSPARSER_SoaRecord::serial, and GNUNET_TUN_DnsSoaRecord::serial.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_parse_record(), handle_gns_resolution_result(), and reply_to_dns().

404 {
405  struct GNUNET_DNSPARSER_SoaRecord *soa;
406  struct GNUNET_TUN_DnsSoaRecord soa_bin;
407  size_t old_off;
408 
409  old_off = *off;
410  soa = GNUNET_new (struct GNUNET_DNSPARSER_SoaRecord);
411  soa->mname =
412  GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
413  soa->rname =
414  GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
415  if ((NULL == soa->mname) || (NULL == soa->rname) ||
416  (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > udp_payload_length))
417  {
418  GNUNET_break_op (0);
420  *off = old_off;
421  return NULL;
422  }
423  GNUNET_memcpy (&soa_bin,
424  &udp_payload[*off],
425  sizeof (struct GNUNET_TUN_DnsSoaRecord));
426  soa->serial = ntohl (soa_bin.serial);
427  soa->refresh = ntohl (soa_bin.refresh);
428  soa->retry = ntohl (soa_bin.retry);
429  soa->expire = ntohl (soa_bin.expire);
430  soa->minimum_ttl = ntohl (soa_bin.minimum);
431  (*off) += sizeof (struct GNUNET_TUN_DnsSoaRecord);
432  return soa;
433 }
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:119
Information from SOA records (RFC 1035).
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:344
uint32_t refresh
Time interval before the zone should be refreshed.
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t serial
The version number of the original copy of the zone.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
Payload of DNS SOA record (header).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_cert()

struct GNUNET_DNSPARSER_CertRecord* GNUNET_DNSPARSER_parse_cert ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off 
)

Parse a DNS CERT record.

Parameters
udp_payloadreference to UDP packet
udp_payload_lengthlength of udp_payload
offpointer to the offset of the query to parse in the CERT record (to be incremented by the size of the record), unchanged on error
Returns
the parsed CERT record, NULL on error

Definition at line 528 of file dnsparser.c.

References GNUNET_DNSPARSER_CertRecord::algorithm, GNUNET_TUN_DnsCertRecord::algorithm, GNUNET_DNSPARSER_CertRecord::cert_tag, GNUNET_TUN_DnsCertRecord::cert_tag, GNUNET_DNSPARSER_CertRecord::cert_type, GNUNET_TUN_DnsCertRecord::cert_type, GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_DNSPARSER_CertRecord::certificate_size, GNUNET_break_op, GNUNET_malloc, GNUNET_memcpy, and GNUNET_new.

Referenced by dns_value_to_string().

531 {
532  struct GNUNET_DNSPARSER_CertRecord *cert;
533  struct GNUNET_TUN_DnsCertRecord dcert;
534 
535  if (*off + sizeof (struct GNUNET_TUN_DnsCertRecord) >= udp_payload_length)
536  {
537  GNUNET_break_op (0);
538  return NULL;
539  }
540  GNUNET_memcpy (&dcert,
541  &udp_payload[*off],
542  sizeof (struct GNUNET_TUN_DnsCertRecord));
543  (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord);
544  cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord);
545  cert->cert_type = ntohs (dcert.cert_type);
546  cert->cert_tag = ntohs (dcert.cert_tag);
547  cert->algorithm = dcert.algorithm;
548  cert->certificate_size = udp_payload_length - (*off);
551  &udp_payload[*off],
552  cert->certificate_size);
553  (*off) += cert->certificate_size;
554  return cert;
555 }
enum GNUNET_DNSPARSER_CertAlgorithm algorithm
Algorithm.
enum GNUNET_DNSPARSER_CertType cert_type
Certificate type.
uint16_t cert_tag
Certificate KeyTag.
Information from CERT records (RFC 4034).
Payload of DNS CERT record.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
size_t certificate_size
Number of bytes in certificate_data.
char * certificate_data
Data of the certificate.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_mx()

struct GNUNET_DNSPARSER_MxRecord* GNUNET_DNSPARSER_parse_mx ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off 
)

Parse a DNS MX record.

Parameters
udp_payloadreference to UDP packet
udp_payload_lengthlength of udp_payload
offpointer to the offset of the query to parse in the MX record (to be incremented by the size of the record), unchanged on error
Returns
the parsed MX record, NULL on error

Definition at line 446 of file dnsparser.c.

References GNUNET_break_op, GNUNET_DNSPARSER_free_mx(), GNUNET_DNSPARSER_parse_name(), GNUNET_memcpy, GNUNET_new, GNUNET_DNSPARSER_MxRecord::mxhost, and GNUNET_DNSPARSER_MxRecord::preference.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_parse_record(), handle_gns_resolution_result(), and reply_to_dns().

449 {
450  struct GNUNET_DNSPARSER_MxRecord *mx;
451  uint16_t mxpref;
452  size_t old_off;
453 
454  old_off = *off;
455  if (*off + sizeof (uint16_t) > udp_payload_length)
456  {
457  GNUNET_break_op (0);
458  return NULL;
459  }
460  GNUNET_memcpy (&mxpref, &udp_payload[*off], sizeof (uint16_t));
461  (*off) += sizeof (uint16_t);
463  mx->preference = ntohs (mxpref);
464  mx->mxhost =
465  GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
466  if (NULL == mx->mxhost)
467  {
468  GNUNET_break_op (0);
470  *off = old_off;
471  return NULL;
472  }
473  return mx;
474 }
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:344
char * mxhost
Name of the mail server.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Information from MX records (RFC 1035).
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint16_t preference
Preference for this entry (lower value is higher preference).
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_parse_srv()

struct GNUNET_DNSPARSER_SrvRecord* GNUNET_DNSPARSER_parse_srv ( const char *  udp_payload,
size_t  udp_payload_length,
size_t *  off 
)

Parse a DNS SRV record.

Parameters
udp_payloadreference to UDP packet
udp_payload_lengthlength of udp_payload
offpointer to the offset of the query to parse in the SRV record (to be incremented by the size of the record), unchanged on error
Returns
the parsed SRV record, NULL on error

Definition at line 487 of file dnsparser.c.

References GNUNET_DNSPARSER_free_srv(), GNUNET_DNSPARSER_parse_name(), GNUNET_memcpy, GNUNET_new, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_TUN_DnsSrvRecord::port, GNUNET_TUN_DnsSrvRecord::prio, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_SrvRecord::target, GNUNET_DNSPARSER_SrvRecord::weight, and GNUNET_TUN_DnsSrvRecord::weight.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_parse_record(), and handle_gns_resolution_result().

490 {
491  struct GNUNET_DNSPARSER_SrvRecord *srv;
492  struct GNUNET_TUN_DnsSrvRecord srv_bin;
493  size_t old_off;
494 
495  old_off = *off;
496  if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > udp_payload_length)
497  return NULL;
498  GNUNET_memcpy (&srv_bin,
499  &udp_payload[*off],
500  sizeof (struct GNUNET_TUN_DnsSrvRecord));
501  (*off) += sizeof (struct GNUNET_TUN_DnsSrvRecord);
502  srv = GNUNET_new (struct GNUNET_DNSPARSER_SrvRecord);
503  srv->priority = ntohs (srv_bin.prio);
504  srv->weight = ntohs (srv_bin.weight);
505  srv->port = ntohs (srv_bin.port);
506  srv->target =
507  GNUNET_DNSPARSER_parse_name (udp_payload, udp_payload_length, off);
508  if (NULL == srv->target)
509  {
511  *off = old_off;
512  return NULL;
513  }
514  return srv;
515 }
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
Definition: dnsparser.c:344
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:150
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_memcpy(dst, src, n)
uint16_t port
TCP or UDP port of the service.
char * target
Hostname offering the service.
Payload of DNS SRV record (header).
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
Information from SRV records (RFC 2782).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_duplicate_record()

struct GNUNET_DNSPARSER_Record* GNUNET_DNSPARSER_duplicate_record ( const struct GNUNET_DNSPARSER_Record r)

Duplicate (deep-copy) the given DNS record.

Parameters
rthe record
Returns
the newly allocated record

Definition at line 743 of file dnsparser.c.

References GNUNET_DNSPARSER_Record::cert, GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_RawRecord::data_len, GNUNET_DNSPARSER_duplicate_cert_record(), GNUNET_DNSPARSER_duplicate_mx_record(), GNUNET_DNSPARSER_duplicate_soa_record(), GNUNET_DNSPARSER_duplicate_srv_record(), GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_memdup, GNUNET_strdup, GNUNET_DNSPARSER_Record::hostname, GNUNET_DNSPARSER_Record::mx, GNUNET_DNSPARSER_Record::name, GNUNET_DNSPARSER_Record::raw, GNUNET_DNSPARSER_Record::soa, GNUNET_DNSPARSER_Record::srv, and GNUNET_DNSPARSER_Record::type.

Referenced by cache_answers().

744 {
745  struct GNUNET_DNSPARSER_Record *dup = GNUNET_memdup (r, sizeof (*r));
746 
747  dup->name = GNUNET_strdup (r->name);
748  switch (r->type)
749  {
754  break;
755  }
758  break;
759  }
762  break;
763  }
766  break;
767  }
770  break;
771  }
772  default: {
774  }
775  }
776  return dup;
777 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
#define GNUNET_DNSPARSER_TYPE_CNAME
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_duplicate_soa_record(const struct GNUNET_DNSPARSER_SoaRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:787
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_duplicate_cert_record(const struct GNUNET_DNSPARSER_CertRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:805
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_PTR
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_duplicate_srv_record(const struct GNUNET_DNSPARSER_SrvRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:838
#define GNUNET_DNSPARSER_TYPE_SOA
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
A DNS response record.
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_duplicate_mx_record(const struct GNUNET_DNSPARSER_MxRecord *r)
Duplicate (deep-copy) the given DNS record.
Definition: dnsparser.c:822
size_t data_len
Number of bytes in data.
void * data
Binary record data.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
#define GNUNET_DNSPARSER_TYPE_NS
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
#define GNUNET_DNSPARSER_TYPE_SRV
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_DNSPARSER_TYPE_CERT
struct GNUNET_DNSPARSER_CertRecord * cert
CERT data for CERT records.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_duplicate_soa_record()

struct GNUNET_DNSPARSER_SoaRecord* GNUNET_DNSPARSER_duplicate_soa_record ( const struct GNUNET_DNSPARSER_SoaRecord r)

Duplicate (deep-copy) the given DNS record.

Parameters
rthe record
Returns
the newly allocated record

Definition at line 787 of file dnsparser.c.

References GNUNET_memdup, GNUNET_strdup, GNUNET_DNSPARSER_SoaRecord::mname, and GNUNET_DNSPARSER_SoaRecord::rname.

Referenced by GNUNET_DNSPARSER_duplicate_record().

789 {
790  struct GNUNET_DNSPARSER_SoaRecord *dup = GNUNET_memdup (r, sizeof (*r));
791 
792  dup->mname = GNUNET_strdup (r->mname);
793  dup->rname = GNUNET_strdup (r->rname);
794  return dup;
795 }
Information from SOA records (RFC 1035).
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_duplicate_cert_record()

struct GNUNET_DNSPARSER_CertRecord* GNUNET_DNSPARSER_duplicate_cert_record ( const struct GNUNET_DNSPARSER_CertRecord r)

Duplicate (deep-copy) the given DNS record.

Parameters
rthe record
Returns
the newly allocated record

Definition at line 805 of file dnsparser.c.

References GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_memdup, and GNUNET_strdup.

Referenced by GNUNET_DNSPARSER_duplicate_record().

807 {
808  struct GNUNET_DNSPARSER_CertRecord *dup = GNUNET_memdup (r, sizeof (*r));
809 
811  return dup;
812 }
Information from CERT records (RFC 4034).
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * certificate_data
Data of the certificate.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_duplicate_mx_record()

struct GNUNET_DNSPARSER_MxRecord* GNUNET_DNSPARSER_duplicate_mx_record ( const struct GNUNET_DNSPARSER_MxRecord r)

Duplicate (deep-copy) the given DNS record.

Parameters
rthe record
Returns
the newly allocated record

Definition at line 822 of file dnsparser.c.

References GNUNET_memdup, GNUNET_strdup, and GNUNET_DNSPARSER_MxRecord::mxhost.

Referenced by GNUNET_DNSPARSER_duplicate_record().

823 {
824  struct GNUNET_DNSPARSER_MxRecord *dup = GNUNET_memdup (r, sizeof (*r));
825 
826  dup->mxhost = GNUNET_strdup (r->mxhost);
827  return dup;
828 }
char * mxhost
Name of the mail server.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Information from MX records (RFC 1035).
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_duplicate_srv_record()

struct GNUNET_DNSPARSER_SrvRecord* GNUNET_DNSPARSER_duplicate_srv_record ( const struct GNUNET_DNSPARSER_SrvRecord r)

Duplicate (deep-copy) the given DNS record.

Parameters
rthe record
Returns
the newly allocated record

Definition at line 838 of file dnsparser.c.

References GNUNET_memdup, GNUNET_strdup, and GNUNET_DNSPARSER_SrvRecord::target.

Referenced by GNUNET_DNSPARSER_duplicate_record().

840 {
841  struct GNUNET_DNSPARSER_SrvRecord *dup = GNUNET_memdup (r, sizeof (*r));
842 
843  dup->target = GNUNET_strdup (r->target);
844  return dup;
845 }
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * target
Hostname offering the service.
Information from SRV records (RFC 2782).
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_record()

void GNUNET_DNSPARSER_free_record ( struct GNUNET_DNSPARSER_Record r)

Free the given DNS record.

Parameters
rrecord to free

Definition at line 180 of file dnsparser.c.

References GNUNET_DNSPARSER_Record::cert, GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_free_cert(), GNUNET_DNSPARSER_free_mx(), GNUNET_DNSPARSER_free_soa(), GNUNET_DNSPARSER_free_srv(), GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_free_non_null, GNUNET_DNSPARSER_Record::hostname, GNUNET_DNSPARSER_Record::mx, GNUNET_DNSPARSER_Record::name, GNUNET_DNSPARSER_Record::raw, GNUNET_DNSPARSER_Record::soa, GNUNET_DNSPARSER_Record::srv, and GNUNET_DNSPARSER_Record::type.

Referenced by free_cache_entry(), free_hosts_entry(), GNUNET_DNSPARSER_free_packet(), and remove_expired().

181 {
183  switch (r->type)
184  {
187  break;
190  break;
193  break;
196  break;
201  break;
202  default:
204  break;
205  }
206 }
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
Definition: dnsparser.c:119
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
Definition: dnsparser.c:150
#define GNUNET_DNSPARSER_TYPE_CNAME
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_SOA
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
void * data
Binary record data.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
#define GNUNET_DNSPARSER_TYPE_NS
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Definition: dnsparser.c:135
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
#define GNUNET_DNSPARSER_TYPE_SRV
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
Definition: dnsparser.c:165
#define GNUNET_DNSPARSER_TYPE_CERT
struct GNUNET_DNSPARSER_CertRecord * cert
CERT data for CERT records.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_mx()

void GNUNET_DNSPARSER_free_mx ( struct GNUNET_DNSPARSER_MxRecord mx)

Free MX information record.

Parameters
mxrecord to free

Definition at line 165 of file dnsparser.c.

References GNUNET_free, GNUNET_free_non_null, and GNUNET_DNSPARSER_MxRecord::mxhost.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_free_record(), GNUNET_DNSPARSER_parse_mx(), and handle_gns_resolution_result().

166 {
167  if (NULL == mx)
168  return;
170  GNUNET_free (mx);
171 }
char * mxhost
Name of the mail server.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_srv()

void GNUNET_DNSPARSER_free_srv ( struct GNUNET_DNSPARSER_SrvRecord srv)

Free SRV information record.

Parameters
srvrecord to free

Definition at line 150 of file dnsparser.c.

References GNUNET_free, GNUNET_free_non_null, and GNUNET_DNSPARSER_SrvRecord::target.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_free_record(), GNUNET_DNSPARSER_parse_srv(), and handle_gns_resolution_result().

151 {
152  if (NULL == srv)
153  return;
155  GNUNET_free (srv);
156 }
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * target
Hostname offering the service.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_soa()

void GNUNET_DNSPARSER_free_soa ( struct GNUNET_DNSPARSER_SoaRecord soa)

Free SOA information record.

Parameters
soarecord to free

Definition at line 119 of file dnsparser.c.

References GNUNET_free, GNUNET_free_non_null, GNUNET_DNSPARSER_SoaRecord::mname, and GNUNET_DNSPARSER_SoaRecord::rname.

Referenced by dns_value_to_string(), GNUNET_DNSPARSER_free_record(), GNUNET_DNSPARSER_parse_soa(), and handle_gns_resolution_result().

120 {
121  if (NULL == soa)
122  return;
125  GNUNET_free (soa);
126 }
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_free_cert()

void GNUNET_DNSPARSER_free_cert ( struct GNUNET_DNSPARSER_CertRecord cert)

Free CERT information record.

Parameters
certrecord to free

Definition at line 135 of file dnsparser.c.

References GNUNET_DNSPARSER_CertRecord::certificate_data, GNUNET_free, and GNUNET_free_non_null.

Referenced by dns_value_to_string(), and GNUNET_DNSPARSER_free_record().

136 {
137  if (NULL == cert)
138  return;
140  GNUNET_free (cert);
141 }
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * certificate_data
Data of the certificate.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_bin_to_hex()

char* GNUNET_DNSPARSER_bin_to_hex ( const void *  data,
size_t  data_size 
)

Convert a block of binary data to HEX.

Parameters
databinary data to convert
data_sizenumber of bytes in data
Returns
HEX string (lower case)

Definition at line 1356 of file dnsparser.c.

References data, data_size, GNUNET_malloc, and ret.

Referenced by dns_value_to_string().

1357 {
1358  char *ret;
1359  size_t off;
1360  const uint8_t *idata;
1361 
1362  idata = data;
1363  ret = GNUNET_malloc (data_size * 2 + 1);
1364  for (off = 0; off < data_size; off++)
1365  sprintf (&ret[off * 2], "%02x", idata[off]);
1366  return ret;
1367 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_DNSPARSER_hex_to_bin()

size_t GNUNET_DNSPARSER_hex_to_bin ( const char *  hex,
void *  data 
)

Convert a HEX string to block of binary data.

Parameters
hexHEX string to convert (may contain mixed case)
datawhere to write result, must be at least strlen(hex)/2 bytes long
Returns
number of bytes written to data

Definition at line 1379 of file dnsparser.c.

References data, data_size, and h.

Referenced by dns_string_to_value().

1380 {
1381  size_t data_size;
1382  size_t off;
1383  uint8_t *idata;
1384  unsigned int h;
1385  char in[3];
1386 
1387  data_size = strlen (hex) / 2;
1388  idata = data;
1389  in[2] = '\0';
1390  for (off = 0; off < data_size; off++)
1391  {
1392  in[0] = tolower ((unsigned char) hex[off * 2]);
1393  in[1] = tolower ((unsigned char) hex[off * 2 + 1]);
1394  if (1 != sscanf (in, "%x", &h))
1395  return off;
1396  idata[off] = (uint8_t) h;
1397  }
1398  return off;
1399 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the caller graph for this function: