forked from bettercap/bettercap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udp.go
46 lines (38 loc) · 957 Bytes
/
udp.go
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
package packets
import (
"github.com/google/gopacket/layers"
"net"
)
func NewUDPProbe(from net.IP, from_hw net.HardwareAddr, to net.IP, port int) (error, []byte) {
eth := layers.Ethernet{
SrcMAC: from_hw,
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
EthernetType: layers.EthernetTypeIPv4,
}
udp := layers.UDP{
SrcPort: layers.UDPPort(12345),
DstPort: layers.UDPPort(port),
}
udp.Payload = []byte{0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef}
if to.To4() == nil {
ip6 := layers.IPv6{
NextHeader: layers.IPProtocolUDP,
Version: 6,
SrcIP: from,
DstIP: to,
HopLimit: 64,
}
udp.SetNetworkLayerForChecksum(&ip6)
return Serialize(ð, &ip6, &udp)
} else {
ip4 := layers.IPv4{
Protocol: layers.IPProtocolUDP,
Version: 4,
TTL: 64,
SrcIP: from,
DstIP: to,
}
udp.SetNetworkLayerForChecksum(&ip4)
return Serialize(ð, &ip4, &udp)
}
}