Commit 41068aa6 authored by Steven Allen's avatar Steven Allen

correctly format ip4-in-6 addresses

fixes part one of #77
parent a80cfc33
......@@ -451,6 +451,7 @@ func TestBinaryRepresentation(t *testing.T) {
func TestRoundTrip(t *testing.T) {
for _, s := range []string{
"/unix/a/b/c/d",
"/ip6/::ffff:127.0.0.1/tcp/111",
"/ip4/127.0.0.1/tcp/123",
"/ip4/127.0.0.1/udp/123",
"/ip4/127.0.0.1/udp/123/ip6/::",
......
......@@ -46,8 +46,8 @@ func (t twrp) ValidateBytes(b []byte) error {
return t.validbyte(b)
}
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ipBtS, nil)
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ipBtS, nil)
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ip4BtS, nil)
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ip6BtS, nil)
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
func ip4StB(s string) ([]byte, error) {
......@@ -88,7 +88,16 @@ func ip6StB(s string) ([]byte, error) {
return i, nil
}
func ipBtS(b []byte) (string, error) {
func ip6BtS(b []byte) (string, error) {
ip := net.IP(b)
if ip4 := ip.To4(); ip4 != nil {
// Go fails to prepend the `::ffff:` part.
return "::ffff:" + ip4.String(), nil
}
return ip.String(), nil
}
func ip4BtS(b []byte) (string, error) {
return net.IP(b).String(), nil
}
......
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