Click here to Skip to main content
15,895,709 members
Articles / Programming Languages / VBScript

ProSysLib: Dissecting the Process

Rate me:
Please Sign up or sign in to vote.
4.84/5 (69 votes)
22 Nov 2010CPOL12 min read 129.1K   2.6K   174  
Access detailed information about the current process the easiest way.
// PSLIPv6.cpp : Implementation of CPSLIPv6

#include "stdafx.h"
#include "PSLIPv6.h"

CPSLIPv6::CPSLIPv6()
{
	::memset(m_uAddr, 0, sizeof(m_uAddr));
	m_uPort = 0;
	m_uPrefix = 0;
	m_Format = ip6Default;
}

HRESULT CPSLIPv6::FinalConstruct()
{
	return S_OK;
}

void CPSLIPv6::FinalRelease()
{
}

/*
Formats;

with prefix: x:x:x:x:x:x:x:x/prefix
with port: [x:x:x:x:x:x:x:x]:port
with time zone: x:x:x:x:x:x:x:x%zone

with everything: [x:x:x:x:x:x:x:x%zone/prefix]:port
which is invalid, by the way :)

*/
_bstr_t CPSLIPv6::GetIPName()
{
	int iCompressIdx = -1;	// Index of the largest zero gap;
	int iMaxGapSize = 0;	// Size of the largest zero gap;

	if(m_Format & ip6Compressed) // If zero-compression is required;
	{
		int iCurrentGapSize = 0;
		for(int i = 0;i < 8;i ++)
		{
			if(m_uAddr[i])
				iCurrentGapSize = 0;
			else
				iCurrentGapSize ++;
			if(iCurrentGapSize > iMaxGapSize)
			{
				iMaxGapSize = iCurrentGapSize;
				iCompressIdx = i - iMaxGapSize + 1;
			}
		}
		// Now we have gap from index iCompressIdx of size iMaxGapSize,
		// or no zero gap at all, if iMaxGapSize is 0 or iCompressIdx is -1;
	}

	TCHAR separator = ':';
	if(m_Format & ip6WebAddress)
		separator = '-';

	// further parsing...

	return _bstr_t("NOT IMPLEMENTED");
}

/*
An empty string is a valid zero address
when passed during object initialization,
i.e. bCreating = true;
*/
bool CPSLIPv6::Initialize(LPCTSTR sIP, bool bCreating)
{
	tstring s(sIP);
	remove_chars(s, SPACES);
	size_t size = s.length();
	if(!size)
	{
		if(bCreating)
		{
			// It is Ok to pass an empty string
			// to create a zero-address object;
			Clear(VARIANT_FALSE);
			return true;
		}
		return false;
	}

	if(size < 2) // 2 is the smallest size of a valid IP address "::";
		return false; // Invalid IP address;

	make_upper(s);

	// Now parse the address here
	// ...

	// NOT IMPLEMENTED YET!

	return true;
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLIPv6::get_A1(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[0];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A1(long newValue)
{
	PSL_BEGIN

	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[0] = (USHORT)newValue;
	
	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A2(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[1];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A2(long newValue)
{
	PSL_BEGIN

	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[1] = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A3(long * pValue)
{
	PSL_BEGIN

	*pValue = m_uAddr[2];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A3(long newValue)
{
	PSL_BEGIN

	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[2] = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A4(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[3];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A4(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[3] = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A5(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[4];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A5(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[4] = (USHORT)newValue;
	
	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A6(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[5];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A6(long newValue)
{
	PSL_BEGIN

	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[5] = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A7(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[6];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A7(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[6] = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_A8(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uAddr[7];

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_A8(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uAddr[7] = (USHORT)newValue;

	PSL_END
}


STDMETHODIMP CPSLIPv6::get_Port(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uPort;

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_Port(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uPort = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_Prefix(long * pValue)
{
	PSL_BEGIN
	
	*pValue = m_uPrefix;

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_Prefix(long newValue)
{
	PSL_BEGIN
	
	if(newValue < 0 || newValue > 0xFFFF)
		return MakeException(exInvalidParameter);

	m_uPrefix = (USHORT)newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_Text(BSTR * pValue)
{
	PSL_BEGIN
	
	*pValue = GetIPName().copy();

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_Text(BSTR newValue)
{
	PSL_BEGIN

	if(!newValue)
		return MakeException(exInvalidParameter);

	if(!Initialize(_bstr_t(newValue), false))
		SetException(exInvalidParameter);

	PSL_END
}

STDMETHODIMP CPSLIPv6::get_Format(PSLIPv6Format * pValue)
{
	PSL_BEGIN
	
	*pValue = m_Format;

	PSL_END
}

STDMETHODIMP CPSLIPv6::put_Format(PSLIPv6Format newValue)
{
	PSL_BEGIN
	
	m_Format = newValue;

	PSL_END
}

STDMETHODIMP CPSLIPv6::Clear(VARIANT_BOOL bClearFormat)
{
	PSL_BEGIN
	
	::memset(m_uAddr, 0, sizeof(m_uAddr));
	m_uPort = 0;
	m_uPrefix = 0;
	if(bClearFormat)
		m_Format = ip6Default;

	PSL_END
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Sibedge IT
Ireland Ireland
My online CV: cv.vitalytomilov.com

Comments and Discussions