diff --git a/trace/icmp_ipv4.go b/trace/icmp_ipv4.go index 5434072..5b9065e 100644 --- a/trace/icmp_ipv4.go +++ b/trace/icmp_ipv4.go @@ -150,8 +150,9 @@ func (t *ICMPTracer) listenICMP() { } continue } + ttl := int(msg.Msg[36]) packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2) - if process_id, ttl, err := reverseID(packet_id); err == nil { + if process_id, _, err := reverseID(packet_id); err == nil { if process_id == int64(os.Getpid()&0x7f) { dstip := net.IP(msg.Msg[24:28]) if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv4zero) { @@ -266,15 +267,20 @@ func (t *ICMPTracer) send(ttl int) error { return nil } - id := gernerateID(ttl) + //id := gernerateID(ttl) + id := gernerateID(0) // log.Println("发送的", id) + data := []byte{byte(ttl)} + data = append(data, bytes.Repeat([]byte{1}, t.Config.PktSize-5)...) + data = append(data, 0x00, 0x00, 0x4f, 0xff) + icmpHeader := icmp.Message{ Type: ipv4.ICMPTypeEcho, Code: 0, Body: &icmp.Echo{ ID: id, //Data: []byte("HELLO-R-U-THERE"), - Data: append(bytes.Repeat([]byte{1}, t.Config.PktSize-4), 0x00, 0x00, 0x4f, 0xff), + Data: data, Seq: ttl, }, } diff --git a/trace/icmp_ipv6.go b/trace/icmp_ipv6.go index 7202788..ecb4a70 100644 --- a/trace/icmp_ipv6.go +++ b/trace/icmp_ipv6.go @@ -171,8 +171,9 @@ func (t *ICMPTracerv6) listenICMP() { } } + ttl := int(msg.Msg[56]) packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2) - if process_id, ttl, err := reverseID(packet_id); err == nil { + if process_id, _, err := reverseID(packet_id); err == nil { if process_id == int64(os.Getpid()&0x7f) { dstip := net.IP(msg.Msg[32:48]) // 无效包本地环回包 @@ -260,14 +261,19 @@ func (t *ICMPTracerv6) send(ttl int) error { if t.final != -1 && ttl > t.final { return nil } - id := gernerateID(ttl) + //id := gernerateID(ttl) + id := gernerateID(0) + + data := []byte{byte(ttl)} + data = append(data, bytes.Repeat([]byte{1}, t.Config.PktSize-5)...) + data = append(data, 0x00, 0x00, 0x4f, 0xff) icmpHeader := icmp.Message{ Type: ipv6.ICMPTypeEchoRequest, Code: 0, Body: &icmp.Echo{ ID: id, //Data: []byte("HELLO-R-U-THERE"), - Data: append(bytes.Repeat([]byte{1}, t.Config.PktSize-4), 0x00, 0x00, 0x4f, 0xff), + Data: data, Seq: ttl, }, }