Skip to content

Commit

Permalink
fix: ip response
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra committed Sep 24, 2024
1 parent ac3a493 commit cb2bb8e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bufio"
"fmt"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -158,8 +157,10 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
if r.Opcode == dns.OpcodeQuery {
for _, q := range m.Question {
switch q.Qtype {
case dns.TypeA:
ip := net.ParseIP(strings.TrimSuffix(q.Name, "."))
case dns.TypeTXT:
name := strings.TrimSuffix(q.Name, ".")
ip := net.ParseIP(name)

if ip == nil {
continue
}
Expand All @@ -173,11 +174,11 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
txt = "SAFE"
}

rr, err := dns.NewRR(fmt.Sprintf("%s %d IN TXT \"%s\"", q.Name, cacheTTL, txt))
if err == nil {
rr.Header().Ttl = cacheTTL
m.Answer = append(m.Answer, rr)
rr := &dns.TXT{
Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: cacheTTL},
Txt: []string{txt},
}
m.Answer = append(m.Answer, rr)
}
}
}
Expand Down

0 comments on commit cb2bb8e

Please sign in to comment.