tcpiputils/dnd/Test/te_dnssuffix/src/te_dnssuffixtestwrapper.cpp
branchRCL_3
changeset 75 c1029e558ef5
parent 67 bb2423252ea3
child 76 27c54f8619d4
equal deleted inserted replaced
67:bb2423252ea3 75:c1029e558ef5
     1 // Copyright (c) 2010 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 // Contains the implementation of all the commands, which is used by the script file.
       
    15 //
       
    16 
       
    17 /**
       
    18  @file
       
    19  @internalTechnology
       
    20  */
       
    21 
       
    22 #include "te_dnssuffixtestwrapper.h"
       
    23 #include "DNSSuffixHostResolver.h"
       
    24 
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <in_sock.h>
       
    28 #include <es_sock.h>
       
    29 #include <commdbconnpref.h>
       
    30 #include <commdb.h>
       
    31 
       
    32 /*
       
    33  * TODO: 1. Try to test with end to end real scenario. Means resolving over real tunnel.
       
    34  * 
       
    35  * 
       
    36  */
       
    37 #define KIPAddrLen 39
       
    38 
       
    39 // Used for handle the multiple hosts in same test cases. @See TC006
       
    40 #define KMaxHosts 8
       
    41 
       
    42 // Commands
       
    43 _LIT(KInitDNSSuffixTesting, "InitDNSSuffixTesting");
       
    44 _LIT(KEnumerateInterface,   "EnumerateInterface");
       
    45 _LIT(KSetAndGetSuffixList,  "SetAndGetSuffixList");
       
    46 _LIT(KDoResolve,            "DoResolve");
       
    47 _LIT(KDoResolveHostWithoutDomainWithSuffix,     "DoResolveHostWithoutDomainWithSuffix");
       
    48 _LIT(KDoResolveHostWithoutDomainWithoutSuffix,  "DoResolveHostWithoutDomainWithoutSuffix");
       
    49 
       
    50 _LIT(KDNSSuffixSupportTC005,    "DNSSuffixSupportTC005");
       
    51 _LIT(KDNSSuffixSupportTC006,    "DNSSuffixSupportTC006");
       
    52 _LIT(KDNSSuffixSupportTC007,    "DNSSuffixSupportTC007");
       
    53 _LIT(KDNSSuffixSupportTC008,    "DNSSuffixSupportTC008");
       
    54 _LIT(KDNSSuffixSupportTC009,    "DNSSuffixSupportTC009");
       
    55 _LIT(KDNSSuffixSupportTC010,    "DNSSuffixSupportTC010");
       
    56 _LIT(KDNSSuffixSupportTC011,    "DNSSuffixSupportTC011");
       
    57 
       
    58 
       
    59 //Test code
       
    60 _LIT(KCommand, 			    "aCommand = %S");
       
    61 _LIT(KSection, 			    "aSection = %S");
       
    62 _LIT(KAsyncErrorIndex, 	    "aAsyncErrorIndex = %D");
       
    63 
       
    64 _LIT(KKeyDNSSuffixTestSuffixList,   "suffixlist");
       
    65 _LIT(KKeyDNSSuffixTestSuffixList1,   "suffixlist1");
       
    66 _LIT(KKeyDNSSuffixTestSuffixList2,   "suffixlist2");
       
    67 _LIT(KKeyDNSSuffixTestSuffixList3,   "suffixlist3");
       
    68 
       
    69 _LIT(KKeyDNSSuffixTestHostname,     "hostname");
       
    70 
       
    71 _LIT(KSectionDNSSuffixTest001,      "dnssuffix_test001");
       
    72 _LIT(KSectionDNSSuffixTest002,      "dnssuffix_test002");
       
    73 _LIT(KSectionDNSSuffixTest003,      "dnssuffix_test003");
       
    74 _LIT(KSectionDNSSuffixTest004,      "dnssuffix_test004");
       
    75 _LIT(KSectionDNSSuffixTest005,      "dnssuffix_test005");
       
    76 
       
    77 _LIT(KSectionDNSSuffixTest006,          "dnssuffix_test006");
       
    78 _LIT(KKeyDNSSuffixTest006NoOfHostname,  "noofhosts");
       
    79 _LIT(KKeyDNSSuffixTest006Hostname,      "hostname%D");
       
    80 
       
    81 _LIT(KSectionDNSSuffixTest007,              "dnssuffix_test007");
       
    82 _LIT(KKeyDNSSuffixTest007ValidHostname,     "validhostname");
       
    83 _LIT(KKeyDNSSuffixTest007InValidHostname,   "invalidhostname");
       
    84 
       
    85 _LIT(KSectionDNSSuffixTest008,      "dnssuffix_test008");
       
    86 _LIT(KKeyDNSSuffixTestHostname1,    "hostname1");
       
    87 _LIT(KKeyDNSSuffixTestHostname2,    "hostname2");
       
    88 
       
    89 _LIT(KSectionDNSSuffixTest009,      "dnssuffix_test009");
       
    90 
       
    91 _LIT(KSectionDNSSuffixTest010,      "dnssuffix_test010");
       
    92 
       
    93 _LIT(KSectionDNSSuffixTest011,      "dnssuffix_test011");
       
    94 
       
    95 _LIT(KSectionDNSSuffixFirstInterface, "dnssuffix_first_interface");
       
    96 _LIT(KSectionDNSSuffixSecondInterface, "dnssuffix_second_interface");
       
    97 _LIT(KKeyDNSSuffixIAPId,"iapid");
       
    98 _LIT(KKeyInterfaceName,                "interfacename");
       
    99 
       
   100 /*
       
   101  * @author: Santosh K Patil
       
   102  * TODO: Needs to verify the interfaces used to resolve the hosts in each test case.
       
   103  * It is required to verify wheather test executed as desired or not. 
       
   104  * In other words to confirm the new solution is working as expected we need to get 
       
   105  * and verify the inteface name used to resolve the host.
       
   106  * @See Test spec for more details.
       
   107  * 
       
   108  * TODO: Check all config sections
       
   109  */
       
   110 
       
   111 
       
   112 /**
       
   113 Constructor.
       
   114 
       
   115 @internalTechnology
       
   116  */
       
   117 CDNSSuffixTestWrapper::CDNSSuffixTestWrapper()
       
   118     {
       
   119     }
       
   120 
       
   121 /**
       
   122 Destructor.
       
   123 
       
   124 @internalTechnology
       
   125  */
       
   126 CDNSSuffixTestWrapper::~CDNSSuffixTestWrapper()
       
   127     {  
       
   128     
       
   129     }
       
   130 
       
   131 /**
       
   132 Function to instantiate TestWrapper.
       
   133 @return Returns constructed TestWrapper instance pointer
       
   134 @internalTechnology
       
   135  */
       
   136 CDNSSuffixTestWrapper* CDNSSuffixTestWrapper::NewL()
       
   137     {
       
   138     CDNSSuffixTestWrapper*	ret = new (ELeave) CDNSSuffixTestWrapper();
       
   139     CleanupStack::PushL(ret);
       
   140     ret->ConstructL();
       
   141     CleanupStack::Pop(ret);
       
   142     return ret;	
       
   143     }
       
   144 
       
   145 /**
       
   146 Second level constructor, constructs TestWrapper instance.
       
   147 @internalTechnology
       
   148  */
       
   149 void CDNSSuffixTestWrapper::ConstructL()
       
   150     {    
       
   151     }
       
   152 
       
   153 
       
   154 /*
       
   155  * @HandleCallBackL Called by the CDNSSuffixHostResolver::RunL
       
   156  * 
       
   157  */
       
   158 void CDNSSuffixTestWrapper::HandleCallBackL(TInt aError)
       
   159     {
       
   160     INFO_PRINTF1(_L("HandleCallBackL - Entry"));    
       
   161     INFO_PRINTF2(_L("Error code: %D"),aError);
       
   162     
       
   163     if (KErrNone != aError)
       
   164         SetError(KErrNone);
       
   165     else
       
   166         SetError(KErrGeneral);
       
   167     
       
   168     if (iWait.IsStarted())
       
   169         {
       
   170         INFO_PRINTF1(_L("Stoping waiter"));
       
   171         iWait.AsyncStop();
       
   172         }
       
   173     INFO_PRINTF1(_L("HandleCallBackL - Exit"));
       
   174     }
       
   175 
       
   176 /**
       
   177 Function to map the input command to respective function.
       
   178 
       
   179 @return - True Upon successfull command to Function name mapping otherwise False
       
   180 @param aCommand Function name has to be called
       
   181 @param aSection INI file paramenter section name
       
   182 @param aAsyncErrorIndex Error index
       
   183 @see Refer the script file COMMAND section.
       
   184 
       
   185 @internalTechnology
       
   186  */
       
   187 TBool CDNSSuffixTestWrapper::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   188     {
       
   189     TBool ret = ETrue;
       
   190 
       
   191     // Print out the parameters for debugging
       
   192     INFO_PRINTF2( KCommand, &aCommand );
       
   193     INFO_PRINTF2( KSection, &aSection );
       
   194     INFO_PRINTF2( KAsyncErrorIndex, aAsyncErrorIndex );
       
   195     
       
   196     if(KInitDNSSuffixTesting() == aCommand)
       
   197         {
       
   198         DoInitTestingL();
       
   199         }
       
   200     else if(KEnumerateInterface() == aCommand)
       
   201         {
       
   202         DoEnumerateInterfacesL();
       
   203         }
       
   204     else if (KSetAndGetSuffixList() == aCommand)
       
   205         {
       
   206         DoSetAndGetSuffixListL();
       
   207         }
       
   208     else if( KDoResolve() == aCommand)
       
   209         {
       
   210         DoResolveL();
       
   211         }
       
   212     else if( KDoResolveHostWithoutDomainWithSuffix() == aCommand)
       
   213         {
       
   214         DoResolveHostWithoutDomainWithSuffixListSetL();
       
   215         }    
       
   216     else if( KDoResolveHostWithoutDomainWithoutSuffix() == aCommand)
       
   217         {
       
   218         DoResolveHostWithoutDomainWithoutSuffixListL();
       
   219         }
       
   220     else if( KDNSSuffixSupportTC005() == aCommand)
       
   221         {
       
   222         DNSSuffixSupportTC005L();
       
   223         }
       
   224     else if( KDNSSuffixSupportTC006() == aCommand)
       
   225         {
       
   226         DNSSuffixSupportTC006L();
       
   227         }
       
   228     else if( KDNSSuffixSupportTC007() == aCommand)
       
   229         {
       
   230         DNSSuffixSupportTC007L();
       
   231         }
       
   232     else if( KDNSSuffixSupportTC008() == aCommand)
       
   233         {
       
   234         DNSSuffixSupportTC008L();
       
   235         }
       
   236     else if( KDNSSuffixSupportTC009() == aCommand)
       
   237         {
       
   238         DNSSuffixSupportTC009L();
       
   239         }
       
   240     else if( KDNSSuffixSupportTC010() == aCommand)
       
   241        {
       
   242        DNSSuffixSupportTC010L();
       
   243        }
       
   244     else if( KDNSSuffixSupportTC011() == aCommand)
       
   245        {
       
   246        DNSSuffixSupportTC011L();
       
   247        }    
       
   248     else
       
   249         {        
       
   250         ret = EFalse;
       
   251         User::LeaveIfError(KErrNone); // just to suppress LeaveScan warning
       
   252         }
       
   253     
       
   254     return ret;
       
   255     }
       
   256 
       
   257 
       
   258 TInt CDNSSuffixTestWrapper::StartConnections(RSocketServ& aSockServ, RConnection& aConn1, RConnection& aConn2)
       
   259     {
       
   260     INFO_PRINTF1(_L("StartConnections - Entry"));
       
   261     
       
   262     TUint iapId = GetFirstIapId();
       
   263     
       
   264     if ((TInt)iapId == KErrNotFound)
       
   265         return KErrNotFound;
       
   266     
       
   267     TInt err = StartConnection(aSockServ,aConn1,iapId);
       
   268         
       
   269     if (err != KErrNone)
       
   270         {
       
   271         ERR_PRINTF1(_L("Failed to start first connection"));
       
   272         SetError(err);
       
   273         return err;
       
   274         }
       
   275         
       
   276     INFO_PRINTF2(_L("First connection started successfully - IAP: %D"),iapId);        
       
   277         
       
   278     iapId = GetSecondIapId();
       
   279              
       
   280     if ((TInt)iapId == KErrNotFound)
       
   281         {       
       
   282         aConn1.Close();
       
   283         return KErrNotFound;
       
   284         }
       
   285         
       
   286     err = StartConnection(iSocketServ,aConn2,iapId);
       
   287         
       
   288     if (err != KErrNone)
       
   289         {
       
   290         ERR_PRINTF1(_L("Failed to start second connection"));
       
   291         aConn1.Close();
       
   292         return err;
       
   293         }
       
   294         
       
   295     INFO_PRINTF2(_L("Second connection started successfully - IAP: %D"),iapId);        
       
   296             
       
   297     INFO_PRINTF1(_L("StartConnections - Exit"));
       
   298     return KErrNone;
       
   299     }
       
   300 
       
   301 
       
   302 
       
   303 TInt CDNSSuffixTestWrapper::StartConnection(RSocketServ& aSockServ, RConnection& aConn, TUint aIapId)
       
   304     {
       
   305     INFO_PRINTF1(_L("StartConnection - Entry"));
       
   306     
       
   307     TInt err(KErrNone);
       
   308     
       
   309     TCommDbConnPref connPref;
       
   310     INFO_PRINTF1(_L("Getting conn preference"));
       
   311     
       
   312     TRAP(err, GetConnPrefL(aIapId,connPref));
       
   313     
       
   314     if (KErrNone != err)
       
   315         {
       
   316         ERR_PRINTF1(_L("Failed to read conn preference"));
       
   317         return err;
       
   318         }
       
   319     
       
   320     INFO_PRINTF1(_L("Got conn preference"));
       
   321     
       
   322     if((err = aConn.Open(aSockServ, KAfInet)) != KErrNone )
       
   323         {
       
   324         ERR_PRINTF2(_L("Failed to open Connection: %D"),err);
       
   325         return err;
       
   326         }
       
   327         
       
   328     INFO_PRINTF1(_L("Connection opened"));
       
   329     
       
   330     INFO_PRINTF1(_L("Starting Connection"));
       
   331     err = aConn.Start(connPref);
       
   332     
       
   333     if (KErrNone != err)
       
   334         {
       
   335         ERR_PRINTF2(_L("Failed starting Connection: %D"),err);
       
   336         aConn.Close();
       
   337         return err;
       
   338         }
       
   339     
       
   340     INFO_PRINTF1(_L("Connection Started"));
       
   341     
       
   342     INFO_PRINTF1(_L("StartConnection - Exit"));
       
   343     
       
   344     return KErrNone;    
       
   345     }
       
   346 
       
   347    
       
   348 
       
   349 void CDNSSuffixTestWrapper::GetConnPrefL(TUint aIapId,TCommDbConnPref& aPref)
       
   350     {
       
   351     INFO_PRINTF1(_L("GetConnPrefL - Entry"));
       
   352     
       
   353     INFO_PRINTF1(_L("Instantiating CCommsDatabase"));
       
   354     CCommsDatabase* commsDb = CCommsDatabase::NewL();
       
   355     CleanupStack::PushL(commsDb);
       
   356     
       
   357     INFO_PRINTF1(_L("Calling OpenConnectionPrefTableLC"));
       
   358     CCommsDbConnectionPrefTableView* commsDbView = commsDb->OpenConnectionPrefTableLC();
       
   359     
       
   360     INFO_PRINTF1(_L("Going to first record"));
       
   361     User::LeaveIfError(commsDbView->GotoFirstRecord());
       
   362     
       
   363     TInt isFound(KErrNotFound);
       
   364     do
       
   365         {
       
   366         CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
       
   367         INFO_PRINTF1(_L("Reading conn preferecne."));
       
   368         commsDbView->ReadConnectionPreferenceL(pref);
       
   369         
       
   370         if (pref.iBearer.iIapId == aIapId)
       
   371             {
       
   372             INFO_PRINTF1(_L("Match found"));
       
   373             aPref.SetIapId(aIapId);
       
   374             aPref.SetBearerSet(pref.iBearer.iBearerSet);
       
   375             aPref.SetDirection(pref.iDirection);
       
   376             aPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   377             isFound = KErrNone;
       
   378             break;
       
   379             }
       
   380         } while(!commsDbView->GotoNextRecord());    
       
   381     
       
   382     INFO_PRINTF1(_L("Cleanup resources"));
       
   383     CleanupStack::PopAndDestroy(2, commsDb); // commsDbView, commsDb
       
   384     
       
   385     User::LeaveIfError(isFound);
       
   386     
       
   387     INFO_PRINTF1(_L("GetConnPrefL - Exit"));    
       
   388     }
       
   389 
       
   390 
       
   391 
       
   392 TInt32 CDNSSuffixTestWrapper::GetFirstIapId()
       
   393     {
       
   394     INFO_PRINTF1(_L("GetFirstIapId - Entry"));
       
   395     
       
   396     TInt iapId(KErrNotFound);
       
   397     
       
   398     if (!GetIntFromConfig(KSectionDNSSuffixFirstInterface,KKeyDNSSuffixIAPId,iapId))
       
   399          {
       
   400          ERR_PRINTF1(_L("Failed to read the First IAP id"));
       
   401          }
       
   402       else
       
   403          {
       
   404          INFO_PRINTF2(_L("Got the IAP: %D"),iapId);
       
   405          }
       
   406     
       
   407     INFO_PRINTF1(_L("GetFirstIapId - Exit"));
       
   408     return iapId;
       
   409     }
       
   410 
       
   411 
       
   412 TInt32 CDNSSuffixTestWrapper::GetSecondIapId()
       
   413    {
       
   414    INFO_PRINTF1(_L("GetSecondIapId - Entry"));
       
   415    
       
   416    TInt iapId(KErrNotFound);
       
   417    
       
   418    if (!GetIntFromConfig(KSectionDNSSuffixSecondInterface,KKeyDNSSuffixIAPId,iapId))
       
   419         {
       
   420         ERR_PRINTF1(_L("Failed to read second IAP id"));
       
   421         }
       
   422      else
       
   423         {
       
   424         INFO_PRINTF2(_L("Got the IAP: %D"),iapId);
       
   425         }
       
   426    
       
   427    INFO_PRINTF1(_L("GetSecondIapId - Exit"));
       
   428    return iapId;
       
   429    }
       
   430  
       
   431 
       
   432 TInt CDNSSuffixTestWrapper::GetFirstInterfaceNameL(TDes& aIfaceName)
       
   433     {
       
   434     INFO_PRINTF1(_L("GetFirstInterfaceNameL - Entry"));
       
   435     TInt err(KErrNone);    
       
   436     
       
   437     TPtrC interfaceName;
       
   438     if (!GetStringFromConfig(KSectionDNSSuffixFirstInterface,KKeyInterfaceName,interfaceName))
       
   439         {
       
   440         ERR_PRINTF1(_L("Failed to read the interface name from config"));
       
   441         err = KErrNotFound;
       
   442         SetError(err);
       
   443         return err;
       
   444         }
       
   445         
       
   446     err = GetInterfaceNameL(interfaceName,aIfaceName);
       
   447     
       
   448     INFO_PRINTF1(_L("GetFirstInterfaceNameL - Exit"));
       
   449     return err;
       
   450     }
       
   451     
       
   452 
       
   453 TInt CDNSSuffixTestWrapper::GetSecondInterfaceNameL(TDes& aIfaceName)
       
   454     {    
       
   455     INFO_PRINTF1(_L("GetSecondInterfaceNameL - Entry"));
       
   456     TInt err(KErrNone);    
       
   457     
       
   458     TPtrC interfaceName;
       
   459     if (!GetStringFromConfig(KSectionDNSSuffixSecondInterface,KKeyInterfaceName,interfaceName))
       
   460         {
       
   461         ERR_PRINTF1(_L("Failed to read the interface name from config"));
       
   462         err = KErrNotFound;
       
   463         SetError(err);
       
   464         return err;
       
   465         }    
       
   466     
       
   467     err = GetInterfaceNameL(interfaceName,aIfaceName);
       
   468     
       
   469     INFO_PRINTF1(_L("GetSecondInterfaceNameL - Exit"));
       
   470     return err;    
       
   471     }
       
   472 
       
   473     
       
   474 TInt CDNSSuffixTestWrapper::GetInterfaceNameL(const TDesC& aCriteria,TDes& aIfaceName)
       
   475     {
       
   476     INFO_PRINTF1(_L("GetInterfaceNameL - Entry"));
       
   477 
       
   478     TInt err = KErrNone;
       
   479     CDesCArray* interfaceNameArray = new(ELeave) CDesCArrayFlat(4);
       
   480     CleanupStack::PushL(interfaceNameArray);
       
   481     TRAP(err,GetAvaiableInterfacesL(interfaceNameArray));
       
   482     
       
   483     if (KErrNone != err)
       
   484         {       
       
   485         ERR_PRINTF2(_L("Failed to enumeate the interfaces with error: %D"),err);
       
   486         return err;
       
   487         }
       
   488     
       
   489     INFO_PRINTF2(_L("No of interfaces: %D"),interfaceNameArray->Count());
       
   490     
       
   491     if (interfaceNameArray->Count() <= 0)
       
   492        {
       
   493        INFO_PRINTF1(_L("No interfaces available:"));
       
   494        CleanupStack::PopAndDestroy(interfaceNameArray);
       
   495        err = KErrNotFound;
       
   496        SetError(err);
       
   497        return err;
       
   498        }
       
   499     
       
   500     TBool isInterfaceFound(EFalse);
       
   501     TInt index = -1;
       
   502    
       
   503     for (TInt a=0; a<interfaceNameArray->Count();a++)
       
   504        {
       
   505        HBufC* interfaceNameBuf = (*interfaceNameArray)[a].AllocL();
       
   506        
       
   507        TInt pos = interfaceNameBuf->FindF(aCriteria);
       
   508        
       
   509        delete interfaceNameBuf;
       
   510        
       
   511        if ( KErrNotFound != pos)
       
   512            {
       
   513            isInterfaceFound = ETrue;
       
   514            index = a;
       
   515            break;
       
   516            }
       
   517        }
       
   518     
       
   519     if (!isInterfaceFound)
       
   520         {
       
   521         ERR_PRINTF1(_L("Interface not found"));
       
   522         CleanupStack::PopAndDestroy(interfaceNameArray);
       
   523         err = KErrNotFound;
       
   524         SetError(err);
       
   525         return err;
       
   526         }    
       
   527     
       
   528     aIfaceName.Copy((*interfaceNameArray)[index]);
       
   529     
       
   530     CleanupStack::PopAndDestroy(interfaceNameArray);
       
   531     
       
   532     TPtr tempName((TUint16*)aIfaceName.Ptr(),aIfaceName.Length(),aIfaceName.Length());
       
   533     INFO_PRINTF2(_L("Found Interface and name is: %S"),&tempName);
       
   534     
       
   535     INFO_PRINTF1(_L("GetInterfaceNameL - Exit"));
       
   536     return KErrNone;
       
   537     }
       
   538 
       
   539 /**
       
   540  * DoInitTestingL. Configures the initial connections. 
       
   541  * Function to start the connection to configure the named server on one interface. 
       
   542  */
       
   543 void CDNSSuffixTestWrapper::DoInitTestingL()
       
   544     {
       
   545     INFO_PRINTF1(_L("********************************************"));
       
   546     INFO_PRINTF1(_L("DoInitTestingL"));
       
   547     INFO_PRINTF1(_L("********************************************"));
       
   548 
       
   549     /*@Note, We need to configure the named servers on vTunnel and ethernet interfaces.
       
   550      * So, Configuring them by starting connections on both interfaces. 
       
   551      * 
       
   552      */
       
   553     TInt err = KErrNone;
       
   554     
       
   555     if((err = iSocketServ.Connect()) == KErrNone )
       
   556         INFO_PRINTF1(_L("Socket Server Opened."));
       
   557     else
       
   558         {
       
   559         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), err);
       
   560         SetError(err);
       
   561         return;
       
   562         }
       
   563     
       
   564     ERR_PRINTF2(_L("Error Opening Socket Server: %d"), err);
       
   565     
       
   566     RConnection firstConn; 
       
   567     RConnection vTunConn; // Usef for virtual Tunnel interface
       
   568     
       
   569     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
   570     
       
   571     if (KErrNone != err)
       
   572         {
       
   573         ERR_PRINTF2(_L("Failed to start the Connections: %D"),err);
       
   574         CloseSocketSrv();
       
   575         SetError(err);
       
   576         return;
       
   577         }
       
   578     INFO_PRINTF1(_L("Started the connections successfully"));
       
   579     
       
   580     INFO_PRINTF1(_L("Close the connections"));
       
   581    
       
   582     if (vTunConn.SubSessionHandle())
       
   583         vTunConn.Close();
       
   584 
       
   585     if (firstConn.SubSessionHandle())
       
   586         firstConn.Close();
       
   587     
       
   588     SetError(err);      
       
   589     CloseSocketSrv();    
       
   590     }
       
   591 
       
   592 /**
       
   593  * @DoEnumerateInterfacesL. Enumerates the all available interfaces.
       
   594  */
       
   595 void CDNSSuffixTestWrapper::DoEnumerateInterfacesL()
       
   596     {
       
   597     INFO_PRINTF1(_L("********************************************"));
       
   598     INFO_PRINTF1(_L("DoEnumerateInterfacesL"));
       
   599     INFO_PRINTF1(_L("********************************************"));
       
   600     
       
   601     CDesCArray* interfaceNameArray = new(ELeave) CDesCArrayFlat(4);
       
   602     CleanupStack::PushL(interfaceNameArray);
       
   603     TRAPD(err,GetAvaiableInterfacesL(interfaceNameArray));
       
   604    
       
   605     if (KErrNone == err)
       
   606         {
       
   607         // Print the interface names        
       
   608         INFO_PRINTF2(_L("Found %D interfaces"),interfaceNameArray->Count());
       
   609         
       
   610         for(TInt a=0;a<interfaceNameArray->Count();a++)
       
   611             {
       
   612             TPtrC interfaceName = (*interfaceNameArray)[a];
       
   613             INFO_PRINTF2(_L("Interface: %S"),&interfaceName);
       
   614             }
       
   615         }
       
   616     else
       
   617         {
       
   618         ERR_PRINTF2(_L("Failed to enumeate the interfaces with error: %D"),err);
       
   619         }
       
   620     
       
   621     CleanupStack::PopAndDestroy(interfaceNameArray);
       
   622     
       
   623     SetError(err);
       
   624     }
       
   625 
       
   626 /*
       
   627  * GetAvaiableInterfacesL. Function to get the names of all available names of  all interfaces.
       
   628  * @arg aInterfaceNamesArray (out param), Array of interface names owned by caller. 
       
   629  */
       
   630 void CDNSSuffixTestWrapper::GetAvaiableInterfacesL(MDesCArray* aInterfaceNamesArray)
       
   631     {
       
   632     INFO_PRINTF1(_L("GetAvaiableInterfacesL - Entry"));
       
   633     
       
   634     CDesCArray* interfacesArray = static_cast<CDesCArray*>(aInterfaceNamesArray);
       
   635     interfacesArray->Reset();
       
   636     
       
   637     TInt err = KErrNone;
       
   638     RSocketServ socketSrv;
       
   639     
       
   640     if ( (err = socketSrv.Connect()) != KErrNone)
       
   641         {
       
   642         ERR_PRINTF2(_L("Failed Connecting to Socet server error: %D"),err);
       
   643         SetError(err);
       
   644         return;
       
   645         }
       
   646     INFO_PRINTF1( _L("Connected to Socket server"));
       
   647     
       
   648     INFO_PRINTF1(_L("Opening socket..."));
       
   649     
       
   650     RSocket socket;
       
   651     err = socket.Open(socketSrv,KAfInet, KSockDatagram, KProtocolInetUdp);
       
   652     
       
   653     if (KErrNone != err)
       
   654         {
       
   655         INFO_PRINTF2(_L("Failed Opening socket with error: %D"),err);
       
   656         SetError(err);
       
   657         socketSrv.Close();
       
   658         return;
       
   659         }
       
   660     
       
   661     INFO_PRINTF1(_L("Socket opened"));
       
   662     
       
   663     err = socket.SetOpt(KSoInetEnumInterfaces,KSolInetIfCtrl);
       
   664   
       
   665     if (KErrNone != err)
       
   666         {
       
   667         INFO_PRINTF2(_L("Failed enumerating interfaces with error: %D"),err);
       
   668         SetError(err);
       
   669         socket.Close();
       
   670         socketSrv.Close();
       
   671         return;
       
   672         }
       
   673     
       
   674     TSoInetInterfaceInfo info;
       
   675     TPckg<TSoInetInterfaceInfo> opt(info);
       
   676     
       
   677     while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt) == KErrNone)
       
   678         {
       
   679        // INFO_PRINTF2(_L("Interface Name %S"),&opt().iName);
       
   680         interfacesArray->AppendL(opt().iName);
       
   681         }
       
   682     
       
   683     INFO_PRINTF1(_L("Finished"));
       
   684     
       
   685     INFO_PRINTF1(_L("Closing connections"));
       
   686     socket.Close();
       
   687     socketSrv.Close();
       
   688     SetError(KErrNone);
       
   689     INFO_PRINTF1(_L("GetAvaiableInterfacesL - Exit"));
       
   690     }
       
   691 
       
   692 
       
   693 /**
       
   694 Function test the setting of suffix list and getting suffix list on interface.
       
   695 */
       
   696 void CDNSSuffixTestWrapper::DoSetAndGetSuffixListL()
       
   697     {
       
   698     INFO_PRINTF1(_L("************************************************************"));
       
   699     INFO_PRINTF1(_L("DoSetAndGetSuffixListL - DNS_Suffix_Support_TC001"));
       
   700     INFO_PRINTF1(_L("************************************************************"));
       
   701         
       
   702     TInt err(KErrNone);
       
   703     
       
   704     TName interfaceName;
       
   705     
       
   706     TRAP(err, err = GetFirstInterfaceNameL(interfaceName));
       
   707         
       
   708     if (err != KErrNone )
       
   709         {
       
   710         ERR_PRINTF2(_L("Failed to get the interface error: %D"),err);
       
   711         SetError(err);
       
   712         return;
       
   713         }
       
   714     
       
   715     TPtrC suffixList;
       
   716     iSuffixList.Reset();
       
   717     
       
   718     if (!GetStringFromConfig(KSectionDNSSuffixTest001,KKeyDNSSuffixTestSuffixList,suffixList))
       
   719         {
       
   720         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
   721         SetError(KErrNotFound);
       
   722         return;
       
   723         }
       
   724     else
       
   725         {
       
   726         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
   727         FillSuffixList(iSuffixList,suffixList);
       
   728         }
       
   729             
       
   730     err = iSocketServ.Connect();
       
   731            
       
   732     if(KErrNone != err)
       
   733        {
       
   734        ERR_PRINTF1(_L("Failed to connect socket Server"));
       
   735        SetError(err);
       
   736        return;
       
   737        }
       
   738     
       
   739     INFO_PRINTF1(_L("Connected to socket Server"));
       
   740     
       
   741     TUint iapId = GetFirstIapId();
       
   742     
       
   743     if (KErrNotFound == (TInt)iapId)
       
   744        {
       
   745        ERR_PRINTF2(_L("Failed to get the iap id: %D"),err);
       
   746        SetError(err);
       
   747        CloseSocketSrv();
       
   748        return;
       
   749        }
       
   750     
       
   751     RConnection firstConn; 
       
   752     err = StartConnection(iSocketServ,firstConn,iapId);
       
   753     
       
   754     if (KErrNone != err)
       
   755       {
       
   756       ERR_PRINTF2(_L("Failed to start the Connections: %D"),err);
       
   757       CloseSocketSrv();
       
   758       SetError(err);
       
   759       return;
       
   760       }
       
   761     
       
   762     INFO_PRINTF1(_L("Started the connections successfully"));
       
   763     
       
   764     
       
   765     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);
       
   766     
       
   767     if (KErrNone != err)
       
   768         {
       
   769         ERR_PRINTF2(_L("Failed Setting the suffix list with errror : %D"),err);
       
   770         SetError(err);  
       
   771         firstConn.Close();
       
   772         CloseSocketSrv();
       
   773         return;
       
   774         }
       
   775     
       
   776     INFO_PRINTF1(_L("Getting the suffix list on interface:"));
       
   777     
       
   778     iSuffixList2.Reset();
       
   779     
       
   780     err = GetDNSSuffixList(iSocketServ,interfaceName,iSuffixList2);
       
   781         
       
   782     if (KErrNone != err)
       
   783         {
       
   784         ERR_PRINTF2(_L("Failed to get the suffix list with errror : %D"),err);
       
   785         }
       
   786     
       
   787     
       
   788     if (err == KErrNone)
       
   789         {        
       
   790         if ( (err = IsSuffixListEqual(iSuffixList,iSuffixList2)) == KErrNone)
       
   791             {
       
   792             INFO_PRINTF1(_L("Suffix list are same and Test is successfull"));
       
   793             }
       
   794         else
       
   795             {
       
   796             ERR_PRINTF1(_L("Suffix list are not same and Test failed"));
       
   797             }
       
   798         }
       
   799     
       
   800     SetError(err);
       
   801     
       
   802     firstConn.Close();
       
   803     CloseSocketSrv();
       
   804     
       
   805     INFO_PRINTF1(_L("Set and Get Suffix list Test - Finished"));
       
   806     }
       
   807 
       
   808 
       
   809 
       
   810 TInt CDNSSuffixTestWrapper::SetDNSSuffixListOnInterface(RSocketServ& aServ,RConnection& /*aConn*/,const TDesC& aInterfaceName,RInetSuffixList& aData)
       
   811     {
       
   812     INFO_PRINTF1(_L("SetDNSSuffixListOnInterfaceL - Entry"));
       
   813     
       
   814     INFO_PRINTF1(_L("Opening socket..."));    
       
   815        
       
   816     RSocket socket;
       
   817     TInt err = socket.Open(aServ,KAfInet, KSockDatagram, KProtocolInetUdp);    
       
   818     
       
   819     if (KErrNone != err)
       
   820         {
       
   821         INFO_PRINTF2(_L("Failed Opening socket with error: %D"),err);
       
   822         SetError(err);
       
   823         return err;
       
   824         }
       
   825   
       
   826     INFO_PRINTF1(_L("Socket opened"));
       
   827     
       
   828     err = socket.SetOpt(KSoInetEnumInterfaces,KSolInetIfCtrl);
       
   829     
       
   830     if (KErrNone != err)
       
   831         {
       
   832         INFO_PRINTF2(_L("Failed enumerating interfaces with error: %D"),err);
       
   833         SetError(err);        
       
   834         socket.Close();
       
   835         return err;
       
   836         }
       
   837     
       
   838 	TSoInetInterfaceInfo getOpt;
       
   839     TPckg<TSoInetInterfaceInfo> opt_out(getOpt);
       
   840     
       
   841     TBool isSuffixListSet(EFalse);
       
   842     
       
   843     while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt_out)== KErrNone)        
       
   844         {    
       
   845         
       
   846         INFO_PRINTF2(_L("Interface Name: %S"),&opt_out().iName);        
       
   847         INFO_PRINTF2(_L("Name Server: %D"),!opt_out().iNameSer1.IsUnspecified());
       
   848         
       
   849         TBuf<KIPAddrLen> ipBuf;
       
   850         opt_out().iAddress.Output(ipBuf);
       
   851         INFO_PRINTF2(_L("IP Address: %S"),&ipBuf);
       
   852 
       
   853         TBuf<KIPAddrLen> nameserBuf;
       
   854         opt_out().iNameSer1.Output(nameserBuf);
       
   855         INFO_PRINTF2(_L("Name Server IP: %S"),&nameserBuf);
       
   856 
       
   857         if( (opt_out().iName.Length()>0) /*&& !(opt_out().iNameSer1.IsUnspecified())*/ && (aInterfaceName.CompareF(opt_out().iName)==0) )       
       
   858             {
       
   859             INFO_PRINTF2(_L("Setting suffix list on Interface: %S"),&opt_out().iName);
       
   860             INFO_PRINTF2(_L("MTU on the interface is : %d"), opt_out().iMtu);
       
   861 
       
   862             TSoInetInterfaceInfoExtnDnsSuffix setOpt;
       
   863             (TSoInetInterfaceInfo &)setOpt = opt_out();
       
   864             TPckg<TSoInetInterfaceInfoExtnDnsSuffix> opt_in(setOpt);
       
   865             /*opt_in().iName = opt_out().iName;
       
   866             opt_in().iAddress = opt_out().iAddress;
       
   867             opt_in().iNetMask = opt_out().iNetMask;*/
       
   868             opt_in().iDoId = ETrue;
       
   869             opt_in().iDelete = EFalse;
       
   870             opt_in().iDomainSuffix.DeleteAll();
       
   871             
       
   872             err = socket.SetOpt(KSoInetConfigInterface,KSolInetIfCtrl,opt_in);
       
   873             
       
   874             if (err != KErrNone)
       
   875                 {
       
   876                 ERR_PRINTF2(_L("Failed to reset suffix list on the interface: %D"),err);
       
   877                 break;
       
   878                 }
       
   879             else
       
   880 	            INFO_PRINTF1(_L("Interface domain suffix list reset successful"));
       
   881             	
       
   882             if (aData.Count() == 0) // We plan to set empty record, so only reset is sufficient
       
   883                 isSuffixListSet = ETrue;
       
   884             
       
   885             for(TInt a=0;a<aData.Count();a++)
       
   886                 {
       
   887                 opt_in().iDomainSuffix.Copy(aData[a]);
       
   888                 err = socket.SetOpt(KSoInetConfigInterface,KSolInetIfCtrl,opt_in);
       
   889                 if (err != KErrNone)
       
   890                 	{
       
   891                 	ERR_PRINTF2(_L("Failed to set suffix list: %D"),err);
       
   892                 	break;
       
   893             		}
       
   894                 else
       
   895                 	{
       
   896 	                INFO_PRINTF1(_L("Suffix list added successfully"));
       
   897                 	isSuffixListSet = ETrue;
       
   898             		}
       
   899                 }
       
   900             break;
       
   901             }
       
   902         }
       
   903     
       
   904     if (!isSuffixListSet)
       
   905         {
       
   906         err = KErrNotFound;
       
   907         ERR_PRINTF2(_L("Failed to set suffix list with error: %D"),err);       
       
   908         }
       
   909         
       
   910     SetError(err);
       
   911     
       
   912     INFO_PRINTF1(_L("Closing socket"));
       
   913     
       
   914     socket.Close();
       
   915     INFO_PRINTF1(_L("SetDNSSuffixListOnInterfaceL - Exit"));
       
   916     return err;
       
   917     }
       
   918 
       
   919 
       
   920 
       
   921 /**
       
   922  * GetDNSSuffixList. Gets the suffix list set on an interface.
       
   923  * 
       
   924  * @arg  aServ, session handle to a socket server. 
       
   925  * @arg  aData (in/out param) Data having the suffix list. Packed buffer of type TInetSuffixList
       
   926  *
       
   927  */
       
   928 TInt CDNSSuffixTestWrapper::GetDNSSuffixList(RSocketServ& aServ,const TDesC& aInterfaceName,RInetSuffixList& aData)
       
   929     {
       
   930     INFO_PRINTF1(_L("GetDNSSuffixList - Entry"));
       
   931     
       
   932     INFO_PRINTF1(_L("Opening socket..."));
       
   933     RSocket socket;
       
   934     TInt err = socket.Open(aServ,KAfInet, KSockDatagram, KProtocolInetUdp);
       
   935     
       
   936     if (KErrNone != err)
       
   937        {
       
   938        INFO_PRINTF2(_L("Failed Opening socket with error: %D"),err);
       
   939        SetError(err);
       
   940        return err;
       
   941        }
       
   942     
       
   943     INFO_PRINTF1(_L("Socket opened"));
       
   944     
       
   945     err = socket.SetOpt(KSoInetEnumInterfaces,KSolInetIfCtrl);
       
   946     
       
   947     if (KErrNone != err)
       
   948        {
       
   949        INFO_PRINTF2(_L("Failed enumerating interfaces with error: %D"),err);
       
   950        SetError(err);
       
   951        socket.Close();
       
   952        return err;
       
   953        }
       
   954 
       
   955 	TSoInetInterfaceInfo getOpt;
       
   956     TPckg<TSoInetInterfaceInfo> opt(getOpt);
       
   957        
       
   958     while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt) == KErrNone)
       
   959 		{
       
   960 		if (aInterfaceName.CompareF(opt().iName) == KErrNone)
       
   961 			{
       
   962 			INFO_PRINTF2(_L("Reading suffix list from interface: %S"),&opt().iName);     
       
   963 
       
   964 			TBuf<KIPAddrLen> tempIp;
       
   965 			opt().iAddress.Output(tempIp);
       
   966 			INFO_PRINTF2(_L("IP: %S"),&tempIp);
       
   967 
       
   968 			TInetSuffix domainSuffix;
       
   969 			TPckg<TInetSuffix> dom_opt(domainSuffix);
       
   970 			if (err = socket.SetOpt(KSoInetEnumDomainSuffix, KSolInetIfCtrl) != KErrNone)
       
   971 				return err; 
       
   972 			while( socket.GetOpt(KSoInetNextDomainSuffix, KSolInetIfCtrl, dom_opt) == KErrNone)
       
   973 				{
       
   974                 aData.AppendL(dom_opt().iSuffixName);
       
   975 				}
       
   976 			break;
       
   977 			}
       
   978 		}
       
   979     
       
   980     INFO_PRINTF1(_L("Closing socket"));
       
   981     socket.Close();
       
   982 
       
   983     INFO_PRINTF1(_L("GetDNSSuffixList - Exit"));
       
   984     return KErrNone;
       
   985     }
       
   986 
       
   987 
       
   988 
       
   989 /**
       
   990  * FillSuffixListL, Function to fill the suffix names in the TInetSuffixList object. 
       
   991  * @arg aSuffixList, out param, on return has the suffix list set in it.
       
   992  * @arg aData, has the list of domain suffix names in the form of abc.xyz.com;efg.xyz.com
       
   993  */
       
   994 TInt CDNSSuffixTestWrapper::FillSuffixList(RInetSuffixList& aSuffixList,TDesC& aData)
       
   995     {
       
   996     INFO_PRINTF1(_L("FillSuffixList - Entry"));
       
   997     
       
   998     INFO_PRINTF2(_L("Processing Suffix list: %S"),&aData);
       
   999     
       
  1000     TPtr data((TUint16*)aData.Ptr(),aData.Length(),aData.Length());
       
  1001     data.TrimAll();
       
  1002     
       
  1003     TInt pos = KErrNone;
       
  1004     while( (pos = data.Find(_L(";"))) != KErrNotFound)
       
  1005         {
       
  1006         TPtr suffixItem((TUint16*)data.Left(pos).Ptr(),pos,pos);
       
  1007         INFO_PRINTF3(_L("Processing %D suffix name: %S"),/*sListBuf()*/iSuffixList.Count()+1,&suffixItem);
       
  1008         
       
  1009         TSuffixName tmpBuf;
       
  1010         tmpBuf.Copy(suffixItem);
       
  1011         aSuffixList.AppendL(tmpBuf);
       
  1012         data.Copy(data.Mid(pos+1));
       
  1013         }
       
  1014     data.TrimAll();
       
  1015     INFO_PRINTF3(_L("Processing %D suffix name: %S"),/*sListBuf()*/iSuffixList.Count()+1,&data);
       
  1016     INFO_PRINTF2(_L("Data Len: %D"),data.Length());
       
  1017     
       
  1018     TSuffixName tmpBuf;
       
  1019     tmpBuf.Copy(data);
       
  1020     aSuffixList.AppendL(tmpBuf);
       
  1021     
       
  1022     INFO_PRINTF1(_L("FillSuffixList - Exit"));
       
  1023     
       
  1024     return aSuffixList.Count() == 0 ? KErrNotFound : KErrNone;
       
  1025     }
       
  1026 
       
  1027 
       
  1028 void CDNSSuffixTestWrapper::CloseSocketSrv()
       
  1029     {
       
  1030     INFO_PRINTF1(_L("Closing socket server"));
       
  1031     
       
  1032     if (iSocketServ.Handle())
       
  1033         {
       
  1034         iSocketServ.Close();
       
  1035         INFO_PRINTF1(_L("Closed Sock Srv successfully"));
       
  1036         }
       
  1037     else
       
  1038         {
       
  1039         INFO_PRINTF1(_L("Inavild Sock Srv handle"));
       
  1040         }
       
  1041     }
       
  1042 
       
  1043 /* 
       
  1044  * IsSuffixListEqual, Utility function, compares the two suffix list structures. 
       
  1045  * @arg aSuffixList1 First structure holding the suffix list
       
  1046  * @arg aSuffixList2 second structure holding the suffix list
       
  1047  * 
       
  1048  * @return KErrNone if both suffix list strucures same otherwise KErrArgument.  
       
  1049  * 
       
  1050  */
       
  1051 TInt CDNSSuffixTestWrapper::IsSuffixListEqual(const RInetSuffixList& aSuffixList1, const RInetSuffixList& aSuffixList2)
       
  1052     {
       
  1053     INFO_PRINTF1(_L("IsSuffixListEqual - Entry"));
       
  1054     
       
  1055     if (aSuffixList1.Count() != aSuffixList2.Count())
       
  1056         {
       
  1057         return KErrArgument;
       
  1058         }
       
  1059     
       
  1060     for (TInt a=0; a<aSuffixList1.Count();a++)
       
  1061         {
       
  1062         if (aSuffixList1[a].CompareF(aSuffixList2[a]) != KErrNone)
       
  1063             {
       
  1064             return KErrArgument;
       
  1065             }
       
  1066         }
       
  1067     INFO_PRINTF1(_L("IsSuffixListEqual - Exit"));
       
  1068     return KErrNone;
       
  1069     }
       
  1070 
       
  1071 
       
  1072 /*
       
  1073  * Prerequisite: Two interfaces required to be up and running (virtual Tunnel and ethernet).
       
  1074  * 
       
  1075  * DoResolveL. Resolves the domain name
       
  1076  * 
       
  1077  * 
       
  1078  */
       
  1079 void CDNSSuffixTestWrapper::DoResolveL()
       
  1080     {
       
  1081     INFO_PRINTF1(_L("********************************************"));
       
  1082     INFO_PRINTF1(_L("DoResolveL  - DNS_Suffix_Support_TC002"));
       
  1083     INFO_PRINTF1(_L("********************************************"));
       
  1084     
       
  1085     TPtrC hostname;
       
  1086     
       
  1087     if (!GetStringFromConfig(KSectionDNSSuffixTest002,KKeyDNSSuffixTestHostname,hostname))
       
  1088         {
       
  1089         ERR_PRINTF1(_L("Failed to read the host name value"));    
       
  1090         SetError(KErrNotFound);
       
  1091         return;
       
  1092         }
       
  1093     else
       
  1094         {
       
  1095         INFO_PRINTF2(_L("Host name: %S"),&hostname);       
       
  1096         }
       
  1097 
       
  1098 	TInt err = KErrNone;
       
  1099     TName interfaceName;
       
  1100     
       
  1101     TRAP(err, err = GetFirstInterfaceNameL(interfaceName));
       
  1102         
       
  1103     if (err != KErrNone )
       
  1104         {
       
  1105         ERR_PRINTF2(_L("Failed to get the interface error: %D"),err);
       
  1106         SetError(err);
       
  1107         return;
       
  1108         }
       
  1109         
       
  1110     TPtrC suffixList;
       
  1111     iSuffixList.Reset();
       
  1112     
       
  1113     if (!GetStringFromConfig(KSectionDNSSuffixTest002,KKeyDNSSuffixTestSuffixList,suffixList))
       
  1114         {
       
  1115         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  1116         SetError(KErrNotFound);
       
  1117         return;
       
  1118         }
       
  1119     else
       
  1120         {
       
  1121         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
  1122         FillSuffixList(iSuffixList,suffixList);
       
  1123         }
       
  1124 
       
  1125     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1126         {
       
  1127         ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1128         SetError(err);
       
  1129         return;
       
  1130         }
       
  1131     
       
  1132     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1133     
       
  1134     /*
       
  1135      * @Note: Start more than one interface. 
       
  1136      * Here starting vitual tunnel nif interface as a default. @see ethernet ced.xml file in which I have made 
       
  1137      * vTun as default in pref table.
       
  1138      */ 
       
  1139     RConnection vTunConn; // used for vTunnel
       
  1140     RConnection firstConn; 
       
  1141     
       
  1142     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1143    
       
  1144     if (err != KErrNone)
       
  1145         {
       
  1146         ERR_PRINTF1(_L("Failed to start connections"));
       
  1147         CloseSocketSrv();
       
  1148         SetError(err);
       
  1149         return;
       
  1150         }
       
  1151     
       
  1152     INFO_PRINTF1(_L("Connections started successfully"));
       
  1153    
       
  1154     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);
       
  1155     
       
  1156     if (KErrNone != err)
       
  1157         {
       
  1158         ERR_PRINTF2(_L("Failed Setting the suffix list with errror : %D"),err);
       
  1159         SetError(err);  
       
  1160         firstConn.Close();
       
  1161         CloseSocketSrv();
       
  1162         return;
       
  1163         }
       
  1164 
       
  1165     // Open implicit resolver.
       
  1166     RHostResolver resolver;
       
  1167     
       
  1168     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp)) != KErrNone)
       
  1169         {
       
  1170         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1171         firstConn.Close();
       
  1172         vTunConn.Close();
       
  1173         CloseSocketSrv();
       
  1174         SetError(err);        
       
  1175         return;
       
  1176         }       
       
  1177     
       
  1178     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1179                
       
  1180     TNameEntry nameEntry;
       
  1181     
       
  1182     INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname);
       
  1183     
       
  1184     if ( (err = resolver.GetByName(hostname,nameEntry)) != KErrNone)
       
  1185       {
       
  1186       ERR_PRINTF3(_L("Failed host resolution for %S with error: %D"),&hostname,err);       
       
  1187       }
       
  1188     else
       
  1189       {
       
  1190       TInetAddr& netAddress = TInetAddr::Cast(nameEntry().iAddr);
       
  1191       
       
  1192       if (netAddress.IsUnspecified())
       
  1193           {
       
  1194           ERR_PRINTF1(_L("Invalid host address"));
       
  1195           err = KErrArgument;
       
  1196           }
       
  1197       else
       
  1198           {
       
  1199           TBuf<KIPAddrLen> address;
       
  1200           netAddress.Output(address);
       
  1201           INFO_PRINTF1(_L("Got valid IP address:"));
       
  1202           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  1203           INFO_PRINTF2(_L("Host address: %S"),&address);
       
  1204           }
       
  1205       }
       
  1206     
       
  1207     INFO_PRINTF1(_L("Closing host resolver"));
       
  1208     resolver.Close();
       
  1209 
       
  1210     SetError(err);
       
  1211     
       
  1212     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  1213     firstConn.Close();
       
  1214     vTunConn.Close();
       
  1215     CloseSocketSrv();           
       
  1216     }
       
  1217 
       
  1218 
       
  1219 
       
  1220 void CDNSSuffixTestWrapper::DoResolveHostWithoutDomainWithSuffixListSetL()
       
  1221     {
       
  1222     INFO_PRINTF1(_L("******************************************************"));
       
  1223     INFO_PRINTF1(_L("DoResolveHostWithoutDomainL with Domain suffix Set"));
       
  1224     INFO_PRINTF1(_L(" - DNS_Suffix_Support_TC003"));
       
  1225     INFO_PRINTF1(_L("******************************************************"));
       
  1226     
       
  1227     TPtrC hostname;
       
  1228     
       
  1229     if (!GetStringFromConfig(KSectionDNSSuffixTest003,KKeyDNSSuffixTestHostname,hostname))
       
  1230         {
       
  1231         ERR_PRINTF1(_L("Failed to read the host name value"));    
       
  1232         SetError(KErrNotFound);
       
  1233         return;
       
  1234         }
       
  1235     else
       
  1236         {
       
  1237         INFO_PRINTF2(_L("Host name: %S"),&hostname);       
       
  1238         }
       
  1239     
       
  1240     TInt err = KErrNone;
       
  1241     
       
  1242     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1243         {
       
  1244         ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1245         SetError(err);
       
  1246         return;
       
  1247         }
       
  1248     
       
  1249     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1250         
       
  1251     RConnection vTunConn; // used for vTunnel
       
  1252     RConnection firstConn; 
       
  1253     
       
  1254     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1255     
       
  1256     if (err != KErrNone)
       
  1257        {
       
  1258        ERR_PRINTF1(_L("Failed to start connections"));
       
  1259        CloseSocketSrv();
       
  1260        SetError(err);
       
  1261        return;
       
  1262        }
       
  1263 
       
  1264    INFO_PRINTF1(_L("Connections started successfully"));
       
  1265        
       
  1266     // Open explicit resolver with ethernet
       
  1267     RHostResolver resolver;
       
  1268     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  1269         {
       
  1270         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1271         firstConn.Close();
       
  1272         vTunConn.Close();
       
  1273         CloseSocketSrv();
       
  1274         SetError(err);
       
  1275         return;
       
  1276         }       
       
  1277     
       
  1278     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1279                
       
  1280     TNameEntry nameEntry;
       
  1281     
       
  1282     if ( (err = resolver.GetByName(hostname,nameEntry)) != KErrNone)
       
  1283       {
       
  1284       ERR_PRINTF3(_L("Failed host resolution for %S with error: %D"),&hostname,err);
       
  1285       INFO_PRINTF1(_L("Test success"));
       
  1286       SetError(err);
       
  1287       }
       
  1288     else
       
  1289       {
       
  1290       TInetAddr address = nameEntry().iAddr;
       
  1291       
       
  1292       if (address.IsUnspecified())
       
  1293           {
       
  1294           ERR_PRINTF1(_L("Invalid host address"));
       
  1295           err = KErrArgument;
       
  1296           }
       
  1297       else
       
  1298           {
       
  1299           TBuf<KIPAddrLen> ipAddr;
       
  1300           address.Output(ipAddr);
       
  1301           INFO_PRINTF1(_L("Got valid IP address:"));
       
  1302           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  1303           INFO_PRINTF2(_L("Host address: %S"),&ipAddr);
       
  1304           }
       
  1305       SetError(err);
       
  1306       }
       
  1307     
       
  1308     INFO_PRINTF1(_L("Closing host resolver"));
       
  1309     resolver.Close();
       
  1310     firstConn.Close();
       
  1311     vTunConn.Close();   
       
  1312     CloseSocketSrv();           
       
  1313     }
       
  1314 
       
  1315 
       
  1316 void CDNSSuffixTestWrapper::DoResolveHostWithoutDomainWithoutSuffixListL()
       
  1317     {
       
  1318     INFO_PRINTF1(_L("******************************************************"));
       
  1319     INFO_PRINTF1(_L("DoResolveHostWithoutDomainL  With no Suffix list"));
       
  1320     INFO_PRINTF1(_L("DNS_Suffix_Support_TC004"));
       
  1321     INFO_PRINTF1(_L("******************************************************"));
       
  1322     
       
  1323     TPtrC hostname;
       
  1324     
       
  1325     if (!GetStringFromConfig(KSectionDNSSuffixTest004,KKeyDNSSuffixTestHostname,hostname))
       
  1326         {
       
  1327         ERR_PRINTF1(_L("Failed to read the host name value"));    
       
  1328         SetError(KErrNotFound);
       
  1329         return;
       
  1330         }
       
  1331     else
       
  1332         {
       
  1333         INFO_PRINTF2(_L("Host name: %S"),&hostname);       
       
  1334         }
       
  1335     
       
  1336     TInt err(KErrNone);
       
  1337     // Note: Remove the suffix list set on Ethernet interface.
       
  1338   
       
  1339     TName interfaceName;
       
  1340     err = GetFirstInterfaceNameL(interfaceName);   
       
  1341    
       
  1342     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1343         {
       
  1344         ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1345         SetError(err);
       
  1346         return;
       
  1347         }
       
  1348     
       
  1349     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1350         
       
  1351     RConnection vTunConn; // used for vTunnel
       
  1352     RConnection firstConn;
       
  1353     
       
  1354     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1355     
       
  1356     if (err != KErrNone)
       
  1357       {
       
  1358       ERR_PRINTF1(_L("Failed to start connections"));
       
  1359       CloseSocketSrv();
       
  1360       SetError(err);
       
  1361       return;
       
  1362       }
       
  1363     
       
  1364     /*
       
  1365     * @Note: Remove the suffix list (which we set in TC001) set on the interface by just setting empty list on it.
       
  1366     */
       
  1367     INFO_PRINTF1(_L("Setting empty suffix list on interface:"));
       
  1368     iSuffixList.Reset();
       
  1369     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);
       
  1370     
       
  1371     if (err != KErrNone)
       
  1372         {
       
  1373         ERR_PRINTF2(_L("Failed to remove the suffix list set on interface with error: %D"),err);
       
  1374         SetError(err);
       
  1375         firstConn.Close();
       
  1376         vTunConn.Close();
       
  1377         CloseSocketSrv();
       
  1378         return;
       
  1379         }
       
  1380     
       
  1381     INFO_PRINTF1(_L("Removed suffix list from interface:"));
       
  1382     
       
  1383     // Open explicit resolver with ethernet
       
  1384     RHostResolver resolver;
       
  1385     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  1386         {
       
  1387         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1388         firstConn.Close();
       
  1389         vTunConn.Close();
       
  1390         CloseSocketSrv();
       
  1391         SetError(err);
       
  1392         return;
       
  1393         }       
       
  1394     
       
  1395     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1396                
       
  1397     TNameEntry nameEntry;
       
  1398     
       
  1399     if ( (err = resolver.GetByName(hostname,nameEntry)) != KErrNone)
       
  1400       {
       
  1401       ERR_PRINTF3(_L("Failed host resolution for %S with error: %D"),&hostname,err);
       
  1402       INFO_PRINTF1(_L("Test success"));
       
  1403       SetError(EPass);
       
  1404       }
       
  1405     else
       
  1406       {
       
  1407       TInetAddr address = nameEntry().iAddr;
       
  1408       
       
  1409       if (address.IsUnspecified())
       
  1410           {
       
  1411           ERR_PRINTF1(_L("Invalid host address"));
       
  1412           err = KErrArgument;
       
  1413           }
       
  1414       else
       
  1415           {
       
  1416           TBuf<KIPAddrLen> ipAddr;
       
  1417           address.Output(ipAddr);
       
  1418           INFO_PRINTF1(_L("Got valid IP address:"));
       
  1419           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  1420           INFO_PRINTF2(_L("Host address: %S"),&ipAddr);
       
  1421           }
       
  1422       SetError(EFail);
       
  1423       }
       
  1424     
       
  1425     INFO_PRINTF1(_L("Closing host resolver"));
       
  1426     resolver.Close();
       
  1427     firstConn.Close();
       
  1428     vTunConn.Close();   
       
  1429     CloseSocketSrv();      
       
  1430     INFO_PRINTF1(_L("DoResolveHostWithoutDomainWithoutSuffixListL - Exit"));
       
  1431     }
       
  1432 
       
  1433 
       
  1434 
       
  1435 void CDNSSuffixTestWrapper::DNSSuffixSupportTC005L()
       
  1436     {
       
  1437     INFO_PRINTF1(_L("****************************************************"));
       
  1438     INFO_PRINTF1(_L("DNSSuffixSupportTC005L - DNS_Suffix_Support_TC005"));
       
  1439     INFO_PRINTF1(_L("****************************************************"));
       
  1440     
       
  1441     TPtrC hostname;
       
  1442     
       
  1443     if (!GetStringFromConfig(KSectionDNSSuffixTest005,KKeyDNSSuffixTestHostname,hostname))
       
  1444         {
       
  1445         ERR_PRINTF1(_L("Failed to read the host name value"));    
       
  1446         SetError(KErrNotFound);
       
  1447         return;
       
  1448         }
       
  1449     else
       
  1450         {
       
  1451         INFO_PRINTF2(_L("Host name: %S"),&hostname);       
       
  1452         }
       
  1453     
       
  1454     TInt err(KErrNone);
       
  1455         
       
  1456     TFileName interfaceName;
       
  1457     
       
  1458     TRAP(err, err = GetFirstInterfaceNameL(interfaceName));
       
  1459     
       
  1460     if (err != KErrNone )
       
  1461         {
       
  1462         ERR_PRINTF2(_L("Failed to get the interface error: %D"),err);
       
  1463         SetError(err);
       
  1464         return;
       
  1465         }
       
  1466     
       
  1467     TPtrC suffixList;    
       
  1468     iSuffixList.Reset();
       
  1469     
       
  1470     if (!GetStringFromConfig(KSectionDNSSuffixTest005,KKeyDNSSuffixTestSuffixList,suffixList))
       
  1471         {
       
  1472         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  1473         SetError(KErrNotFound);
       
  1474         return;
       
  1475         }
       
  1476     else
       
  1477         {
       
  1478         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
  1479         FillSuffixList(iSuffixList,suffixList);
       
  1480         }
       
  1481      
       
  1482     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1483         {
       
  1484         ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1485         SetError(err);
       
  1486         return;
       
  1487         }
       
  1488     
       
  1489     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1490     
       
  1491     RConnection vTunConn; // used for vTunnel
       
  1492     RConnection firstConn; 
       
  1493     
       
  1494     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1495     
       
  1496     if (err != KErrNone)
       
  1497        {
       
  1498        ERR_PRINTF1(_L("Failed to start connections"));
       
  1499        CloseSocketSrv();
       
  1500        SetError(err);
       
  1501        return;
       
  1502        }
       
  1503     
       
  1504     INFO_PRINTF1(_L("Connections started successfully"));
       
  1505     
       
  1506     INFO_PRINTF2(_L("Setting suffix list on : %S"),&interfaceName);
       
  1507     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);    
       
  1508         
       
  1509     if (KErrNone != err)
       
  1510         {
       
  1511         ERR_PRINTF2(_L("Failed Setting the suffix list with errror : %D"),err);
       
  1512         SetError(err);    
       
  1513         firstConn.Close();
       
  1514         vTunConn.Close();
       
  1515         CloseSocketSrv();
       
  1516         return;
       
  1517         }
       
  1518     
       
  1519     INFO_PRINTF1(_L("Suffix list set successfully"));
       
  1520     
       
  1521     INFO_PRINTF1(_L("Creating explicit host resolver"));
       
  1522     
       
  1523     // Open explicit resolver
       
  1524     RHostResolver resolver;
       
  1525     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  1526         {
       
  1527         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1528         firstConn.Close();
       
  1529         vTunConn.Close();
       
  1530         CloseSocketSrv();
       
  1531         SetError(err);
       
  1532         return;
       
  1533         }       
       
  1534     
       
  1535     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1536                
       
  1537     TNameEntry nameEntry;
       
  1538     
       
  1539     if ( (err = resolver.GetByName(hostname,nameEntry)) != KErrNone)
       
  1540         {
       
  1541         INFO_PRINTF3(_L("Host resolution for %S with error: %D"),&hostname,err);
       
  1542         INFO_PRINTF1(_L("Test success"));
       
  1543         err = KErrNone;
       
  1544         }    
       
  1545     else
       
  1546         {
       
  1547         err = KErrArgument;
       
  1548         ERR_PRINTF1(_L("Test failed: Expected no resolution, but resolved"));
       
  1549         }
       
  1550     
       
  1551     SetError(err);
       
  1552     INFO_PRINTF1(_L("Closing host resolver, connections and Sock Srv session"));
       
  1553     resolver.Close();
       
  1554     firstConn.Close();
       
  1555     vTunConn.Close();    
       
  1556     CloseSocketSrv();
       
  1557     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC005L - Exit"));
       
  1558     }
       
  1559 
       
  1560 
       
  1561 void CDNSSuffixTestWrapper::DNSSuffixSupportTC006L()
       
  1562     {
       
  1563     INFO_PRINTF1(_L("****************************************************"));
       
  1564     INFO_PRINTF1(_L("DNSSuffixSupportTC006L - DNS_Suffix_Support_TC006"));
       
  1565     INFO_PRINTF1(_L("****************************************************"));
       
  1566     
       
  1567     TInt numberOfHosts(0);
       
  1568     
       
  1569     if (!GetIntFromConfig(KSectionDNSSuffixTest006,KKeyDNSSuffixTest006NoOfHostname,numberOfHosts))
       
  1570         {
       
  1571         ERR_PRINTF1(_L("Failed to read the no of hosts from config"));    
       
  1572         SetError(KErrNotFound);
       
  1573         return;
       
  1574         }
       
  1575     else
       
  1576         {
       
  1577         INFO_PRINTF2(_L("No of hosts: %D"),numberOfHosts);       
       
  1578         }       
       
  1579 
       
  1580     TPtrC hostnames[KMaxHosts];
       
  1581     
       
  1582     for (TInt b=0;b<numberOfHosts;b++)
       
  1583         {
       
  1584         TFileName keyName;
       
  1585         keyName.Format(KKeyDNSSuffixTest006Hostname,b+1);
       
  1586         
       
  1587         if (!GetStringFromConfig(KSectionDNSSuffixTest006,keyName,hostnames[b]))
       
  1588             {
       
  1589             ERR_PRINTF1(_L("Failed to read the 1st host name value"));    
       
  1590             SetError(KErrNotFound);
       
  1591             return;
       
  1592             }
       
  1593         else
       
  1594             {
       
  1595             INFO_PRINTF3(_L("Host name%D: %S"),b,&hostnames[b]);       
       
  1596             }        
       
  1597         }
       
  1598         
       
  1599     TInt err(KErrNone);
       
  1600         
       
  1601     TName interfaceName;
       
  1602     
       
  1603     TRAP(err, err = GetFirstInterfaceNameL(interfaceName));
       
  1604     
       
  1605     if (err != KErrNone )
       
  1606         {
       
  1607         ERR_PRINTF2(_L("Failed to get the interface error: %D"),err);
       
  1608         SetError(err);
       
  1609         return;
       
  1610         }
       
  1611     
       
  1612     TPtrC suffixList;
       
  1613     iSuffixList.Reset();
       
  1614     
       
  1615     if (!GetStringFromConfig(KSectionDNSSuffixTest006,KKeyDNSSuffixTestSuffixList,suffixList))
       
  1616         {
       
  1617         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  1618         SetError(KErrNotFound);
       
  1619         return;
       
  1620         }
       
  1621     else
       
  1622         {
       
  1623         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
  1624         FillSuffixList(iSuffixList,suffixList);
       
  1625         }
       
  1626      
       
  1627     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1628         {
       
  1629         ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1630         SetError(err);
       
  1631         return;
       
  1632         }
       
  1633     
       
  1634     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1635     
       
  1636     RConnection vTunConn; // used for vTunnel
       
  1637     RConnection firstConn; 
       
  1638     
       
  1639     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1640     
       
  1641     if (err != KErrNone)
       
  1642       {
       
  1643       ERR_PRINTF1(_L("Failed to start connections"));
       
  1644       CloseSocketSrv();
       
  1645       SetError(err);
       
  1646       return;
       
  1647       }
       
  1648     
       
  1649     INFO_PRINTF1(_L("Connections started successfully"));
       
  1650     
       
  1651     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);
       
  1652        
       
  1653     if (KErrNone != err)
       
  1654         {
       
  1655         ERR_PRINTF2(_L("Failed Setting the suffix list with errror : %D"),err);
       
  1656         SetError(err);
       
  1657         firstConn.Close();
       
  1658         vTunConn.Close();
       
  1659         CloseSocketSrv();
       
  1660         return;
       
  1661         }
       
  1662 
       
  1663     INFO_PRINTF1(_L("Set suffix list on interface successfully"));
       
  1664     
       
  1665     RHostResolver resolver;
       
  1666     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  1667         {
       
  1668         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1669         firstConn.Close();
       
  1670         vTunConn.Close();
       
  1671         CloseSocketSrv();
       
  1672         SetError(err);
       
  1673         return;
       
  1674         }       
       
  1675     
       
  1676     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1677                
       
  1678     TNameEntry nameEntry[KMaxHosts];
       
  1679     
       
  1680     // Resolve all three hosts
       
  1681     for (TInt a=0;a<numberOfHosts;a++)
       
  1682         {
       
  1683         INFO_PRINTF2(_L("Resolving host: %S"),&hostnames[a]);
       
  1684         
       
  1685         if ( (err = resolver.GetByName(hostnames[a],nameEntry[a])) != KErrNone)
       
  1686             {
       
  1687             INFO_PRINTF3(_L("Host resolution for %S failed with error: %D"),&hostnames[a],err);
       
  1688             INFO_PRINTF1(_L("Test Failed"));
       
  1689             SetError(err);
       
  1690             break;
       
  1691             }
       
  1692         }
       
  1693     
       
  1694     if (err == KErrNone)
       
  1695         {
       
  1696         for (TInt a=0;a<numberOfHosts;a++)
       
  1697             {
       
  1698             TInetAddr address = nameEntry[a]().iAddr;
       
  1699             
       
  1700             if (address.IsUnspecified())
       
  1701                 {
       
  1702                 ERR_PRINTF1(_L("Invalid host address"));
       
  1703                 err = KErrArgument;
       
  1704                 }
       
  1705             else
       
  1706                 {
       
  1707                 TBuf<KIPAddrLen> ipAddr;
       
  1708                 address.Output(ipAddr);
       
  1709                 INFO_PRINTF1(_L("Got valid IP address:"));
       
  1710                 INFO_PRINTF2(_L("Host name: %S"),&nameEntry[a]().iName);
       
  1711                 INFO_PRINTF2(_L("Host address: %S"),&ipAddr);
       
  1712                 }            
       
  1713             }       
       
  1714         }
       
  1715     
       
  1716     SetError(err);
       
  1717     INFO_PRINTF1(_L("Closing host resolver, connections and Sock Srv session"));
       
  1718     resolver.Close();
       
  1719     firstConn.Close();
       
  1720     vTunConn.Close();    
       
  1721     CloseSocketSrv();
       
  1722     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC006L - Exit"));
       
  1723     }
       
  1724 
       
  1725 
       
  1726 /*
       
  1727  * TODO: Needs to find the way to change the ranking IAP's programatically. 
       
  1728  * Note: Before running this test case make ethernet iap as default
       
  1729  * by changing its ranking to one(1). 
       
  1730  * @ See te_dnssuffixcedv2.xml
       
  1731  * @See te_dnssuffixsuite.script for below line
       
  1732  * ced -i z:\testdata\configs\te_dnssuffixcedv2.xml 
       
  1733  *
       
  1734  */
       
  1735 void CDNSSuffixTestWrapper::DNSSuffixSupportTC007L()
       
  1736     {
       
  1737     INFO_PRINTF1(_L("**********************************************************************"));
       
  1738     INFO_PRINTF1(_L("DNS_Suffix_Test007L - DNS_Suffix_Support_007"));
       
  1739     INFO_PRINTF1(_L("**********************************************************************"));
       
  1740     
       
  1741     TPtrC validHostname;
       
  1742     TPtrC inValidHostname;
       
  1743     
       
  1744     if (!GetStringFromConfig(KSectionDNSSuffixTest007,KKeyDNSSuffixTest007ValidHostname,validHostname))
       
  1745         {
       
  1746         ERR_PRINTF1(_L("Failed to read the valid host name from config"));    
       
  1747         SetError(KErrNotFound);
       
  1748         return;
       
  1749         }
       
  1750     else
       
  1751         {
       
  1752         INFO_PRINTF2(_L("Valid Host name: %S"),&validHostname);       
       
  1753         }
       
  1754     
       
  1755     if (!GetStringFromConfig(KSectionDNSSuffixTest007,KKeyDNSSuffixTest007InValidHostname,inValidHostname))
       
  1756         {
       
  1757         ERR_PRINTF1(_L("Failed to read the invalid host name from config"));    
       
  1758         SetError(KErrNotFound);
       
  1759         return;
       
  1760         }
       
  1761     else
       
  1762         {
       
  1763         INFO_PRINTF2(_L("Invalid Host name: %S"),&inValidHostname);       
       
  1764         }   
       
  1765    
       
  1766     // @Santosh K Patil
       
  1767     // Note: Remove the suffix lists from the interfaces set by previous test cases, if any.    
       
  1768     // Note: start multiple interfaces
       
  1769     
       
  1770     TFileName interfaceName;
       
  1771     TInt err = KErrNone;
       
  1772     err = GetFirstInterfaceNameL(interfaceName);
       
  1773     
       
  1774     /*
       
  1775      * @Note: Remove the suffix list set on the interface (which we set in earlier test cases) 
       
  1776      *  by just setting empty list on it.
       
  1777      */
       
  1778     INFO_PRINTF1(_L("Setting empty suffix list on interface:"));
       
  1779     iSuffixList.Reset();
       
  1780     
       
  1781     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1782        {
       
  1783        ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1784        SetError(err);
       
  1785        return;
       
  1786        }
       
  1787     
       
  1788     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1789     
       
  1790     RConnection vTunConn; // used for vTunnel
       
  1791     RConnection firstConn; 
       
  1792     
       
  1793     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1794     
       
  1795     if (err != KErrNone)
       
  1796       {
       
  1797       ERR_PRINTF1(_L("Failed to start connections"));
       
  1798       CloseSocketSrv();
       
  1799       SetError(err);
       
  1800       return;
       
  1801       }
       
  1802     
       
  1803     INFO_PRINTF1(_L("Connections started successfully"));
       
  1804     
       
  1805     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,interfaceName,iSuffixList);
       
  1806            
       
  1807     if (KErrNone != err)
       
  1808         {
       
  1809         ERR_PRINTF2(_L("Failed Setting the suffix list with errror : %D"),err);
       
  1810         SetError(err);
       
  1811         firstConn.Close();
       
  1812         vTunConn.Close();
       
  1813         CloseSocketSrv();
       
  1814         return;
       
  1815         }
       
  1816     
       
  1817     INFO_PRINTF1(_L("Removed suffix list from interface:"));
       
  1818 
       
  1819     INFO_PRINTF1(_L("Opening implicit resolver"));
       
  1820     // Open implicit resolver.
       
  1821     RHostResolver resolver;
       
  1822     
       
  1823     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp)) != KErrNone)
       
  1824         {
       
  1825         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  1826         firstConn.Close();
       
  1827         vTunConn.Close();
       
  1828         CloseSocketSrv();
       
  1829         SetError(err);        
       
  1830         return;
       
  1831         }       
       
  1832     
       
  1833     INFO_PRINTF1(_L("Connected to Host resolver successfully"));
       
  1834                
       
  1835     TNameEntry nameEntry;
       
  1836     
       
  1837     INFO_PRINTF2(_L("Requesting to resolve valid hostname: %S"),&validHostname);
       
  1838     
       
  1839     if ( (err = resolver.GetByName(validHostname,nameEntry)) != KErrNone)
       
  1840       {
       
  1841       ERR_PRINTF3(_L("Host resolution failed for %S with error: %D"),&validHostname,err);       
       
  1842       }
       
  1843     else
       
  1844       {
       
  1845       TInetAddr& netAddress = TInetAddr::Cast(nameEntry().iAddr);
       
  1846       
       
  1847       if (netAddress.IsUnspecified())
       
  1848           {
       
  1849           ERR_PRINTF1(_L("Invalid host address"));
       
  1850           err = KErrArgument;
       
  1851           }
       
  1852       else
       
  1853           {
       
  1854           TBuf<KIPAddrLen> address;
       
  1855           netAddress.Output(address);
       
  1856           INFO_PRINTF1(_L("Got valid IP address:"));
       
  1857           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  1858           INFO_PRINTF2(_L("Host address: %S"),&address);
       
  1859           }
       
  1860       }    
       
  1861     
       
  1862     if (err == KErrNone)
       
  1863         {
       
  1864         TNameEntry nameEntry2;
       
  1865         
       
  1866         INFO_PRINTF2(_L("Requesting to resolve invalid hostname: %S"),&inValidHostname);
       
  1867         
       
  1868         if ( (err = resolver.GetByName(inValidHostname,nameEntry2)) != KErrNone)
       
  1869           {
       
  1870           INFO_PRINTF3(_L("Host resolution failed for %S with error: %D"),&inValidHostname,err);
       
  1871           INFO_PRINTF1(_L("Test scenario passed"));
       
  1872           err = KErrNone;
       
  1873           }
       
  1874         else
       
  1875           {
       
  1876           err = KErrArgument;
       
  1877           INFO_PRINTF1(_L("Error: Seems host is resolvable"));
       
  1878           }        
       
  1879         }
       
  1880     
       
  1881     SetError(err);
       
  1882     
       
  1883     INFO_PRINTF1(_L("Closing host resolver"));
       
  1884     resolver.Close();    
       
  1885     
       
  1886     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  1887     firstConn.Close();
       
  1888     vTunConn.Close();
       
  1889     CloseSocketSrv();           
       
  1890     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC007L - Exit"));
       
  1891     }
       
  1892 
       
  1893 
       
  1894 void CDNSSuffixTestWrapper::DNSSuffixSupportTC008L()
       
  1895     {
       
  1896     INFO_PRINTF1(_L("**********************************************************************"));
       
  1897     INFO_PRINTF1(_L("DNS_Suffix_Test008L - DNS_Suffix_Support_008"));
       
  1898     INFO_PRINTF1(_L("**********************************************************************"));
       
  1899     
       
  1900     TPtrC hostname1;
       
  1901     TPtrC hostname2;
       
  1902     
       
  1903     if (!GetStringFromConfig(KSectionDNSSuffixTest008,KKeyDNSSuffixTestHostname1,hostname1))
       
  1904         {
       
  1905         ERR_PRINTF1(_L("Failed to read the 1 host name from config"));    
       
  1906         SetError(KErrNotFound);
       
  1907         return;
       
  1908         }
       
  1909     else
       
  1910         {
       
  1911         INFO_PRINTF2(_L("Host name1: %S"),&hostname1);       
       
  1912         }
       
  1913     
       
  1914     if (!GetStringFromConfig(KSectionDNSSuffixTest008,KKeyDNSSuffixTestHostname2,hostname2))
       
  1915         {
       
  1916         ERR_PRINTF1(_L("Failed to read the 2 host name from config"));    
       
  1917         SetError(KErrNotFound);
       
  1918         return;
       
  1919         }
       
  1920     else
       
  1921         {
       
  1922         INFO_PRINTF2(_L("Host name2: %S"),&hostname2);       
       
  1923         }   
       
  1924    
       
  1925     // @Santosh K Patil
       
  1926     // @note: Set suffix lists on both interfaces (eth and vtun)    
       
  1927     // @note: start multiple interfaces
       
  1928     
       
  1929     TName ethernetInterface;
       
  1930     TName vTunInterface;
       
  1931     TInt err = KErrNone;
       
  1932     err = GetFirstInterfaceNameL(ethernetInterface);
       
  1933     
       
  1934     if (KErrNone != err)
       
  1935         { 
       
  1936         ERR_PRINTF1(_L("Failed get the name of the interface (ethernet)"));    
       
  1937         SetError(KErrNotFound);
       
  1938         return;
       
  1939         }
       
  1940     
       
  1941     err = GetSecondInterfaceNameL(vTunInterface);
       
  1942     
       
  1943     if (KErrNone != err)
       
  1944         { 
       
  1945         ERR_PRINTF1(_L("Failed get the name of the interface (vTun)"));    
       
  1946         SetError(KErrNotFound);
       
  1947         return;
       
  1948         }
       
  1949    
       
  1950     INFO_PRINTF1(_L("Setting suffix list on interface:"));
       
  1951     
       
  1952     iSuffixList2.Reset();
       
  1953     
       
  1954     TPtrC suffixList;
       
  1955     if (!GetStringFromConfig(KSectionDNSSuffixTest008,KKeyDNSSuffixTestSuffixList,suffixList))
       
  1956         {
       
  1957         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  1958         SetError(KErrNotFound);
       
  1959         return;
       
  1960         }
       
  1961     else
       
  1962         {
       
  1963         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
  1964         FillSuffixList(iSuffixList2,suffixList);
       
  1965         }   
       
  1966     
       
  1967     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  1968        {
       
  1969        ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  1970        SetError(err);
       
  1971        return;
       
  1972        }
       
  1973     
       
  1974     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  1975     
       
  1976     RConnection vTunConn; // used for vTunnel
       
  1977     RConnection firstConn; 
       
  1978     
       
  1979     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  1980     
       
  1981     if (err != KErrNone)
       
  1982       {
       
  1983       ERR_PRINTF1(_L("Failed to start connections"));
       
  1984       CloseSocketSrv();
       
  1985       SetError(err);
       
  1986       return;
       
  1987       }
       
  1988     
       
  1989     INFO_PRINTF1(_L("Connections started successfully"));
       
  1990     
       
  1991     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,ethernetInterface,iSuffixList2);
       
  1992              
       
  1993     if (KErrNone != err)
       
  1994         {
       
  1995         ERR_PRINTF3(_L("Failed Setting the suffix list on %S with errror : %D"),&ethernetInterface,err);
       
  1996         SetError(err);
       
  1997         firstConn.Close();
       
  1998         vTunConn.Close();
       
  1999         CloseSocketSrv();
       
  2000         return;
       
  2001         }
       
  2002     
       
  2003     INFO_PRINTF2(_L("Set suffix list on %S successfully"),&ethernetInterface);
       
  2004     
       
  2005     err = SetDNSSuffixListOnInterface(iSocketServ,vTunConn,vTunInterface,iSuffixList2);
       
  2006                
       
  2007     if (KErrNone != err)
       
  2008         {
       
  2009         ERR_PRINTF3(_L("Failed Setting the suffix list on %S with errror : %D"),&vTunInterface,err);
       
  2010         SetError(err);
       
  2011         firstConn.Close();
       
  2012         vTunConn.Close();
       
  2013         CloseSocketSrv();
       
  2014         return;
       
  2015         }
       
  2016     
       
  2017     INFO_PRINTF2(_L("Set suffix list on %S successfully"),&vTunInterface);        
       
  2018     
       
  2019     INFO_PRINTF1(_L("Opening implicit resolver"));
       
  2020     // Open implicit resolver.
       
  2021     RHostResolver resolver;
       
  2022     INFO_PRINTF1(_L("Creating implicit resolver"));
       
  2023     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp)) != KErrNone)
       
  2024         {
       
  2025         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  2026         firstConn.Close();
       
  2027         vTunConn.Close();
       
  2028         CloseSocketSrv();
       
  2029         SetError(err);        
       
  2030         return;
       
  2031         }       
       
  2032     
       
  2033     INFO_PRINTF1(_L("Connected to implicit Host resolver successfully"));
       
  2034                
       
  2035     TNameEntry nameEntry;
       
  2036     
       
  2037     INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname1);
       
  2038     
       
  2039     if ( (err = resolver.GetByName(hostname1,nameEntry)) != KErrNone)
       
  2040       {
       
  2041       ERR_PRINTF3(_L("Failed to resolve the host %S with error: %D"),&hostname1,err);       
       
  2042       }
       
  2043     else
       
  2044       {
       
  2045       TInetAddr& netAddress = TInetAddr::Cast(nameEntry().iAddr);
       
  2046       
       
  2047       if (netAddress.IsUnspecified())
       
  2048           {
       
  2049           ERR_PRINTF1(_L("Invalid host address"));
       
  2050           err = KErrArgument;
       
  2051           }
       
  2052       else
       
  2053           {
       
  2054           TBuf<KIPAddrLen> address;
       
  2055           netAddress.Output(address);
       
  2056           INFO_PRINTF1(_L("Got valid IP address:"));
       
  2057           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  2058           INFO_PRINTF2(_L("Host address: %S"),&address);
       
  2059           }
       
  2060       }    
       
  2061     
       
  2062     INFO_PRINTF1(_L("Closing implicit host resolver"));
       
  2063     resolver.Close(); 
       
  2064         
       
  2065     if (err == KErrNone)
       
  2066         {
       
  2067         // Open explicit resolver.
       
  2068         RHostResolver resolver2;
       
  2069         INFO_PRINTF1(_L("Creating explicit resolver"));
       
  2070         if ( (err = resolver2.Open(iSocketServ,KAfInet,KProtocolInetUdp,vTunConn)) != KErrNone)
       
  2071             {
       
  2072             ERR_PRINTF2(_L("Failed Connecting to explicit Host resolver with error: %D"),err);
       
  2073             firstConn.Close();
       
  2074             vTunConn.Close();
       
  2075             CloseSocketSrv();
       
  2076             SetError(err);        
       
  2077             return;
       
  2078             }       
       
  2079         
       
  2080         INFO_PRINTF1(_L("Connected to explicit Host resolver successfully"));
       
  2081         
       
  2082         
       
  2083         TNameEntry nameEntry2;        
       
  2084         INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname2);
       
  2085         
       
  2086         if ( (err = resolver2.GetByName(hostname2,nameEntry2)) != KErrNone)
       
  2087           {
       
  2088           INFO_PRINTF3(_L("Host resolution failed for %S with error: %D"),&hostname2,err);
       
  2089           INFO_PRINTF1(_L("Test scenario passed"));
       
  2090           err = KErrNone;
       
  2091           }
       
  2092         else
       
  2093           {
       
  2094           err = KErrArgument;
       
  2095           INFO_PRINTF1(_L("Error: Seems host is resolvable"));
       
  2096           }      
       
  2097         
       
  2098         INFO_PRINTF1(_L("Closing explicit host resolver"));
       
  2099         resolver2.Close();    
       
  2100         }
       
  2101     
       
  2102     SetError(err);
       
  2103     
       
  2104     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  2105     firstConn.Close();
       
  2106     vTunConn.Close();
       
  2107     CloseSocketSrv();           
       
  2108     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC008L - Exit"));
       
  2109     }
       
  2110 
       
  2111 
       
  2112 // TODO: Cross check the correct ness of the implementation.
       
  2113 void CDNSSuffixTestWrapper::DNSSuffixSupportTC009L()
       
  2114     {
       
  2115     INFO_PRINTF1(_L("**********************************************************************"));
       
  2116     INFO_PRINTF1(_L("DNSSuffixSupportTC009L - DNS_Suffix_Support_009"));
       
  2117     INFO_PRINTF1(_L("**********************************************************************"));
       
  2118     
       
  2119     TPtrC hostname1;
       
  2120     TPtrC hostname2;
       
  2121     
       
  2122     if (!GetStringFromConfig(KSectionDNSSuffixTest009,KKeyDNSSuffixTestHostname1,hostname1))
       
  2123         {
       
  2124         ERR_PRINTF1(_L("Failed to read the 1 host name from config"));    
       
  2125         SetError(KErrNotFound);
       
  2126         return;
       
  2127         }
       
  2128     else
       
  2129         {
       
  2130         INFO_PRINTF2(_L("Host name1: %S"),&hostname1);       
       
  2131         }
       
  2132     
       
  2133     if (!GetStringFromConfig(KSectionDNSSuffixTest009,KKeyDNSSuffixTestHostname2,hostname2))
       
  2134         {
       
  2135         ERR_PRINTF1(_L("Failed to read the 2 host name from config"));    
       
  2136         SetError(KErrNotFound);
       
  2137         return;
       
  2138         }
       
  2139     else
       
  2140         {
       
  2141         INFO_PRINTF2(_L("Host name2: %S"),&hostname2);       
       
  2142         }
       
  2143     
       
  2144     /*
       
  2145      * @Santosh K Patil        
       
  2146      * @note: start multiple interfaces
       
  2147      * Set suffix lists on vTunnel interface    
       
  2148      * Open explicit connection on other interface
       
  2149      */
       
  2150     
       
  2151     TFileName vTunInterface;
       
  2152     TInt err = GetSecondInterfaceNameL(vTunInterface);
       
  2153     
       
  2154     if (KErrNone != err)
       
  2155         { 
       
  2156         ERR_PRINTF1(_L("Failed get the name of the interface (vTun)"));    
       
  2157         SetError(KErrNotFound);
       
  2158         return;
       
  2159         }    
       
  2160    
       
  2161     INFO_PRINTF1(_L("Setting suffix list on vTun interface:"));
       
  2162     
       
  2163     iSuffixList.Reset();
       
  2164     
       
  2165     TPtrC suffixList;
       
  2166     if (!GetStringFromConfig(KSectionDNSSuffixTest009,KKeyDNSSuffixTestSuffixList,suffixList))
       
  2167         {
       
  2168         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  2169         SetError(KErrNotFound);
       
  2170         return;
       
  2171         }
       
  2172     else
       
  2173         {
       
  2174         INFO_PRINTF2(_L("Suffix list: %S"),&suffixList);
       
  2175         FillSuffixList(iSuffixList,suffixList);
       
  2176         }
       
  2177     
       
  2178     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  2179        {
       
  2180        ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  2181        SetError(err);
       
  2182        return;
       
  2183        }
       
  2184     
       
  2185     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  2186     
       
  2187     RConnection vTunConn; // used for vTunnel
       
  2188     RConnection firstConn; 
       
  2189     
       
  2190     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  2191     
       
  2192     if (err != KErrNone)
       
  2193       {
       
  2194       ERR_PRINTF1(_L("Failed to start connections"));
       
  2195       CloseSocketSrv();
       
  2196       SetError(err);
       
  2197       return;
       
  2198       }
       
  2199     
       
  2200     INFO_PRINTF1(_L("Connections started successfully"));
       
  2201     
       
  2202     err = SetDNSSuffixListOnInterface(iSocketServ,vTunConn,vTunInterface,iSuffixList);
       
  2203                    
       
  2204     if (KErrNone != err)
       
  2205         {
       
  2206         ERR_PRINTF3(_L("Failed Setting the suffix list on %S with errror : %D"),&vTunInterface,err);
       
  2207         SetError(err);
       
  2208         firstConn.Close();
       
  2209         vTunConn.Close();
       
  2210         CloseSocketSrv();
       
  2211         return;
       
  2212         }
       
  2213     
       
  2214     INFO_PRINTF2(_L("Set suffix list on %S successfully"),&vTunInterface);  
       
  2215 
       
  2216     INFO_PRINTF1(_L("Opening explicit resolver"));
       
  2217     // Open implicit resolver.
       
  2218     RHostResolver resolver;
       
  2219     INFO_PRINTF1(_L("Creating explicit resolver"));
       
  2220     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  2221         {
       
  2222         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  2223         firstConn.Close();
       
  2224         vTunConn.Close();
       
  2225         CloseSocketSrv();
       
  2226         SetError(err);        
       
  2227         return;
       
  2228         }       
       
  2229     
       
  2230     INFO_PRINTF1(_L("Connected to explicit Host resolver successfully"));
       
  2231                
       
  2232     TNameEntry nameEntry;
       
  2233     
       
  2234     INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname1);
       
  2235     
       
  2236     if ( (err = resolver.GetByName(hostname1,nameEntry)) != KErrNone)
       
  2237       {
       
  2238       ERR_PRINTF3(_L("Failed to resolve the host %S with error: %D"),&hostname1,err);       
       
  2239       }
       
  2240     else
       
  2241       {
       
  2242       TInetAddr& netAddress = TInetAddr::Cast(nameEntry().iAddr);
       
  2243       
       
  2244       if (netAddress.IsUnspecified())
       
  2245           {
       
  2246           ERR_PRINTF1(_L("Invalid host address"));
       
  2247           err = KErrArgument;
       
  2248           }
       
  2249       else
       
  2250           {
       
  2251           TBuf<KIPAddrLen> address;
       
  2252           netAddress.Output(address);
       
  2253           INFO_PRINTF1(_L("Got valid IP address:"));
       
  2254           INFO_PRINTF2(_L("Host name: %S"),&nameEntry().iName);
       
  2255           INFO_PRINTF2(_L("Host address: %S"),&address);
       
  2256           }
       
  2257       }
       
  2258         
       
  2259     if (err == KErrNone)
       
  2260         { 
       
  2261         TNameEntry nameEntry2;        
       
  2262         INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname2);
       
  2263         
       
  2264         if ( (err = resolver.GetByName(hostname2,nameEntry2)) != KErrNone)
       
  2265           {
       
  2266           INFO_PRINTF3(_L("Host resolution failed for %S with error: %D"),&hostname2,err);
       
  2267           INFO_PRINTF1(_L("Test scenario passed"));
       
  2268           err = KErrNone;
       
  2269           }
       
  2270         else
       
  2271           {
       
  2272           // TODO: We have to change this once we come up with end to end setup for VTun err = KErrArgument;
       
  2273           INFO_PRINTF1(_L("We assumed that host is resolved through explicit connection and hence test is pass."));
       
  2274           INFO_PRINTF1(_L("We have to change this once we come up with end to end setup for VTun."));
       
  2275           err = KErrNone;
       
  2276          // INFO_PRINTF1(_L("Error: Seems host is resolvable"));
       
  2277           } 
       
  2278         }   
       
  2279     
       
  2280     SetError(err);
       
  2281 
       
  2282     INFO_PRINTF1(_L("Closing host resolver"));
       
  2283     resolver.Close(); 
       
  2284     
       
  2285     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  2286     firstConn.Close();
       
  2287     vTunConn.Close();
       
  2288     CloseSocketSrv();           
       
  2289     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC009L - Exit"));
       
  2290     }
       
  2291 
       
  2292 
       
  2293 // TODO: If I set suffix list name of length with max size then client panic's.
       
  2294 void CDNSSuffixTestWrapper::DNSSuffixSupportTC010L()
       
  2295     {
       
  2296     INFO_PRINTF1(_L("**********************************************************************"));
       
  2297     INFO_PRINTF1(_L("DNSSuffixSupportTC010L - DNS_Suffix_Support_010"));
       
  2298     INFO_PRINTF1(_L("**********************************************************************"));
       
  2299     
       
  2300     TPtrC hostname;
       
  2301     
       
  2302     if (!GetStringFromConfig(KSectionDNSSuffixTest010,KKeyDNSSuffixTestHostname,hostname))
       
  2303         {
       
  2304         ERR_PRINTF1(_L("Failed to read the host name from config"));    
       
  2305         SetError(KErrNotFound);
       
  2306         return;
       
  2307         }
       
  2308     else
       
  2309         {
       
  2310         INFO_PRINTF2(_L("Host name1: %S"),&hostname);       
       
  2311         }
       
  2312     
       
  2313     // @Santosh K Patil     
       
  2314     // @note: start multiple interfaces
       
  2315     // @note: Set long suffix lists on both interface  
       
  2316     // @note: Create explicit resolver and set the suffixlist with max size.
       
  2317     
       
  2318     TFileName ethernetInterface;
       
  2319     TInt err = KErrNone;
       
  2320     err = GetFirstInterfaceNameL(ethernetInterface);
       
  2321     
       
  2322     if (KErrNone != err)
       
  2323         { 
       
  2324         ERR_PRINTF1(_L("Failed get the name of the interface (ethernet)"));    
       
  2325         SetError(KErrNotFound);
       
  2326         return;
       
  2327         }
       
  2328   
       
  2329     INFO_PRINTF1(_L("Setting suffix list on interface:"));
       
  2330     iSuffixList.Reset();
       
  2331     
       
  2332     
       
  2333     // @Ganesh - Constructing suffix list for FillSuffixList with 3 separate suffix name entries in ini
       
  2334     // @Ganesh - as the names are too long for the parser to parse and add it in one GetStringFromConfig call 
       
  2335     TPtrC suffixName;
       
  2336     TBuf<1024> suffixList;
       
  2337     if (!GetStringFromConfig(KSectionDNSSuffixTest010,KKeyDNSSuffixTestSuffixList1,suffixName))
       
  2338         {
       
  2339         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  2340         SetError(KErrNotFound);
       
  2341         return;
       
  2342         }
       
  2343     else
       
  2344         {
       
  2345         INFO_PRINTF1(_L("Suffix name:"));
       
  2346         INFO_PRINTF2(_L("%S"),&suffixName);
       
  2347         suffixList.Append(suffixName);
       
  2348         suffixList.Append(_L(";"));
       
  2349         }
       
  2350 
       
  2351     if (!GetStringFromConfig(KSectionDNSSuffixTest010,KKeyDNSSuffixTestSuffixList2,suffixName))
       
  2352         {
       
  2353         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  2354         SetError(KErrNotFound);
       
  2355         return;
       
  2356         }
       
  2357     else
       
  2358         {
       
  2359         INFO_PRINTF1(_L("Suffix name:"));
       
  2360         INFO_PRINTF2(_L("%S"),&suffixName);
       
  2361         suffixList.Append(suffixName);
       
  2362         suffixList.Append(_L(";"));
       
  2363         }
       
  2364     
       
  2365     if (!GetStringFromConfig(KSectionDNSSuffixTest010,KKeyDNSSuffixTestSuffixList3,suffixName))
       
  2366         {
       
  2367         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  2368         SetError(KErrNotFound);
       
  2369         return;
       
  2370         }
       
  2371     else
       
  2372         {
       
  2373         INFO_PRINTF1(_L("Suffix name:"));
       
  2374         INFO_PRINTF2(_L("%S"),&suffixName);
       
  2375         suffixList.Append(suffixName);
       
  2376         }
       
  2377     FillSuffixList(iSuffixList,suffixList);
       
  2378     
       
  2379     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  2380        {
       
  2381        ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  2382        SetError(err);
       
  2383        return;
       
  2384        }
       
  2385     
       
  2386     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  2387     
       
  2388     RConnection vTunConn; // used for vTunnel
       
  2389     RConnection firstConn; 
       
  2390     
       
  2391     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  2392     
       
  2393     if (err != KErrNone)
       
  2394       {
       
  2395       ERR_PRINTF1(_L("Failed to start connections"));
       
  2396       CloseSocketSrv();
       
  2397       SetError(err);
       
  2398       return;
       
  2399       }
       
  2400     
       
  2401     INFO_PRINTF1(_L("Connections started successfully"));
       
  2402     
       
  2403     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,ethernetInterface,iSuffixList);
       
  2404                   
       
  2405     if (KErrNone != err)
       
  2406         {
       
  2407         ERR_PRINTF3(_L("Failed Setting the suffix list on %S with errror : %D"),&ethernetInterface,err);
       
  2408         SetError(err);
       
  2409         firstConn.Close();
       
  2410         vTunConn.Close();
       
  2411         CloseSocketSrv();
       
  2412         return;
       
  2413         }
       
  2414     
       
  2415     INFO_PRINTF2(_L("Set suffix list on %S successfully"),&ethernetInterface);  
       
  2416     
       
  2417     INFO_PRINTF1(_L("Opening explicit resolver"));
       
  2418     
       
  2419     RHostResolver resolver;
       
  2420     INFO_PRINTF1(_L("Creating explicit resolver"));
       
  2421     if ( (err = resolver.Open(iSocketServ,KAfInet,KProtocolInetUdp,firstConn)) != KErrNone)
       
  2422         {
       
  2423         ERR_PRINTF2(_L("Failed Connecting to Host resolver with error: %D"),err);
       
  2424         firstConn.Close();
       
  2425         vTunConn.Close();
       
  2426         CloseSocketSrv();
       
  2427         SetError(err);        
       
  2428         return;
       
  2429         }       
       
  2430     
       
  2431     INFO_PRINTF1(_L("Connected to explicit Host resolver successfully"));
       
  2432                
       
  2433     TNameEntry nameEntry;
       
  2434     
       
  2435     INFO_PRINTF2(_L("Requesting to resolve hostname: %S"),&hostname);
       
  2436     
       
  2437     if ( (err = resolver.GetByName(hostname,nameEntry)) != KErrNone)
       
  2438       {
       
  2439       INFO_PRINTF3(_L("Failed to resolve the host %S with error: %D"),&hostname,err);   
       
  2440       INFO_PRINTF1(_L("Test Pass"));
       
  2441       err = KErrNone;
       
  2442       }
       
  2443     else
       
  2444       {
       
  2445       err = KErrArgument;
       
  2446       INFO_PRINTF1(_L("Host seems to be resolvable"));
       
  2447       }    
       
  2448     
       
  2449     SetError(err);
       
  2450     
       
  2451     INFO_PRINTF1(_L("Closing host resolver"));
       
  2452     resolver.Close();  
       
  2453     
       
  2454     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  2455     firstConn.Close();
       
  2456     vTunConn.Close();
       
  2457     CloseSocketSrv();           
       
  2458     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC010L - Exit"));
       
  2459     }
       
  2460 
       
  2461 
       
  2462 /*
       
  2463  * @Test: Connection dissconnection test
       
  2464  * 
       
  2465  * Make vTun as default interface
       
  2466  * Set suffix on ethernet
       
  2467  * Open implicit resolver (assumed that it is opened on vTun)
       
  2468  * Request for name resolution (Async one)
       
  2469  * Stop the connection and observe the behaviour.(Expected, resolution should fail gracefully)
       
  2470  * With appropriate error code.
       
  2471  * 
       
  2472  */
       
  2473 void CDNSSuffixTestWrapper::DNSSuffixSupportTC011L()
       
  2474     {
       
  2475     INFO_PRINTF1(_L("**********************************************************************"));
       
  2476     INFO_PRINTF1(_L("DNSSuffixSupportTC011L - DNS_Suffix_Support_011"));
       
  2477     INFO_PRINTF1(_L("**********************************************************************"));
       
  2478     
       
  2479     TPtrC hostname;
       
  2480     
       
  2481     if (!GetStringFromConfig(KSectionDNSSuffixTest011,KKeyDNSSuffixTestHostname,hostname))
       
  2482         {
       
  2483         ERR_PRINTF1(_L("Failed to read the host name from config"));    
       
  2484         SetError(KErrNotFound);
       
  2485         return;
       
  2486         }
       
  2487     else
       
  2488         {
       
  2489         INFO_PRINTF2(_L("Host name1: %S"),&hostname);       
       
  2490         }
       
  2491     
       
  2492     TFileName ethernetInterface;
       
  2493     TInt err = KErrNone;
       
  2494     err = GetFirstInterfaceNameL(ethernetInterface);
       
  2495     
       
  2496     if (KErrNone != err)
       
  2497         { 
       
  2498         ERR_PRINTF1(_L("Failed get the name of the interface (ethernet)"));    
       
  2499         SetError(KErrNotFound);
       
  2500         return;
       
  2501         }
       
  2502   
       
  2503     INFO_PRINTF1(_L("Setting suffix list on interface:"));
       
  2504     iSuffixList.Reset();
       
  2505         
       
  2506     
       
  2507     TPtrC suffixList;
       
  2508     if (!GetStringFromConfig(KSectionDNSSuffixTest011,KKeyDNSSuffixTestSuffixList,suffixList))
       
  2509         {
       
  2510         ERR_PRINTF1(_L("Failed to read suffix lists from config"));    
       
  2511         SetError(KErrNotFound);
       
  2512         return;
       
  2513         }
       
  2514     else
       
  2515         {
       
  2516         INFO_PRINTF1(_L("Suffix list:"));
       
  2517         INFO_PRINTF2(_L("%S"),&suffixList);
       
  2518         FillSuffixList(iSuffixList,suffixList);
       
  2519         }   
       
  2520     
       
  2521     if ( (err = iSocketServ.Connect()) != KErrNone)
       
  2522        {
       
  2523        ERR_PRINTF1(_L("Failed Connecting to socket server"));
       
  2524        SetError(err);
       
  2525        return;
       
  2526        }
       
  2527     
       
  2528     INFO_PRINTF1(_L("Connected to socket server successfully"));
       
  2529     
       
  2530     RConnection vTunConn; // used for vTunnel
       
  2531     RConnection firstConn; 
       
  2532     
       
  2533     err = StartConnections(iSocketServ,firstConn, vTunConn);
       
  2534     
       
  2535     if (err != KErrNone)
       
  2536       {
       
  2537       ERR_PRINTF1(_L("Failed to start connections"));
       
  2538       CloseSocketSrv();
       
  2539       SetError(err);
       
  2540       return;
       
  2541       }
       
  2542     
       
  2543     INFO_PRINTF1(_L("Connections started successfully"));
       
  2544     
       
  2545     err = SetDNSSuffixListOnInterface(iSocketServ,firstConn,ethernetInterface,iSuffixList);
       
  2546                      
       
  2547     if (KErrNone != err)
       
  2548         {
       
  2549         ERR_PRINTF3(_L("Failed Setting the suffix list on %S with errror : %D"),&ethernetInterface,err);
       
  2550         SetError(err);
       
  2551         firstConn.Close();
       
  2552         vTunConn.Close();
       
  2553         CloseSocketSrv();
       
  2554         return;
       
  2555         }
       
  2556     
       
  2557     INFO_PRINTF2(_L("Set suffix list on %S successfully"),&ethernetInterface);  
       
  2558 
       
  2559     
       
  2560     // Open explcit resolver. using CDNSSuffixHostResolver    
       
  2561     CDNSSuffixHostResolver* resolver = CDNSSuffixHostResolver::NewLC(*this,iSocketServ,firstConn);
       
  2562     
       
  2563     INFO_PRINTF2(_L("Request to resolve host(async): %S"),&hostname);
       
  2564     err = resolver->ResolveL(hostname);
       
  2565     
       
  2566     INFO_PRINTF1(_L("Stoping the connection"));
       
  2567     
       
  2568     err = firstConn.Stop();
       
  2569     
       
  2570     // Note: we have to stop the wait loop in HandleCallBackL
       
  2571     iWait.Start();
       
  2572     
       
  2573     CleanupStack::PopAndDestroy();
       
  2574     
       
  2575     INFO_PRINTF1(_L("Closing connections and socket serv session"));
       
  2576     firstConn.Close();
       
  2577     vTunConn.Close();
       
  2578     CloseSocketSrv();           
       
  2579     INFO_PRINTF1(_L("CDNSSuffixTestWrapper::DNSSuffixSupportTC011L - Exit"));
       
  2580     }
       
  2581 
       
  2582 
       
  2583 // End of file