Laboratories/Lab05/utils.c
int relevant_packet(int sockfd, struct packet *orig, struct packet *reply)
{
	struct ether_header *eth_hdr = (struct ether_header *)reply->payload;
	uint8_t own_mac[ETH_ALEN];
	get_interface_mac(sockfd, IFNAME, own_mac);

	// Discard packets that aren't for this machine
	if (memcmp(own_mac, eth_hdr->ether_dhost, ETH_ALEN))
		return 0;

	// Discard non-IP packets
	if (ntohs(eth_hdr->ether_type) != ETHERTYPE_IP)
		return 0;

	struct iphdr *ip_hdr = (struct iphdr *)(reply->payload + IP_OFF);
	// Discard non-ICMP packets
	if (ip_hdr->protocol != IPPROTO_ICMP)
		return 0;

	return 1;
}
// Unfortunatey, our raw socket gets all packets...
Unfortunatey, our raw socket gets all packets
Unfortunatey our raw socket gets all packets
int relevant_packet(int sockfd, struct packet *orig, struct packet *reply)
{
	struct ether_header *eth_hdr = (struct ether_header *)reply->payload;
	uint8_t own_mac[ETH_ALEN];
	get_interface_mac(sockfd, IFNAME, own_mac);
	if (memcmp(own_mac, eth_hdr->ether_dhost, ETH_ALEN))
		return 0;
	if (ntohs(eth_hdr->ether_type) != ETHERTYPE_IP)
		return 0;
	struct iphdr *ip_hdr = (struct iphdr *)(reply->payload + IP_OFF);
	if (ip_hdr->protocol != IPPROTO_ICMP)
		return 0;
	return 1;
}
int relevant_packet ( int sockfd , struct packet * orig , struct packet * reply ) { struct ether_header * eth_hdr = ( struct ether_header * ) reply -> payload ; uint8_t own_mac [ ETH_ALEN ] ; get_interface_mac ( sockfd , IFNAME , own_mac ) ; if ( memcmp ( own_mac , eth_hdr -> ether_dhost , ETH_ALEN ) ) return 0 ; if ( ntohs ( eth_hdr -> ether_type ) != ETHERTYPE_IP ) return 0 ; struct iphdr * ip_hdr = ( struct iphdr * ) ( reply -> payload + IP_OFF ) ; if ( ip_hdr -> protocol != IPPROTO_ICMP ) return 0 ; return 1 ; }
Unfortunatey, our raw socket gets all packets...
Unfortunatey our raw socket gets all packets ...
// Discard packets that aren't for this machine // Discard non-IP packets // Discard non-ICMP packets