我可以将字符串转换为IP地址在多个平台上的c + + Windows(各种版本)和Unix系统?C++字符串到ipAddress windows/unix系统
2
A
回答
3
您可以使用inet_addr()
函数将表示为字符串的IP地址转换为可与其他套接字函数一起使用的表单。
下面是一个例子使用(从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");
/* specific interface */
myname.sin_port = htons(1024);
0
如果你有一个主机名或FQDN,你需要一个DNS查询或内部主机列表中查询其转换为IP地址,那么你需要使用gethostbyname
。
相关问题
- 1. 系统字符串^添加字符到堆栈(Visual C++)
- 2. 如何将IpAddress项目隐藏到字符串c#
- 3. .NET系统::字符串到std ::字符串
- 4. 将IPAddress []转换为字符串
- 5. C++/CLI转换系统::字符串转换为const char *
- 6. C++ - 从变量字符串BOOST文件系统路径
- 7. C++系统函数不接受字符串?
- 8. 传递字符串用空格作为系统参数C++
- 9. 无法隐式转换 'System.Collections.Generic.Dictionary <字符串,System.Collections.Generic.List <string>>' 到 '系统... <字符串,字符串>'
- 10. 将字符串扫描到scanf会自动结束系统(“/ bin/sh”)C
- 11. 如何将字符串打印到系统控制台?
- 12. Python3模块将字符串复制到系统剪贴板
- 13. 系统::字符串^到十六进制表示,需要帮助
- 14. C字符串字符串
- 15. 在C字符添加到字符串
- 16. c字符串指针
- 17. C#AnsiString到字符串
- 18. C#得到字符串
- 19. C字符串到阵列
- 20. 字符串到枚举C++
- 21. 枚举到字符串C++
- 22. 将字符串IP转换为IPADDRESS控制
- 23. 如何改变从字符串的URL查询字符串值由系统
- 24. AngularJs选择系统字符
- 25. C字符串长度
- 26. c#注册表System.Byte []到字符串
- 27. 如何获得系统的货币符号的字符串
- 28. JVM系统属性 - 如何看待字符串文字
- 29. Android - 检索默认系统字体字符串名称
- 30. 从系统::串串
你需要什么令人兴奋的......你必须将字符串转换为格式化为这样xxx.xxx.xxx.xxx astring? – Kevin 2011-03-21 13:16:30
目前尚不清楚你想要什么。这是什么字符串?主机名或IP地址,还是...? – 2011-03-21 13:36:08