diff --git a/scan_engine.cc b/scan_engine.cc index 8534bc1fb..9dd093db4 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -2458,6 +2458,7 @@ static UltraProbe *sendConnectScanProbe(UltraScanInfo *USI, HostScanStats *hss, if (CP->sd == -1) pfatal("Socket creation in %s", __func__); unblock_socket(CP->sd); init_socket(CP->sd); + set_ttl(CP->sd, o.ttl); if (hss->target->TargetSockAddr(&sock, &socklen) != 0) { fatal("Failed to get target socket address in %s", __func__); } diff --git a/tcpip.cc b/tcpip.cc index d32fae852..3ce19adfb 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -161,6 +161,16 @@ setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (const char *) &one, sizeof(one)); #endif } +void set_ttl(int sd, int ttl) +{ +#ifdef IP_TTL + if (sd == -1) + return; + + setsockopt(sd, IPPROTO_IP, IP_TTL, &ttl, sizeof ttl); +#endif +} + // Takes a protocol number like IPPROTO_TCP, IPPROTO_UDP, or // IPPROTO_IP and returns a ascii representation (or "unknown" if it // doesn't recognize the number). If uppercase is true, the returned diff --git a/tcpip.h b/tcpip.h index 611e5399e..03267a53e 100644 --- a/tcpip.h +++ b/tcpip.h @@ -663,6 +663,8 @@ pcap_if_t *getpcapinterfaces(); struct sys_route *getsysroutes(int *howmany); void sethdrinclude(int sd); +void set_ttl(int sd, int ttl); + /* Fill buf (up to buflen -- truncate if necessary but always terminate) with a short representation of the packet stats. Returns buf. Aborts if there is a problem. */