// ExternalAddress returns external IP address information from a NAT gateway,
// as described in RFC 4886, section 3.2.
ExternalAddress returns external IP address information from a NAT gateway,
as described in RFC 4886, section 3.2.
// ExternalAddress returns external IP address information from a NAT gateway // as described in RFC 4886 section 3 . 2 .
func (c *Client) ExternalAddress(ctx context.Context) (*ExternalAddress, net.Addr, error) {
	const (
		size  = 12
		reqOp = 0x00
		resOp = 128
	)
	b := make([]byte, size)
	n, addr, err := c.request(ctx, []byte{Version, reqOp}, b, resOp)
	if err != nil {
		return nil, nil, err
	}
	if n != size {
		return nil, nil, io.ErrUnexpectedEOF
	}
	return &ExternalAddress{
		SinceStartOfEpoch: time.Duration(binary.BigEndian.Uint32(b[4:8])) * time.Second,
		ExternalIP:        b[8:12],
	}, addr, nil
}
func ( c * Client ) ExternalAddress ( ctx context . Context ) ( * ExternalAddress , net . Addr , error ) { const ( size = 12 reqOp = 0x00 resOp = 128 ) b := make ( [ ] byte , size ) n , addr , err := c . request ( ctx , [ ] byte { Version , reqOp } , b , resOp ) if err != nil { return nil , nil , err } if n != size { return nil , nil , io . ErrUnexpectedEOF } return & ExternalAddress { SinceStartOfEpoch : time . Duration ( binary . BigEndian . Uint32 ( b [ 4 : 8 ] ) ) * time . Second , ExternalIP : b [ 8 : 12 ] , } , addr , nil }
ExternalAddress returns external IP address information from a NAT gateway,
as described in RFC 4886, section 3.2.
ExternalAddress returns external IP address information from a NAT gateway as described in RFC 4886 section 3 . 2 .
// This messages's request is always fixed, and the response always has a // fixed size and response opcode. See: // https://tools.ietf.org/html/rfc6886#section-3.2. // We allocated a buffer internally, no need to produce a copy of the data // for the output IP address.