gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/ipv4/sockopt_posix.go (about)

     1  // Copyright 2012 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  //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows || zos
     6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows zos
     7  
     8  package ipv4
     9  
    10  import (
    11  	"net"
    12  	"unsafe"
    13  
    14  	"gitee.com/ks-custle/core-gm/net/bpf"
    15  	"gitee.com/ks-custle/core-gm/net/internal/socket"
    16  )
    17  
    18  func (so *sockOpt) getMulticastInterface(c *socket.Conn) (*net.Interface, error) {
    19  	switch so.typ {
    20  	case ssoTypeIPMreqn:
    21  		return so.getIPMreqn(c)
    22  	default:
    23  		return so.getMulticastIf(c)
    24  	}
    25  }
    26  
    27  func (so *sockOpt) setMulticastInterface(c *socket.Conn, ifi *net.Interface) error {
    28  	switch so.typ {
    29  	case ssoTypeIPMreqn:
    30  		return so.setIPMreqn(c, ifi, nil)
    31  	default:
    32  		return so.setMulticastIf(c, ifi)
    33  	}
    34  }
    35  
    36  func (so *sockOpt) getICMPFilter(c *socket.Conn) (*ICMPFilter, error) {
    37  	b := make([]byte, so.Len)
    38  	n, err := so.Get(c, b)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  	if n != sizeofICMPFilter {
    43  		return nil, errNotImplemented
    44  	}
    45  	return (*ICMPFilter)(unsafe.Pointer(&b[0])), nil
    46  }
    47  
    48  func (so *sockOpt) setICMPFilter(c *socket.Conn, f *ICMPFilter) error {
    49  	b := (*[sizeofICMPFilter]byte)(unsafe.Pointer(f))[:sizeofICMPFilter]
    50  	return so.Set(c, b)
    51  }
    52  
    53  func (so *sockOpt) setGroup(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
    54  	switch so.typ {
    55  	case ssoTypeIPMreq:
    56  		return so.setIPMreq(c, ifi, grp)
    57  	case ssoTypeIPMreqn:
    58  		return so.setIPMreqn(c, ifi, grp)
    59  	case ssoTypeGroupReq:
    60  		return so.setGroupReq(c, ifi, grp)
    61  	default:
    62  		return errNotImplemented
    63  	}
    64  }
    65  
    66  func (so *sockOpt) setSourceGroup(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
    67  	return so.setGroupSourceReq(c, ifi, grp, src)
    68  }
    69  
    70  func (so *sockOpt) setBPF(c *socket.Conn, f []bpf.RawInstruction) error {
    71  	return so.setAttachFilter(c, f)
    72  }