the lookup function takes an IP address (ip_address, unsigned int) as an argument and does a bitwise AND between ip_address and net_mask. If the result is equal to net_address, the function returns the port value. Otherwise ¡, it continues the lookup (by incrementing an iterator).
Do you know wether the input IP_address is always in the list, or never? If yes, do you already have the iterator to this one? It could give you a good starting position for your search. Then browse the list in both directions starting from there until you find an element that has a different net_mask.
If not, find a first element of a corresponding net_mask and do the same from this position
The IP_address is not in the list. This is an attemp to implement a prefix-match lookup. In doing so:
1 . I take de IP_address (actually, it's a destination address)
2 . In every node, I do a bitwise AND between IP_address and net_mask.
3 . If the result is equal to net_address, there's a match!!
4 . IF not, I continue to the next node (by means of an iterator)