These are exactly the things that database vendors have dealt with for years. If you are going to search sequentially by src / dst IP / port, you can use this as a criterion for sorting and look for it more or less directly.
Otherwise, a typical approach is to sort the data by one field and construct indexes for other fields. You can then perform a binary search in each index to find a set of records that match the criteria for this field. The intersection of these sets will be the records you are looking for.
Of course, if you prefer, you can also reduce the number of indexes, so (for example) you can use indexes to get a set of records with the correct source and destination IP addresses, and then just scan it (maybe quite small) to get numbers with The correct port number.
source share