當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。