Merge pull request #4248 from Unity-Technologies/boehm-gc-alloc-fixed
[mono.git] / mcs / class / System / System.Net.NetworkInformation / IPv4InterfaceStatistics.cs
1 //
2 // System.Net.NetworkInformation.IPv4InterfaceStatistics
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //      Atsushi Enomoto (atsushi@ximian.com)
7 //      Miguel de Icaza (miguel@ximian.com)
8 //
9 // Copyright (c) 2006-2008 Novell, Inc. (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 namespace System.Net.NetworkInformation {
31 #if WIN_PLATFORM
32         class Win32IPv4InterfaceStatistics : IPv4InterfaceStatistics
33         {
34                 Win32_MIB_IFROW info;
35
36                 public Win32IPv4InterfaceStatistics (Win32_MIB_IFROW info)
37                 {
38                         this.info = info;
39                 }
40
41                 public override long BytesReceived {
42                         get { return info.InOctets; }
43                 }
44
45                 public override long BytesSent {
46                         get { return info.OutOctets; }
47                 }
48
49                 public override long IncomingPacketsDiscarded {
50                         get { return info.InDiscards; }
51                 }
52
53                 public override long IncomingPacketsWithErrors {
54                         get { return info.InErrors; }
55                 }
56
57                 public override long IncomingUnknownProtocolPackets {
58                         get { return info.InUnknownProtos; }
59                 }
60
61                 public override long NonUnicastPacketsReceived {
62                         get { return info.InNUcastPkts; }
63                 }
64
65                 public override long NonUnicastPacketsSent {
66                         get { return info.OutNUcastPkts; }
67                 }
68
69                 public override long OutgoingPacketsDiscarded {
70                         get { return info.OutDiscards; }
71                 }
72
73                 public override long OutgoingPacketsWithErrors {
74                         get { return info.OutErrors; }
75                 }
76
77                 public override long OutputQueueLength {
78                         get { return info.OutQLen; }
79                 }
80
81                 public override long UnicastPacketsReceived {
82                         get { return info.InUcastPkts; }
83                 }
84
85                 public override long UnicastPacketsSent {
86                         get { return info.OutUcastPkts; }
87                 }
88         
89         }
90 #endif
91
92         class LinuxIPv4InterfaceStatistics : IPv4InterfaceStatistics
93         {
94                 LinuxNetworkInterface linux;
95                 
96                 public LinuxIPv4InterfaceStatistics (LinuxNetworkInterface parent)
97                 {
98                         linux = parent;
99                 }
100
101                 long Read (string file)
102                 {
103                         try {
104                                 return long.Parse (LinuxNetworkInterface.ReadLine (linux.IfacePath + file));
105                         } catch {
106                                 return 0;
107                         }
108                 }
109                 
110                 public override long BytesReceived {
111                         get {
112                                 return Read ("statistics/rx_bytes");
113                         }
114                 }
115
116                 public override long BytesSent {
117                         get {
118                                 return Read ("statistics/tx_bytes");
119                         }
120                 }
121
122                 public override long IncomingPacketsDiscarded {
123                         get {
124                                 return Read ("statistics/rx_dropped");
125                         }
126                 }
127
128                 public override long IncomingPacketsWithErrors {
129                         get {
130                                 return Read ("statistics/rx_errors");
131                         }
132                 }
133
134                 public override long IncomingUnknownProtocolPackets {
135                         get {
136                                 // TODO
137                                 return 0;
138                         }
139                 }
140
141                 public override long NonUnicastPacketsReceived {
142                         get {
143                                 // We cant distinguish these
144                                 return Read ("statistics/multicast");
145                         }
146                 }
147
148                 public override long NonUnicastPacketsSent {
149                         get {
150                                 // We cant distinguish these
151                                 return Read ("statistics/multicast");
152                         }
153                 }
154
155                 public override long OutgoingPacketsDiscarded {
156                         get {
157                                 return Read ("statistics/tx_dropped");
158                         }
159                 }
160
161                 public override long OutgoingPacketsWithErrors {
162                         get {
163                                 return Read ("statistics/tx_errors");
164                         }
165                 }
166
167                 public override long OutputQueueLength {
168                         get {
169                                 return 1024;
170                         }
171                 }
172
173                 public override long UnicastPacketsReceived {
174                         get {
175                                 return Read ("statistics/rx_packets");
176                         }
177                 }
178
179                 public override long UnicastPacketsSent {
180                         get {
181                                 return Read ("statistics/tx_packets");
182                         }
183                 }
184         }
185
186         // dummy class
187         class MacOsIPv4InterfaceStatistics : IPv4InterfaceStatistics
188         {
189                 //MacOsNetworkInterface macos;
190                 
191                 public MacOsIPv4InterfaceStatistics (MacOsNetworkInterface parent)
192                 {
193                         //macos = parent;
194                 }
195
196                 public override long BytesReceived {
197                         get { return 0; }
198                 }
199
200                 public override long BytesSent {
201                         get { return 0; }
202                 }
203
204                 public override long IncomingPacketsDiscarded {
205                         get { return 0; }
206                 }
207
208                 public override long IncomingPacketsWithErrors {
209                         get { return 0; }
210                 }
211
212                 public override long IncomingUnknownProtocolPackets {
213                         get { return 0; }
214                 }
215
216                 public override long NonUnicastPacketsReceived {
217                         get { return 0; }
218                 }
219
220                 public override long NonUnicastPacketsSent {
221                         get { return 0; }
222                 }
223
224                 public override long OutgoingPacketsDiscarded {
225                         get { return 0; }
226                 }
227
228                 public override long OutgoingPacketsWithErrors {
229                         get { return 0; }
230                 }
231
232                 public override long OutputQueueLength {
233                         get { return 0; }
234                 }
235
236                 public override long UnicastPacketsReceived {
237                         get { return 0; }
238                 }
239
240                 public override long UnicastPacketsSent {
241                         get { return 0; }
242                 }
243         }
244         
245 }
246