コード例 #1
0
ファイル: Process.cpp プロジェクト: kotene/Pcap_DNSProxy
bool __fastcall DNSCurveRequestProcess(
	const char *OriginalSend, 
	const size_t SendSize, 
	PSTR OriginalRecv, 
	const uint16_t Protocol, 
	const SOCKET_DATA &LocalSocketData)
{
	size_t DataLength = 0;

//TCP requesting
	if (DNSCurveParameter.DNSCurveProtocol_Transport == REQUEST_MODE_TCP || Protocol == IPPROTO_TCP)
	{
	//Multi requesting.
		if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U)
			DataLength = DNSCurveTCPRequestMulti(OriginalSend, SendSize, OriginalRecv, LARGE_PACKET_MAXSIZE);
	//Normal requesting
		else 
			DataLength = DNSCurveTCPRequest(OriginalSend, SendSize, OriginalRecv, LARGE_PACKET_MAXSIZE);

	//Send response.
		if (DataLength >= DNS_PACKET_MINSIZE && DataLength < LARGE_PACKET_MAXSIZE)
		{
			SendToRequester(OriginalRecv, DataLength, Protocol, LocalSocketData);
			return true;
		}
	}

//UDP Mode(REQUEST_MODE_UDP)
	if (Protocol == IPPROTO_TCP) //TCP requesting
		DataLength = LARGE_PACKET_MAXSIZE;
	else //UDP requesting
		DataLength = PACKET_MAXSIZE;

//Multi requesting.
	if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U)
		DataLength = DNSCurveUDPRequestMulti(OriginalSend, SendSize, OriginalRecv, DataLength);
	//Normal requesting
	else 
		DataLength = DNSCurveUDPRequest(OriginalSend, SendSize, OriginalRecv, DataLength);

//Send response.
	if (DataLength >= DNS_PACKET_MINSIZE && (DataLength < PACKET_MAXSIZE || Protocol == IPPROTO_TCP && DataLength < LARGE_PACKET_MAXSIZE))
	{
		SendToRequester(OriginalRecv, DataLength, Protocol, LocalSocketData);
		return true;
	}

	return false;
}
コード例 #2
0
ファイル: Process.cpp プロジェクト: ChaoWing/Pcap_DNSProxy
bool __fastcall DNSCurveRequestProcess(
	const DNS_PACKET_DATA &Packet, 
	char *OriginalRecv, 
	const size_t RecvSize, 
	const SOCKET_DATA &LocalSocketData)
{
	size_t DataLength = 0;
	memset(OriginalRecv, 0, RecvSize);

//EDNS switching(Part 1)
	size_t EDNS_SwitchLength = Packet.Length;
	uint16_t EDNS_Packet_Flags = ((dns_hdr *)(Packet.Buffer))->Flags;
	if (Parameter.EDNS_Label && !Parameter.EDNS_Switch.EDNS_DNSCurve)
	{
	//Reset EDNS flags, resource record counts and packet length.
		((dns_hdr *)(Packet.Buffer))->Flags = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Flags) & (~DNS_GET_BIT_AD));
		((dns_hdr *)(Packet.Buffer))->Flags = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Flags) & (~DNS_GET_BIT_CD));
		if (((dns_hdr *)(Packet.Buffer))->Additional > 0)
			((dns_hdr *)(Packet.Buffer))->Additional = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Additional) - 1U);
		EDNS_SwitchLength -= Packet.EDNS_Record;
	}

//TCP request
	if (DNSCurveParameter.DNSCurveProtocol_Transport == REQUEST_MODE_TCP || Packet.Protocol == IPPROTO_TCP)
	{
	//Multi request process
		if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U)
			DataLength = DNSCurveTCPRequestMulti(Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize);
	//Normal request process
		else 
			DataLength = DNSCurveTCPRequest(Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize);

	//Send response.
		if (DataLength >= DNS_PACKET_MINSIZE && DataLength < RecvSize)
		{
			SendToRequester(OriginalRecv, DataLength, RecvSize, Packet.Protocol, LocalSocketData);
			return true;
		}
	}

//UDP request
	if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U) //Multi request process
		DataLength = DNSCurveUDPRequestMulti(Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize);
	else //Normal request process
		DataLength = DNSCurveUDPRequest(Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize);

//Send response.
	if (DataLength >= DNS_PACKET_MINSIZE && DataLength < RecvSize)
	{
		SendToRequester(OriginalRecv, DataLength, RecvSize, Packet.Protocol, LocalSocketData);
		return true;
	}

//EDNS switching(Part 2)
	if (Parameter.EDNS_Label && !Parameter.EDNS_Switch.EDNS_DNSCurve)
	{
		((dns_hdr *)(Packet.Buffer))->Flags = EDNS_Packet_Flags;
		((dns_hdr *)(Packet.Buffer))->Additional = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Additional) + 1U);
	}

	return false;
}