@@ -42,7 +42,7 @@ func (pinger *Pinger) Ping(destination *net.IPAddr, timeout time.Duration) (time
42
42
func (pinger * Pinger ) PingContext (ctx context.Context , destination * net.IPAddr ) (time.Duration , error ) {
43
43
req := simpleRequest {}
44
44
45
- seq , err := pinger .sendRequest (destination , & req )
45
+ idseq , err := pinger .sendRequest (destination , & req )
46
46
if err != nil {
47
47
return 0 , err
48
48
}
@@ -54,7 +54,7 @@ func (pinger *Pinger) PingContext(ctx context.Context, destination *net.IPAddr)
54
54
err = req .result
55
55
case <- ctx .Done ():
56
56
// dequeue request
57
- pinger .removeRequest (seq )
57
+ pinger .removeRequest (idseq )
58
58
err = & timeoutError {}
59
59
}
60
60
@@ -77,7 +77,7 @@ func (pinger *Pinger) PingMulticast(destination *net.IPAddr, wait time.Duration)
77
77
func (pinger * Pinger ) PingMulticastContext (ctx context.Context , destination * net.IPAddr ) (<- chan Reply , error ) {
78
78
req := multiRequest {}
79
79
80
- seq , err := pinger .sendRequest (destination , & req )
80
+ idseq , err := pinger .sendRequest (destination , & req )
81
81
if err != nil {
82
82
return nil , err
83
83
}
@@ -86,7 +86,7 @@ func (pinger *Pinger) PingMulticastContext(ctx context.Context, destination *net
86
86
<- ctx .Done ()
87
87
88
88
// dequeue request
89
- pinger .removeRequest (seq )
89
+ pinger .removeRequest (idseq )
90
90
91
91
req .close ()
92
92
}()
@@ -95,9 +95,12 @@ func (pinger *Pinger) PingMulticastContext(ctx context.Context, destination *net
95
95
}
96
96
97
97
// sendRequest marshals the payload and sends the packet.
98
- // It returns the sequence number and an error if the sending failed.
99
- func (pinger * Pinger ) sendRequest (destination * net.IPAddr , req request ) (uint16 , error ) {
100
- seq := uint16 (atomic .AddUint32 (& sequence , 1 ))
98
+ // It returns the combined id+sequence number and an error if the sending failed.
99
+ func (pinger * Pinger ) sendRequest (destination * net.IPAddr , req request ) (uint32 , error ) {
100
+ id := uint16 (pinger .Id )
101
+ seq := uint16 (atomic .AddUint32 (pinger .SequenceCounter , 1 ))
102
+
103
+ idseq := (uint32 (id ) << 16 ) | uint32 (seq )
101
104
102
105
pinger .payloadMu .RLock ()
103
106
defer pinger .payloadMu .RUnlock ()
@@ -106,7 +109,7 @@ func (pinger *Pinger) sendRequest(destination *net.IPAddr, req request) (uint16,
106
109
wm := icmp.Message {
107
110
Code : 0 ,
108
111
Body : & icmp.Echo {
109
- ID : int (pinger . id ),
112
+ ID : int (id ),
110
113
Seq : int (seq ),
111
114
Data : pinger .payload ,
112
115
},
@@ -128,12 +131,12 @@ func (pinger *Pinger) sendRequest(destination *net.IPAddr, req request) (uint16,
128
131
// serialize packet
129
132
wb , err := wm .Marshal (nil )
130
133
if err != nil {
131
- return seq , err
134
+ return idseq , err
132
135
}
133
136
134
137
// enqueue in currently running requests
135
138
pinger .mtx .Lock ()
136
- pinger .requests [seq ] = req
139
+ pinger .requests [idseq ] = req
137
140
pinger .mtx .Unlock ()
138
141
139
142
// start measurement (tStop is set in the receiving end)
@@ -147,10 +150,10 @@ func (pinger *Pinger) sendRequest(destination *net.IPAddr, req request) (uint16,
147
150
// send failed, need to remove request from list
148
151
if err != nil {
149
152
req .close ()
150
- pinger .removeRequest (seq )
153
+ pinger .removeRequest (idseq )
151
154
152
- return 0 , err
155
+ return idseq , err
153
156
}
154
157
155
- return seq , nil
158
+ return idseq , nil
156
159
}
0 commit comments