Beispiel #1
0
// check if OS have support for IPv6 protocol
bool isIPv6supported()
{
	INT proto[] = {IPPROTO_TCP, 0};

	Firebird::HalfStaticArray<char, sizeof(WSAPROTOCOL_INFO) * 4> buf;

	DWORD len = buf.getCapacity();
	LPWSAPROTOCOL_INFO pi = (LPWSAPROTOCOL_INFO) buf.getBuffer(len);

	int n = WSAEnumProtocols(proto, pi, &len);

	if (n == SOCKET_ERROR && GetLastError() == WSAENOBUFS)
	{
		pi = (LPWSAPROTOCOL_INFO) buf.getBuffer(len);
		n = WSAEnumProtocols(proto, pi, &len);
	}

	if (n == SOCKET_ERROR)
		return false;

	for (int i = 0; i < n; i++)
	{
		if (pi[i].iAddressFamily == AF_INET6 && pi[i].iProtocol == IPPROTO_TCP)
			return true;
	}

	WSASetLastError(0);
	return false;
}
// Function: FindProtocol()
// Description:
//    This function enumerates protocols installed on the system
//    with WSAEnumProtocols and searches for ATM transports
WSAPROTOCOL_INFO* FindProtocol_atm()
{
    WSAPROTOCOL_INFO   *lpProtocolBuf=NULL, *lpRet=NULL;
    DWORD               dwErr, dwRet, dwBufLen=0, i;
 
    if (WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen) != SOCKET_ERROR)
    {
       // This should never happen as there is a NULL buffer
       printf("WSAEnumProtocols() failed with error code %d\n", WSAGetLastError());
       return FALSE;
    }
    else if ((dwErr = WSAGetLastError()) != WSAENOBUFS)
    {
       // We failed for some reason not relating to buffer size - also odd
       printf("WSAEnumProtocols() failed with error code %d\n", dwErr);
       return FALSE;
    }
    else
       printf("WSAEnumProtocols() should be fine!\n");
 
	// Allocate the correct buffer size for WSAEnumProtocols as
	// well as the buffer to return
	lpProtocolBuf = (WSAPROTOCOL_INFO *)GlobalAlloc(GMEM_FIXED, dwBufLen);
 
    if (lpProtocolBuf == NULL)
    {
       printf("GlobalAlloc() failed with error code %d\n", GetLastError());
       return FALSE;
    }
    else
       printf("GlobalAlloc() is OK!\n");
 
    dwRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
    if (dwRet == SOCKET_ERROR)
    {
       printf("WSAEnumProtocols() failed with error code %d\n", WSAGetLastError());
       GlobalFree(lpProtocolBuf);
       return FALSE;
    }
    else
       printf("WSAEnumProtocols() should be fine!\n");
 
    // Loop through the returned protocol information looking for those
    // that are in the AF_ATM address family
    for (i=0; i < dwRet ;i++)
    {
       if ( (lpProtocolBuf[i].iAddressFamily == AF_ATM) 
		 && (lpProtocolBuf[i].iSocketType == SOCK_RAW) 
		 //&& (lpProtocolBuf[i].iProtocol == ATMPROTO_AAL5))
		 && (lpProtocolBuf[i].iProtocol == ATMPROTO_AAL2))
       {
          lpRet = GlobalAlloc(GMEM_FIXED, sizeof(WSAPROTOCOL_INFO));
          memcpy(lpRet, &lpProtocolBuf[i], sizeof(WSAPROTOCOL_INFO));
          break;
       }
    }
 
    GlobalFree(lpProtocolBuf);
    return lpRet;
}
Win32Network::Win32Network():SYNC_NUMBER(1234567)
{
	traceFunction(eNetwork);
	int error;
	WSAData wd;
	error=WSAStartup(MAKEWORD(2,2),&wd);

	
	if(error==SOCKET_ERROR){
		if(LOBYTE(wd.wVersion)!=2 || HIBYTE(wd.wVersion)!=0){
			WSACleanup();
			/////////error occourd
			messages::logMessage(messages::HMSG_NET_START,ELL_ERROR);
			
			return;
		}
	}

	DWORD buffSize=0;

	//Enumerate available protocols
	int numProto=WSAEnumProtocols(0,0,&buffSize);

	if(numProto!=SOCKET_ERROR && WSAGetLastError()!=WSAENOBUFS){
		WSACleanup();
		
		return;
	}

	LPWSAPROTOCOL_INFO selectedProto;

	selectedProto=(LPWSAPROTOCOL_INFO)malloc(buffSize);

	int *proto=new int[2];
	proto[0]=IPPROTO_TCP;
	proto[1]=IPPROTO_UDP;

	numProto=WSAEnumProtocols(proto,selectedProto,&buffSize);

	delete [] proto;
	proto=0; 

	free(selectedProto);
	selectedProto=0;


	 
}
Beispiel #4
0
void diag(FILE *output)
{
	char *yn[] = { "No", "Yes", "Unknown" };

	fprintf(output,"CVSNT Diagnostic output\n");
	fprintf(output,"-----------------------\n");
	fprintf(output,"\n");
	fprintf(output,"Server version: "CVSNT_PRODUCTVERSION_STRING"\n");
	fprintf(output,"OS Version: %s\n",get_os_version());
	fprintf(output,"\n");
	fprintf(output,"CVS Service installed: %s\n",service_installed("Cvsnt")?"Yes":"No");
	fprintf(output,"LockService installed: %s\n",service_installed("CvsLock")?"Yes":"No");
	fprintf(output,"\n");
	fprintf(output,":pserver: installed: %s\n",protocol_installed("pserver")?"Yes":"No");
	fprintf(output,":sserver: installed: %s\n",protocol_installed("sserver")?"Yes":"No");
	fprintf(output,":gserver: installed: %s\n",protocol_installed("gserver")?"Yes":"No");
	fprintf(output,":server: installed: %s\n",protocol_installed("server")?"Yes":"No");
	fprintf(output,":ssh: installed: %s\n",protocol_installed("ssh")?"Yes":"No");
	fprintf(output,":sspi: installed: %s\n",protocol_installed("sspi")?"Yes":"No");
	fprintf(output,":ext: installed: %s\n",protocol_installed("ext")?"Yes":"No");
	fprintf(output,"\n");
	fprintf(output,"Installation Path: %s\n",get_reg_string("InstallPath"));
	fprintf(output,"Repository 0 Path: %s\n",get_reg_string("Repository0"));
	fprintf(output,"Repository 0 Name: %s\n",get_reg_string("Repository0Name"));
	fprintf(output,"Repository 1 Path: %s\n",get_reg_string("Repository1"));
	fprintf(output,"Repository 1 Name: %s\n",get_reg_string("Repository1Name"));
	fprintf(output,"Repository 2 Path: %s\n",get_reg_string("Repository2"));
	fprintf(output,"Repository 2 Name: %s\n",get_reg_string("Repository2Name"));
	fprintf(output,"Repository 3 Path: %s\n",get_reg_string("Repository3"));
	fprintf(output,"Repository 3 Name: %s\n",get_reg_string("Repository3Name"));
	fprintf(output,"CVS Temp directory: %s\n",get_reg_string("TempDir"));
	fprintf(output,"CA Certificate File: %s\n",get_reg_string("CertificateFile"));
	fprintf(output,"Private Key File: %s\n",get_reg_string("PrivateKeyFile"));
	fprintf(output,"Local Users Only: %s\n",get_reg_int("DontUseDomain")?"Yes":"No");
	fprintf(output,"Default LockServer: %s\n",get_reg_string("LockServer"));
	fprintf(output,"Disable Reverse DNS: %s\n",get_reg_int("NoReverseDns")?"Yes":"No");
	fprintf(output,"Server Tracing: %s\n",get_reg_int("AllowTrace")?"Yes":"No");
	fprintf(output,"Case Sensitive: %s\n",get_reg_int("CaseSensitive")?"Yes":"No");
	fprintf(output,"Server listen port: %d\n",get_reg_int("PServerPort"));
	fprintf(output,"Compatibility (Non-cvsnt clients):\n");
	fprintf(output,"\tReport old CVS version: %s\n",get_reg_int("Compat0_OldVersion")?"Yes":"No");
	fprintf(output,"\tHide extended status: %s\n",get_reg_int("Compat0_HideStatus")?"Yes":"No");
	fprintf(output,"\tEmulate co -n bug: %s\n",get_reg_int("Compat0_OldCheckout")?"Yes":"No");
	fprintf(output,"\tIgnore client wrappers: %s\n",get_reg_int("Compat0_IgnoreWrappers")?"Yes":"No");
	fprintf(output,"Compatibility (CVSNT clients):\n");
	fprintf(output,"\tReport old CVS version: %s\n",get_reg_int("Compat1_OldVersion")?"Yes":"No");
	fprintf(output,"\tHide extended status: %s\n",get_reg_int("Compat1_HideStatus")?"Yes":"No");
	fprintf(output,"\tEmulate co -n bug: %s\n",get_reg_int("Compat1_OldCheckout")?"Yes":"No");
	fprintf(output,"\tIgnore client wrappers: %s\n",get_reg_int("Compat1_IgnoreWrappers")?"Yes":"No");
	fprintf(output,"Default domain: %s\n",get_reg_string("DefaultDomain"));
	fprintf(output,"Force run as user: %s\n",get_reg_string("RunAsUser"));
	fprintf(output,"\n");
	fprintf(output,"Temp dir readable by current user: %s\n",yn[is_readable(false,get_reg_string("TempDir"))]);
//	fprintf(output,"Temp dir readable by LocalSystem: %s\n",yn[is_readable(true,get_reg_string("TempDir"))]);
	fprintf(output,"Repository0 readable by current user: %s\n",yn[is_readable(false,get_reg_string("Repository0"))]);
//	fprintf(output,"Repository0 readable by LocalSystem: %s\n",yn[is_readable(true,get_reg_string("Repository0"))]);
	fprintf(output,"Temp dir writable by current user: %s\n",yn[is_writable(false,get_reg_string("TempDir"))]);
//	fprintf(output,"Temp dir writable by LocalSystem: %s\n",yn[is_writable(true,get_reg_string("TempDir"))]);
	fprintf(output,"\n");
	fprintf(output,"AV files detected:\n");
	print_found_files(output,"_AVP32.EXE\0_AVPCC.EXE\0_AVPM.EXE\0AVP32.EXE\0AVPCC.EXE\0AVPM.EXE\0"
							"N32SCANW.EXE\0NAVAPSVC.EXE\0NAVAPW32.EXE\0NAVLU32.EXE\0NAVRUNR.EXE\0NAVW32.EXE"
							"NAVWNT.EXE\0NOD32.EXE\0NPSSVC.EXE\0NRESQ32.EXE\0NSCHED32.EXE\0NSCHEDNT.EXE"
							"NSPLUGIN.EXE\0SCAN.EXE\0AVGSRV.EXE\0AVGSERV.EXE\0AVGCC32.EXE\0AVGCC.EXE\0"
							"AVGAMSVR.EXE\0AVGUPSVC.EXE\0NOD32KRN.EXE\0NOD32KUI.EXE\0");

	fprintf(output,"\n");
	WSADATA wsa = {0};
	if(WSAStartup(MAKEWORD(2,0),&wsa))
		fprintf(output,"Winsock intialisation failed!\n");
	else
	{
		fprintf(output,"Installed Winsock protocols:\n\n");
		DWORD dwSize=0;
		LPWSAPROTOCOL_INFO proto;
		WSAEnumProtocols(NULL,NULL,&dwSize);
		proto=(LPWSAPROTOCOL_INFO)malloc(dwSize);
		WSAEnumProtocols(NULL,proto,&dwSize);
		for(int n=0; n<(int)(dwSize/sizeof(proto[0])); n++)
		{
			if(!strncmp(proto[n].szProtocol,"MSAFD NetBIOS",13))
				continue; // Ignore netbios layers
			fprintf(output,"%d: %s\n",proto[n].dwCatalogEntryId,proto[n].szProtocol);
		}
		free(proto);
	}
}
int DreamWinSock::dreamSock_InitializeWinSock(void)
{
	WORD versionRequested;
	WSADATA wsaData;
	DWORD bufferSize = 0;

	LPWSAPROTOCOL_INFO SelectedProtocol;
	int NumProtocols;

	// Start WinSock2. If it fails, we do not need to call WSACleanup()
	versionRequested = MAKEWORD(2, 0);
	int error = WSAStartup(versionRequested, &wsaData);
    
	if(error)
	{
		LogString("FATAL ERROR: WSAStartup failed (error = %d)", error);
		return 1;
	}
	else
	{
		LogString("WSAStartup OK");

		// Confirm that the WinSock2 DLL supports the exact version
		// we want. If not, call WSACleanup().
		if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0)
		{
			LogString("FATAL ERROR: WinSock2 DLL does not support the correct version (%d.%d)",
				LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));

			WSACleanup();
			return 1;
		}
	}

	// Call WSAEnumProtocols to figure out how big of a buffer we need
	NumProtocols = WSAEnumProtocols(NULL, NULL, &bufferSize);

	if( (NumProtocols != SOCKET_ERROR) && (WSAGetLastError() != WSAENOBUFS) )
	{
		WSACleanup();
		return 1;
	}

	// Allocate a buffer, call WSAEnumProtocols to get an array of
	// WSAPROTOCOL_INFO structs
	SelectedProtocol = (LPWSAPROTOCOL_INFO) malloc(bufferSize);

	if(SelectedProtocol == NULL)
	{
		WSACleanup();
		return 1;
	}

	// Allocate memory for protocol list and define what protocols to look for
	int *protos = (int *) calloc(2, sizeof(int));

	protos[0] = IPPROTO_TCP;
	protos[1] = IPPROTO_UDP;

	NumProtocols = WSAEnumProtocols(protos, SelectedProtocol, &bufferSize);
	
	free(protos);
	protos = NULL;
	
	free(SelectedProtocol);
	SelectedProtocol = NULL;

	if(NumProtocols == SOCKET_ERROR)
	{
		LogString("FATAL ERROR: Didn't find any required protocols");
		WSACleanup();
		return 1;
	}

	return 0;
}
//
// Function: FindServiceProvider
//
// Description:
//    Query the installed protocols, searching for those of the 
//    AF_NETBIOS family and printing out the LANA number.
//
int FindServiceProvider()
{
    WSAPROTOCOL_INFO   *lpProtocolBuf = NULL;
    DWORD               dwBufLen = 0,
                        dwErr,
                        dwRet,
                        i;
    long                lAbs;

    // force WSAEnumProtocols to indicate proper size for buffer
    //
    if (SOCKET_ERROR != WSAEnumProtocols(NULL, lpProtocolBuf, 
        &dwBufLen))
    {
        // This should never happen as there is a NULL buffer
        //
	printf("WSAEnumProtocols failed!\n");
	return 1;
    }
    else if (WSAENOBUFS != (dwErr = WSAGetLastError()))
    {
	// We failed for some reason not relating to buffer size - 
        // also odd
        //
	printf("WSAEnumProtocols failed: %d\n", dwErr);
	return 1;
    }
    //
    // Allocate the correct buffer size
    //
    lpProtocolBuf = (WSAPROTOCOL_INFO *)GlobalAlloc(GMEM_FIXED, 
        dwBufLen);
    if (lpProtocolBuf == NULL)
    {
	printf("GlobalAlloc failed: %d\n", GetLastError());
	return 1;
    }
    dwRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
    if (dwRet == SOCKET_ERROR)
    {
	printf("WSAEnumProtocols failed: %d\n", WSAGetLastError());
	GlobalFree(lpProtocolBuf);
	return 1;
    }
    //
    // Loop through the returned protocol information looking for those
    // that are in the AF_NETBIOS address family.
    //
    for (i=0; i < dwRet ;i++)
    {
	if (lpProtocolBuf[i].iAddressFamily == AF_NETBIOS)
	{
	    lAbs = abs(lpProtocolBuf[i].iProtocol);
            if (lAbs == LANA_ZERO_VALUE)
                printf(" LANA: 0  ");
            else
                printf(" LANA: %ld  ", lAbs);
            printf("Protocol: '%s'\n", lpProtocolBuf[i].szProtocol);
	}
    }
    GlobalFree(lpProtocolBuf);

    return 0;
}
Beispiel #7
0
BOOL CTcpSocket::Startup()
{
	int i, err;
	DWORD dwBufferSize = 0;		// size of m_pProtocolsInfo buffer
	WORD wVersionRequested;
	BOOL bFoundTcp = FALSE;
	WSADATA wsaData;

	m_pProtocolsInfo = NULL;

	// Asynchronous IO and multicast semantics we use supported starting only with WinSock 2.0 
	wVersionRequested = MAKEWORD (2, 2);
    // Start WinSock 2.  If it fails, we don't need to call WSACleanup().
	err = WSAStartup (wVersionRequested, &wsaData);
	if (err != 0)
	{
		OutputDebugString(_T("Could not find high enough version of WinSock\n"));
		return FALSE;
	}
/*	if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) 
	{	
		OutputDebugString(_T("Could not find the correct version of WinSock\n"));
		goto Error;
	}
*/
	// Call WSAEnumProtocols to figure out how big of a buffer we need.
	err = WSAEnumProtocols(NULL, NULL, &dwBufferSize);
	if (err != SOCKET_ERROR && WSAGetLastError() != WSAENOBUFS) 
	{
		OutputDebugString(_T("WSAEnumProtocols is broken\n"));
		goto Error;
	}
	// Allocate a buffer, call WSAEnumProtocols to get an array of WSAPROTOCOL_INFO structs.
	m_pProtocolsInfo = (LPWSAPROTOCOL_INFO)malloc(dwBufferSize);
	if (m_pProtocolsInfo == NULL) 
	{
		OutputDebugString(_T("malloc m_pProtocolsInfo failed\n"));
		goto Error;
	}
	err = WSAEnumProtocols(NULL, m_pProtocolsInfo, &dwBufferSize);
	if (err == SOCKET_ERROR) 
	{
		OutputDebugString(_T("WSAEnumProtocols failed\n"));
		goto Error;
    }

	for (i = 0; i < err; i ++) 
	{
		m_pTcpInfo = &m_pProtocolsInfo[i];
		ASSERT(m_pTcpInfo != NULL);
		if (m_pTcpInfo->iAddressFamily == AF_INET
			&& m_pTcpInfo->iProtocol == IPPROTO_TCP
			&& m_pTcpInfo->iSocketType == SOCK_STREAM
			&& m_pTcpInfo->iMaxSockAddr == 0x10) 
		{
			bFoundTcp = TRUE;
			break;
		}
//		OutputDebugString(m_pTcpInfo->szProtocol);
//		OutputDebugString(_T("\n");
	}

	if (!bFoundTcp)		goto Error;

	OutputDebugString(_T("WinSock2 Init\n"));
	return TRUE;

Error:
	Shutdown();
	return FALSE;
}