I am working on an embedded TCP/IP4 stack and HTTP/SNMP/SMTP stuff.
It functionally works but I want to make it work faster on LAN.
Because of the Nagle’s Algorithm and the delayed TCP-ACK,
The HTTP application seems to work slow even on LAN.
As can be seen on http://en.wikipedia.org/wiki/IPv4#Private_networks ,
There are 3 different Private Networks with different bit-block values.
What I will do is that:
- I will first be sure that I am a LAN member by looking at my own IP
- I will look at the dst_ip and check if it belongs to the same LAN as me
Are these enough to prove that me and the other party belong to the same LAN ?
Then of course, I will use a simple hack like sending the same packet twice to
speed up the communication. I already tested this and it works but it’s
optional right now. I want to turn it into a built-in feature.
Thanks in advance…
You need to check your subnet mask to know if a destination IPv4 address is on the same network as you. Only addresses with the same prefix will share the same network for sure.
For instance, if your IP address is 10.2.3.87 and your subnet mask is /26 that means that addresses between 10.2.3.64 and 10.2.3.127 are on the same subnet as you because they will all use the same prefix 10.2.3.64. The /26 subnet mask is 255.255.255.192.
Of course, you will do all this in binary so you will not be checking to make sure the address is between a min and a max value, instead you will use the subnet mask to get the prefix of your address and the destination address, then check that they are equal.
In binary:
As you can see, the AND mask has 26 one bits (/26) and therefore the two IP addresses share the same prefix when the subnet mask is applied.
It is possible, but not common, for other subnets to reside on the same LAN broadcast domain so in odd circumstances your performance trick will not work. If you use the subnet mask to identify the closeness of the destination IP address, then you may not need to worry about RFC 1918 private addressing.