3636
3737static int sockfd = -1 ;
3838
39+ static int hop_estimate (uint8_t ttl )
40+ {
41+ if (ttl <= 64 ) {
42+ return 64 - ttl ;
43+ } else if (ttl <= 128 ) {
44+ return 128 - ttl ;
45+ } else {
46+ return 255 - ttl ;
47+ }
48+ }
49+
3950static void ipaddr_to_str (struct sockaddr * addr , char ipstr [INET6_ADDRSTRLEN ])
4051{
4152 static const char invalid [] = "INVALID" ;
@@ -220,7 +231,8 @@ int fh_rawsend_handle(struct sockaddr_ll *sll, uint8_t *pkt_data, int pkt_len)
220231{
221232 uint32_t ack_new ;
222233 uint16_t ethertype ;
223- int res , i , tcp_payload_len ;
234+ int res , i , tcp_payload_len , hop ;
235+ uint8_t src_ttl ;
224236 struct tcphdr * tcph ;
225237 char src_ip [INET6_ADDRSTRLEN ], dst_ip [INET6_ADDRSTRLEN ];
226238 struct sockaddr_storage saddr_store , daddr_store ;
@@ -231,14 +243,14 @@ int fh_rawsend_handle(struct sockaddr_ll *sll, uint8_t *pkt_data, int pkt_len)
231243
232244 ethertype = ntohs (sll -> sll_protocol );
233245 if (g_ctx .use_ipv4 && ethertype == ETHERTYPE_IP ) {
234- res = fh_pkt4_parse (pkt_data , pkt_len , saddr , daddr , & tcph ,
246+ res = fh_pkt4_parse (pkt_data , pkt_len , saddr , daddr , & src_ttl , & tcph ,
235247 & tcp_payload_len );
236248 if (res < 0 ) {
237249 E (T (fh_pkt4_parse ));
238250 return -1 ;
239251 }
240252 } else if (g_ctx .use_ipv6 && ethertype == ETHERTYPE_IPV6 ) {
241- res = fh_pkt6_parse (pkt_data , pkt_len , saddr , daddr , & tcph ,
253+ res = fh_pkt6_parse (pkt_data , pkt_len , saddr , daddr , & src_ttl , & tcph ,
242254 & tcp_payload_len );
243255 if (res < 0 ) {
244256 E (T (fh_pkt6_parse ));
@@ -254,6 +266,15 @@ int fh_rawsend_handle(struct sockaddr_ll *sll, uint8_t *pkt_data, int pkt_len)
254266 ipaddr_to_str (daddr , dst_ip );
255267 }
256268
269+ if (!g_ctx .nohopest ) {
270+ hop = hop_estimate (src_ttl );
271+ if (hop <= g_ctx .ttl ) {
272+ E_INFO ("%s:%u ===LOCAL(?)===> %s:%u" , src_ip , ntohs (tcph -> source ),
273+ dst_ip , ntohs (tcph -> dest ));
274+ return 0 ;
275+ }
276+ }
277+
257278 if (tcp_payload_len > 0 ) {
258279 E_INFO ("%s:%u ===PAYLOAD(?)===> %s:%u" , src_ip , ntohs (tcph -> source ),
259280 dst_ip , ntohs (tcph -> dest ));
0 commit comments