[C/C++] Local client/server using raw socket /pcap
Hi,
We are trying to write a client/server program in c++. We have tried to use pcap to inject raw packets and sockets to receive packets. When the traffic are sent between two different computers everything seems to be ok. The problem occurs when the traffic are sent to the loopback. The packets are visible via Wireshark (driver level) but they never reaches the destination (application level). Thanks in advance! Best regards, CC and EE |
Quote:
Why not just write a standard socket server and client? Make the server listen on INADDR_ANY: and it will listen on all available interfaces. Make the client connect to "127.0.0.1", and it can run on the same machine as the server. If you need the ability to run the client on the same machine as the server and on other machines, make the default address "127.0.0.1" and add a command line option to specify the server address. |
Quote:
I'll try to describe the whole scenario a bit more. The client (A) will try to establish a TCP connection to the server (B). B is listening using standard sockets while A first ensembles the whole packet internally via it's own stack and we must then make this packet appear at B. Since it is TCP we are using then we must establish the connection in a way so that the stack in linux, somehow, get's in the same stat as the stack inside A. In short: Stack in A should be synced with linux stack (at B). |
Quote:
|
Quote:
Since we are using standard sockets (server-side) there is no need to use that mode for that purpose, but at the client-side it is necessary for receiving packets without having to bind to a specific port etc.. We have tried two different raw sockets, namely: link-layer and ip-layer. When we are using the ip-layer the server receives, for example a TCP-syn, the packet successfully, but when the server answers with TCP-syn-ack it will be blocked by the TCP/IP-stack in the linux kernel, because there is no process which is listening/expecting such packet. Linux kernel will therefore send a TCP-rst back to the server, which destroys our connection. Problem: How to get the linux kernel accept the TCP-syn-ack without listening via standard sockets (client-side)? Problem: How to receive packets, locally, which are sent via PF_PACKET socket? |
Quote:
Quote:
You are basically violating the rules used by the stack for determining how to respond to a SYN request. It sees that there is no corresponding local client and (properly) rejects it. |
Quote:
Have you ever been in contact with UML (User mode linux) ? They must have solved this in some neat way, because they actually have two, or more, instances of the Linux's TCP/IP-stack. It seems that TAP is somewhat central around the UML, and perhaps that could be something to investigate as well? Thank you very much for your feedback, it's really nice to have someone to share our thoughts with! :) |
Quote:
|
All times are GMT -5. The time now is 06:28 AM. |