NAT-Server Implementation-4
Continued from NAT-Server-3
We sniff the packets coming from the internet by simply sniffing the packets and distinguishing them from the packets from the local network packets by Checking for the destination IP address; this is because while manipulating the packets from the local network we changed the source IP to our NAT Server’s IP. So therefore all the packets coming from the Internet side would be destined for the NAT Server.
Now the Packets are re-manipulated such that the IP of the destination and the port number is now changed by first searching which of the node originated this request and then this ip address and the port number is changed accordingly.
Sending packets back in the network
Now when all the basic NAT process is done we send the packet back in the network where it reaches the respective node.
IMPORTANT FUNCTIONS
Some of the main functions which contribute to the proper working and implementation of our NAT Server are as follows:
Get_start_list():
This function along with the callback () function is used for sniffing the packets and extracting the fields of headers of different layers. This is the main combination of function which contributes a major portion to the sniffing process.
Update record:
This function is used to maintain the database for the nodes for which we have sent the data on the internet.
Time_to_live:
This function is used in synchronization with the reply of the packets sent on the internet
Search_db:
This function searches the maintained database when a reply from the internet comes, for determining which node in the internal network originated this request.
Make_tcp:
This function is used for the manipulating the packet which is to be NAT.
Make_udp:
This is used for the manipulation of the UDP packet to send on the internet.
IMPORTANT TECHNIQUES
Some of the important techniques used while implementing the NAT server are that we have done the sniffing technique using the socket programming library. Different processes of time to live, sniffing and database update and synchronized using posix threads using the pthread.h library.
Choices And Assumptions
First of all: we have to take make a change in approach of using two network interface card for local and outside network, this is because we are modeling the NATing Technique and not implementing the firewall in our design. In short we are only implementing the SNAT.
Secondly: we this design is implemented with consideration that we have a small network of about two or three nodes because of the memory limitation of the machines in the lab and at our home of handling large traffics.
Thirdly: COMPLEXITY IN IMPLEMENTATION

While implementing the NAT Server the first difficulty which we faced was of sniffing the packet and correctly extracting the fields of the headers of different layers this problem was solved by thoroughly studying the related topics by taking help from the google.com and by using function such as ntohs(), e.g. to read total length field of the IP header. Second complexity which was raised was of correct Checksum of the packet at different layers this obstacle was cleared by carefully calculating the parameters of the checksum function. Thirdly and mainly we are having some problems with the reply back of the packets sent on the internet and as the reply are so un-predictable that nothing can be said about it.
Conclusion
In the end we have tried our best to meet the design of the SNAT to provide internet access to the local network connect to the NAT Server but there are still some complexities which are hindering the server to completely function as a true NAT Server.


















