|
>>
|
No. 42
>>40
found this on the web. might be relevant. donno how it works or what the fxns do yet:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main ( void )
{
pid_t pid;
int sock, send_sock, i;
struct sockaddr_in addr, info;
setsid ( );
umask ( 0 );
signal ( SIGCHLD, SIG_IGN );
if ( fork ( ) ) return 0;
sock = socket ( AF_INET, SOCK_STREAM, 0 );
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl ( INADDR_ANY );
addr.sin_port = htons ( 50 );
bind ( sock, ( struct sockaddr *) &addr, sizeof ( addr ) );
i = sizeof ( info );
listen ( sock, 1 );
for (;;)
{
i = sizeof ( info );
send_sock = accept ( sock, ( struct sockaddr * ) &info, &i );
pid = fork ( );
if ( pid )
{
close ( send_sock );
continue;
}
else
{
send ( send_sock, "sh-2.03# ", 9, 0 );
puts("sending sock");
sleep ( 4 );
send (send_sock, "\nNah, just kidding :P\n", 24, 0);
sleep ( 3 );
close ( send_sock );
return 0;
}
}
return 0;
}
|