-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcapture_freebsd.go
More file actions
61 lines (54 loc) · 1.51 KB
/
Copy pathcapture_freebsd.go
File metadata and controls
61 lines (54 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"syscall"
"unsafe"
)
// Data structure needed by the SIOCADDMULTI ioctl call.
// Based upon the code found in the diagnostic and test
// utility for multicast sockets shipped with FreeBSD:
// https://github.com/freebsd/freebsd/blob/2f4b735c66deb54490042a818e8fd26fa46818f1/usr.sbin/mtest/mtest.c#L759
type IfReq struct {
Name [16]byte
Len uint8
Family uint8
Index uint16
Type uint8
Nlen uint8
Alen uint8
Slen uint8
Data [8]byte
}
// Setup the given device to join the EAP(OL) link layer multicast group.
func joinMulticastGroup(device string) (fd int) {
var ifname [16]byte
copy(ifname[:], device)
fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_UDP)
if err != nil {
log.WithFields(logrus.Fields{"device": device}).Fatal("Error opening socket")
}
ifReq := IfReq{
Name: ifname,
Len: unix.SizeofSockaddrDatalink,
Family: unix.AF_LINK,
Index: 0,
Type: 0,
Nlen: 0,
Alen: hwAddressLength,
Slen: 0,
Data: [8]uint8{0x01, 0x80, 0xc2, 0x00, 0x00, 0x03},
}
_, _, errNo := unix.Syscall(
unix.SYS_IOCTL,
uintptr(fd),
uintptr(unix.SIOCADDMULTI),
uintptr(unsafe.Pointer(&ifReq)),
)
if errNo == syscall.EADDRINUSE {
log.WithFields(logrus.Fields{"device": device}).Debug("Already a member in the EAP link-layer multicast group")
} else if errNo > 0 {
log.WithFields(logrus.Fields{"device": device}).Fatal("Could not join EAP link-layer multicast group")
}
return fd
}