Click here to Skip to main content
16,006,594 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGradient RoundRect Pin
HakunaMatada23-May-06 18:56
HakunaMatada23-May-06 18:56 
AnswerRe: Gradient RoundRect Pin
Nibu babu thomas23-May-06 19:04
Nibu babu thomas23-May-06 19:04 
AnswerRe: Gradient RoundRect Pin
Hamid_RT23-May-06 19:18
Hamid_RT23-May-06 19:18 
Questioncontrolling the creation of objects Pin
kumar_mk23-May-06 18:47
kumar_mk23-May-06 18:47 
AnswerRe: controlling the creation of objects Pin
_AnsHUMAN_ 23-May-06 19:15
_AnsHUMAN_ 23-May-06 19:15 
AnswerRe: controlling the creation of objects Pin
Nibu babu thomas23-May-06 19:16
Nibu babu thomas23-May-06 19:16 
QuestionHow to Get Current System ip Pin
bujji_bec23-May-06 18:38
bujji_bec23-May-06 18:38 
AnswerRe: How to Get Current System ip [modified] Pin
Nibu babu thomas23-May-06 18:52
Nibu babu thomas23-May-06 18:52 
Here is a function that does that...

Use the function as follows:

LPSTR lpszBuf;
 
//lpszBuf will have the IPAddress. There could be more than one IPAddresses separated by comma.
GetIPAddress(lpszBuf);
 
<code>//Use it...</code>
 
<code>//don't forget to delete, coz memory is allocated inside the module</code>
delete [] lpszBuf;
BOOL GetIPAddress(LPSTR* lpszBuffer)
{
         WSADATA wsaData;
	::ZeroMemory(&wsaData, sizeof(WSADATA));
	
	 <code>//init winsock</code>
	int retCode = WSAStartup(MAKEWORD(2,2), &wsaData);
	
	if(retCode != 0)
		return FALSE;//probably version not supported
	
	CHAR szHostName[MAX_COMPUTERNAME_LENGTH];
	<code>//get computer name</code>
	gethostname(szHostName, MAX_COMPUTERNAME_LENGTH);
	
	//host entry structure
	LPHOSTENT hstEnt;
         <code>//get the IPAddress</code>
	hstEnt = gethostbyname(szHostName);
	
	if(hstEnt != NULL)
	{
		int nCount=0;
		
		<code>//get total ip's</code>
		while(hstEnt->h_addr_list[nCount++]!=NULL)
			;
		
		<code>*lpszBuffer = new CHAR[20*nCount];</code>
		**lpszBuffer = NULL;

		int nIndex = 0;
		
		<code>//start retrieving the ip's</code>
		while(hstEnt->h_addr_list[nIndex] != NULL)
		{
			strcat(
			*lpszBuffer,(CHAR*) 
			inet_ntoa(*(struct in_addr *)hstEnt->h_addr_list[nIndex++])
			);
 
                           //we should not have a comma after the last IPAddress, in case there are more that one IPAddresses.
			if(nCount < nCount-1)
				strcat(*lpszBuffer, (","));
		}
	}
	else
		return FALSE;
	
	WSACleanup();//close up :)

	return TRUE;
}


The function that does the process of IP retrieval is the gethostbyname function. The above function just facilitates the use of this function.



Nibu thomas
A Developer

Programming tips[^]  My site[^]

AnswerRe: How to Get Current System ip Pin
Hamid_RT23-May-06 19:03
Hamid_RT23-May-06 19:03 
QuestionMy Access DB Got Mad! Pin
Hamed Musavi23-May-06 18:21
Hamed Musavi23-May-06 18:21 
NewsC++ vs C# vs C++/CLI Performance [modified] Pin
Ed K23-May-06 17:08
Ed K23-May-06 17:08 
GeneralRe: C++ vs C# vs C++/CLI Performance [modified] Pin
bob1697223-May-06 17:36
bob1697223-May-06 17:36 
GeneralRe: C++ vs C# vs C++/CLI Performance [modified] Pin
Maxwell Chen23-May-06 18:06
Maxwell Chen23-May-06 18:06 
GeneralRe: C++ vs C# vs C++/CLI Performance [modified] Pin
Sarath C23-May-06 18:13
Sarath C23-May-06 18:13 
GeneralRe: C++ vs C# vs C++/CLI Performance [modified] Pin
Maxwell Chen23-May-06 18:21
Maxwell Chen23-May-06 18:21 
AnswerRe: C++ vs C# vs C++/CLI Performance [modified] Pin
Ed K24-May-06 6:49
Ed K24-May-06 6:49 
GeneralRe: C++ vs C# vs C++/CLI Performance [modified] Pin
bob1697224-May-06 18:01
bob1697224-May-06 18:01 
Questionprogressbar and xp themes help Pin
locoone23-May-06 17:07
locoone23-May-06 17:07 
AnswerRe: progressbar and xp themes help Pin
Nibu babu thomas23-May-06 17:24
Nibu babu thomas23-May-06 17:24 
GeneralRe: progressbar and xp themes help Pin
locoone24-May-06 13:25
locoone24-May-06 13:25 
AnswerRe: progressbar and xp themes help Pin
Hamid_RT23-May-06 19:23
Hamid_RT23-May-06 19:23 
GeneralRe: progressbar and xp themes help Pin
locoone24-May-06 13:54
locoone24-May-06 13:54 
QuestionPrinting CEditView Pin
richard stott23-May-06 16:53
richard stott23-May-06 16:53 
AnswerRe: Printing CEditView Pin
bob1697223-May-06 17:24
bob1697223-May-06 17:24 
Questionrecv question Pin
followait23-May-06 16:32
followait23-May-06 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.