#include <winsock2.h>
// ...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
AnsiString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
Label1->Caption = name;
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(in_addr *)*hostinfo->h_addr_list);
Label2->Caption = ip;
}
}
WSACleanup( );
}
}