PDA

View Full Version : help with sockets .. client-server programming



milan
01-03-2003, 02:18 PM
i write small linux code just to spawn me shell when connect on it .. i use nc to connect on it ... but i want to code an client

server just do regular things like... socket()... bind() .. listen() .. etc.etc and then execl("bin/sh"....
I just need litle guiding for stdin and how to send that on sockets .. catch my drift ?

Prelude
01-03-2003, 02:19 PM
http://www.ecst.csuchico.edu/~beej/guide/net/

-Prelude

milan
01-04-2003, 09:32 AM
So the ``Hello world!'' goes to the client connected.
Next time post your question to the Linux Programming forum. And what do you need this for? I surely hope you're not trying to write lame ``malware''... [/B]

Sorry for my bad english .. my question was about writing a client ... i need a hint to do that, like client for telnetd but without auth.
It isn't malware or something like that .. i am reading Beej guide to socket programing and just trying things.
I know to write client and send mesg from comand line ./client IP_server mesg .. but i need interactive client.

Hammer
01-04-2003, 06:43 PM
>>but i need interactive client
Then use the standard IO functions to read input from the keyboard, write the data to the socket, and then write the servers response to the screen.

milan
01-05-2003, 06:15 AM
Originally posted by Hammer
>>but i need interactive client
Then use the standard IO functions to read input from the keyboard, write the data to the socket, and then write the servers response to the screen.
ok... i'm into that now but ...
more problems for me ... my server can only accept one connection and after i disconnect with client server dies (cant accept connections)
I know that it's something with fork() .... but dont have idea how to solve it.
One more ... how to throw server in backround after i start it ? i want solution in code not just './server &'

milan
01-05-2003, 06:47 AM
Originally posted by vVv
I don't feel like writing you the entire thing, so take this pseudo-code as suggestion and read on the topic.


#include <sys/types.h>
#include <unistd.h>
...
pid_t child;
child = fork( );
if( child == -1 ) {
/* error handling */
} else if( child == 0 ) {
if( setsid( ) != 0 ) {
/* error handling */
}
} else
return 0;
I have been trying similar code except setsid() .. thanks vVv.
.. and of course i dont expect whole code ... just a hint
Thanks again !!