Bonjour ,
j'ai porter un module réseau windows sur linux et je l'ai réadapter, cependant lorsque j'essaye de recuperer mon IP soit avec :
char ac [ 80 ];
if ( gethostname ( ac, sizeof ( ac ) ) == -1 )
{
KIGS_ERROR ( "Can not get local host name.", 1 );
return 1;
}
struct hostent *phe = gethostbyname ( ac );
if ( phe == 0 )
{
KIGS_ERROR ( "Bad host lookup.", 1 );
return 1;
}
int i;
for ( int i = 0; phe->h_addr_list [ i ] != 0; ++i )
{
in_addr addr;
memcpy ( &addr, phe->h_addr_list [ i ], sizeof ( struct in_addr ) );
printf ( "Address %d : %s \n", i, inet_ntoa ( addr ) );
myIP = addr.s_addr;
}
soit avec
in_addr addr = INADDR_ANY;
les 2 méthodes me retourne mon ip local soit 127.0.1.1 ( qui n'est dailleur pas tout a fait l'ip local ( 127.0.0.1 ) ).
je cherche a recuperer mon adresse ethernet soit : 192.168.x.x
comment devrais je faire sur linux plz ?
Partager