1ff5a5598e00c33b59a168cd71dc1d02ae7fb3c4
[mono.git] / mcs / class / referencesource / System / net / System / Net / NetworkInformation / SystemTcpConnection.cs
1
2
3 namespace System.Net.NetworkInformation {
4
5     using System.Net;
6     using System.Net.Sockets;
7     using System.Security.Permissions;
8     using System;
9     using System.Runtime.InteropServices;
10     using System.Collections;
11     using System.ComponentModel;
12     using System.Threading;
13
14    
15
16
17     /// <summary>
18     /// Represents an active Tcp connection.</summary>
19     internal class SystemTcpConnectionInformation:TcpConnectionInformation {
20         IPEndPoint localEndPoint;
21         IPEndPoint remoteEndPoint;
22         TcpState state;
23
24         internal SystemTcpConnectionInformation(MibTcpRow row) {
25             state = row.state;
26
27             //port is returned in Big-Endian - most significant bit on left
28             //unfortunately, its done at the word level and not the dword level.
29
30             int localPort = row.localPort1<<8|row.localPort2;
31             int remotePort = ((state == TcpState.Listen)?0:row.remotePort1<<8|row.remotePort2);
32
33             localEndPoint = new IPEndPoint(row.localAddr,(int)localPort);
34             remoteEndPoint= new IPEndPoint(row.remoteAddr,(int)remotePort);
35         }
36
37         // IPV6 version of the Tcp row 
38         internal SystemTcpConnectionInformation(MibTcp6RowOwnerPid row) {
39             state = row.state;
40
41             //port is returned in Big-Endian - most significant bit on left
42             //unfortunately, its done at the word level and not the dword level.
43             
44             int localPort = row.localPort1 << 8 | row.localPort2;
45             int remotePort = ((state == TcpState.Listen) ? 0 : row.remotePort1 << 8 | row.remotePort2);
46
47             localEndPoint = new IPEndPoint(new IPAddress(row.localAddr, row.localScopeId), (int)localPort);
48             remoteEndPoint = new IPEndPoint(new IPAddress(row.remoteAddr, row.remoteScopeId), (int)remotePort);
49         }
50
51
52         public override TcpState State{get {return state;}}
53         public override IPEndPoint LocalEndPoint{get {return localEndPoint;}}
54         public override IPEndPoint RemoteEndPoint{get {return remoteEndPoint;}}
55     }
56  }
57