【问题标题】:WSAGetLastError with unknown error code带有未知错误代码的 WSAGetLastError
【发布时间】:2010-02-16 12:23:36
【问题描述】:

在使用 getHostByName 函数时,我正在使用 WSAGetLastError 函数来检索失败详细信息。但是该函数返回的错误代码是 0042124C 在文档中不可用。我是否收到了其他格式的错误代码,还是我以错误的方式使用了该功能?

谢谢。

PS。下面的代码段

// 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;
}

【问题讨论】:

    标签: error-handling dns gethostbyname


    【解决方案1】:

    getHostByName 已弃用,请改用 getaddrinfo。

    【讨论】:

    • 没有以任何方式解释这种现象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 2011-11-12
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    相关资源
    最近更新 更多