替代gethostbyname [英] Alternative to gethostbyname

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

问题描述

我不能使用 gethostbyname 来获取主机的IP地址,这是一个已弃用的功能,在Windows上只能使用10%的时间!

I can't use gethostbyname to grab a host's IP address, it is a deprecated function that only works 10% of the fricken' time on Windows!

我无法找到其他方法来使用其他功能来找到主机的IP地址的足够资源(MSDN建议 getaddrinfo ,但这似乎不是我想要的.)

I can't find any adequate resources on other ways to find a host's IP address using other functions (MSDN recommended getaddrinfo but that doesn't seem like what I want.)

推荐答案

实际上, getaddrinfo 是您想要的.这只是一个漫长的过程,更不用说有时会找到多个IP地址(例如,一个 IPv4地址和一个 IPv6地址).我建议您查看《 Beej网络编程指南》 ,尤其是

Actually, getaddrinfo is what you want. It's just a long-winded way to do it, not to mention the fact that sometimes multiple IP addresses are found (e.g. one IPv4 address and one IPv6 address). I'd recommend looking at Beej's Guide to Network Programming, specifically getaddrinfo.

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

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