github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/ipv4/sys_ssmreq.go (about)

     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  
     5  // +build darwin freebsd linux solaris
     6  
     7  package ipv4
     8  
     9  import (
    10  	"net"
    11  	"unsafe"
    12  
    13  	"golang.org/x/net/internal/socket"
    14  )
    15  
    16  func (so *sockOpt) setGroupReq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
    17  	var gr groupReq
    18  	if ifi != nil {
    19  		gr.Interface = uint32(ifi.Index)
    20  	}
    21  	gr.setGroup(grp)
    22  	var b []byte
    23  	if compatFreeBSD32 {
    24  		var d [sizeofGroupReq + 4]byte
    25  		s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))
    26  		copy(d[:4], s[:4])
    27  		copy(d[8:], s[4:])
    28  		b = d[:]
    29  	} else {
    30  		b = (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))[:sizeofGroupReq]
    31  	}
    32  	return so.Set(c, b)
    33  }
    34  
    35  func (so *sockOpt) setGroupSourceReq(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
    36  	var gsr groupSourceReq
    37  	if ifi != nil {
    38  		gsr.Interface = uint32(ifi.Index)
    39  	}
    40  	gsr.setSourceGroup(grp, src)
    41  	var b []byte
    42  	if compatFreeBSD32 {
    43  		var d [sizeofGroupSourceReq + 4]byte
    44  		s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
    45  		copy(d[:4], s[:4])
    46  		copy(d[8:], s[4:])
    47  		b = d[:]
    48  	} else {
    49  		b = (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))[:sizeofGroupSourceReq]
    50  	}
    51  	return so.Set(c, b)
    52  }