@@ -1908,7 +1908,7 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
19081908{
19091909 uint8_t tx_buf = 0xab ;
19101910 uint8_t rx_buf ;
1911- int ret , count = 10 ;
1911+ int ret , count = 10 , opt ;
19121912#define IPV4_HDR_SIZE sizeof(struct net_ipv4_hdr)
19131913#define IPV6_HDR_SIZE sizeof(struct net_ipv6_hdr)
19141914#define UDP_HDR_SIZE sizeof(struct net_udp_hdr)
@@ -2007,6 +2007,32 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
20072007
20082008 zassert_true (count > 0 , "timeout while waiting data" );
20092009
2010+ if (family == AF_INET ) {
2011+ /* Set TTL to 0 and make sure the packet is dropped and not
2012+ * received
2013+ */
2014+ int option ;
2015+
2016+ if (expected_ttl > 0 ) {
2017+ option = IP_TTL ;
2018+ } else {
2019+ option = IP_MULTICAST_TTL ;
2020+ }
2021+
2022+ opt = 0 ;
2023+ ret = setsockopt (sock_c , IPPROTO_IP , option , & opt , sizeof (opt ));
2024+ zassert_equal (ret , 0 , "Cannot set %s TTL (%d)" ,
2025+ option == IP_TTL ? "unicast" : "multicast" ,
2026+ - errno );
2027+
2028+ ret = sendto (sock_c , & tx_buf , sizeof (tx_buf ), 0 ,
2029+ addr_sendto , addrlen_sendto );
2030+ zassert_equal (ret , sizeof (tx_buf ), "send failed (%d)" , - errno );
2031+
2032+ ret = recv (sock_s , & rx_buf , sizeof (rx_buf ), 0 );
2033+ zassert_true (ret < 0 && errno == EAGAIN , "recv succeed (%d)" , - errno );
2034+ }
2035+
20102036 ret = close (sock_c );
20112037 zassert_equal (ret , 0 , "close failed" );
20122038 ret = close (sock_s );
0 commit comments