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