sockopt_mreqn.go 868 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build linux
  5. package ipv4
  6. import (
  7. "net"
  8. "os"
  9. "syscall"
  10. )
  11. func joinIPv4Group(fd int, ifi *net.Interface, grp net.IP) error {
  12. mreqn := syscall.IPMreqn{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
  13. if ifi != nil {
  14. mreqn.Ifindex = int32(ifi.Index)
  15. }
  16. return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreqn(fd, ianaProtocolIP, sysSockoptJoinGroup, &mreqn))
  17. }
  18. func leaveIPv4Group(fd int, ifi *net.Interface, grp net.IP) error {
  19. mreqn := syscall.IPMreqn{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
  20. if ifi != nil {
  21. mreqn.Ifindex = int32(ifi.Index)
  22. }
  23. return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreqn(fd, ianaProtocolIP, sysSockoptLeaveGroup, &mreqn))
  24. }