0
votes

I have a client and a server. They communicate through a socket, created with this command:

socket(AF_INET, SOCK_STREAM, 0);

The communication between them goes good.

I want to create a third program that poses as the server and send fake messages to the client. This program have to use the socket that client and server had been created previously.

I am using the send command with the socket id set up statically by mine

write(socket_number,message,1024);

but it doesn't work (and I'm not sure that is the right way).

So I've tried with telnet and nc (on the client port), but I can't send messages to the client.

Have you any ideas...

1
Maybe you can get more information on my question which goes the same direction: stackoverflow.com/questions/19299638/… - The Wavelength
what you are looking for is a proxy service to the third program which needs to be in the middle. As @Nicolas is saying in his answer, you cannot inject into a established connection, but you can configure a proxy and then connect to that which will give you the ability to trace/debug the communication -- proxeis can be written in almost any language, and there should be a plentify selection of them on the web. - Soren

1 Answers

0
votes

When the client connects to the server, the socket is a private pipe between them, you cannot inject data in that pipe. You can consider creating a 'man in the middle': your client connects to it, then it connects to your server. This guy can pass traffic back and forth and inject test data if needed. The only change on the client will be the IP address or the port, to point to the man in the middle rather than the real server.