Beispiel #1
0
static void test_WSAEnumProtocolsW(void)
{
    INT ret;
    DWORD len = 0;
    WSAPROTOCOL_INFOW info, *buffer;

    ret = WSAEnumProtocolsW( NULL, NULL, &len );
    ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly: %d\n",
        WSAGetLastError() );

    len = 0;

    ret = WSAEnumProtocolsW( NULL, &info, &len );
    ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly: %d\n",
        WSAGetLastError() );

    buffer = HeapAlloc( GetProcessHeap(), 0, len );

    if (buffer)
    {
        INT i;

        ret = WSAEnumProtocolsW( NULL, buffer, &len );
        ok( ret != SOCKET_ERROR, "WSAEnumProtocolsW() failed unexpectedly: %d\n",
            WSAGetLastError() );

        for (i = 0; i < ret; i++)
        {
            ok( lstrlenW( buffer[i].szProtocol ), "No protocol name found\n" );
        }

        HeapFree( GetProcessHeap(), 0, buffer );
    }
}
Beispiel #2
0
static void test_WSAEnumProtocolsW(void)
{
    INT ret;
    DWORD len = 0, error;
    WSAPROTOCOL_INFOW info, *buffer;

    ret = WSAEnumProtocolsW( NULL, NULL, &len );
    ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly\n");
    error = WSAGetLastError();
    ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);

    len = 0;

    ret = WSAEnumProtocolsW( NULL, &info, &len );
    ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly\n");
    error = WSAGetLastError();
    ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);

    buffer = HeapAlloc( GetProcessHeap(), 0, len );

    if (buffer)
    {
        INT i;

        ret = WSAEnumProtocolsW( NULL, buffer, &len );
        ok( ret != SOCKET_ERROR, "WSAEnumProtocolsW() failed unexpectedly: %d\n",
            WSAGetLastError() );

        for (i = 0; i < ret; i++)
        {
            ok( lstrlenW( buffer[i].szProtocol ), "No protocol name found\n" );
            test_service_flags( buffer[i].iAddressFamily, buffer[i].iVersion,
                                buffer[i].iSocketType, buffer[i].iProtocol,
                                buffer[i].dwServiceFlags1);
        }

        HeapFree( GetProcessHeap(), 0, buffer );
    }
}
Beispiel #3
0
int SystemCheck( void )
{
	WSADATA wd;
	int i;
	int protoIndex = -1;
	int size;
	//lprintf( "Global is %d %p", sizeof( globalNetworkData ), &globalNetworkData.uNetworkPauseTimer, &globalNetworkData.nProtos );

	if (WSAStartup(MAKEWORD(2, 0), &wd) != 0)
	{
		lprintf(WIDE( "WSAStartup 2.0 failed: %d" ), h_errno);
		return 0;
	}
	if( globalNetworkData.flags.bLogProtocols )
		lprintf(WIDE( "Winsock Version: %d.%d" ), LOBYTE(wd.wVersion), HIBYTE(wd.wVersion));

	size = 0;
	if ((globalNetworkData.nProtos = WSAEnumProtocolsW(NULL, NULL, (DWORD *) &size)) == -1)
	{
		if( WSAGetLastError() != WSAENOBUFS )
		{
			lprintf(WIDE( "WSAEnumProtocols: %d" ), h_errno);
			return 0;
		}
	}

	globalNetworkData.pProtos = (WSAPROTOCOL_INFOW*)Allocate( size );
	if ((globalNetworkData.nProtos = WSAEnumProtocolsW(NULL, globalNetworkData.pProtos, (DWORD *) &size)) == -1)
	{
		lprintf(WIDE( "WSAEnumProtocols: %d" ), h_errno);
		return 0;
	}
	for (i = 0; i < globalNetworkData.nProtos; i++)
	{
		// IPv6
		if (wcscmp(globalNetworkData.pProtos[i].szProtocol, L"MSAFD Tcpip [TCP/IP]" ) == 0)
		{
			globalNetworkData.tcp_protocol = i;
			protoIndex = i;
		}
		if (wcscmp(globalNetworkData.pProtos[i].szProtocol, L"MSAFD Tcpip [UDP/IP]" ) == 0)
		{
			globalNetworkData.udp_protocol = i;
		}
		if (wcscmp(globalNetworkData.pProtos[i].szProtocol, L"MSAFD Tcpip [TCP/IPv6]" ) == 0)
		{
			globalNetworkData.tcp_protocolv6 = i;
		}
		if (wcscmp(globalNetworkData.pProtos[i].szProtocol, L"MSAFD Tcpip [UDP/IPv6]" ) == 0)
		{
			globalNetworkData.udp_protocolv6 = i;
		}
		if( globalNetworkData.flags.bLogProtocols )
			lprintf(WIDE( "Index #%d - name: '%S', type: %d, proto: %d" ), i, globalNetworkData.pProtos[i].szProtocol,
					  globalNetworkData.pProtos[i].iSocketType, globalNetworkData.pProtos[i].iProtocol);
	}
	if (protoIndex == -1)
	{
		lprintf(WIDE( "no valid TCP/IP protocol available" ));
		return 0;
	}
	return 0;
}
JNIEXPORT jint JNICALL Java_com_act365_net_SocketWrenchSession__1deinstallProvider( JNIEnv* env , jclass , jint protocol )
{
    int nDeinstalled = 0 ;

#ifdef WIN32

    int i = -1 ;

    // Find the installed service providers for the given protocol.

    int protocolList[1];

    protocolList[0] = (int) protocol ;

    if( ( nProtocols = WSAEnumProtocolsW( protocolList , protocolBuffer , & protocolBufferSize ) ) == SOCKET_ERROR ){

        jclass exceptionClass = env -> FindClass("java/net/SocketException");
            
        SocketUtils::throwError( env , exceptionClass , "WSAEnumProtocols()" );

        env -> DeleteLocalRef( exceptionClass );

        return nDeinstalled ;
    }

    // Find the path of the DLL in which the services are implemented. 
    // (It's assumed that they're all implemented in a single MS DLL).

    int errorCode = 0 , dllPathLength = maxDllPathLength ;

    if( nProtocols > 0 ){
        WSCGetProviderPath( & protocolBuffer[0].ProviderId , dllPath , & dllPathLength , & errorCode );
    }

    if( errorCode > 0 ){

        jclass exceptionClass = env -> FindClass("java/net/SocketException");
            
        SocketUtils::throwError( env , exceptionClass , "WSCGetProviderPath()" );

        env -> DeleteLocalRef( exceptionClass );

        return nDeinstalled ;
    }

    // Deinstall.
    

    while( ++ i < nProtocols && ! errorCode ){        
        nDeinstalled += WSCDeinstallProvider( & protocolBuffer[i].ProviderId , & errorCode );
    }

    if( errorCode > 0 ){

        jclass exceptionClass = env -> FindClass("java/net/SocketException");
            
        SocketUtils::throwError( env , exceptionClass , "WSCDeinstallProvider()" );

        env -> DeleteLocalRef( exceptionClass );
    }

#endif

    return nDeinstalled ;
}