struct addrinfo hints,*res; memset(&hints,0,sizeof(hints));
hints.ai_family=AF_INET6; hints.ai_socktype=SOCK_STREAM; hints.ai_protocol=IPPROTO_TCP; hints.ai_flags=AI_PASSIVE; char cName[256]; ::gethostname(cName,256); std::string m_strPort = "4567"; int rc=getaddrinfo(cName,m_strPort.c_str(),&hints,&res); if(rc != 0) { CString msg; msg.Format(L"地址解析出错!错误代码:%d",WSAGetLastError()); MessageBox(msg,NULL,MB_ICONERROR); return ; } else { TCHAR IPV6[200]; memset(IPV6,'\0',200); DWORD bufflen = 200; //将本地地址转换成字符串显示 WSAAddressToString(res->ai_addr,res->ai_addrlen,NULL,IPV6,&bufflen); CString msg = IPV6; MessageBox(msg,NULL,MB_ICONERROR); return ; }
|