chiark / gitweb /
resolved: MX records
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 1 Aug 2014 01:06:00 +0000 (21:06 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 Jul 2014 12:56:03 +0000 (08:56 -0400)
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-rr.c
src/resolve/resolved-dns-rr.h

index 3e6c9a4..217bdaf 100644 (file)
@@ -549,6 +549,13 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star
                 break;
 
         case DNS_TYPE_MX:
+                r = dns_packet_append_uint16(p, rr->mx.priority, NULL);
+                if (r < 0)
+                        goto fail;
+
+                r = dns_packet_append_name(p, rr->mx.exchange, NULL);
+                break;
+
         case DNS_TYPE_TXT:
         case DNS_TYPE_SRV:
         case DNS_TYPE_DNAME:
@@ -951,6 +958,13 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
                 break;
 
         case DNS_TYPE_MX:
+                r = dns_packet_read_uint16(p, &rr->mx.priority, NULL);
+                if (r < 0)
+                        goto fail;
+
+                r = dns_packet_read_name(p, &rr->mx.exchange, NULL);
+                break;
+
         case DNS_TYPE_TXT:
         case DNS_TYPE_SRV:
         case DNS_TYPE_DNAME:
index e1200c9..2e13b9c 100644 (file)
@@ -237,6 +237,8 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
                 } else if (rr->key->type == DNS_TYPE_SOA) {
                         free(rr->soa.mname);
                         free(rr->soa.rname);
+                } else if (rr->key->type == DNS_TYPE_MX) {
+                        free(rr->mx.exchange);
                 } else if (!IN_SET(rr->key->type, DNS_TYPE_A, DNS_TYPE_AAAA))
                         free(rr->generic.data);
 
@@ -322,6 +324,12 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
                        a->soa.retry   == b->soa.retry &&
                        a->soa.expire  == b->soa.expire &&
                        a->soa.minimum == b->soa.minimum;
+        case DNS_TYPE_MX:
+                if (a->mx.priority != b->mx.priority)
+                        return 0;
+
+                return dns_name_equal(a->mx.exchange, b->mx.exchange);
+
         default:
                 return a->generic.size == b->generic.size &&
                         memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
@@ -396,6 +404,15 @@ int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
                         return -ENOMEM;
                 break;
 
+        case DNS_TYPE_MX:
+                r = asprintf(&s, "%s %u %s",
+                             k,
+                             rr->mx.priority,
+                             rr->mx.exchange);
+                if (r < 0)
+                        return -ENOMEM;
+                break;
+
         default: {
                 _cleanup_free_ char *x = NULL;
 
index 7b73cdc..359d662 100644 (file)
@@ -119,6 +119,11 @@ struct DnsResourceRecord {
                         uint32_t expire;
                         uint32_t minimum;
                 } soa;
+
+                struct {
+                        uint16_t priority;
+                        char *exchange;
+                } mx;
         };
 };