Bon j'ai un pitit problème avec mon thread. En fait je suis en train faire un programme qui a besoin de traîter plusieur connection en même tps. Pour cela je voudrai utiliser les threads mais je comprend pas pkoi ms ma source ne fonctionne pas. Le programme ne veut pas se connecter alors que sans le thread le pgm se connecte sans pb.
Si qlq1 pe m'aider !!!
#include <windows.h>
#include <winsock2.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "ws2_32.lib")
struct config
{
SOCKET sock;
SOCKADDR_IN sin;
int ip;
};
//void connection(struct config * conf)
DWORD WINAPI connection( LPVOID Param )
{
struct config * conf = (struct config *)Param;
printf("-> ip long %i\n",conf->ip);
conf->sin.sin_addr.s_addr = ntohl(conf->ip);
conf->sin.sin_family = AF_INET;
conf->sin.sin_port = htons(555);
conf->sock = socket(AF_INET,SOCK_STREAM,0);
bind(conf->sock, (SOCKADDR *)&conf->sin, sizeof(conf->sin));
if ( !connect(conf->sock, (SOCKADDR *)&conf->sin, sizeof(conf->sin)) )
printf("***connection to succed\n");
closesocket(conf->sock);
free(conf);
}
int main(int argc, char *argv[])
{
int startip;
int endip;
struct config * conf = NULL;
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
if ( argc > 2 )
{
startip = htonl(inet_addr(argv[1]));
endip = htonl(inet_addr(argv[2]));
conf = (struct config *) malloc(sizeof(struct config) );
conf->ip = startip;
//connection(conf);
CreateThread(NULL, 0, &connection, conf, 0, 0);
}
else
printf("Usage : scan.exe ip_start ip_end\n");
WSACleanup();
system("pause");
return 0;
}