Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

DNS Resolver RFC 1035

, 14 Aug 2004
DNS resolving by RFC 1035; complete library for all versions of Windows.
akashkavadnsresolver_demo.zip
DnsClient.exe
akashkavadnsresolver_src.zip
DnsClient.dsw
DnsClient.clw
DnsClient.dsp
#if (!defined(__NEURO__BYTES__BUFFER__))
#define __NEURO__BYTES__BUFFER__

/************************************************************************
		 
		 Name   : CNeuroBuffer
		 Type   : Class
------------------------------------------------------------------------
		 Author : Akash Kava
		 Purpose: Bytes Buffer to store, allocate, reallocate etc.
		          Append etc
************************************************************************/

class CNeuroBuffer{
protected:

	BYTE *	m_pBuffer;
	int		m_nAllocatedSize;
	int		m_nSize;
	int		m_nGrowBy;
	int		m_nPointer;

	void UnsafeClear()
	{
		m_pBuffer = NULL;
		m_nAllocatedSize = 0;
		m_nSize = 0;
		m_nGrowBy = 64;
		m_nPointer = 0;
	}

public:

	CNeuroBuffer()
	{
		UnsafeClear();
	}

	CNeuroBuffer(BYTE * pBuffer,int nSize)
	{
		UnsafeClear();
		Allocate(nSize);
		Copy(pBuffer,nSize);
	}

	int GetSize()
	{
		return m_nSize;
	}

	BYTE * GetBuffer()
	{
		return m_pBuffer;
	}

	BYTE * GetBufferSetLength(int nSize)
	{
		UnsafeClear();
		Allocate(nSize);
		m_nSize = nSize;
		return m_pBuffer;
	}

	CNeuroBuffer(CNeuroBuffer & Buffer)
	{
		UnsafeClear();
		Allocate(Buffer.GetSize());
		Copy(Buffer.GetBuffer(),Buffer.GetSize());
	}

	virtual ~CNeuroBuffer()
	{
		Clear();
	}

	BOOL Allocate(int nSize)
	{
		int nAllocatedSize = ((nSize / m_nGrowBy) + 1)*m_nGrowBy;

		void * pBuffer = new BYTE [nAllocatedSize];

		if(!pBuffer)
			return false;
		
		if(m_nAllocatedSize)
		{
			memcpy(pBuffer,m_pBuffer,m_nAllocatedSize);
			delete m_pBuffer;
		}

		m_pBuffer = (BYTE *)pBuffer;
		m_nAllocatedSize = nAllocatedSize;
		return true;
	}

	BOOL Append(BYTE * pBuffer,int nSize)
	{
		if(m_nSize + nSize > m_nAllocatedSize)
		{
			if(!Allocate(m_nSize + nSize))
				return false;
		}
		memcpy((m_pBuffer + m_nSize),pBuffer,nSize);
		m_nSize += nSize;
		return true;
	}

	int Copy(BYTE * pBuffer,int nSize)
	{
		int nSizeCopied = m_nAllocatedSize > nSize ? nSize : m_nAllocatedSize;
		memcpy(m_pBuffer,pBuffer,nSizeCopied);
		m_nSize = nSizeCopied;
		return nSizeCopied;
	}

	void Clear()
	{
		if(m_nAllocatedSize)
			delete m_pBuffer;
		UnsafeClear();
	}

	void operator = (CNeuroBuffer & Buffer)
	{
		//UnsafeClear();
		Clear();
		Allocate(Buffer.GetSize());
		Copy(Buffer.GetBuffer(),Buffer.GetSize());
	}

	void operator += (CNeuroBuffer & Buffer)
	{
		Append(Buffer.GetBuffer(),Buffer.GetSize());
	}

	CString Detach()
	{
		CString Data = (LPCTSTR)m_pBuffer;
		Clear();
		return Data;
	}
};









#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Akash Kava
Web Developer
United States United States
Programmer with WILL

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150327.1 | Last Updated 15 Aug 2004
Article Copyright 2004 by Akash Kava
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid