1 // Copyright 2013 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.
11 "golang.org/x/net/bpf"
14 // MulticastHopLimit returns the hop limit field value for outgoing
16 func (c *dgramOpt) MulticastHopLimit() (int, error) {
18 return 0, syscall.EINVAL
20 so, ok := sockOpts[ssoMulticastHopLimit]
22 return 0, errOpNoSupport
24 return so.GetInt(c.Conn)
27 // SetMulticastHopLimit sets the hop limit field value for future
28 // outgoing multicast packets.
29 func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
33 so, ok := sockOpts[ssoMulticastHopLimit]
37 return so.SetInt(c.Conn, hoplim)
40 // MulticastInterface returns the default interface for multicast
41 // packet transmissions.
42 func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
44 return nil, syscall.EINVAL
46 so, ok := sockOpts[ssoMulticastInterface]
48 return nil, errOpNoSupport
50 return so.getMulticastInterface(c.Conn)
53 // SetMulticastInterface sets the default interface for future
54 // multicast packet transmissions.
55 func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
59 so, ok := sockOpts[ssoMulticastInterface]
63 return so.setMulticastInterface(c.Conn, ifi)
66 // MulticastLoopback reports whether transmitted multicast packets
67 // should be copied and send back to the originator.
68 func (c *dgramOpt) MulticastLoopback() (bool, error) {
70 return false, syscall.EINVAL
72 so, ok := sockOpts[ssoMulticastLoopback]
74 return false, errOpNoSupport
76 on, err := so.GetInt(c.Conn)
83 // SetMulticastLoopback sets whether transmitted multicast packets
84 // should be copied and send back to the originator.
85 func (c *dgramOpt) SetMulticastLoopback(on bool) error {
89 so, ok := sockOpts[ssoMulticastLoopback]
93 return so.SetInt(c.Conn, boolint(on))
96 // JoinGroup joins the group address group on the interface ifi.
97 // By default all sources that can cast data to group are accepted.
98 // It's possible to mute and unmute data transmission from a specific
99 // source by using ExcludeSourceSpecificGroup and
100 // IncludeSourceSpecificGroup.
101 // JoinGroup uses the system assigned multicast interface when ifi is
102 // nil, although this is not recommended because the assignment
103 // depends on platforms and sometimes it might require routing
105 func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
107 return syscall.EINVAL
109 so, ok := sockOpts[ssoJoinGroup]
111 return errOpNoSupport
113 grp := netAddrToIP16(group)
115 return errMissingAddress
117 return so.setGroup(c.Conn, ifi, grp)
120 // LeaveGroup leaves the group address group on the interface ifi
121 // regardless of whether the group is any-source group or
122 // source-specific group.
123 func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
125 return syscall.EINVAL
127 so, ok := sockOpts[ssoLeaveGroup]
129 return errOpNoSupport
131 grp := netAddrToIP16(group)
133 return errMissingAddress
135 return so.setGroup(c.Conn, ifi, grp)
138 // JoinSourceSpecificGroup joins the source-specific group comprising
139 // group and source on the interface ifi.
140 // JoinSourceSpecificGroup uses the system assigned multicast
141 // interface when ifi is nil, although this is not recommended because
142 // the assignment depends on platforms and sometimes it might require
143 // routing configuration.
144 func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
146 return syscall.EINVAL
148 so, ok := sockOpts[ssoJoinSourceGroup]
150 return errOpNoSupport
152 grp := netAddrToIP16(group)
154 return errMissingAddress
156 src := netAddrToIP16(source)
158 return errMissingAddress
160 return so.setSourceGroup(c.Conn, ifi, grp, src)
163 // LeaveSourceSpecificGroup leaves the source-specific group on the
165 func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
167 return syscall.EINVAL
169 so, ok := sockOpts[ssoLeaveSourceGroup]
171 return errOpNoSupport
173 grp := netAddrToIP16(group)
175 return errMissingAddress
177 src := netAddrToIP16(source)
179 return errMissingAddress
181 return so.setSourceGroup(c.Conn, ifi, grp, src)
184 // ExcludeSourceSpecificGroup excludes the source-specific group from
185 // the already joined any-source groups by JoinGroup on the interface
187 func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
189 return syscall.EINVAL
191 so, ok := sockOpts[ssoBlockSourceGroup]
193 return errOpNoSupport
195 grp := netAddrToIP16(group)
197 return errMissingAddress
199 src := netAddrToIP16(source)
201 return errMissingAddress
203 return so.setSourceGroup(c.Conn, ifi, grp, src)
206 // IncludeSourceSpecificGroup includes the excluded source-specific
207 // group by ExcludeSourceSpecificGroup again on the interface ifi.
208 func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
210 return syscall.EINVAL
212 so, ok := sockOpts[ssoUnblockSourceGroup]
214 return errOpNoSupport
216 grp := netAddrToIP16(group)
218 return errMissingAddress
220 src := netAddrToIP16(source)
222 return errMissingAddress
224 return so.setSourceGroup(c.Conn, ifi, grp, src)
227 // Checksum reports whether the kernel will compute, store or verify a
228 // checksum for both incoming and outgoing packets. If on is true, it
229 // returns an offset in bytes into the data of where the checksum
231 func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
233 return false, 0, syscall.EINVAL
235 so, ok := sockOpts[ssoChecksum]
237 return false, 0, errOpNoSupport
239 offset, err = so.GetInt(c.Conn)
246 return true, offset, nil
249 // SetChecksum enables the kernel checksum processing. If on is ture,
250 // the offset should be an offset in bytes into the data of where the
251 // checksum field is located.
252 func (c *dgramOpt) SetChecksum(on bool, offset int) error {
254 return syscall.EINVAL
256 so, ok := sockOpts[ssoChecksum]
258 return errOpNoSupport
263 return so.SetInt(c.Conn, offset)
266 // ICMPFilter returns an ICMP filter.
267 func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
269 return nil, syscall.EINVAL
271 so, ok := sockOpts[ssoICMPFilter]
273 return nil, errOpNoSupport
275 return so.getICMPFilter(c.Conn)
278 // SetICMPFilter deploys the ICMP filter.
279 func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
281 return syscall.EINVAL
283 so, ok := sockOpts[ssoICMPFilter]
285 return errOpNoSupport
287 return so.setICMPFilter(c.Conn, f)
290 // SetBPF attaches a BPF program to the connection.
292 // Only supported on Linux.
293 func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
295 return syscall.EINVAL
297 so, ok := sockOpts[ssoAttachFilter]
299 return errOpNoSupport
301 return so.setBPF(c.Conn, filter)