diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-18 05:02:35 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-18 05:02:35 +0200 |
commit | 125976edcec65265d9ea3ca38a9826c71b4a88d9 (patch) | |
tree | 388dfcd6e63ba934873e8c347349d9952b967d5b /conn_default.go | |
parent | 52d797ce1ab590a7988edcbe13ce7ca31ab7c4ef (diff) |
Avoid using v6-mapped-v4
Diffstat (limited to 'conn_default.go')
-rw-r--r-- | conn_default.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/conn_default.go b/conn_default.go index 7556210..7204a03 100644 --- a/conn_default.go +++ b/conn_default.go @@ -45,7 +45,10 @@ func (e *NativeEndpoint) SrcIP() net.IP { func (e *NativeEndpoint) DstToBytes() []byte { addr := (*net.UDPAddr)(e) - out := addr.IP + out := addr.IP.To4() + if out == nil { + out = addr.IP + } out = append(out, byte(addr.Port&0xff)) out = append(out, byte((addr.Port>>8)&0xff)) return out @@ -112,6 +115,9 @@ func (bind *NativeBind) Close() error { func (bind *NativeBind) ReceiveIPv4(buff []byte) (int, Endpoint, error) { n, endpoint, err := bind.ipv4.ReadFromUDP(buff) + if endpoint != nil { + endpoint.IP = endpoint.IP.To4() + } return n, (*NativeEndpoint)(endpoint), err } @@ -123,10 +129,10 @@ func (bind *NativeBind) ReceiveIPv6(buff []byte) (int, Endpoint, error) { func (bind *NativeBind) Send(buff []byte, endpoint Endpoint) error { var err error nend := endpoint.(*NativeEndpoint) - if nend.IP.To16() != nil { - _, err = bind.ipv6.WriteToUDP(buff, (*net.UDPAddr)(nend)) - } else { + if nend.IP.To4() != nil { _, err = bind.ipv4.WriteToUDP(buff, (*net.UDPAddr)(nend)) + } else { + _, err = bind.ipv6.WriteToUDP(buff, (*net.UDPAddr)(nend)) } return err } |