Programming - cpueblo.com

피씨의 IP 얻기 - gethostbyname()


글쓴이 : 유광희 날짜 : 2002-05-13 (월) 16:40 조회 : 13860
#include <winsock.hpp> AnsiString GetLocalIP() { AnsiString IPStr; WSAData wsaData; if (!WSAStartup(MAKEWORD(1, 1), &wsaData)) { char ac[80]; if (gethostname(ac, sizeof(ac)) != SOCKET_ERROR) { hostent *phe = gethostbyname(ac); if (phe) { in_addr addr; for (int i = 0; phe->h_addr_list[i] != 0; ++i) { CopyMemory(&addr, phe->h_addr_list[i], sizeof(in_addr)); if (i > 0) AppendStr(IPStr, "."); AppendStr(IPStr, inet_ntoa(addr)); } } } } WSACleanup(); return IPStr; }