...
Run Format

Source file src/net/sockoptip_posix.go

     1	// Copyright 2011 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	
     5	// +build darwin dragonfly freebsd linux netbsd openbsd windows
     6	
     7	package net
     8	
     9	import (
    10		"os"
    11		"syscall"
    12	)
    13	
    14	func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
    15		mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
    16		if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
    17			return err
    18		}
    19		if err := fd.incref(); err != nil {
    20			return err
    21		}
    22		defer fd.decref()
    23		return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq))
    24	}
    25	
    26	func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
    27		var v int
    28		if ifi != nil {
    29			v = ifi.Index
    30		}
    31		if err := fd.incref(); err != nil {
    32			return err
    33		}
    34		defer fd.decref()
    35		return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v))
    36	}
    37	
    38	func setIPv6MulticastLoopback(fd *netFD, v bool) error {
    39		if err := fd.incref(); err != nil {
    40			return err
    41		}
    42		defer fd.decref()
    43		return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v)))
    44	}
    45	
    46	func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
    47		mreq := &syscall.IPv6Mreq{}
    48		copy(mreq.Multiaddr[:], ip)
    49		if ifi != nil {
    50			mreq.Interface = uint32(ifi.Index)
    51		}
    52		if err := fd.incref(); err != nil {
    53			return err
    54		}
    55		defer fd.decref()
    56		return os.NewSyscallError("setsockopt", syscall.SetsockoptIPv6Mreq(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq))
    57	}
    58	

View as plain text