In: Computer Science
If a incoming packet maps to more than one entry in routing table,the packet is forwarded to interface having longest prefix .
Example:
Prefix next hop
131.16.0.0/12 3
131.28.0.0/14 5
131.22.0.0/15 1
if router recieves a packet with address 131.23.151.76,following is done:
131.16.0.0/12 =>subnet mask=255.240.0.0
131.23.151.76 bitwise and 255.240.0.0=131.16.0.0
Hence the network address of packet and prefix are matching.
131.28.0.0/14=>subnet mask=255.252.0.0
131.23.151.76 bitwise and 255.252.0.0=131.20.0.0
Here network address of packet and prefix are not matching.
131.22.0.0/15=>subnet mask=255.254.0.0
131.23.151.76 bitwise and 255.254.0.0=131.22.0.0
Hence the network address of packet and prefix are matching
Here prefixes of 3 and 1 are matching.
But according to longest prefix matching rule, we have to forward it to 131.22.0.0/15 instead of 131.16.0.0/12 .(since 131.22.0.0/15 has longer prefix than 131.16.0.0/12)
Router is not same as interface.
A router has more than one interface and each interface is assigned a ip address.
default address of a router is the address of interface on which a packet is forwarded when packet doesn't match to any of entries in router.
Generally default address =0.0.0.0 and subnet mask is 0.0.0.0.
Hence if a packet doesn't match with any of entries and ip address bitwise and 0.0.0.0=0.0.0.0 which is default address.
Hence packet is forwarded onto that interface.