Error handling 错误代码未知的WSAGetLastError
在使用getHostByName函数时,我正在使用WSAGetLastError函数检索故障详细信息。但是该函数返回的错误代码为0042124C,在文档中不可用。我是否收到其他格式的错误代码,或者我是否以错误的方式使用该函数 谢谢 下面是代码段Error handling 错误代码未知的WSAGetLastError,error-handling,dns,gethostbyname,Error Handling,Dns,Gethostbyname,在使用getHostByName函数时,我正在使用WSAGetLastError函数检索故障详细信息。但是该函数返回的错误代码为0042124C,在文档中不可用。我是否收到其他格式的错误代码,或者我是否以错误的方式使用该函数 谢谢 下面是代码段 // DNS Hostname.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "DNS Hostname.h" #
// DNS Hostname.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "DNS Hostname.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
HOSTENT* pHostDetails = NULL;
pHostDetails = gethostbyname("IE10-FLYFB1S");
if(pHostDetails)
{
int nList = 0;
CString sAddressString;
CString sSQLAddress;
CString sSQLMachine;
unsigned long addr;
while ( pHostDetails->h_addr_list[nList] )
{
addr = (*(u_long FAR *) pHostDetails->h_addr_list[nList]);
sAddressString.Format(_T("%d.%d.%d.%d"),(addr & 255),((addr >> 8) & 255),((addr >> 16) & 255),((addr >> 24) & 255));
sSQLAddress.Format(_T(" OR Machine = '%s' "),sAddressString);
sSQLMachine += sSQLAddress;
nList++;
}
cout << sSQLMachine << endl;
}
else
{
int error = WSAGetLastError();
cout << error << endl;
}
}
WSACleanup();
return nRetCode;
}
//DNS Hostname.cpp:定义控制台应用程序的入口点。
//
#包括“stdafx.h”
#包括“DNS主机名.h”
#ifdef_调试
#定义新调试\u新
#取消定义此文件
静态字符此\u文件[]=\u文件\u;
#恩迪夫
/////////////////////////////////////////////////////////////////////////////
//唯一的应用程序对象
CWinApp-theApp;
使用名称空间std;
int_tmain(int-argc,TCHAR*argv[],TCHAR*envp[]
{
int nRetCode=0;
//初始化MFC并打印,失败时出错
如果(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
{
//TODO:更改错误代码以满足您的需要
cerr h_地址列表[nList];
格式(_T(“%d.%d.%d.%d”),(addr&255),((addr>>8)和255),((addr>>16)和255),((addr>>24)和255);
格式(_T(“或机器=“%s”),sAddressString);
sSQLMachine+=sSQLAddress;
nList++;
}
如果不推荐使用getHostByName,请改用getaddrinfo。不会以任何方式解释这种现象。