feat: 尝试添加IPV6路由追踪

This commit is contained in:
spiritlhl 2025-04-05 03:24:04 +00:00
parent 0c6b11883f
commit 7efc61cbe4
2 changed files with 30 additions and 0 deletions

30
bk/trace_ipv6.go Normal file
View File

@ -0,0 +1,30 @@
package bk
import (
"net"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv6"
)
func newPacketV6(id uint16, dst net.IP, ttl int) []byte {
msg := icmp.Message{
Type: ipv6.ICMPTypeEchoRequest,
Body: &icmp.Echo{
ID: int(id),
Seq: int(id),
},
}
p, _ := msg.Marshal(nil)
ip := &ipv6.Header{
Version: ipv6.Version,
NextHeader: ProtocolIPv6ICMP,
HopLimit: ttl,
Dst: dst,
}
buf, err := ip.Marshal()
if err != nil {
return nil
}
return append(buf, p...)
}