// SetTTL sets the time-to-live field value for future outgoing
// packets.
func (c *genericOpt) SetTTL(ttl int) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return err
	}
	return setInt(s, &sockOpts[ssoTTL], ttl)
}
// TTL returns the time-to-live field value for outgoing packets.
func (c *genericOpt) TTL() (int, error) {
	if !c.ok() {
		return 0, syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return 0, err
	}
	return getInt(s, &sockOpts[ssoTTL])
}
// SetHopLimit sets the hop limit field value for future outgoing
// packets.
func (c *genericOpt) SetHopLimit(hoplim int) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return err
	}
	return setInt(s, &sockOpts[ssoHopLimit], hoplim)
}
// SetTrafficClass sets the traffic class field value for future
// outgoing packets.
func (c *genericOpt) SetTrafficClass(tclass int) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return err
	}
	return setInt(s, &sockOpts[ssoTrafficClass], tclass)
}
Exemple #5
0
// PathMTU returns a path MTU value for the destination associated
// with the endpoint.
func (c *Conn) PathMTU() (int, error) {
	if !c.genericOpt.ok() {
		return 0, syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.genericOpt.Conn)
	if err != nil {
		return 0, err
	}
	_, mtu, err := getMTUInfo(s, &sockOpts[ssoPathMTU])
	if err != nil {
		return 0, err
	}
	return mtu, nil
}
func TestSocketOf(t *testing.T) {
	for _, network := range []string{"tcp", "unix", "unixpacket"} {
		switch network {
		case "unix":
			switch runtime.GOOS {
			case "nacl", "plan9", "windows":
				continue
			}
		case "unixpacket":
			switch runtime.GOOS {
			case "darwin", "nacl", "plan9", "windows":
				continue
			}
		}
		ln, err := newLocalListener(network)
		if err != nil {
			t.Error(err)
			continue
		}
		defer func() {
			path := ln.Addr().String()
			ln.Close()
			if network == "unix" || network == "unixpacket" {
				os.Remove(path)
			}
		}()
		c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
		if err != nil {
			t.Error(err)
			continue
		}
		defer c.Close()
		if _, err := netreflect.SocketOf(c); err != nil {
			t.Error(err)
			continue
		}
	}
}