字符串到IP地址. [英] string to ip address.

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

问题描述

如何在C ++中使函数将字符串转换为ipaddress或是否有任何内置函数来执行此操作. (例如atoi)plz帮助...

how to make a function convert string into ipaddress in c++ or is there any inbuilt function to do this. (like atoi) plz help...

推荐答案

您的问题不清楚,因为C ++中没有默认变量类型可以将IP地址保存为IP地址.但是,如果必须使用此IP地址进行某种类型的Socket通信,则必须使用类似sockaddr_in的结构.如果是这样,这是一个解决方案(摘自
Your question is not clear since there is no default variable type in C++ which can hold an IP Address as an IP Address. However, if you have to use this IP Address for some sort of Socket communication, you will have to use a structure like sockaddr_in. If it is so, here is a solution (Taken from here[^]:

int rc;
int s;
struct sockaddr_in myname;
/* clear the structure to be sure that the sin_zero field is clear */
memset(&myname, 0, sizeof(myname));
myname.sin_family = AF_INET;
myname.sin_addr = inet_addr("129.5.24.1");
myname.sin_port = htons(1024);


我认为您想要的是
101.22.34.55< ----> www.something.com

好吧,这是 DNS 的工作.

该链接可能会对您有所帮助:
http://www.stromcode.com/2008/03/02 /cwin32-dns-resolution/ [ ^ ]

要了解有关DNS的更多信息,请参见 http://en.wikipedia.org/wiki/Domain_Name_System [
I think what you want is
101.22.34.55 <----> www.something.com

Well look this is work of DNS.

This link may help you: http://www.stromcode.com/2008/03/02/cwin32-dns-resolution/[^]

To know more about DNS: see http://en.wikipedia.org/wiki/Domain_Name_System[^]

Hope this might help you!!! :)


不要认为有任何内置的解决方案(在C ++或MFC中,尽管MFC确实具有IP地址控件),但是如果您需要解析IP地址的字符串,只需使用''.''字符来解析八位字节,然后检查以确保每个数字都在0-255之间.

要使用它,您可能最终不得不将其放入aamir建议的结构中.
Don''t think there''s any built in solution for this (in C++ or MFC, although MFC does have an IP address control), but if you need to parse a string to an IP address, just use the ''.'' character to parse the octets, then check to make sure each number is between 0-255.

To use it, you''ll probably end up having to put it in a structure as aamir suggested.


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

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