// Copyright 2016 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package tcp

import (
	
	
	
)

func ( *Conn) (,  *net.TCPAddr) (net.Addr, error) {
	var ,  int
	var  []byte
	if .IP.To4() != nil {
		 = ianaProtocolIP
		 = sysSO_ORIGINAL_DST
		 = make([]byte, sizeofSockaddrInet)
	}
	if .IP.To16() != nil && .IP.To4() == nil {
		 = ianaProtocolIPv6
		 = sysIP6T_SO_ORIGINAL_DST
		 = make([]byte, sizeofSockaddrInet6)
	}
	if ,  := .option(, , );  != nil {
		return nil, 
	}
	 := new(net.TCPAddr)
	switch len() {
	case sizeofSockaddrInet:
		 := (*sockaddrInet)(unsafe.Pointer(&[0]))
		.IP = make(net.IP, net.IPv4len)
		copy(.IP, .Addr[:])
		.Port = int(binary.BigEndian.Uint16((*[2]byte)(unsafe.Pointer(&.Port))[:]))
	case sizeofSockaddrInet6:
		 := (*sockaddrInet6)(unsafe.Pointer(&[0]))
		.IP = make(net.IP, net.IPv6len)
		copy(.IP, .Addr[:])
		.Port = int(binary.BigEndian.Uint16((*[2]byte)(unsafe.Pointer(&.Port))[:]))
		.Zone = zoneCache.name(int(.Scope_id))
	}
	return , nil
}