Merge pull request #3011 from akoeplinger/ci-fixes
[mono.git] / mcs / class / System / System.Net.NetworkInformation / IPGlobalStatistics.cs
1 //
2 // System.Net.NetworkInformation.IPGlobalProperties
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //      Atsushi Enomoto (atsushi@ximian.com)
7 //
8 // Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 using System.Collections.Specialized;
30 using System.Globalization;
31 using System.Runtime.InteropServices;
32
33 namespace System.Net.NetworkInformation {
34         class MibIPGlobalStatistics : IPGlobalStatistics
35         {
36                 StringDictionary dic;
37
38                 public MibIPGlobalStatistics (StringDictionary dic)
39                 {
40                         this.dic = dic;
41                 }
42
43                 long Get (string name)
44                 {
45                         return dic [name] != null ? long.Parse (dic [name], NumberFormatInfo.InvariantInfo) : 0;
46                 }
47
48                 public override int DefaultTtl {
49                         get { return (int) Get ("DefaultTTL"); }
50                 }
51                 public override bool ForwardingEnabled {
52                         get { return Get ("Forwarding") != 0; }
53                 }
54                 public override int NumberOfInterfaces {
55                         get { return (int) Get ("NumIf"); }
56                 }
57                 public override int NumberOfIPAddresses {
58                         get { return (int) Get ("NumAddr"); }
59                 }
60                 public override int NumberOfRoutes {
61                         get { return (int) Get ("NumRoutes"); }
62                 }
63                 public override long OutputPacketRequests {
64                         get { return Get ("OutRequests"); }
65                 }
66                 public override long OutputPacketRoutingDiscards {
67                         get { return Get ("RoutingDiscards"); }
68                 }
69                 public override long OutputPacketsDiscarded {
70                         get { return Get ("OutDiscards"); }
71                 }
72                 public override long OutputPacketsWithNoRoute {
73                         get { return Get ("OutNoRoutes"); }
74                 }
75                 public override long PacketFragmentFailures {
76                         get { return Get ("FragFails"); }
77                 }
78                 public override long PacketReassembliesRequired {
79                         get { return Get ("ReasmReqds"); }
80                 }
81                 public override long PacketReassemblyFailures {
82                         get { return Get ("ReasmFails"); }
83                 }
84                 public override long PacketReassemblyTimeout {
85                         get { return Get ("ReasmTimeout"); }
86                 }
87                 public override long PacketsFragmented {
88                         get { return Get ("FragOks"); }
89                 }
90                 public override long PacketsReassembled {
91                         get { return Get ("ReasmOks"); }
92                 }
93                 public override long ReceivedPackets {
94                         get { return Get ("InReceives"); }
95                 }
96                 public override long ReceivedPacketsDelivered {
97                         get { return Get ("InDelivers"); }
98                 }
99                 public override long ReceivedPacketsDiscarded {
100                         get { return Get ("InDiscards"); }
101                 }
102                 public override long ReceivedPacketsForwarded {
103                         get { return Get ("ForwDatagrams"); }
104                 }
105                 public override long ReceivedPacketsWithAddressErrors {
106                         get { return Get ("InAddrErrors"); }
107                 }
108                 public override long ReceivedPacketsWithHeadersErrors {
109                         get { return Get ("InHdrErrors"); }
110                 }
111                 public override long ReceivedPacketsWithUnknownProtocol {
112                         get { return Get ("InUnknownProtos"); }
113                 }
114         }
115
116 #if !MOBILE
117         class Win32IPGlobalStatistics : IPGlobalStatistics 
118         {
119                 Win32_MIB_IPSTATS info;
120
121                 public Win32IPGlobalStatistics (Win32_MIB_IPSTATS info)
122                 {
123                         this.info = info;
124                 }
125
126                 public override int DefaultTtl {
127                         get { return info.DefaultTTL; }
128                 }
129                 public override bool ForwardingEnabled {
130                         get { return info.Forwarding != 0; }
131                 }
132                 public override int NumberOfInterfaces {
133                         get { return info.NumIf; }
134                 }
135                 public override int NumberOfIPAddresses {
136                         get { return info.NumAddr; }
137                 }
138                 public override int NumberOfRoutes {
139                         get { return info.NumRoutes; }
140                 }
141                 public override long OutputPacketRequests {
142                         get { return info.OutRequests; }
143                 }
144                 public override long OutputPacketRoutingDiscards {
145                         get { return info.RoutingDiscards; }
146                 }
147                 public override long OutputPacketsDiscarded {
148                         get { return info.OutDiscards; }
149                 }
150                 public override long OutputPacketsWithNoRoute {
151                         get { return info.OutNoRoutes; }
152                 }
153                 public override long PacketFragmentFailures {
154                         get { return info.FragFails; }
155                 }
156                 public override long PacketReassembliesRequired {
157                         get { return info.ReasmReqds; }
158                 }
159                 public override long PacketReassemblyFailures {
160                         get { return info.ReasmFails; }
161                 }
162                 public override long PacketReassemblyTimeout {
163                         get { return info.ReasmTimeout; }
164                 }
165                 public override long PacketsFragmented {
166                         get { return info.FragOks; }
167                 }
168                 public override long PacketsReassembled {
169                         get { return info.ReasmOks; }
170                 }
171                 public override long ReceivedPackets {
172                         get { return info.InReceives; }
173                 }
174                 public override long ReceivedPacketsDelivered {
175                         get { return info.InDelivers; }
176                 }
177                 public override long ReceivedPacketsDiscarded {
178                         get { return info.InDiscards; }
179                 }
180                 public override long ReceivedPacketsForwarded {
181                         get { return info.ForwDatagrams; }
182                 }
183                 public override long ReceivedPacketsWithAddressErrors {
184                         get { return info.InAddrErrors; }
185                 }
186                 public override long ReceivedPacketsWithHeadersErrors {
187                         get { return info.InHdrErrors; }
188                 }
189                 public override long ReceivedPacketsWithUnknownProtocol {
190                         get { return info.InUnknownProtos; }
191                 }
192         }
193         
194         [StructLayout (LayoutKind.Sequential)]
195         struct Win32_MIB_IPSTATS
196         {
197                 public int Forwarding;
198                 public int DefaultTTL;
199                 public uint InReceives;
200                 public uint InHdrErrors;
201                 public uint InAddrErrors;
202                 public uint ForwDatagrams;
203                 public uint InUnknownProtos;
204                 public uint InDiscards;
205                 public uint InDelivers;
206                 public uint OutRequests;
207                 public uint RoutingDiscards;
208                 public uint OutDiscards;
209                 public uint OutNoRoutes;
210                 public uint ReasmTimeout;
211                 public uint ReasmReqds;
212                 public uint ReasmOks;
213                 public uint ReasmFails;
214                 public uint FragOks;
215                 public uint FragFails;
216                 public uint FragCreates;
217                 public int NumIf;
218                 public int NumAddr;
219                 public int NumRoutes;
220         }
221 #endif
222 }
223