none
getsockopt returning 1014 RRS feed

  • Question

  • I'm trying to open up a Bluetooth server socket but when trying to grab the socket options I can't get getsockopt to retreive the CSADDR_INFO structure that I need in order to set the bluetooth service (which is a WSAQUERTYSET member), it's simply returning the 1014 error code which suggests that I haven't allocated enough memory for the structure, my code is as follows (sa is a SOCKADDR_BTH) :

        if(bind(server_socket, (SOCKADDR*)&sa, sizeof(sa)))
        {
            //Failed to bind so close the socket.
            closesocket(server_socket);
            return 0;
        }
    
        //set the connection in the listening state
        if(listen(server_socket, 5))
        {
            //Failed to listen so close the socket.
            closesocket(server_socket);
            return 0;
        }
    
    
        //create the info structure.
        CSADDR_INFO infoStruct;
        int optlen = sizeof(CSADDR_INFO);
    
        memset(&infoStruct, 0, optlen);
    
        if(getsockopt(server_socket, SOL_SOCKET, SO_BSP_STATE, (char*)&infoStruct, &optlen))
        {
    
         //....Error handling
    
        }

    I've also tried creating the SDADDR_INFO struct myself but then WSASetService returns the error code 1022 (Invalid parameter).

        int sockAddrSize = sizeof(sa);
    
        SOCKET_ADDRESS localAddress;
        localAddress.lpSockaddr = (SOCKADDR*)&sa;
        localAddress.iSockaddrLength = sockAddrSize;
      
        CSADDR_INFO infoStruct;
        memset(&infoStruct, 0, sizeof(CSADDR_INFO));
        infoStruct.iProtocol = BTHPROTO_RFCOMM;
        infoStruct.iSocketType = SOCK_STREAM;
        infoStruct.LocalAddr = localAddress;
      
       //Create the query set.
        WSAQUERYSET qs;
        memset(&qs, 0, sizeof(qs));
    
        qs.dwNameSpace = NS_BTH;
        qs.lpszServiceInstanceName = "MyService"
        qs.lpServiceClassId = &clsid;
        qs.dwSize = sizeof(WSAQUERYSET);
        qs.dwNumberOfCsAddrs = 1;
        qs.lpcsaBuffer = &infoStruct;
    
        int retVal = WSASetService(&qs, RNRSERVICE_REGISTER, 0);
        if(retVal == SOCKET_ERROR)
        {
    
        // ...Error handling
    
        }

    Any ideas what I could be missing?

    Cheers

    Wednesday, October 10, 2012 10:23 AM