ringrazio per il link...ho letto un pò la discussione e un altro link presente nella discussione, ma ho capito che bisogna usare le socket e le funzioni gethostname e poi dopo aver ricevuto il nome, passarlo alla funzione gethostebyname che ritorna un puntatore a stuttura se non ho capito male, e poi da questa struttura tramite la funzione inet_ntoa si ricava la stringa dell'ip...giusto? detta così sembra facile...ma per me che sono totalmente allo scuro in questo campo della programmazione...non è poi tanto semplice! ho provato anche quel programma che è stato postato nella discussione da PeppePes88:
ma onestamente a me non funziona niente...sarà che sbaglio a compilare...perchè mi da questi errori:codice:#include <stdio.h> #include <stdlib.h> #include <winsock.h> int main(int argc, char *argv[]) { WSADATA data; HOSTENT *host; int err = WSAStartup(MAKEWORD(2,2), &data), i = 0; char nome_host[100]; if ( err == SOCKET_ERROR) fprintf(stderr, "WSAStartup ERRORE : %d", WSAGetLastError()); err = gethostname( nome_host, sizeof(nome_host)); if ( err == SOCKET_ERROR) fprintf(stderr, "Gesthostname ERRORE : %d", WSAGetLastError()); printf("Il nome dell' host e' : %s\n", nome_host); host = gethostbyname(nome_host); if ( host == NULL) printf("GetHostByNAme ERRORE : %d", WSAGetLastError()); else { while ( host->h_addr_list[i]) { printf("%s\n",inet_ntoa(*((struct in_addr*)host->h_addr_list[i]))); i++; } } system("PAUSE"); return 0; }
codice:[Linker error] undefined reference to `WSAStartup@8' [Linker error] undefined reference to `WSAGetLastError@0' [Linker error] undefined reference to `gethostname@8' [Linker error] undefined reference to `WSAGetLastError@0' [Linker error] undefined reference to `gethostbyname@4' [Linker error] undefined reference to `WSAGetLastError@0' [Linker error] undefined reference to `inet_ntoa@4'

Rispondi quotando