|
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 MWT, August 1997 |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32cons.h> |
|
19 #include <in_sock.h> |
|
20 #include <in_iface.h> |
|
21 #include <nifman.h> |
|
22 |
|
23 |
|
24 void ProgramL(CConsoleBase& aCons); |
|
25 void PrintFeature(CConsoleBase& aCons, TUint& aMask, TUint aFeature, const TDesC& aDes); |
|
26 |
|
27 GLDEF_C TInt E32Main() |
|
28 { |
|
29 __UHEAP_MARK; |
|
30 // Standard stuff |
|
31 CTrapCleanup* trap = CTrapCleanup::New(); |
|
32 if(trap==NULL) |
|
33 return KErrNoMemory; |
|
34 |
|
35 CConsoleBase* cons=NULL; |
|
36 TRAPD(e, cons=Console::NewL(_L("IpConfig"),TSize(KConsFullScreen,KConsFullScreen));) |
|
37 if(e!=KErrNone) |
|
38 { |
|
39 delete trap; |
|
40 return e; |
|
41 } |
|
42 |
|
43 TRAPD(res, ProgramL(*cons);) |
|
44 if(res!=KErrNone) |
|
45 { |
|
46 cons->Printf(_L("Error %d\n"), res); |
|
47 cons->Printf(_L("Press any key to exit")); |
|
48 cons->Getch(); |
|
49 } |
|
50 |
|
51 delete cons; |
|
52 delete trap; |
|
53 |
|
54 __UHEAP_MARKEND; |
|
55 return KErrNone; |
|
56 } |
|
57 |
|
58 void PrintFeature(CConsoleBase& aCons, TUint& aMask, TUint aFeature, const TDesC& aDes) |
|
59 { |
|
60 if(aMask&aFeature) |
|
61 { |
|
62 aMask&=~aFeature; |
|
63 aCons.Printf(aDes); |
|
64 if(aMask) |
|
65 aCons.Printf(_L(",")); |
|
66 } |
|
67 } |
|
68 |
|
69 void ProgramL(CConsoleBase& aCons) |
|
70 { |
|
71 |
|
72 // User::LeaveIfError(Nifman::CheckIniConfig()); |
|
73 |
|
74 TAutoClose<RSocketServ> ss; |
|
75 User::LeaveIfError(ss.iObj.Connect()); |
|
76 ss.PushL(); |
|
77 |
|
78 TAutoClose<RSocket> sock; |
|
79 User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); |
|
80 sock.PushL(); |
|
81 |
|
82 User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); |
|
83 |
|
84 TProtocolDesc in; |
|
85 User::LeaveIfError(sock.iObj.Info(in)); |
|
86 aCons.Printf(_L("EPOC32 IP Configuration TCPIP Version %d.%d.%d\n\n"), in.iVersion.iMajor, in.iVersion.iMinor, in.iVersion.iBuild); |
|
87 |
|
88 TPckgBuf<TSoInetInterfaceInfo> info, next; |
|
89 |
|
90 TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info); |
|
91 if(res!=KErrNone) |
|
92 User::Leave(res); |
|
93 |
|
94 while(res==KErrNone) |
|
95 { |
|
96 |
|
97 res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next); |
|
98 |
|
99 aCons.Printf(_L(" Interface name \"%S\"\n"), &info().iName); |
|
100 aCons.Printf(_L(" Interface tag \"%S\"\n"), &info().iTag); |
|
101 aCons.Printf(_L(" State ")); |
|
102 switch (info().iState) |
|
103 { |
|
104 case EIfPending: |
|
105 aCons.Printf(_L("pending\n")); |
|
106 break; |
|
107 case EIfUp: |
|
108 aCons.Printf(_L("up\n")); |
|
109 break; |
|
110 case EIfBusy: |
|
111 aCons.Printf(_L("busy\n")); |
|
112 break; |
|
113 default: |
|
114 aCons.Printf(_L("down\n")); |
|
115 break; |
|
116 } |
|
117 |
|
118 aCons.Printf(_L(" Mtu %d\n"), info().iMtu); |
|
119 aCons.Printf(_L(" Speed Metric %d\n"), info().iSpeedMetric); |
|
120 aCons.Printf(_L(" Features ")); |
|
121 |
|
122 TBool hardwareaddr = info().iFeatures&KIfHasHardwareAddr; |
|
123 |
|
124 PrintFeature(aCons, info().iFeatures, KIfIsLoopback, _L("loopback")); |
|
125 PrintFeature(aCons, info().iFeatures, KIfIsDialup, _L("dialup")); |
|
126 PrintFeature(aCons, info().iFeatures, KIfIsPointToPoint, _L("pointtopoint")); |
|
127 PrintFeature(aCons, info().iFeatures, KIfCanBroadcast, _L("canbroadcast")); |
|
128 PrintFeature(aCons, info().iFeatures, KIfCanMulticast, _L("canmulticast")); |
|
129 PrintFeature(aCons, info().iFeatures, KIfCanSetMTU, _L("cansetmtu")); |
|
130 PrintFeature(aCons, info().iFeatures, KIfHasHardwareAddr, _L("hardwareaddr")); |
|
131 PrintFeature(aCons, info().iFeatures, KIfCanSetHardwareAddr, _L("cansethardwareaddr")); |
|
132 aCons.Printf(_L("\n")); |
|
133 |
|
134 TName address; |
|
135 info().iAddress.Output(address); |
|
136 aCons.Printf(_L(" Address %S"), &address); |
|
137 if(info().iAddress.IsLinkLocal()) |
|
138 aCons.Printf(_L(" Link local\n")); |
|
139 else if(info().iAddress.IsSiteLocal()) |
|
140 aCons.Printf(_L(" Site local\n")); |
|
141 else |
|
142 aCons.Printf(_L(" Global\n")); |
|
143 |
|
144 info().iBrdAddr.Output(address); |
|
145 aCons.Printf(_L("Broadcast address %S\n"), &address); |
|
146 info().iDefGate.Output(address); |
|
147 aCons.Printf(_L(" Default gateway %S\n"), &address); |
|
148 info().iNameSer1.Output(address); |
|
149 aCons.Printf(_L(" Primary DNS %S\n"), &address); |
|
150 info().iNameSer2.Output(address); |
|
151 aCons.Printf(_L(" Secondary DNS %S\n"), &address); |
|
152 |
|
153 if(hardwareaddr) |
|
154 { |
|
155 aCons.Printf(_L(" Hardware address ")); |
|
156 TUint j; |
|
157 for(j=sizeof(SSockAddr) ; j<sizeof(SSockAddr)+6 ; ++j) |
|
158 { |
|
159 if(j<(TUint)info().iHwAddr.Length()) |
|
160 aCons.Printf(_L("%02X"), info().iHwAddr[j]); |
|
161 else |
|
162 aCons.Printf(_L("??")); |
|
163 if(j<sizeof(SSockAddr)+5) |
|
164 aCons.Printf(_L("-")); |
|
165 else |
|
166 aCons.Printf(_L("\n")); |
|
167 } |
|
168 } |
|
169 |
|
170 if(res==KErrNone) |
|
171 { |
|
172 info = next; |
|
173 aCons.Printf(_L("\nPress any key for next\n")); |
|
174 } |
|
175 else |
|
176 aCons.Printf(_L("\nPress any key to exit\n")); |
|
177 |
|
178 aCons.Getch(); |
|
179 } |
|
180 |
|
181 sock.Pop(); |
|
182 ss.Pop(); |
|
183 } |