View | Details | Raw Unified | Return to bug 194660 | Differences between
and this patch

Collapse All | Expand All

(-)mcs/class/System/System.Net.NetworkInformation/IPInterfaceProperties.cs (-22 / +61 lines)
Lines 27-32 Link Here
27
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
//
28
//
29
using System.Collections.Generic;
29
using System.Collections.Generic;
30
using System.Diagnostics;
30
using System.Globalization;
31
using System.Globalization;
31
using System.IO;
32
using System.IO;
32
using System.Net.Sockets;
33
using System.Net.Sockets;
Lines 77-105 Link Here
77
		void ParseRouteInfo (string iface)
78
		void ParseRouteInfo (string iface)
78
		{
79
		{
79
			try {
80
			try {
80
				gateways = new IPAddressCollection ();
81
				gateways = new IPAddressCollection ();
81
				using (StreamReader reader = new StreamReader ("/proc/net/route")) {
82
				if (File.Exists ("/proc/net/route")) {
82
					string line;
83
					using (StreamReader reader = new StreamReader ("/proc/net/route")) {
83
					reader.ReadLine (); // Ignore first line
84
						string line;
84
					while ((line = reader.ReadLine ()) != null) {
85
						reader.ReadLine (); // Ignore first line
85
						line = line.Trim ();
86
						while ((line = reader.ReadLine ()) != null) {
86
						if (line.Length == 0)
87
							line = line.Trim ();
87
							continue;
88
							if (line.Length == 0)
88
89
								continue;
89
						string [] parts = line.Split ('\t');
90
90
						if (parts.Length < 3)
91
							string [] parts = line.Split ('\t');
91
							continue;
92
							if (parts.Length < 3)
92
						string gw_address = parts [2].Trim ();
93
								continue;
93
						byte [] ipbytes = new byte [4];  
94
							string gw_address = parts [2].Trim ();
94
						if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) {
95
							byte [] ipbytes = new byte [4];
95
							for (int i = 0; i < 4; i++) {
96
							if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) {
96
								if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
97
								for (int i = 0; i < 4; i++) {
97
									continue;
98
									if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
98
							}
99
										continue;
99
							IPAddress ip = new IPAddress (ipbytes);
100
								}
100
							if (!ip.Equals (IPAddress.Any))
101
								IPAddress ip = new IPAddress (ipbytes);
101
								gateways.Add (ip);
102
								if (!ip.Equals (IPAddress.Any))
102
						}
103
									gateways.Add (ip);
104
							}
105
						}
106
					}
107
				} else {
108
					ProcessStartInfo ps = new ProcessStartInfo ("netstat", "-rnW");
109
					ps.UseShellExecute = false;
110
					ps.RedirectStandardOutput = true;
111
					using (Process p = Process.Start (ps)) {
112
						string line;
113
						int iface_part = 0;
114
						int gw_part = 0;
115
						while ((line = p.StandardOutput.ReadLine ()) != null) {
116
							line = line.Trim ();
117
							if (line.Length == 0)
118
								continue;
119
120
							string [] parts = line.Split (new char[0], StringSplitOptions.RemoveEmptyEntries);
121
							if (parts.Length < 6)
122
								continue;
123
124
							if (iface_part == gw_part) {
125
								for (int i = 0; i < parts.Length; i++) {
126
									if (parts[i].Equals ("gateway", StringComparison.OrdinalIgnoreCase))
127
										gw_part = i;
128
									if (parts[i].Equals ("netif", StringComparison.OrdinalIgnoreCase))
129
										iface_part = i;
130
								}
131
							}
132
133
							if (iface.Equals (parts [iface_part], StringComparison.OrdinalIgnoreCase)) {
134
								IPAddress ip;
135
								if (IPAddress.TryParse (parts [gw_part], out ip)) {
136
									if (!ip.Equals (IPAddress.Any))
137
										gateways.Add (ip);
138
								}
139
							}
140
						}
141
						p.WaitForExit ();
103
					}
142
					}
104
				}
143
				}
105
			} catch {
144
			} catch {

Return to bug 194660