Search code examples
socketstcpnetwork-programmingraw-sockets

Please, can anybody help in writing a server-client raw socket program in c/c++


I am new to raw socket. I want write a server and a client application that use raw sockets to send and receive raw data in one or more files. Each file may contain one or more data segments of 50 bytes each with a designated delimiters (i.e., space, carriage return, and etc.) The job of my server is to read from the file and send each segment at a time. Each packet should only contain the data without any traditional header information such as the Ethernet header like the MAC addresses (the packet may contain some form of data in front of the packet to indicate the length and/or the start of the packet and the delimiter to indicate the end of the packet). The client application should simply listen to the port, parse the data and write the raw data into a file.

Please, guide me. I have found many raw socket programs but, none were clear. If anybody could give me a solid start then that would be great.


Solution

  • You can see here : http://sock-raw.org/papers/sock_raw, but what you say is really possible. In fact, imagine that, in your data, you have data that match a protocol which can be routed, the packet will be routed. Indeed, if you see documentation, Raw socket handle header and payload. You MUST have a header (in your case, it must begin with 0 to say personnal header, and after no header, juste payload). And, maybe it can be work with a very basic router/switch, but nowaday, it's sound difficult because router look data and may imagine this is corrupted data.