#include #include #include #include #include /** * u /etc/hosts pored 127.0.0.1 ne sme da bude NISTA * drugo OSIM "localhost.localdomain" i/ili "localhost" * ......... * The source below is written by Dejan Lekic * and licensed under GPL license... */ int main(char argc, char** argv) { char ac[80]; int i = 0; struct hostent* phe; struct in_addr addr; if (gethostname(ac, sizeof(ac)) != 0) { printf("Yoy, ne mogu da uzmem ime lokal-host-a bwe!\n"); return 1; } else printf("Ime hosta je: %s\n", ac); /* 'aj sad da odradimo posao... */ phe = gethostbyname(ac); if (phe == NULL) { printf("Uh! Host lukap pandrknuo.\n"); return 1; } /* ofo zapravo wadi poswitj */ for (i = 0; phe->h_addr_list[i] != NULL; ++i) { bzero(&addr, sizeof(struct in_addr)); memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr)); printf("Adresa %d : %s\n", i, inet_ntoa(addr)); } printf("Peco, ako ti ovo ne radi, onda baci kompjuter kroz prozor.\n"); return 0; }