Thread: WSAGetLastError returns 0

  1. #1
    Registered User
    Join Date
    Aug 2007

    WSAGetLastError returns 0

    I have the following code:

    void CUSimCtrlDlg::initializeSockets()
    	int status = 0;
    	// Start Winsock Version 1.1 DLL
    	WSAStartup ( MAKEWORD ( 1,1 ), &wsaData );
    	// Setup Socket to Rx all messages
    	m_rx_pulse_socket = socket(AF_INET,SOCK_DGRAM,INADDR_ANY);
        sAddrRxAll.sin_family = AF_INET;
        sAddrRxAll.sin_addr.s_addr = htonl ( INADDR_ANY );
        sAddrRxAll.sin_port = htons ( PORT_NUM_RX_FROM_HOST );
        status = bind ( m_rx_pulse_socket, (SOCKADDR FAR *)&sAddrRxAll, sizeof ( SOCKADDR_IN ) );
    	if (status == SOCKET_ERROR)
    		AfxMessageBox("Socket Error");
    	m_tx_pulse_socket = socket(AF_INET,SOCK_DGRAM,INADDR_ANY);
        sAddrTxAll.sin_family = AF_INET;
        sAddrTxAll.sin_addr.s_addr = htonl ( INADDR_ANY );
        sAddrTxAll.sin_port = htons ( PORT_NUM_TX_TO_HOST );
        bind ( m_rx_pulse_socket, (SOCKADDR FAR *)&sAddrTxAll, sizeof ( SOCKADDR_IN ) );
    I was wondering why the last Bind(...) was not assigned into a status as the first one was. So I added the code status = to the bind(...) and the status did return a SOCKET_ERROR (-1)
    So I called WSAGetLastError() and the return was 0. What does this mean? I could not find any corresponding error for value of 0.


  2. #2
    Registered User
    Join Date
    Aug 2007
    I found the error in the 2nd bind statement, misspelled word to cause another bind of first socket name.
    But still wondering what a 0 return from WSAGetlastError() means.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Well ask MSDN ( ... But depending on where you added WSAGetLastError()

    Quote Originally Posted by msdn
    If a function call's return value indicates that error or other relevant data was returned in the error code, WSAGetLastError should be called immediately. This is necessary because some functions may reset the last extended error code to 0 if they succeed, overwriting the extended error code returned by a previously failed function.
    And to my limited winsock knowledge, you cannot call bind() and/or socket() again on the same initialized socket.

Popular pages Recent additions subscribe to a feed