From 63c3bc6bccf095209361f898ff28e05c5580ea27 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Wed, 31 Oct 2018 17:57:11 +0100
Subject: [PATCH] Add handling of hosts with same name as domain

---
 src/hostinfo/named.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/hostinfo/named.py b/src/hostinfo/named.py
index f5db8fe..2d2e0a5 100755
--- a/src/hostinfo/named.py
+++ b/src/hostinfo/named.py
@@ -197,6 +197,18 @@ class DomainDict:
 def generate_forward(tree, hosts):
     def callback(domain):
         result = header(tree, domain, domain)
+        for name,address,ttl in hosts:
+            if name == '%s.' % (domain):
+                # Host with same name as domain goes into header
+                if address.version == 4:
+                    result += ('@      %-8s IN      A       %s' %
+                               (ttl, str(address.exploded)))
+                elif address.version == 6:
+                    result += ('@      %-8s IN      AAAA    %s' %
+                               (ttl, str(address.exploded)))
+                    pass
+                pass
+            pass
         for mx in [ m for m in tree._host_._interface_._mailhost_ 
                     if m.domain[0] == domain]:
             pri = int(mx.priority[0] or 0)
-- 
GitLab