I am currently working on a programming assignment. Purpose - to implement the client, network emulator and server. The client sends packets to the network emulator, and the network emulator goes to the server. And vice versa. The prerequisite for the assignment is that I can only use raw sockets. Therefore, I will create my own IP and UDP headers. I checked my packages with wirehark. They are all correct and in the correct format (they read them correctly).
Another requirement is that the emulator, client, and server have specific ports to which they must bind. Now I do not understand how to bind a raw socket to a specific port. All my raw sockets receive all traffic to the host address to which they are bound. According to man pages and everywhere on the Internet, including Richard Stevens' Unix Network Programming, this is how they should work. My teacher did not answer any of my letters, and I probably could not ask him until Tuesday. I see two options in front of me. First, I can use libpcap to filter from a specific device, and then to output to my raw socket. I feel that this is a way out of the scope of our assignment. Or I can filter them after getting from the socket. Apparently this has a lot of overhead,because all packages are copied / moved through the kernel. At least this is my understanding (please feel free to correct me if I am wrong).
So my question is: Their option or something that I can install for this? Where will the raw socket bind to the port? Am I missing something obvious?
Thank you for your time.
-
source
share