Merge pull request #3011 from akoeplinger/ci-fixes
[mono.git] / mcs / class / System / System.Net.NetworkInformation / TcpStatistics.cs
1 //
2 // System.Net.NetworkInformation.TcpStatistics
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
32 namespace System.Net.NetworkInformation {
33         class MibTcpStatistics : TcpStatistics
34         {
35                 StringDictionary dic;
36
37                 public MibTcpStatistics (StringDictionary dic)
38                 {
39                         this.dic = dic;
40                 }
41
42                 long Get (string name)
43                 {
44                         return dic [name] != null ? long.Parse (dic [name], NumberFormatInfo.InvariantInfo) : 0;
45                 }
46
47                 public override long ConnectionsAccepted {
48                         get { return Get ("PassiveOpens"); }
49                 }
50                 public override long ConnectionsInitiated {
51                         get { return Get ("ActiveOpens"); }
52                 }
53                 public override long CumulativeConnections {
54                         get { return Get ("NumConns"); }
55                 }
56                 public override long CurrentConnections {
57                         get { return Get ("CurrEstab"); }
58                 }
59                 public override long ErrorsReceived {
60                         get { return Get ("InErrs"); }
61                 }
62                 public override long FailedConnectionAttempts {
63                         get { return Get ("AttemptFails"); }
64                 }
65                 public override long MaximumConnections {
66                         get { return Get ("MaxConn"); }
67                 }
68                 public override long MaximumTransmissionTimeout {
69                         get { return Get ("RtoMax"); }
70                 }
71                 public override long MinimumTransmissionTimeout {
72                         get { return Get ("RtoMin"); }
73                 }
74                 public override long ResetConnections {
75                         get { return Get ("EstabResets"); }
76                 }
77                 public override long ResetsSent {
78                         get { return Get ("OutRsts"); }
79                 }
80                 public override long SegmentsReceived {
81                         get { return Get ("InSegs"); }
82                 }
83                 public override long SegmentsResent {
84                         get { return Get ("RetransSegs"); }
85                 }
86                 public override long SegmentsSent {
87                         get { return Get ("OutSegs"); }
88                 }
89         }
90
91 #if !MOBILE
92         class Win32TcpStatistics : TcpStatistics
93         {
94                 Win32_MIB_TCPSTATS info;
95
96                 public Win32TcpStatistics (Win32_MIB_TCPSTATS info)
97                 {
98                         this.info = info;
99                 }
100
101                 public override long ConnectionsAccepted {
102                         get { return info.PassiveOpens; }
103                 }
104
105                 public override long ConnectionsInitiated {
106                         get { return info.ActiveOpens; }
107                 }
108
109                 public override long CumulativeConnections {
110                         get { return info.NumConns; }
111                 }
112
113                 public override long CurrentConnections {
114                         get { return info.CurrEstab; }
115                 }
116
117                 public override long ErrorsReceived {
118                         get { return info.InErrs; }
119                 }
120
121                 public override long FailedConnectionAttempts {
122                         get { return info.AttemptFails; }
123                 }
124
125                 public override long MaximumConnections {
126                         get { return info.MaxConn; }
127                 }
128
129                 public override long MaximumTransmissionTimeout {
130                         get { return info.RtoMax; }
131                 }
132
133                 public override long MinimumTransmissionTimeout {
134                         get { return info.RtoMin; }
135                 }
136
137                 public override long ResetConnections {
138                         get { return info.EstabResets; }
139                 }
140
141                 public override long ResetsSent {
142                         get { return info.OutRsts; }
143                 }
144
145                 public override long SegmentsReceived {
146                         get { return info.InSegs; }
147                 }
148
149                 public override long SegmentsResent {
150                         get { return info.RetransSegs; }
151                 }
152
153                 public override long SegmentsSent {
154                         get { return info.OutSegs; }
155                 }
156         }
157
158         struct Win32_MIB_TCPSTATS
159         {
160                 public uint RtoAlgorithm;
161                 public uint RtoMin;
162                 public uint RtoMax;
163                 public uint MaxConn;
164                 public uint ActiveOpens;
165                 public uint PassiveOpens;
166                 public uint AttemptFails;
167                 public uint EstabResets;
168                 public uint CurrEstab;
169                 public uint InSegs;
170                 public uint OutSegs;
171                 public uint RetransSegs;
172                 public uint InErrs;
173                 public uint OutRsts;
174                 public uint NumConns;
175         }
176 #endif
177 }
178