@@ -71,12 +71,12 @@ func runPingFallback(ctx context.Context, addr common.Address, count int, timeou
71
71
return common .Output ("" ), err
72
72
}
73
73
74
- return common .Output (po .AvgRTT ), nil
74
+ return common .Output (po .AvgRTT + "ms" ), nil
75
75
}
76
76
77
77
func executeCommand (shell , command string ) (string , error ) {
78
78
var errb bytes.Buffer
79
- var out bytes. Buffer
79
+ var out string
80
80
81
81
cmd := exec .Command (shell , "-c" , command )
82
82
cmd .Stderr = & errb
@@ -91,14 +91,14 @@ func executeCommand(shell, command string) (string, error) {
91
91
92
92
scanner := bufio .NewScanner (stdout )
93
93
for scanner .Scan () {
94
- out . Write ( scanner .Bytes ())
94
+ out += scanner .Text () + " \n "
95
95
}
96
96
97
97
if err := cmd .Wait (); err != nil {
98
98
return "" , fmt .Errorf ("got error: %v, stderr: %v" , err , errb .String ())
99
99
}
100
100
101
- return out . String () , nil
101
+ return out , nil
102
102
}
103
103
104
104
type pingOutput struct {
@@ -112,7 +112,7 @@ type pingOutput struct {
112
112
113
113
var (
114
114
RequestTimeoutError = fmt .Errorf ("requests timed out" )
115
- PacketLossError = fmt .Errorf ("100.0%% packet loss" )
115
+ PacketLossError = fmt .Errorf ("timeout error: 100.0%% packet loss" )
116
116
)
117
117
118
118
// parsePingOutput parses the output of ping by parsing the stdout
@@ -134,14 +134,14 @@ func parsePingOutput(out string) (pingOutput, error) {
134
134
135
135
for _ , line := range lines {
136
136
switch {
137
- case strings .Contains (line , "packets transmitted" ) && strings . Contains ( line , "packets received" ) :
137
+ case strings .Contains (line , "packets transmitted" ):
138
138
arr := strings .Split (line , "," )
139
-
139
+ fmt . Println ( arr )
140
140
if len (arr ) != 3 {
141
141
continue
142
142
}
143
143
144
- po .MinRTT , po .AvgRTT , po .MaxRTT = arr [0 ], arr [1 ], arr [2 ]
144
+ po .PacketTransmitted , po .PacketReceived , po .PacketLoss = arr [0 ], arr [1 ], arr [2 ]
145
145
146
146
case strings .Contains (line , "round-trip min/avg/max" ):
147
147
l := strings .ReplaceAll (line , " = " , " " )
0 commit comments