Skip to content

Commit

Permalink
get new port from OS for each TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-schneider committed Sep 24, 2024
1 parent 6eb5663 commit 345158b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/networkpath/traceroute/tcp/tcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ func (t *TCPv4) TracerouteSequential() (*Results, error) {
}

func (t *TCPv4) sendAndReceive(rawIcmpConn *ipv4.RawConn, rawTCPConn *ipv4.RawConn, ttl int, seqNum uint32, timeout time.Duration) (*Hop, error) {
srcPort := t.srcPort + uint16(ttl) // increment source port number by TTL to introduce some randomness to source port
srcPort := t.srcPort
if ttl > 1 {
addr, err := localAddrForHost(t.Target, t.DestPort)
if err != nil {
return nil, fmt.Errorf("failed to get local address for target: %w", err)
}
srcPort = addr.AddrPort().Port()
log.Warnf("Using new source port: %d", srcPort)
}
tcpHeader, tcpPacket, err := createRawTCPSyn(t.srcIP, srcPort, t.Target, t.DestPort, seqNum, ttl)
if err != nil {
log.Errorf("failed to create TCP packet with TTL: %d, error: %s", ttl, err.Error())
Expand Down

0 comments on commit 345158b

Please sign in to comment.