Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If the return value of the IP address is NULL, I'm trying to change it to 0.0.0.0
I'm using this (trying) but it is not compiling.

C++
HOSTENT *pHostEnt2;
		int  **ppaddr2;
		SOCKADDR_IN sockAddr2;
		//char* addr2;
		pHostEnt2 = gethostbyname(NewLogURL.c_str());
		ppaddr2 = (int**)pHostEnt2->h_addr_list;
		sockAddr2.sin_addr.s_addr = **ppaddr2;
		addr2 = inet_ntoa(sockAddr2.sin_addr);
		//char currentaddress[100] = { 0 };
		//strcpy( currentaddress, inet_ntoa(sockAddr2.sin_addr ) );
		if(addr2 != NULL && addr2[0] == "0.0.0.0")
		{  
		}
		printf("\n   Current Website IP:%s", addr2);

addr2 is a pointer. Any help and direction is appreciated. Thank you.

Tried this, not working.
if ( addr2 == NULL ) "0.0.0.0"; 
Posted
Updated 9-Nov-11 16:00pm
v3

1 solution

From what I know from this, previous and some other of your past questions, it looks like you still did not get the idea of a pointer. Could using std::string work for you better.

You see: "If the return value of the IP address is NULL…". No, "return value" can be an attribute of a function, not "IP address"; "addr2 is a pointer, should I convert it to a string first?" No, a string in the sense of the string you are trying to use is a pointer.

I don't know how else to explain. Probably get back to the very basics and start learning about pointers and null-terminated strings in some elementary C++ book from the place they are first mentioned and learn it all until you are quite confident. You are entered the dead end. If you try to move forward, you will get to deeper and even deeper confusion. Nothing can help unless you step back to basics and learn them well.

Sorry, but this is all help you can get right now.

(For those experts who may disagree and try to help OP: first take a look at past OP's questions and the answers; it might make it more clear why I address OP in this way.)

Good luck,
—SA
 
Share this answer
 
Comments
Member 7766180 9-Nov-11 21:51pm    
Thank you.
Sergey Alexandrovich Kryukov 9-Nov-11 23:03pm    
Seriously, think about it...
--SA
LanFanNinja 9-Nov-11 22:52pm    
+5
Sergey Alexandrovich Kryukov 9-Nov-11 23:03pm    
Thank you, Lan Fan Ninja.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900