LEFT | RIGHT |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ipv4 | 5 package ipv4 |
6 | 6 |
7 import "net" | 7 // supportsPacketInfo reports whether the platform supports |
8 | 8 // IP_PKTINFO. |
9 type sysSockoptLen uint32 | 9 var supportsPacketInfo bool |
10 | |
11 const ( | |
12 » sysSizeofMulticastReq = 0x8 | |
13 ) | |
14 | |
15 type sysMulticastReq struct { | |
16 » IP [4]byte | |
17 » Interface [4]byte | |
18 } | |
19 | |
20 func (mreq *sysMulticastReq) setInterface(ifi *net.Interface) error { | |
21 » if ifi == nil { | |
22 » » return nil | |
23 » } | |
24 » ifat, err := ifi.Addrs() | |
25 » if err != nil { | |
26 » » return err | |
27 » } | |
28 » for _, ifa := range ifat { | |
29 » » switch v := ifa.(type) { | |
30 » » case *net.IPAddr: | |
31 » » » if ip := v.IP.To4(); ip != nil { | |
32 » » » » copy(mreq.Interface[:], ip) | |
33 » » » » return nil | |
34 » » » } | |
35 » » case *net.IPNet: | |
36 » » » if ip := v.IP.To4(); ip != nil { | |
37 » » » » copy(mreq.Interface[:], ip) | |
38 » » » » return nil | |
39 » » » } | |
40 » » } | |
41 » } | |
42 » return errNoSuchInterface | |
43 } | |
LEFT | RIGHT |