Author: kumpera
Date: 2007-07-10 16:49:55 -0400 (Tue, 10 Jul 2007)
New Revision: 81743
Modified:
trunk/moon/desklet/glassymonitor/ChangeLog
trunk/moon/desklet/glassymonitor/monitor.cs
Log:
2007-07-10 Rodrigo Kumpera <[EMAIL PROTECTED]>
* monitor.cs: add patch from Silvio Gissi to select the interface with
lower metric
Modified: trunk/moon/desklet/glassymonitor/ChangeLog
===================================================================
--- trunk/moon/desklet/glassymonitor/ChangeLog 2007-07-10 20:38:52 UTC (rev
81742)
+++ trunk/moon/desklet/glassymonitor/ChangeLog 2007-07-10 20:49:55 UTC (rev
81743)
@@ -1,3 +1,7 @@
+2007-07-10 Rodrigo Kumpera <[EMAIL PROTECTED]>
+
+ * monitor.cs: add patch from Silvio Gissi to select the interface with
lower metric
+
2007-06-27 Everaldo Canuto <[EMAIL PROTECTED]>
* deafult.html: Adjust desklet width to same calendar width.
Modified: trunk/moon/desklet/glassymonitor/monitor.cs
===================================================================
--- trunk/moon/desklet/glassymonitor/monitor.cs 2007-07-10 20:38:52 UTC (rev
81742)
+++ trunk/moon/desklet/glassymonitor/monitor.cs 2007-07-10 20:49:55 UTC (rev
81743)
@@ -23,7 +23,7 @@
public class Monitor : Canvas
{
// TODO: use eth0 for now, later we must have a place to select
it.
- string device = "eth0";
+ string device = GetActiveInterface();
Storyboard storyboard;
TextBlock device_text;
@@ -34,7 +34,28 @@
Brush buttonHilite = new SolidColorBrush (Color.FromArgb (0xAA,
0xFF, 0xFF, 0xFF));
Brush buttonNormal = new SolidColorBrush (Color.FromArgb (0x66,
0xFF, 0xFF, 0xFF));
-
+
+ static string GetActiveInterface()
+ {
+ string iface="eth0";
+ using (StreamReader sr = new StreamReader ("/proc/net/route")) {
+ string line;
+ int cur_metric=Int32.MaxValue;
+ // Ignore first line
+ sr.ReadLine();
+
+ while ((line = sr.ReadLine()) != null) {
+ String[] pieces = line.Split (new char[]
{'\t'});
+ int m = Int32.Parse(pieces[6]);
+ if ( (pieces[1] == "00000000") && (m <
cur_metric) ) {
+ iface=pieces[0];
+ cur_metric=m;
+ }
+ }
+ }
+ return iface;
+ }
+
public void UpdateInfo (object o, EventArgs e)
{
using (StreamReader sr = new StreamReader
("/proc/net/dev")) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches