File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -769,7 +769,11 @@ func (ip Addr) String() string {
769
769
default :
770
770
if ip .Is4In6 () {
771
771
// TODO(bradfitz): this could alloc less.
772
- return "::ffff:" + ip .Unmap ().String ()
772
+ if z := ip .Zone (); z != "" {
773
+ return "::ffff:" + ip .Unmap ().String () + "%" + z
774
+ } else {
775
+ return "::ffff:" + ip .Unmap ().String ()
776
+ }
773
777
}
774
778
return ip .string6 ()
775
779
}
@@ -787,7 +791,12 @@ func (ip Addr) AppendTo(b []byte) []byte {
787
791
default :
788
792
if ip .Is4In6 () {
789
793
b = append (b , "::ffff:" ... )
790
- return ip .Unmap ().appendTo4 (b )
794
+ b = ip .Unmap ().appendTo4 (b )
795
+ if z := ip .Zone (); z != "" {
796
+ b = append (b , '%' )
797
+ b = append (b , z ... )
798
+ }
799
+ return b
791
800
}
792
801
return ip .appendTo6 (b )
793
802
}
@@ -947,10 +956,16 @@ func (ip Addr) MarshalText() ([]byte, error) {
947
956
b := make ([]byte , 0 , max )
948
957
if ip .Is4In6 () {
949
958
b = append (b , "::ffff:" ... )
950
- return ip .Unmap ().appendTo4 (b ), nil
959
+ b = ip .Unmap ().appendTo4 (b )
960
+ if z := ip .Zone (); z != "" {
961
+ b = append (b , '%' )
962
+ b = append (b , z ... )
963
+ }
964
+ return b , nil
951
965
}
952
966
return ip .appendTo6 (b ), nil
953
967
}
968
+
954
969
}
955
970
956
971
// UnmarshalText implements the encoding.TextUnmarshaler interface.
Original file line number Diff line number Diff line change @@ -114,6 +114,12 @@ func TestParseAddr(t *testing.T) {
114
114
ip : MkAddr (Mk128 (0x0001000200000000 , 0x0000ffffc0a88cff ), intern .Get ("eth1" )),
115
115
str : "1:2::ffff:c0a8:8cff%eth1" ,
116
116
},
117
+ // 4-in-6 with zone
118
+ {
119
+ in : "::ffff:192.168.140.255%eth1" ,
120
+ ip : MkAddr (Mk128 (0 , 0x0000ffffc0a88cff ), intern .Get ("eth1" )),
121
+ str : "::ffff:192.168.140.255%eth1" ,
122
+ },
117
123
// IPv6 with capital letters.
118
124
{
119
125
in : "FD9E:1A04:F01D::1" ,
You can’t perform that action at this time.
0 commit comments