roswell117
Messages postés
61
Date d'inscription
jeudi 31 janvier 2002
Statut
Membre
Dernière intervention
18 novembre 2005
21 avril 2003 à 16:56
Pour obtenir ton adresse IP en utilisant les sockets, utilise ce code :
struct sockaddr_in sin;
struct hostent *phe;
char buffer[64];
WSADATA wsaData;
WSAStartup(MAKEWORD(2,0),&wsaData);
gethostname(buffer, sizeof(buffer));
phe = gethostbyname(buffer);
memcpy(&sin.sin_addr.s_addr, phe->h_addr, phe->h_length);
Ton adresse IP est contenue dans sin.sin_addr
Si tu veut l'utiliser en tant que chaine de caracteres, rajoutes ca :
char FAR *IP;
IP = inet_ntoa(sin.sin_addr);
Et bonne chance.