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