FreeBSD Bugzilla – Attachment 148734 Details for
Bug 194660
lang/mono Add mono/metadata/mono-route.c for non-Linux ParseRouteInfo_local
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Use netstat to get routes if no /proc/net/route
patch-mcs__class__System__System.Net.NetworkInformation__IPInterfaceProperties.cs (text/plain), 3.53 KB, created by
Ben Woods
on 2014-10-28 13:48:13 UTC
(
hide
)
Description:
Use netstat to get routes if no /proc/net/route
Filename:
MIME Type:
Creator:
Ben Woods
Created:
2014-10-28 13:48:13 UTC
Size:
3.53 KB
patch
obsolete
>--- mcs/class/System/System.Net.NetworkInformation/IPInterfaceProperties.cs.orig 2014-09-25 21:31:42.717533580 +0800 >+++ mcs/class/System/System.Net.NetworkInformation/IPInterfaceProperties.cs 2014-09-25 21:49:47.154529125 +0800 >@@ -27,6 +27,7 @@ > // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. > // > using System.Collections.Generic; >+using System.Diagnostics; > using System.Globalization; > using System.IO; > using System.Net.Sockets; >@@ -77,29 +78,67 @@ > void ParseRouteInfo (string iface) > { > try { >- gateways = new IPAddressCollection (); >- using (StreamReader reader = new StreamReader ("/proc/net/route")) { >- string line; >- reader.ReadLine (); // Ignore first line >- while ((line = reader.ReadLine ()) != null) { >- line = line.Trim (); >- if (line.Length == 0) >- continue; >- >- string [] parts = line.Split ('\t'); >- if (parts.Length < 3) >- continue; >- string gw_address = parts [2].Trim (); >- byte [] ipbytes = new byte [4]; >- if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) { >- for (int i = 0; i < 4; i++) { >- if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i])) >- continue; >- } >- IPAddress ip = new IPAddress (ipbytes); >- if (!ip.Equals (IPAddress.Any)) >- gateways.Add (ip); >- } >+ if (File.Exists ("/proc/net/route")) { >+ gateways = new IPAddressCollection (); >+ using (StreamReader reader = new StreamReader ("/proc/net/route")) { >+ string line; >+ reader.ReadLine (); // Ignore first line >+ while ((line = reader.ReadLine ()) != null) { >+ line = line.Trim (); >+ if (line.Length == 0) >+ continue; >+ >+ string [] parts = line.Split ('\t'); >+ if (parts.Length < 3) >+ continue; >+ string gw_address = parts [2].Trim (); >+ byte [] ipbytes = new byte [4]; >+ if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) { >+ for (int i = 0; i < 4; i++) { >+ if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i])) >+ continue; >+ } >+ IPAddress ip = new IPAddress (ipbytes); >+ if (!ip.Equals (IPAddress.Any)) >+ gateways.Add (ip); >+ } >+ } >+ } >+ } else { >+ ProcessStartInfo ps = new ProcessStartInfo ("netstat", "-rnW"); >+ ps.UseShellExecute = false; >+ ps.RedirectStandardOutput = true; >+ using (Process p = Process.Start (ps)) { >+ string line; >+ int iface_part = 0; >+ int gw_part = 0; >+ while ((line = p.StandardOutput.ReadLine ()) != null) { >+ line = line.Trim (); >+ if (line.Length == 0) >+ continue; >+ >+ string [] parts = line.Split (new char[0], StringSplitOptions.RemoveEmptyEntries); >+ if (parts.Length < 6) >+ continue; >+ >+ if (iface_part == gw_part) { >+ for (int i = 0; i < parts.Length; i++) { >+ if (parts[i].Equals ("gateway", StringComparison.OrdinalIgnoreCase)) >+ gw_part = i; >+ if (parts[i].Equals ("netif", StringComparison.OrdinalIgnoreCase)) >+ iface_part = i; >+ } >+ } >+ >+ if (iface.Equals (parts [iface_part], StringComparison.OrdinalIgnoreCase)) { >+ IPAddress ip; >+ if (IPAddress.TryParse (parts [gw_part], out ip)) { >+ if (!ip.Equals (IPAddress.Any)) >+ gateways.Add (ip); >+ } >+ } >+ } >+ p.WaitForExit (); > } > } > } catch {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 194660
:
148734
|
149029
|
149451
|
149452
|
149739
|
150260