-
Notifications
You must be signed in to change notification settings - Fork 60
/
utils_windows.go
88 lines (73 loc) · 2.23 KB
/
utils_windows.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//go:build windows
// +build windows
package probing
import (
"math"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
)
const (
minimumBufferLength = 2048
)
// Returns the length of an ICMP message, plus the IP packet header.
// Calculated as:
// len(ICMP request data) + 2 * (len(ICMP header) + len(IP header))
//
// On Windows, the buffer needs to be able to contain:
// - Response IP Header
// - Response ICMP Header
// - Request IP Header
// - Request ICMP Header
// - Request Data
func (p *Pinger) getMessageLength() int {
if p.ipv4 {
calculatedLength := p.Size + (ipv4.HeaderLen+8)*2
return int(math.Max(float64(calculatedLength), float64(minimumBufferLength)))
}
calculatedLength := p.Size + (ipv6.HeaderLen+8)*2
return int(math.Max(float64(calculatedLength), float64(minimumBufferLength)))
}
// Attempts to match the ID of an ICMP packet.
func (p *Pinger) matchID(ID int) bool {
if ID != p.id {
return false
}
return true
}
// SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN.
func (c *icmpConn) SetMark(mark uint) error {
return ErrMarkNotSupported
}
// SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN.
func (c *icmpv4Conn) SetMark(mark uint) error {
return ErrMarkNotSupported
}
// SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN.
func (c *icmpV6Conn) SetMark(mark uint) error {
return ErrMarkNotSupported
}
// SetDoNotFragment sets the do-not-fragment bit in the IP header of outgoing ICMP packets.
func (c *icmpConn) SetDoNotFragment() error {
return ErrDFNotSupported
}
// SetDoNotFragment sets the do-not-fragment bit in the IP header of outgoing ICMP packets.
func (c *icmpv4Conn) SetDoNotFragment() error {
return ErrDFNotSupported
}
// SetDoNotFragment sets the do-not-fragment bit in the IPv6 header of outgoing ICMPv6 packets.
func (c *icmpV6Conn) SetDoNotFragment() error {
return ErrDFNotSupported
}
// No need for SetBroadcastFlag in non-linux OSes
func (c *icmpConn) SetBroadcastFlag() error {
return nil
}
func (c *icmpv4Conn) SetBroadcastFlag() error {
return nil
}
func (c *icmpV6Conn) SetBroadcastFlag() error {
return nil
}