2010-08-24 14 views
0

J'essaie de produire un serveur simple qui me permettra de tester les fonctionnalités de sécurité Androids. J'ai besoin de développer une application qui va ouvrir une socket. J'ai produit quelque chose de similaire en C, mais je ne regarde pas avec java. Voici l'application en CEssayer de produire un serveur Android exploitable

// simpleserver3.c 


#define MY_PORT  9999 
#define MAXBUF  99 


void indata(int clientfd, struct sockaddr_in client_addr) 
{ 
char buffer[12]; 
printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); 
recv(clientfd, buffer, MAXBUF, 0); //this is will overflow the buffer 
printf("%X \n", &buffer); 
} 

int main(int Count, char *Strings[]) 
{ 
struct sockaddr_in self, client_addr; 
int sockfd,clientfd; 
/*---Create streaming socket---*/ 
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) //socketfd = handle for socket 
{ 
    perror("Socket"); 
    exit(errno); 
} 

/*---Initialize address/port structure---*/ 
bzero(&self, sizeof(self)); 
self.sin_family = AF_INET; 
self.sin_port = htons(MY_PORT); 
self.sin_addr.s_addr = INADDR_ANY; 

/*---Bind the structure to the socket handle ---*/ 
if (bind(sockfd, (struct sockaddr*)&self, sizeof(self)) != 0) 
{ 
    perror("socket--bind"); 
    exit(errno); 
} 

/*---Make it a "listening socket"---*/ 
if (listen(sockfd, 20) != 0) 
{ 
    perror("socket--listen"); 
    exit(errno); 
} 

//set socklen_t to length of client address 
socklen_t addrlen=sizeof(client_addr); 
/*---accept a connection (creating a data pipe)---*/ 

clientfd = accept(sockfd, (struct sockaddr*)&client_addr, &addrlen); //create handle for communicating 
indata(clientfd, client_addr); 
close(clientfd); 
close(sockfd); 
return; 
} 

Tout sugguestion serait génial, Aneel

Répondre