It was actually simpler, I have packed from and to range into uint64, added data offset, ordered at generation of db file and searched using bisection. Used the fact that ip is just a uint32 and range can fit into one register on 64 bit machine. Fixed size range (+data) enabled me to calculate position in file so bisection was simple.