networkingtestandutils/exampleinternetutilities/ROUTE/ROUTE.CPP
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Started by AY, August 1997
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32cons.h>
       
    19 #include <in_sock.h>
       
    20 #include <nifman.h>
       
    21 
       
    22 
       
    23 void ProgramL(CConsoleBase& aCons);
       
    24 
       
    25 GLDEF_C TInt E32Main()
       
    26     {
       
    27 	__UHEAP_MARK;
       
    28 	// Standard stuff
       
    29 	CTrapCleanup* trap = CTrapCleanup::New();
       
    30 	if(trap==NULL)
       
    31 		return KErrNoMemory;
       
    32 
       
    33 	CConsoleBase* cons=NULL;
       
    34 	TRAPD(e, cons=Console::NewL(_L("Route"),TSize(KConsFullScreen,KConsFullScreen));)
       
    35 	if(e!=KErrNone)
       
    36 		{
       
    37 		delete trap;
       
    38 		return e;
       
    39 		}
       
    40 	
       
    41 	TRAPD(res, ProgramL(*cons);)
       
    42 	if(res!=KErrNone)
       
    43 		{
       
    44 		cons->Printf(_L("Error %d\n"), res);
       
    45 		cons->Printf(_L("Press any key to exit"));
       
    46 		cons->Getch();
       
    47 		}
       
    48 
       
    49 	delete cons;
       
    50 	delete trap;
       
    51 	__UHEAP_MARKEND;
       
    52 	return KErrNone;
       
    53     }
       
    54 
       
    55 void ProgramL(CConsoleBase& aCons)
       
    56 	{
       
    57 
       
    58 //	User::LeaveIfError(Nifman::CheckIniConfig());
       
    59 
       
    60 	TAutoClose<RSocketServ> ss;
       
    61 	User::LeaveIfError(ss.iObj.Connect());
       
    62 	ss.PushL();
       
    63 
       
    64 	TAutoClose<RSocket> sock;
       
    65 	User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp")));
       
    66 	sock.PushL();
       
    67 
       
    68 	User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl));
       
    69 
       
    70 	TProtocolDesc in;
       
    71 	User::LeaveIfError(sock.iObj.Info(in));
       
    72 	aCons.Printf(_L("EPOC32 Route TCPIP Version %d.%d.%d\n\n"), in.iVersion.iMajor, in.iVersion.iMinor, in.iVersion.iBuild);
       
    73 
       
    74 	TPckgBuf<TSoInetRouteInfo> info, next;
       
    75 
       
    76 	TInt res=sock.iObj.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, info);
       
    77 	if(res!=KErrNone)
       
    78 		User::Leave(res);
       
    79 
       
    80 	while(res==KErrNone)
       
    81 		{
       
    82 
       
    83 		res=sock.iObj.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, next);
       
    84 
       
    85 		TName address;
       
    86 		info().iDstAddr.Output(address);
       
    87 		aCons.Printf(_L("Network Address   %S\n"), &address);
       
    88 		if(info().iDstAddr.Family() == KAfInet)
       
    89 			{
       
    90 			info().iNetMask.Output(address);
       
    91 			aCons.Printf(_L("Netmask           %S\n"), &address);
       
    92 			}
       
    93 		info().iGateway.Output(address);
       
    94 		aCons.Printf(_L("Gateway Address   %S\n"), &address);
       
    95 		info().iIfAddr.Output(address);
       
    96 		aCons.Printf(_L("Interface         %S\n"), &address);
       
    97         aCons.Printf(_L("Metric            %d\n\n"), info().iMetric);
       
    98 
       
    99 		
       
   100 		
       
   101 		if(res==KErrNone)
       
   102 			{
       
   103 			info = next;
       
   104 		    aCons.Printf(_L("\nPress any key for next\n\n"));
       
   105 			}
       
   106 		else
       
   107 			aCons.Printf(_L("\nPress any key to exit\n"));
       
   108 		
       
   109 		aCons.Getch();
       
   110 		}
       
   111 
       
   112 	sock.Pop();
       
   113 	ss.Pop();
       
   114 	}