// -----------------------------------------------------------------------------
// CSdpOriginField::IsValidAddress
// Checks if the address is valid
// -----------------------------------------------------------------------------
//
TBool CSdpOriginField::IsValidAddress( 
    const TDesC8& aAddress ) const
    {
    TInetAddr addr;
    TBool valid = ETrue;

    if ( aAddress.Length() > 0 && aAddress.Length() <= KMaxAddressLength )
        {
        TBuf<KMaxAddressLength> address16;
        address16.Copy( aAddress );
        TInt err = addr.Input( address16 );

        if ( !err )
            {
            valid = ( addr.IsUnicast() || addr.IsUnspecified() );
            }
        else
            {
            RStringF addrTypeIP4 = 
                iPool.StringF( SdpCodecStringConstants::EAddressTypeIP4,
                               SdpCodecStringConstants::Table );
            RStringF addrTypeIP6 = 
                iPool.StringF( SdpCodecStringConstants::EAddressType,
                               SdpCodecStringConstants::Table );
            
            if ( iAddressType == addrTypeIP4 || iAddressType == addrTypeIP6 )
                {
                // FQDN address, check that it has only valid characters
                // 0..9, a..z, A..Z, '.', '-'
                        
                for ( TInt i( 0 ); i < aAddress.Length() && valid; i++ )
                    {
                    if (KValidFQDNChars().Locate(aAddress[i]) == KErrNotFound)
                        {
                        valid = EFalse;     
                        }
                    }
                }
            else
                {
                valid = SdpUtil::IsNonWhitespace( aAddress );
                }
            }       
        }
    else
    	{
    	valid = EFalse;
    	}

    return valid;
    }
// -----------------------------------------------------------------------------
// CSdpConnectionField::IsValidAddress
// Checks if the given address is valid
// -----------------------------------------------------------------------------
//
TInt CSdpConnectionField::IsValidAddress(
    const TInetAddr& aAddress,
    TInt aTTL,
    TUint aNumOfAddress ) const
    {
    TInt err( KErrSdpCodecConnectionField );
    // 0 <= TTL <= 255 or KErrNotFound if not defined
    // Number of addresses > 0
    if ( ( aTTL == KErrNotFound || ( aTTL >= 0 && aTTL <= 255 ) ) &&
           aNumOfAddress > 0 )
        {
        TBuf16 <KMaxAddressLength> output;
        aAddress.Output(output);

        // Address has to be either of type IP4 or IP6
        // If IP4 and multicast then it must contain TTL attribute
        // If IP4 and unicast then it must NOT contain TTL and must have 1 address
        // If IP6 and multicast then it must NOT contain TTL
        // If IP6 and unicast then it must NOT contain TTL and must have 1 address
        if ( ( aAddress.Address() && 
               ( ( aAddress.IsMulticast() && aTTL != KErrNotFound ) ||
                 ( aAddress.IsUnicast() && aTTL == KErrNotFound &&
                   aNumOfAddress == 1 ) ) ) ||
             ( !aAddress.Address() &&
               ( ( aAddress.IsMulticast() && aTTL == KErrNotFound ) ||
                 ( aAddress.IsUnicast() && aTTL == KErrNotFound &&
                   aNumOfAddress == 1 ) )   ||
               ( aAddress.IsWildAddr() && 
               ( output.Match(KWildAddr) == 0||
               	 output.Match(KWildAddrIPv6) == 0 )) ) )
           {
           err = KErrNone;
           }
        }

    return err;
    }