Ejemplo n.º 1
0
func simpleResolve(addr network.Addr) (*net.UDPAddr, error) {
	var stringNetwork, stringAddr string
	if addr == nil {
		stringNetwork = "udp4"
		stringAddr = ""
	} else {
		stringNetwork = addr.Network()
		stringAddr = addr.String()
	}
	addrResolved, err := net.ResolveUDPAddr(stringNetwork, stringAddr)
	if err != nil {
		return nil, err
	}
	return addrResolved, nil
}
Ejemplo n.º 2
0
func (c *Conn) WriteTo(b []byte, raddr network.Addr) (int, error) {
	buffer := make([]byte, len(b))
	copy(buffer, b)
	raddrResolved, err := ResolveAddr(raddr.String())
	if err != nil {
		return 0, err
	}
	go func() {
		c.net.toInternet <- packet{
			Src:  c.localAddr,
			Dst:  raddrResolved,
			Data: buffer,
		}
	}()
	return len(buffer), nil
}