radek_s
asked on
My IP address
While I connect to Internet by Dial-up
modem connection, how can I get my IP
ADDRESS and HostName?
modem connection, how can I get my IP
ADDRESS and HostName?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CString m_IPAddress; // holds the numeric dotted address
CString m_IPName; // holds the computer name.
char pszname[ 0x40 ];
::gethostname( pszname, sizeof( pszname ) );
hostent* ph = ::gethostbyname( pszname );
m_IPName = ph->h_name;
unsigned u = *( (unsigned*) ( ph->h_addr_list[ 0 ] ) );
m_IPAddress.Format( "%d.%d.%d.%d", ( u ) & 0x000000ff, ( u >> 8 ) & 0x000000ff, ( u >> 16 ) & 0x000000ff, ( u >> 24 ) & 0x000000ff );