def receives_icmp_unreachable_for_udp(udp_src_ip, udp_dst_ip, udp_src_port=9, udp_dst_port=9, timeout=5): """ Receives an ICMP unreachable reply for a UDP packet. Constructs pcap filter strings for an ICMP unreachable reply received in response for a UDP packet sent. Args: udp_src_ip: Source IP address for the original UDP packet. udp_dst_ip: Destination IP address for the original UDP packet. udp_src_port: Source port for the original UDP packet. udp_dst_port: Destination port for the original UDP packet. """ pcap_filter_string = ( 'icmp and src host %s and ' 'icmp[20:4] = %d and icmp[24:4] = %d and ' 'icmp[28:2] = %d and icmp[30:2] = %d') % ( udp_dst_ip, ipv4_int(udp_src_ip), ipv4_int(udp_dst_ip), udp_src_port, udp_dst_port) return InterfaceExpects(True, pcap_filter_string, timeout)
def test_ipv4_int(self): """Tests ipv4_int() computes a correct IPv4 address integer.""" self.assertEqual(2886729985, ipv4_int('172.16.1.1')) self.assertEqual(2886730241, ipv4_int('172.16.2.1')) self.assertEqual(167772687, ipv4_int('10.0.2.15'))