Commit 7300b43c authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: remove more use of fmt

Also add a TODO for the broken *dnsMsg String method.

R=golang-dev, rsc, borman
CC=golang-dev
https://golang.org/cl/5720075
parent a55a6cb9
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
package net package net
import ( import (
"fmt"
"os"
"reflect" "reflect"
) )
...@@ -394,7 +392,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) ...@@ -394,7 +392,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
f := val.Type().Field(i) f := val.Type().Field(i)
switch fv := val.Field(i); fv.Kind() { switch fv := val.Field(i); fv.Kind() {
default: default:
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) println("net: dns: unknown packing type", f.Type.String())
return len(msg), false return len(msg), false
case reflect.Struct: case reflect.Struct:
off, ok = packStructValue(fv, msg, off) off, ok = packStructValue(fv, msg, off)
...@@ -418,7 +416,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) ...@@ -418,7 +416,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
off += 4 off += 4
case reflect.Array: case reflect.Array:
if fv.Type().Elem().Kind() != reflect.Uint8 { if fv.Type().Elem().Kind() != reflect.Uint8 {
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) println("net: dns: unknown packing type", f.Type.String())
return len(msg), false return len(msg), false
} }
n := fv.Len() n := fv.Len()
...@@ -433,7 +431,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) ...@@ -433,7 +431,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
s := fv.String() s := fv.String()
switch f.Tag { switch f.Tag {
default: default:
fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag) println("net: dns: unknown string tag", string(f.Tag))
return len(msg), false return len(msg), false
case `net:"domain-name"`: case `net:"domain-name"`:
off, ok = packDomainName(s, msg, off) off, ok = packDomainName(s, msg, off)
...@@ -471,7 +469,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo ...@@ -471,7 +469,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
f := val.Type().Field(i) f := val.Type().Field(i)
switch fv := val.Field(i); fv.Kind() { switch fv := val.Field(i); fv.Kind() {
default: default:
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) println("net: dns: unknown packing type", f.Type.String())
return len(msg), false return len(msg), false
case reflect.Struct: case reflect.Struct:
off, ok = unpackStructValue(fv, msg, off) off, ok = unpackStructValue(fv, msg, off)
...@@ -491,7 +489,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo ...@@ -491,7 +489,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
off += 4 off += 4
case reflect.Array: case reflect.Array:
if fv.Type().Elem().Kind() != reflect.Uint8 { if fv.Type().Elem().Kind() != reflect.Uint8 {
fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type) println("net: dns: unknown packing type", f.Type.String())
return len(msg), false return len(msg), false
} }
n := fv.Len() n := fv.Len()
...@@ -504,7 +502,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo ...@@ -504,7 +502,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
var s string var s string
switch f.Tag { switch f.Tag {
default: default:
fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag) println("net: dns: unknown string tag", string(f.Tag))
return len(msg), false return len(msg), false
case `net:"domain-name"`: case `net:"domain-name"`:
s, off, ok = unpackDomainName(msg, off) s, off, ok = unpackDomainName(msg, off)
...@@ -560,7 +558,9 @@ func printStructValue(val reflect.Value) string { ...@@ -560,7 +558,9 @@ func printStructValue(val reflect.Value) string {
i := fv.Interface().([]byte) i := fv.Interface().([]byte)
s += IP(i).String() s += IP(i).String()
} else { } else {
s += fmt.Sprint(fval.Interface()) // TODO(bradfitz,rsc): this next line panics (the String method of
// *dnsMsg has been broken for awhile). Rewrite, ditch reflect.
//s += fmt.Sprint(fval.Interface())
} }
} }
s += "}" s += "}"
......
...@@ -19,6 +19,7 @@ func TestDNSParseSRVReply(t *testing.T) { ...@@ -19,6 +19,7 @@ func TestDNSParseSRVReply(t *testing.T) {
if !ok { if !ok {
t.Fatalf("unpacking packet failed") t.Fatalf("unpacking packet failed")
} }
msg.String() // exercise this code path
if g, e := len(msg.answer), 5; g != e { if g, e := len(msg.answer), 5; g != e {
t.Errorf("len(msg.answer) = %d; want %d", g, e) t.Errorf("len(msg.answer) = %d; want %d", g, e)
} }
...@@ -50,6 +51,7 @@ func TestDNSParseCorruptSRVReply(t *testing.T) { ...@@ -50,6 +51,7 @@ func TestDNSParseCorruptSRVReply(t *testing.T) {
if !ok { if !ok {
t.Fatalf("unpacking packet failed") t.Fatalf("unpacking packet failed")
} }
msg.String() // exercise this code path
if g, e := len(msg.answer), 5; g != e { if g, e := len(msg.answer), 5; g != e {
t.Errorf("len(msg.answer) = %d; want %d", g, e) t.Errorf("len(msg.answer) = %d; want %d", g, e)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment