当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.SetsockoptIPMreq函数代码示例

本文整理汇总了Golang中syscall.SetsockoptIPMreq函数的典型用法代码示例。如果您正苦于以下问题:Golang SetsockoptIPMreq函数的具体用法?Golang SetsockoptIPMreq怎么用?Golang SetsockoptIPMreq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetsockoptIPMreq函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: leaveIPv4Group

func leaveIPv4Group(fd int, ifi *net.Interface, grp net.IP) error {
	mreq := syscall.IPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
	if err := setSyscallIPMreq(&mreq, ifi); err != nil {
		return err
	}
	return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd, ianaProtocolIP, syscall.IP_DROP_MEMBERSHIP, &mreq))
}
开发者ID:98pm,项目名称:docker,代码行数:7,代码来源:sockopt_bsd.go

示例2: ListenMulticastIPv4

// ListenMulticastIPv4 creates a net.IPConn to receive multicast messages for the given group
// address. laddr specifies which network interface to use when joining the group.
func ListenMulticastIPv4(gaddr, laddr net.IP) (*net.IPConn, error) {
	gaddr = gaddr.To4()
	laddr = laddr.To4()
	c, err := net.ListenIP("ip4:112", &net.IPAddr{IP: gaddr})
	if err != nil {
		return nil, err
	}

	f, err := c.File()
	if err != nil {
		return nil, err
	}
	defer f.Close()

	mreq := &syscall.IPMreq{
		Multiaddr: [4]byte{gaddr[0], gaddr[1], gaddr[2], gaddr[3]},
		Interface: [4]byte{laddr[0], laddr[1], laddr[2], laddr[3]},
	}

	err = syscall.SetsockoptIPMreq(int(f.Fd()), syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
	if err != nil {
		return nil, err
	}

	return c, nil
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:28,代码来源:net.go

示例3: joinIPv4Group

func joinIPv4Group(fd int, ifi *net.Interface, grp net.IP) error {
	mreq := syscall.IPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
	if err := setSysIPMreqInterface(&mreq, ifi); err != nil {
		return err
	}
	return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd, ianaProtocolIP, sysSockoptJoinGroup, &mreq))
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:7,代码来源:sockopt_mreq.go

示例4: leaveIPv4GroupUDP

func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
	mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
	if err := setIPv4InterfaceToJoin(mreq, ifi); err != nil {
		return &OpError{"leaveipv4group", "udp", &IPAddr{ip}, err}
	}
	if err := os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq)); err != nil {
		return &OpError{"leaveipv4group", "udp", &IPAddr{ip}, err}
	}
	return nil
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:10,代码来源:udpsock_posix.go

示例5: leaveIPv4Group

func leaveIPv4Group(fd int, ifi *net.Interface, grp net.IP) error {
	mreq := &syscall.IPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
	if err := setSyscallIPMreq(mreq, ifi); err != nil {
		return err
	}
	err := syscall.SetsockoptIPMreq(fd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq)
	if err != nil {
		return os.NewSyscallError("setsockopt", err)
	}
	return nil
}
开发者ID:Bobberino,项目名称:musings,代码行数:11,代码来源:sockopt_bsd.go

示例6: joinIPv4Group

func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
	mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
	if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
		return err
	}
	if err := fd.incref(false); err != nil {
		return err
	}
	defer fd.decref()
	err := syscall.SetsockoptIPMreq(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
	if err != nil {
		return os.NewSyscallError("setsockopt", err)
	}
	return nil
}
开发者ID:pkdevboxy,项目名称:appscale,代码行数:15,代码来源:sockoptip_posix.go

示例7: LeaveGroup

// LeaveGroup exits the IPv4 multicast group named by addr.
func (c *UDPConn) LeaveGroup(addr IP) os.Error {
	if !c.ok() {
		return os.EINVAL
	}
	ip := addr.To4()
	if ip == nil {
		return &OpError{"leavegroup", "udp", &IPAddr{ip}, errInvalidMulticast}
	}
	mreq := &syscall.IPMreq{
		Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]},
	}
	err := os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq))
	if err != nil {
		return &OpError{"leavegroup", "udp", &IPAddr{ip}, err}
	}
	return nil
}
开发者ID:ssrl,项目名称:go,代码行数:18,代码来源:udpsock.go

示例8: createSocket

func (s *Ssdp) createSocket() error {
	// create the socket
	var err error
	s.socket.socket, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
	if err != nil {
		return err
	}
	// make sure we can reuse it / share it
	if err := syscall.SetsockoptInt(s.socket.socket, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
		syscall.Closesocket(s.socket.socket)
		s.socket.socket = 0
		return err
	}
	// going to broadcast
	if err := syscall.SetsockoptInt(s.socket.socket, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil {
		syscall.Closesocket(s.socket.socket)
		s.socket.socket = 0
		return err
	}
	// bind it to the ssdp port
	lsa := &syscall.SockaddrInet4{Port: 1900, Addr: [4]byte{0, 0, 0, 0}}
	err = syscall.Bind(s.socket.socket, lsa)
	if err != nil {
		syscall.Closesocket(s.socket.socket)
		s.socket.socket = 0
		return err
	}
	iter, err := net.Interfaces()
	if err != nil {
		syscall.Closesocket(s.socket.socket)
		s.socket.socket = 0
		return err
	}
	wasFound := false
	for i := range iter {
		if iter[i].Flags&net.FlagMulticast == 0 {
			continue
		}
		addrs, err := iter[i].Addrs()
		if err != nil {
			continue
		}
		for k := range addrs {
			as4 := addrs[k].(*net.IPAddr).IP.To4()
			// join the multicast group
			mreq := &syscall.IPMreq{Multiaddr: [4]byte{239, 255, 255, 250}, Interface: [4]byte{as4[0], as4[1], as4[2], as4[3]}}
			if err := syscall.SetsockoptIPMreq(s.socket.socket, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq); err != nil {
				syscall.Closesocket(s.socket.socket)
				s.socket.socket = 0
				return err
			}
			wasFound = true
		}
	}
	// if we couldn't join a group, fall back to just 0.0.0.0
	if !wasFound {
		mreq := &syscall.IPMreq{Multiaddr: [4]byte{239, 255, 255, 250}, Interface: [4]byte{0, 0, 0, 0}}
		if err := syscall.SetsockoptIPMreq(s.socket.socket, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq); err != nil {
			syscall.Closesocket(s.socket.socket)
			s.socket.socket = 0
			return err
		}
	}

	s.socket.readBytes = make([]byte, 2048)

	return nil
}
开发者ID:mark2b,项目名称:gossdp,代码行数:68,代码来源:broadcast_windows.go


注:本文中的syscall.SetsockoptIPMreq函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。