记录点点滴滴,以防慢慢忘记
vector<string> MyToolPackage::GetIpv4(char* pNodeName/* = "127.0.0.1"*/, char* pServiceName/* = NULL*/)
{
addrinfo *ailist, *aip;
addrinfo hint;
sockaddr_in *sinp4;
int ilRc;
vector<string> vctIpv4;
memset(&hint, 0, sizeof(addrinfo));
char hostname[255];
gethostname(hostname, 255);
string strName(pNodeName);
if (strName == "127.0.0.1")
{
pNodeName = hostname;
}
/*memset(&ailist, 0, sizeof(addrinfo));
memset(&aip, 0, sizeof(addrinfo));*/
hint.ai_family = AF_INET; //hint 的限定设置
hint.ai_socktype = SOCK_STREAM; //这里可是设置 socket type 比如 SOCK_DGRAM
hint.ai_flags = 0; // flags 的标志很多。常用的有AI_CANONNAME;
hint.ai_protocol = 0; //设置协议 一般为0,默认
ilRc = getaddrinfo(pNodeName, pServiceName, &hint, &ailist); //通过主机名获得地址信息
if (ilRc < 0)
{
char str_error[100];
strcpy_s(str_error,100, (char *)g