Skip to content

Commit f1a67ac

Browse files
authored
Merge pull request #3 from babs/fix-df-windows-local
fix: do-not-fragment on unsupported platform and localized pings
2 parents 27a5605 + 67c4d69 commit f1a67ac

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Available probing means are:
3030

3131
Pure Go is the default option but for unprivileged users ([see linux notes](#linux-notes-on-pure-go-ping)), OS/system's ping command (usually available on OS with specific cap or setuid) can be used with a background spawn model with `-s` flag. Privileged mode (default when user is root or on windows) can be forcefully enabled with `-privileged`.
3232

33-
On pure Go implementation, ICMP packet size can be specified using `-size` option. Given size doesn't account for the 28 bytes header (note for usual limits: 1472 or 8972). This has no effect on system's ping, refer to system's manual and use `-ping-options`.
33+
On pure Go implementation, ICMP packet size can be specified using `-size` option, note that do-not-fragment bit is set only for linux platform (kind of defeat the purpose of `-size` on other platforms :/). Given size doesn't account for the 28 bytes header (note for usual limits: 1472 or 8972). This has no effect on system's ping, refer to system's manual and use `-ping-options`.
3434

3535
Hint ca be given about address family resolution using `ip<family>://`, `ip://` is the default, `ip4://` to force IPv4 and `ip6://` to force IPv6, example:
3636
- `google.com` is equivalent to `ip://google.com`

pinger_probing.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func (w *ProbingWrapper) Start() {
3434
w.pinger.OnRecv = w.onRecv
3535
w.pinger.OnDuplicateRecv = w.onDuplicateRecv
3636
w.pinger.Size = w.size
37-
w.pinger.SetDoNotFragment(true)
37+
if runtime.GOOS == "linux" {
38+
w.pinger.SetDoNotFragment(true)
39+
}
3840

3941
if runtime.GOOS == "windows" || os.Getuid() == 0 {
4042
w.pinger.SetPrivileged(true)

pinger_system.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type SystemPingWrapper struct {
2525
}
2626

2727
var time_extractor = regexp.MustCompile(`time[=<]([\d\.]+) *(.?s)`)
28+
var time_extractor_non_local = regexp.MustCompile(`[=<]([\d\.]+) *(.?s)`)
2829

2930
func (w *SystemPingWrapper) Start() {
3031
w.hstring = fmt.Sprintf("%s (%s)", w.host, w.ip.String())
@@ -53,12 +54,16 @@ func (w *SystemPingWrapper) Start() {
5354
log.Fatal(err)
5455
}
5556

57+
extractor := time_extractor
58+
5659
if runtime.GOOS == "windows" {
5760
args = append(args, "-t")
61+
extractor = time_extractor_non_local
5862
}
5963
args = append(args, w.ip.String())
6064

6165
w.cmd = exec.Command(path, args...)
66+
w.cmd.Env = append(w.cmd.Environ(), "LANG=C")
6267

6368
w.stats = &PWStats{
6469
state: true,
@@ -69,7 +74,7 @@ func (w *SystemPingWrapper) Start() {
6974
// Read line by line and process it
7075
for scanner.Scan() {
7176
line := scanner.Text()
72-
extracted := time_extractor.FindAllStringSubmatch(line, -1)
77+
extracted := extractor.FindAllStringSubmatch(line, -1)
7378
if len(extracted) > 0 {
7479
w.stats.lastrecv = time.Now().UnixNano()
7580
w.stats.lastrtt_as_string = extracted[0][1] + extracted[0][2]

0 commit comments

Comments
 (0)