helper function: less code needed

This commit is contained in:
Miek Gieben 2011-02-10 12:53:39 +01:00
parent 61925e2002
commit 75d28c4399

View File

@ -74,15 +74,19 @@ type Funkensturm struct {
Actions []Action // What to do with the packets
}
func verboseprint(i *dns.Msg, msg string) {
fmt.Printf(">>>>>> %s\n", msg)
fmt.Printf("%v", i)
fmt.Printf("<<<<<< %s\n\n", msg)
}
func doFunkensturm(i []byte) ([]byte, os.Error) {
pkt := new(dns.Msg)
if !pkt.Unpack(i) {
return nil, &dns.Error{Error: "Unpacking packet failed"}
}
if *verbose {
fmt.Printf(">>>>>> ORIGINAL INCOMING\n")
fmt.Printf("%v", pkt)
fmt.Printf("<<<<<< ORIGINAL INCOMING\n")
verboseprint(pkt, "ORIGINAL INCOMING")
}
// No matter what, we refuse to answer requests with the response bit set.
if pkt.MsgHdr.Response == true {
@ -104,9 +108,7 @@ func doFunkensturm(i []byte) ([]byte, os.Error) {
}
}
if *verbose {
fmt.Printf(">>>>>> MODIFIED INCOMING\n")
fmt.Printf("%v", pkt1)
fmt.Printf("<<<<<< MODIFIED INCOMING\n")
verboseprint(pkt1, "MODIFIED INCOMING")
}
// Loop through the Actions.Func* and do something with the
@ -118,9 +120,7 @@ func doFunkensturm(i []byte) ([]byte, os.Error) {
}
if *verbose {
fmt.Printf(">>>>>> ORIGINAL OUTGOING\n")
fmt.Printf("%v", resultpkt)
fmt.Printf("<<<<<< ORIGINAL OUTGOING\n")
verboseprint(resultpkt, "ORIGINAL OUTGOING")
}
// loop again for matching, but now with OUT, this is done
@ -138,9 +138,8 @@ func doFunkensturm(i []byte) ([]byte, os.Error) {
}
if *verbose {
fmt.Printf(">>>>>> MODIFIED OUTGOING\n")
fmt.Printf("%v", pkt1)
fmt.Printf("<<<<<< MODIFIED OUTGOING\n")
verboseprint(pkt1, "MODIFIED OUTGOING")
fmt.Printf("-----------------------------------\n\n")
}
out, ok1 := pkt1.Pack()