-
v, err := strconv.Atof(s)
-
v, err := strconv.Atof32(s)
*f = floatValue(v)
return err == nil
}
@@ -378,14 +378,14 @@ func String(name, value string, usage string) *string {
// FloatVar defines a float flag with specified name, default value, and usage string.
// The argument p points to a float variable in which to store the value of the flag.
-func FloatVar(p *float, name string, value float, usage string) {
+func FloatVar(p *float32, name string, value float32, usage string) {
Var(newFloatValue(value, p), name, usage)
}
// Float defines a float flag with specified name, default value, and usage string.
// The return value is the address of a float variable that stores the value of the flag.
-func Float(name string, value float, usage string) *float {
-
+func Float(name string, value float32, usage string) *float32 {
-
p := new(float32)
FloatVar(p, name, value, usage)
return p
}
diff --git a/reflector-responder.go b/reflector-responder.go
index 4a3b933..38d947b 100644
--- a/reflector-responder.go
+++ b/reflector-responder.go
@@ -27,7 +27,7 @@ const includesPort = false // If false, sends only the address for TXT queries.
func txtRecord(client net.Addr) []byte {
sclient := client.String()
if !includesPort {
-
tcpAddr, _ := net.ResolveTCPAddr(sclient)
-
tcpAddr, _ := net.ResolveTCPAddr("tcp", sclient)
sclient = tcpAddr.IP.String()
}
return types.ToTXT(sclient)
@@ -65,12 +65,12 @@ func Respond(query types.DNSquery, config map[string]interface{}) types.DNSrespo
result types.DNSresponse
)
result.Ansection = nil
-
tcpAddr, _ := net.ResolveTCPAddr(query.Client.String())
-
tcpAddr, _ := net.ResolveTCPAddr("tcp", query.Client.String())
ipaddressV4 := tcpAddr.IP.To4()
zonei, zoneset := config["zonename"]
zone := ""
if zoneset {
-
zone = reflect.NewValue(zonei).(*reflect.StringValue).Get()
-
zone = reflect.ValueOf(zonei).String()
}
switch {
case query.Qclass != types.IN:
diff --git a/server.go b/server.go
index 30b9eb4..ded6d42 100644
--- a/server.go
+++ b/server.go
@@ -35,7 +35,7 @@ var (
)
func fatal(msg string) {
-
crisislogger.Logf("%s\n", msg)
-
crisislogger.Printf("%s\n", msg)
os.Exit(1)
}
-
servername := reflect.NewValue(servernamei).(*reflect.StringValue).Get()
-
servername := reflect.ValueOf(servernamei).String()
if packet.Nsid {
binary.BigEndian.PutUint16(result[last+9:last+11],
uint16(4+len(servername)))
@@ -137,7 +137,7 @@ func readShortInteger(buf *bytes.Buffer) (uint16, bool) {
n, error := buf.Read(slice[0:2])
if error != nil || n != 2 {
if debug > 2 {
-
debuglogger.Logf("Error in Read of an int16: %s (%d bytes read)\n", error, n)
-
debuglogger.Printf("Error in Read of an int16: %s (%d bytes read)\n", error, n)
}
return 0, false
}
@@ -149,7 +149,7 @@ func readInteger(buf *bytes.Buffer) (uint32, bool) {
n, error := buf.Read(slice[0:4])
if error != nil || n != 4 {
if debug > 2 {
-
debuglogger.Logf("Error in Read of an int32: %s (%d bytes read)\n", error, n)
-
debuglogger.Printf("Error in Read of an int32: %s (%d bytes read)\n", error, n)
}
return 0, false
}
@@ -219,7 +219,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
-
debuglogger.Logf("Error in ReadByte: %s\n", error)
-
debuglogger.Printf("Error in ReadByte: %s\n", error)
}
return packet, false
}
@@ -236,7 +236,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
-
debuglogger.Logf("Error in Read %d bytes: %s\n", n, error)
-
debuglogger.Printf("Error in Read %d bytes: %s\n", n, error)
}
return packet, false
}
@@ -266,14 +266,14 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
-
debuglogger.Logf("Error in ReadByte: %s\n", error)
-
debuglogger.Printf("Error in ReadByte: %s\n", error)
}
return packet, false
}
}
if labelsize != 0 {
if debug > 2 {
-
debuglogger.Logf("Additional section with non-empty name\n")
-
debuglogger.Printf("Additional section with non-empty name\n")
}
return packet, false
}
@@ -304,7 +304,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
-
debuglogger.Logf("Error in Read %d bytes: %s\n", n, error)
-
debuglogger.Printf("Error in Read %d bytes: %s\n", n, error)
}
return packet, false
}
@@ -328,22 +328,22 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
over = true
}
if debug > 3 {
-
debuglogger.Logf("EDNS option code %d\n", optcode)
-
debuglogger.Printf("EDNS option code %d\n", optcode)
}
}
}
if debug > 2 {
-
debuglogger.Logf("EDNS0 found, buffer size is %d, extended rcode is %d, ", packet.EdnsBufferSize, extrcode)
-
debuglogger.Printf("EDNS0 found, buffer size is %d, extended rcode is %d, ", packet.EdnsBufferSize, extrcode)
if ednslength > 0 {
-
debuglogger.Logf("length of options is %d\n", ednslength)
-
debuglogger.Printf("length of options is %d\n", ednslength)
} else {
-
debuglogger.Logf("no options\n")
-
debuglogger.Printf("no options\n")
}
}
} else {
if debug > 2 {
-
debuglogger.Logf("Ignore additional section if not EDNS")
-
debuglogger.Printf("Ignore additional section if not EDNS")
}
}
}
@@ -359,16 +359,16 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
packet, valid := parse(buf)
if !valid { // Invalid packet or client too impatient
if debug > 3 {
-
debuglogger.Logf("Invalid packet received\n")
-
debuglogger.Printf("Invalid packet received\n")
}
return
}
if debug > 2 {
-
debuglogger.Logf("%s\n", packet)
-
debuglogger.Printf("%s\n", packet)
}
if packet.Query && packet.Opcode == types.STDQUERY {
if debug > 2 {
-
debuglogger.Logf("Replying with ID %d...\n", packet.Id)
-
debuglogger.Printf("Replying with ID %d...\n", packet.Id)
}
noresponse = false
response.Id = packet.Id
@@ -396,7 +396,7 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
if query.Qclass == types.CH && query.Qtype == types.TXT &&
(query.Qname == "hostname.bind" ||
query.Qname == "id.server") && nameexists {
-
servername := reflect.NewValue(servernamei).(*reflect.StringValue).Get()
-
servername := reflect.ValueOf(servernamei).String()
desiredresponse.Responsecode = types.NOERROR
desiredresponse.Ansection = make([]types.RR, 1)
desiredresponse.Ansection[0] = types.RR{
@@ -423,7 +423,7 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
var response types.DNSpacket
if debug > 1 {
-
debuglogger.Logf("%d bytes packet from %s\n", buf.Len(), remaddr)
-
debuglogger.Printf("%d bytes packet from %s\n", buf.Len(), remaddr)
}
response, noresponse := generichandle(buf, remaddr)
if !noresponse {
@@ -431,7 +431,7 @@ func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
_, error := conn.WriteTo(binaryresponse, remaddr)
if error != nil {
if debug > 2 {
-
debuglogger.Logf("Error in Write: %s\n", error)
-
debuglogger.Printf("Error in Write: %s\n", error)
return
}
}
@@ -441,13 +441,13 @@ func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
func tcphandle(connection net.Conn) {
if debug > 1 {
-
debuglogger.Logf("TCP connection accepted from %s\n", connection.RemoteAddr())
-
debuglogger.Printf("TCP connection accepted from %s\n", connection.RemoteAddr())
}
smallbuf := make([]byte, 2)
n, error := connection.Read(smallbuf)
if error != nil {
if debug > 2 {
-
debuglogger.Logf("Cannot read message length from TCP connection: %s\n", error)
-
debuglogger.Printf("Cannot read message length from TCP connection: %s\n", error)
return
}
}
@@ -456,12 +456,12 @@ func tcphandle(connection net.Conn) {
n, error = connection.Read(message)
if error != nil {
if debug > 2 {
-
debuglogger.Logf("Cannot read message from TCP connection with %s: %s\n", connection.RemoteAddr(), error)
-
debuglogger.Printf("Cannot read message from TCP connection with %s: %s\n", connection.RemoteAddr(), error)
return
}
}
if debug > 1 {
-
debuglogger.Logf("%d bytes read from %s\n", n, connection.RemoteAddr())
-
debuglogger.Printf("%d bytes read from %s\n", n, connection.RemoteAddr())
}
response, noresponse := generichandle(bytes.NewBuffer(message), connection.RemoteAddr())
if !noresponse {
@@ -471,14 +471,14 @@ func tcphandle(connection net.Conn) {
n, error := connection.Write(shortbuf)
if n != 2 || error != nil {
if debug > 2 {
-
debuglogger.Logf("Error in TCP message length Write: %s\n", error)
-
debuglogger.Printf("Error in TCP message length Write: %s\n", error)
return
}
}
n, error = connection.Write(binaryresponse)
if error != nil {
if debug > 2 {
-
debuglogger.Logf("Error in TCP message Write: %s\n", error)
-
debuglogger.Printf("Error in TCP message Write: %s\n", error)
return
}
}
@@ -493,7 +493,7 @@ func tcpListener(address *net.TCPAddr, comm chan bool) {
connection, error := listener.Accept()
if error != nil {
if debug > 1 {
-
debuglogger.Logf("Cannot accept TCP connection: %s\n", error)
-
debuglogger.Printf("Cannot accept TCP connection: %s\n", error)
continue
}
}
@@ -512,7 +512,7 @@ func udpListener(address *net.UDPAddr, comm chan bool) {
n, remaddr, error := listener.ReadFrom(message)
if error != nil {
if debug > 1 {
-
debuglogger.Logf("Cannot read UDP from %s: %s\n", remaddr.String(), error)
-
debuglogger.Printf("Cannot read UDP from %s: %s\n", remaddr.String(), error)
continue
}
}
@@ -554,10 +554,10 @@ func main() {
debug = _debugptr
globalConfig["debug"] = *debugptr
globalConfig["daemon"] = !_nodaemonptr
-
daemon = !reflect.NewValue(_nodaemonptr).(_reflect.BoolValue).Get()
-
udpaddr, error := net.ResolveUDPAddr(*listen)
-
daemon = !reflect.ValueOf(*nodaemonptr).Bool()
-
udpaddr, error := net.ResolveUDPAddr("udp", *listen)
checkError(fmt.Sprintf("Cannot parse \"%s\": %s\n", *listen), error)
-
tcpaddr, error := net.ResolveTCPAddr(*listen)
-
tcpaddr, error := net.ResolveTCPAddr("tcp", *listen)
checkError(fmt.Sprintf("Cannot parse \"%s\": %s\n", *listen), error)
if daemon {
debuglogger = syslog.NewLogger(syslog.LOG_DEBUG,
@@ -567,15 +567,15 @@ func main() {
crisislogger = syslog.NewLogger(syslog.LOG_CRIT,
loggerOptions)
} else {
-
debuglogger = log.New(os.Stderr, nil, "[DEBUG] ",
-
debuglogger = log.New(os.Stderr, "[DEBUG] ",
loggerOptions)
-
infologger = log.New(os.Stderr, nil, "[INFO] ",
-
infologger = log.New(os.Stderr, "[INFO] ",
loggerOptions)
-
crisislogger = log.New(os.Stderr, nil, "[FATAL] ",
-
crisislogger = log.New(os.Stderr, "[FATAL] ",
loggerOptions)
}
responder.Init(flag.LastOption())
-
infologger.Logf("%s", fmt.Sprintf("Starting%s%s...", namemsg, zonemsg))
-
infologger.Printf("%s", fmt.Sprintf("Starting%s%s...", namemsg, zonemsg))
udpchan := make(chan bool)
go udpListener(udpaddr, udpchan)
tcpchan := make(chan bool)
@@ -584,5 +584,5 @@ func main() {
<-udpchan // Just to wait the listener, otherwise, the Go runtime ends
// even if there are live goroutines
<-tcpchan
-
infologger.Logf("%s", "Terminating...")
-
infologger.Printf("%s", "Terminating...")
}
diff --git a/types.go b/types.go
index ddca35e..79d99fd 100644
--- a/types.go
+++ b/types.go
@@ -10,7 +10,6 @@ import (
"net"
"strings"
"fmt"
-
"bytes"
"encoding/binary"
)
http://pastebin.com/QdpM46iP
diff --git a/myflag.go b/myflag.go
index d92aa49..29be758 100644
--- a/myflag.go
+++ b/myflag.go
@@ -153,15 +153,15 @@ func (s *stringValue) Set(val string) bool {
func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
// -- Float Value
-type floatValue float
+type floatValue float32
-func newFloatValue(val float, p _float) *floatValue {
+func newFloatValue(val float32, p *float32) *floatValue {
*p = val
return (_floatValue)(p)
}
func (f *floatValue) Set(s string) bool {
}
@@ -378,14 +378,14 @@ func String(name, value string, usage string) *string {
// FloatVar defines a float flag with specified name, default value, and usage string.
// The argument p points to a float variable in which to store the value of the flag.
-func FloatVar(p *float, name string, value float, usage string) {
+func FloatVar(p *float32, name string, value float32, usage string) {
Var(newFloatValue(value, p), name, usage)
}
// Float defines a float flag with specified name, default value, and usage string.
// The return value is the address of a float variable that stores the value of the flag.
-func Float(name string, value float, usage string) *float {
+func Float(name string, value float32, usage string) *float32 {
}
diff --git a/reflector-responder.go b/reflector-responder.go
index 4a3b933..38d947b 100644
--- a/reflector-responder.go
+++ b/reflector-responder.go
@@ -27,7 +27,7 @@ const includesPort = false // If false, sends only the address for TXT queries.
func txtRecord(client net.Addr) []byte {
sclient := client.String()
if !includesPort {
@@ -65,12 +65,12 @@ func Respond(query types.DNSquery, config map[string]interface{}) types.DNSrespo
result types.DNSresponse
)
result.Ansection = nil
diff --git a/server.go b/server.go
index 30b9eb4..ded6d42 100644
--- a/server.go
+++ b/server.go
@@ -35,7 +35,7 @@ var (
)
func fatal(msg string) {
}
@@ -110,7 +110,7 @@ func serialize(packet types.DNSpacket) []byte {
binary.BigEndian.PutUint32(result[last+5:last+9], 0)
servernamei, nameexists := globalConfig["servername"]
if nameexists {
@@ -137,7 +137,7 @@ func readShortInteger(buf *bytes.Buffer) (uint16, bool) {
n, error := buf.Read(slice[0:2])
if error != nil || n != 2 {
if debug > 2 {
@@ -149,7 +149,7 @@ func readInteger(buf *bytes.Buffer) (uint32, bool) {
n, error := buf.Read(slice[0:4])
if error != nil || n != 4 {
if debug > 2 {
@@ -219,7 +219,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
@@ -236,7 +236,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
@@ -266,14 +266,14 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
@@ -304,7 +304,7 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
return packet, false
} else {
if debug > 2 {
@@ -328,22 +328,22 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
over = true
}
if debug > 3 {
@@ -359,16 +359,16 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
packet, valid := parse(buf)
if !valid { // Invalid packet or client too impatient
if debug > 3 {
@@ -396,7 +396,7 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
if query.Qclass == types.CH && query.Qtype == types.TXT &&
(query.Qname == "hostname.bind" ||
query.Qname == "id.server") && nameexists {
@@ -423,7 +423,7 @@ func generichandle(buf *bytes.Buffer, remaddr net.Addr) (response types.DNSpacke
func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
var response types.DNSpacket
if debug > 1 {
@@ -431,7 +431,7 @@ func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
_, error := conn.WriteTo(binaryresponse, remaddr)
if error != nil {
if debug > 2 {
@@ -441,13 +441,13 @@ func udphandle(conn *net.UDPConn, remaddr net.Addr, buf *bytes.Buffer) {
func tcphandle(connection net.Conn) {
if debug > 1 {
@@ -456,12 +456,12 @@ func tcphandle(connection net.Conn) {
n, error = connection.Read(message)
if error != nil {
if debug > 2 {
@@ -471,14 +471,14 @@ func tcphandle(connection net.Conn) {
n, error := connection.Write(shortbuf)
if n != 2 || error != nil {
if debug > 2 {
@@ -493,7 +493,7 @@ func tcpListener(address *net.TCPAddr, comm chan bool) {
connection, error := listener.Accept()
if error != nil {
if debug > 1 {
@@ -512,7 +512,7 @@ func udpListener(address *net.UDPAddr, comm chan bool) {
n, remaddr, error := listener.ReadFrom(message)
if error != nil {
if debug > 1 {
@@ -554,10 +554,10 @@ func main() {
debug = _debugptr
globalConfig["debug"] = *debugptr
globalConfig["daemon"] = !_nodaemonptr
@@ -567,15 +567,15 @@ func main() {
crisislogger = syslog.NewLogger(syslog.LOG_CRIT,
loggerOptions)
} else {
@@ -584,5 +584,5 @@ func main() {
<-udpchan // Just to wait the listener, otherwise, the Go runtime ends
// even if there are live goroutines
<-tcpchan
}
diff --git a/types.go b/types.go
index ddca35e..79d99fd 100644
--- a/types.go
+++ b/types.go
@@ -10,7 +10,6 @@ import (
"net"
"strings"
"fmt"
)
@@ -145,7 +144,7 @@ func Encode(name string) []byte {
)
labels := make([]string, 0)
if name != "." { // The root is a special case. See issue #4
length = length + (5 * 4) // Five 32-bits counter at the end
/* "It's probably cleaner to write to a bytes.Buffer than to
repeatedly call bytes.Add." Russ Cox, go-nuts ML */