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