How to get IP Address of the system using MFC
-
Hi there. I can find the IP address of current system using below code but that's C++ code...
char* CLogger::GetIPAdd()
{
WORD wVersionRequested;
WSADATA wsaData;
char Name[255];
PHOSTENT HostInfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *IPAdd;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( Name, sizeof(Name)) == 0)
{
//printf("Host name: %s\n", name);
if((HostInfo = gethostbyname(Name)) != NULL)
{
int nCount = 0;
while(HostInfo->h_addr_list[nCount])
{
IPAdd = inet_ntoa(*(struct in_addr *)HostInfo->h_addr_list[nCount]);++nCount; } } } }
return IPAdd;
}I want to get an IP Address using MFC. Can any one please help me out to get the same using MFC? Thanks PanB
-
Hi there. I can find the IP address of current system using below code but that's C++ code...
char* CLogger::GetIPAdd()
{
WORD wVersionRequested;
WSADATA wsaData;
char Name[255];
PHOSTENT HostInfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *IPAdd;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( Name, sizeof(Name)) == 0)
{
//printf("Host name: %s\n", name);
if((HostInfo = gethostbyname(Name)) != NULL)
{
int nCount = 0;
while(HostInfo->h_addr_list[nCount])
{
IPAdd = inet_ntoa(*(struct in_addr *)HostInfo->h_addr_list[nCount]);++nCount; } } } }
return IPAdd;
}I want to get an IP Address using MFC. Can any one please help me out to get the same using MFC? Thanks PanB
MFC is just a wrapper over C++ classes functions, but what is the problem with the code above. Even if you do find a class in MFC to get the IP address it must be using a similar sort of mechanism to get the IP Address of the local machine
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
-
MFC is just a wrapper over C++ classes functions, but what is the problem with the code above. Even if you do find a class in MFC to get the IP address it must be using a similar sort of mechanism to get the IP Address of the local machine
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
-
Hi there. I can find the IP address of current system using below code but that's C++ code...
char* CLogger::GetIPAdd()
{
WORD wVersionRequested;
WSADATA wsaData;
char Name[255];
PHOSTENT HostInfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *IPAdd;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( Name, sizeof(Name)) == 0)
{
//printf("Host name: %s\n", name);
if((HostInfo = gethostbyname(Name)) != NULL)
{
int nCount = 0;
while(HostInfo->h_addr_list[nCount])
{
IPAdd = inet_ntoa(*(struct in_addr *)HostInfo->h_addr_list[nCount]);++nCount; } } } }
return IPAdd;
}I want to get an IP Address using MFC. Can any one please help me out to get the same using MFC? Thanks PanB
PankajB wrote:
I can find the IP address of current system using below code but that's C++ code...
PankajB wrote:
I want to get an IP Address using MFC
MFC doesn't have functionality covering IP address resolution - if it works, your C++ code is as good as anything. Don't get too hung up about things being in MFC or not in MFC - MFC is, for the most part, a thin veneer over Win32 functions and, overall, has a very old fashioned design , a lot of which was constrained by the deficiencies of C++ compilers in use when MFC was developed.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Why MFC? I am getting lots of Windows.h already included related error messages. But if we can get IP Address in MFC then that will server my requirement. Thanks
PankajB wrote:
But if we can get IP Address in MFC then that will server my requirement.
do you apply ointment on your feet if you have an headache :)
PankajB wrote:
I am getting lots of Windows.h already included related error messages.
figure out why these errors are popping and resolve them. May be you are missing a library to link to or you didn't include a header file. BTW what are the errors?
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
-
Hi there. I can find the IP address of current system using below code but that's C++ code...
char* CLogger::GetIPAdd()
{
WORD wVersionRequested;
WSADATA wsaData;
char Name[255];
PHOSTENT HostInfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *IPAdd;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( Name, sizeof(Name)) == 0)
{
//printf("Host name: %s\n", name);
if((HostInfo = gethostbyname(Name)) != NULL)
{
int nCount = 0;
while(HostInfo->h_addr_list[nCount])
{
IPAdd = inet_ntoa(*(struct in_addr *)HostInfo->h_addr_list[nCount]);++nCount; } } } }
return IPAdd;
}I want to get an IP Address using MFC. Can any one please help me out to get the same using MFC? Thanks PanB
PankajB wrote:
...but that's C++ code...
Nothing in your code is C++.
PankajB wrote:
return IPAdd;
You are potentially returning an uninitialized pointer.
PankajB wrote:
I want to get an IP Address using MFC.
Then use the same code.
PankajB wrote:
Can any one please help me out to get the same using MFC?
MFC offers no such class.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hi there. I can find the IP address of current system using below code but that's C++ code...
char* CLogger::GetIPAdd()
{
WORD wVersionRequested;
WSADATA wsaData;
char Name[255];
PHOSTENT HostInfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *IPAdd;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( Name, sizeof(Name)) == 0)
{
//printf("Host name: %s\n", name);
if((HostInfo = gethostbyname(Name)) != NULL)
{
int nCount = 0;
while(HostInfo->h_addr_list[nCount])
{
IPAdd = inet_ntoa(*(struct in_addr *)HostInfo->h_addr_list[nCount]);++nCount; } } } }
return IPAdd;
}I want to get an IP Address using MFC. Can any one please help me out to get the same using MFC? Thanks PanB
Thanks for the code! I just had to add the library Ws2_32.lib and the header Windows.h, works perfectly! Thanks!
-
Thanks for the code! I just had to add the library Ws2_32.lib and the header Windows.h, works perfectly! Thanks!