diff --git a/trace/tcp_ipv4.go b/trace/tcp_ipv4.go index 5482230..170dea1 100644 --- a/trace/tcp_ipv4.go +++ b/trace/tcp_ipv4.go @@ -217,7 +217,7 @@ func (t *TCPTracer) send(ttl int) error { DstIP: t.DestIP, Protocol: layers.IPProtocolTCP, TTL: uint8(ttl), - Flags: layers.IPv4DontFragment, + //Flags: layers.IPv4DontFragment, // 我感觉没必要 } // 使用Uint16兼容32位系统,防止在rand的时候因使用int32而溢出 sequenceNumber := uint32(r.Intn(math.MaxUint16)) diff --git a/trace/tcp_ipv6.go b/trace/tcp_ipv6.go index 884acfd..801d1c9 100644 --- a/trace/tcp_ipv6.go +++ b/trace/tcp_ipv6.go @@ -227,9 +227,16 @@ func (t *TCPTracerv6) send(ttl int) error { desiredPayloadSize := t.Config.PktSize payload := make([]byte, desiredPayloadSize) - copy(buf.Bytes(), payload) + // 设置随机种子 + rand.Seed(time.Now().UnixNano()) - if err := gopacket.SerializeLayers(buf, opts, tcpHeader); err != nil { + // 填充随机数 + for i := range payload { + payload[i] = byte(rand.Intn(256)) + } + //copy(buf.Bytes(), payload) + + if err := gopacket.SerializeLayers(buf, opts, tcpHeader, gopacket.Payload(payload)); err != nil { return err } @@ -237,9 +244,6 @@ func (t *TCPTracerv6) send(ttl int) error { if err != nil { return err } - if err != nil { - return err - } start := time.Now() if _, err := t.tcp.WriteTo(buf.Bytes(), &net.IPAddr{IP: t.DestIP}); err != nil {