visualc
asked on
Get my machine IP adress
Hi!
I have developing a client-server application.
When a client request a connection, it must send a password and the client-machine IP-adress (the adress will
be memorate in a database).
How can I obtain in run-time the machine IP adress, where
the application is running?
Tibi
I have developing a client-server application.
When a client request a connection, it must send a password and the client-machine IP-adress (the adress will
be memorate in a database).
How can I obtain in run-time the machine IP adress, where
the application is running?
Tibi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This code will get the host name and the IP address for the computer on wich code is run. This works on VisualC++ 5SP1/2 on NT4 and 95 (98 too)
Requirements:
#include <ltwinsock2.h>
Link with Winsoc32.lib
That is it:
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( 0==WSAStartup( wVersionRequested, &wsaData ) )
{
if( 0 == gethostname ( name, sizeof(name)))
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
}
Requirements:
#include <ltwinsock2.h>
Link with Winsoc32.lib
That is it:
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( 0==WSAStartup( wVersionRequested, &wsaData ) )
{
if( 0 == gethostname ( name, sizeof(name)))
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
}
ASKER