messagingfw/biomsgfw/BIUTSRC/ipaddr.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <ipaddr.h>
       
    17 
       
    18 EXPORT_C CIpAddress* CIpAddress::NewL(const TDesC& aAddr)
       
    19 /** Allocates and constructs a new IP address object with a specified address.
       
    20 
       
    21 A buffer is allocated on the heap and aAddr copied into it.
       
    22 
       
    23 @param aAddr IP address string
       
    24 @return New IP address object */
       
    25 	{
       
    26 	CIpAddress* self = NewLC(aAddr);
       
    27 	CleanupStack::Pop(self);
       
    28 	return self;
       
    29 	}
       
    30 
       
    31 EXPORT_C CIpAddress* CIpAddress::NewLC(const TDesC& aAddr)
       
    32 /** Allocates and constructs a new IP address object with a specified address, 
       
    33 leaving the object on the cleanup stack.
       
    34 
       
    35 A buffer is allocated on the heap and aAddr copied into it.
       
    36 
       
    37 @param aAddr IP address string
       
    38 @return New IP address object */
       
    39 	{
       
    40 	CIpAddress* self = new (ELeave) CIpAddress();
       
    41 	CleanupStack::PushL(self);
       
    42 	self->SetAddrL(aAddr);
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 CIpAddress::CIpAddress()
       
    47 	{
       
    48 	}
       
    49 
       
    50 EXPORT_C CIpAddress::~CIpAddress()
       
    51 /** Destructor. */
       
    52 	{
       
    53 	delete iAddr;
       
    54 	}
       
    55 
       
    56 EXPORT_C void CIpAddress::SetAddrL(const TDesC& aAddr)
       
    57 /** Sets the IP address.
       
    58 
       
    59 A buffer is allocated on the heap and aAddr copied into it.
       
    60 
       
    61 @param aAddr IP address string */
       
    62 	{
       
    63 	HBufC* tempAddr = NULL;
       
    64 	TInetAddr t;
       
    65 	const TInt err = t.Input(aAddr);
       
    66 
       
    67 	if (err == KErrNone)
       
    68 		{
       
    69 		tempAddr = HBufC::NewL(KIpAddressSize);
       
    70 		TPtr buf(tempAddr->Des());
       
    71 		t.Output(buf);
       
    72 		}
       
    73 	else
       
    74 		tempAddr = aAddr.AllocL();
       
    75 
       
    76 	delete iAddr;
       
    77 	iAddr = tempAddr;
       
    78 	}
       
    79 
       
    80 EXPORT_C const TDesC& CIpAddress::Addr() const
       
    81 /** Gets the IP address.
       
    82 
       
    83 @return IP address string */
       
    84 	{
       
    85 	return *iAddr;
       
    86 	}