Commit c336519e authored by Stephane Talbot's avatar Stephane Talbot Committed by pernelle
Browse files

ajout containte pour etre sur de recuperer les bonnes info (socket connectee, etc.)

# Conflicts:
#	communCOL3-TP1.c
parent 50192949
......@@ -115,8 +115,31 @@ int connexionServeurCOL3(const char *adresse_serveur,int port, const char *token
int sock;
/* resolution adresse destination */
static struct addrinfo addrHint = {.ai_socktype=SOCK_STREAM, .ai_protocol=0, .ai_family=AF_UNSPEC, .ai_flags=(AI_ADDRCONFIG|AI_V4MAPPED)};
struct addrinfo* addrInfo;
char sport[10];
int e;
sprintf(sport,"%d",port);
if (e = getaddrinfo(adresse_serveur, sport, &addrHint, &addrInfo)){
if (errno != 0) perror("Unable to resolve host");
else fprintf(stderr, "getaddrinfo error : %s\n", gai_strerror(e));
exit(EXIT_FAILURE);
}
if (addrInfo == NULL){
fprintf(stderr,"Unable to resolve host: %s:%s\n", adresse_serveur, sport);
exit(EXIT_FAILURE);
}
struct sockaddr addr = *(addrInfo->ai_addr);
/* creation socket */
sock = socket(addrInfo->ai_family, addrInfo->ai_socktype, addrInfo->ai_protocol);
/* nettoyage */
freeaddrinfo(addrInfo);
/* creation socket en mode connecté */
sock = socket(AF_INET, SOCK_STREAM, 0);
/* sock = socket(AF_INET, SOCK_STREAM, 0); */
if (sock == INVALID_SOCKET) {
if (!NCURSE) {
printf("%s"," --> creation de la socket [NOK] \n");
......@@ -138,7 +161,7 @@ int connexionServeurCOL3(const char *adresse_serveur,int port, const char *token
}
/* lancement de la demande de connexion */
if( connect(sock,(struct sockaddr *) &sin, sizeof(struct sockaddr)) == SOCKET_ERROR){
if( connect(sock, &addr, sizeof(struct sockaddr)) == SOCKET_ERROR){
printf("%s"," --> connection TCP au serveur COL3 [NOK] \n");
return(INVALID_SOCKET);
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment