NULL和IP地址 [英] NULL and IP Addresses

查看:266
本文介绍了NULL和IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果IP地址的返回值为NULL,我正在尝试将其更改为0.0.0.0
我正在使用此文件(正在尝试),但尚未编译.

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.

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是一个指针.任何帮助和指导表示赞赏.谢谢.

试过这个,不行.


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

Tried this, not working.

if ( addr2 == NULL ) "0.0.0.0"; 

推荐答案

从我所知道的,以前的问题以及过去的其他问题来看,您似乎仍然没有想到指针.可以使用std::string为您更好地工作.

您将看到:如果IP地址的返回值为NULL…".不,返回值"可以是功能的属性,而不是"IP地址"; "addr2是一个指针,我应该先将其转换为字符串吗?"不,在您尝试使用的字符串意义上的字符串是指针.

我不知道还有什么其他解释.可能会回到最基础的知识,并从最初提到的一些C ++基本书中开始学习指针和以空值结尾的字符串,并在您完全有信心之前学习所有内容.您进入了死胡同.如果您尝试前进,您将陷入更深层次的困惑.除非您退一步学习基础知识,否则一切无济于事.

抱歉,这就是您可以立即获得的所有帮助.

(对于那些可能不同意并试图帮助OP的专家:首先看一下OP过去的问题和答案;这可能更清楚我为什么以这种方式解决OP.)

祝你好运,
—SA
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


这篇关于NULL和IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆