1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <string.h>
#include <iostream>
#include <time.h>
#include <winsock2.h>
using namespace std;
SOCKET soc;
bool b_connect;
int co(char* adr, int port)
{
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKADDR_IN sin;
soc = socket(AF_INET, SOCK_STREAM, 0);
hostent *host;
in_addr adresse;
host = gethostbyname(adr);
memcpy(&adresse,host->h_addr,host->h_length);
sin.sin_addr = adresse;
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
if(connect(soc, (struct sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR){
fprintf(stderr,"impossible de se connecte\n");
return 1;
}
return 0;
} |