Projects/1. Router/router.c
int binarySearch(int left, int right, uint32_t dest_ip) {
	int mid;
	while (left <= right) {
		mid = right + (left - right)/2;
		if(ntohl((rtable[mid].mask &dest_ip)) == ntohl(rtable[mid].prefix)) 
			return mid;
		if(ntohl((rtable[mid].mask &dest_ip)) < ntohl(rtable[mid].prefix)) 
			right = mid - 1;
		if(ntohl((rtable[mid].mask &dest_ip)) > ntohl(rtable[mid].prefix)) 
			left = mid + 1;
	}
	return -1;
}
/* binary search function for finding routing table entry */
binary search function for finding routing table entry
binary search function for finding routing table entry
int binarySearch(int left, int right, uint32_t dest_ip) {
	int mid;
	while (left <= right) {
		mid = right + (left - right)/2;
		if(ntohl((rtable[mid].mask &dest_ip)) == ntohl(rtable[mid].prefix)) 
			return mid;
		if(ntohl((rtable[mid].mask &dest_ip)) < ntohl(rtable[mid].prefix)) 
			right = mid - 1;
		if(ntohl((rtable[mid].mask &dest_ip)) > ntohl(rtable[mid].prefix)) 
			left = mid + 1;
	}
	return -1;
}
int binarySearch ( int left , int right , uint32_t dest_ip ) { int mid ; while ( left <= right ) { mid = right + ( left - right ) / 2 ; if ( ntohl ( ( rtable [ mid ] . mask & dest_ip ) ) == ntohl ( rtable [ mid ] . prefix ) ) return mid ; if ( ntohl ( ( rtable [ mid ] . mask & dest_ip ) ) < ntohl ( rtable [ mid ] . prefix ) ) right = mid - 1 ; if ( ntohl ( ( rtable [ mid ] . mask & dest_ip ) ) > ntohl ( rtable [ mid ] . prefix ) ) left = mid + 1 ; } return -1 ; }
binary search function for finding routing table entry
binary search function for finding routing table entry