1 pièce(s) jointe(s)
Problème dans struct in_addr
Bonjour tout le monde,
j'ai créé ce code client :
Code:
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 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#define PORT 2050
void main(){
int sock1 ;
char mess[80] ;
struct sockaddr_in clt ;
struct hostent *hostinfo=NULL ;
//taille du structure :
int taille=sizeof(struct sockaddr);
//creation du socket :
sock1=socket(AF_INET,SOCK_STREAM,0) ;
//recuperation d'information sur le serveur
hostinfo=gethostbyname("www.ps.com");
//INITIALISATION D'ADRESSE SOCKET :
clt.sin_port=htons(PORT);
clt.sin_family=AF_INET ;
clt.sin_addr.s_addr= (struct in_addr*) hostinfo->h_addr ;
connect(sock1,(struct sockaddr *)&clt ,taille);
while(1){
bzero(mess,80);
scanf("%s",mess);
write(sock1,mess,80);
read(sock1,mess,80);
printf(" MESSAGE RECUS : %s" ,mess);
bzero(mess,80);
}
close(sock1);
} |
au niveau de ce ligne qui il y un probleme :
Code:
clt.sin_addr.s_addr= (struct in_addr*) hostinfo->h_addr ;
Si j'écris :
quand je fais clt.sin_addr.s_addr= (struct in_addr*) hostinfo->h_addr ; le compilateur déclare un avertissement
si je fait clt.sin_addr.s_addr=* (struct in_addr*) hostinfo->h_addr ; le compilateur déclare une erreur.
Pièce jointe 281010