Search code examples
c++winsockgetaddrinfo

WSAGetLastError() returns 122


Well.. I am not really sure what that means, but my systems runs and runs and runs without crying for insufficient memeory...

I guess it has to do with the system error 122, because there is no 122 in the winsock error codes (MSDN)...

Anyone got a clue?...

It occures on a call to getaddrinfo(NULL, /*PortNumber*/, &hints, &pFinal)

EDIT alright... heres more code (having it not commented out, doesn´t make sense, too)

            addrinfo hints, *pFinal = nullptr;
            memset(&hints, 0, sizeof(hints));
            hints.ai_flags = AI_PASSIVE;
            hints.ai_socktype = SOCK_STREAM;
            hints.ai_family = AF_INET;

            if(getaddrinfo(NULL, g_ACCEPTOR_PORT_NUMBER, &hints, &pFinal))
                return ERROR_BIND_SOCKET;

The Problem lies in my g_ACCEPTOR_PORT_NUMBER, which is a class containing

operator const char*()
    {
        std::stringstream ss;
        ss << m_nPortNumber;
        return ss.str().c_str();
    }

do I have to change the conversion operator?... I´d prefer to use this "STRINGINT" so i dont need to save the port number as string and number or convert it explicitly...


Solution

  • The problem is your implementation of operator const char*(). Once that function returns, your stringstream object is no longer valid because it is no longer in scope.