...
1
2
3
4
5 package ipv4
6
7 import (
8 "net"
9 "syscall"
10 "unsafe"
11
12 "golang.org/x/net/internal/iana"
13 "golang.org/x/net/internal/socket"
14
15 "golang.org/x/sys/unix"
16 )
17
18 var (
19 ctlOpts = [ctlMax]ctlOpt{
20 ctlPacketInfo: {unix.IP_PKTINFO, sizeofInetPktinfo, marshalPacketInfo, parsePacketInfo},
21 }
22
23 sockOpts = map[int]*sockOpt{
24 ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.IP_MULTICAST_TTL, Len: 1}},
25 ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.IP_MULTICAST_IF, Len: 4}},
26 ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.IP_MULTICAST_LOOP, Len: 1}},
27 ssoPacketInfo: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.IP_RECVPKTINFO, Len: 4}},
28 ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
29 ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
30 ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
31 ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
32 ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
33 ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: unix.MCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
34 }
35 )
36
37 func (pi *inetPktinfo) setIfindex(i int) {
38 pi.Ifindex = uint32(i)
39 }
40
41 func (gr *groupReq) setGroup(grp net.IP) {
42 sa := (*sockaddrInet4)(unsafe.Pointer(&gr.Group))
43 sa.Family = syscall.AF_INET
44 sa.Len = sizeofSockaddrInet4
45 copy(sa.Addr[:], grp)
46 }
47
48 func (gsr *groupSourceReq) setSourceGroup(grp, src net.IP) {
49 sa := (*sockaddrInet4)(unsafe.Pointer(&gsr.Group))
50 sa.Family = syscall.AF_INET
51 sa.Len = sizeofSockaddrInet4
52 copy(sa.Addr[:], grp)
53 sa = (*sockaddrInet4)(unsafe.Pointer(&gsr.Source))
54 sa.Family = syscall.AF_INET
55 sa.Len = sizeofSockaddrInet4
56 copy(sa.Addr[:], src)
57 }
58
View as plain text