Skip to content

Commit

Permalink
prevent panic from type assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maartje Eyskens committed Aug 24, 2018
1 parent dd39cdc commit 8910bb0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions imcp/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@ func listenForSpecific(conn *icmp.PacketConn, deadline time.Time, neededPeer, ne
index := bytes.Index(body, sent[:4])
if index > 0 {
x, _ := icmp.ParseMessage(1, body[index:])
seq := x.Body.(*icmp.Echo).Seq
if seq == needSeq {
return peer.String(), "", nil
switch x.Body.(type) {
case *icmp.Echo:
seq := x.Body.(*icmp.Echo).Seq
if seq == needSeq {
return peer.String(), "", nil
}
default:
// ignore
}
}
}
Expand Down

0 comments on commit 8910bb0

Please sign in to comment.