From 241916bca2c297b78896c453e514a1208e17d416 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:55:36 +0000 Subject: Utilisateur : Fcolin Date : 7/02/06 Heure : 16:54 Archivé dans $/CSharp/Ivy/IvyPPC Commentaire: (vss 50) --- CSharp/Ivy/IvyPPC/Ivy.cs | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'CSharp') diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index 9ab06d7..cc4dd5f 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -397,25 +397,18 @@ namespace IvyBus /// public void start(string domainbus) { - int ndx = 0; - IPAddress localaddr; domainbus = getDomain(domainbus); try { - //TODO remove ALL reverse DNS search !!!! - //TODO possible bug applicationhost = 127.0.0.1 and not IP - do - { - localaddr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[ndx++]; - } while (IPAddress.IsLoopback(localaddr)); app = new MyTcpListener(IPAddress.Any, 0); - applicationPort = (ushort)((IPEndPoint) app.LocalEndpoint).Port; - applicationHost = localaddr; - applicationUniqueId = string.Format("{0}-{1}-{2}", + app.Start(); // should be started before getting port + applicationHost = getLocalIP(); + applicationPort = (ushort)((IPEndPoint)app.LocalEndpoint).Port; + applicationUniqueId = string.Format("{0}-{1}-{2}", DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, - localaddr.ToString().Replace(".",""), + applicationHost.ToString().Replace(".",""), applicationPort ); - app.Start(); + } catch (IOException e) { @@ -842,12 +835,33 @@ namespace IvyBus syncControl.Invoke(bind.callback, new object[] { client, arg }); else bind.callback(client, arg); } - + public static IPAddress getLocalIP() + { + IPAddress returnaddr = null; + //TODO remove ALL reverse DNS search !!!! + IPHostEntry ip = Dns.GetHostEntry(Dns.GetHostName()); + foreach (IPAddress addr in ip.AddressList) + { + returnaddr = addr; + if (IPAddress.IsLoopback(addr)) continue; + break; + } + return returnaddr; + } public static string getDomain(string domainbus) { - //TODO pocket PC BUS default ????? -#if (!PocketPC) +#if (PocketPC) + if (domainbus == null || domainbus.Length == 0) + { + IPAddress addr = getLocalIP(); + //TODO Find Braodcast addr from IP; + byte[] bytes = addr.GetAddressBytes(); + bytes[3] = 255; + IPAddress bcast = new IPAddress( bytes ); + domainbus = bcast + ":" + DEFAULT_PORT; + } +#else if (domainbus == null || domainbus.Length == 0 ) { domainbus = Environment.GetEnvironmentVariable("IVYBUS"); @@ -857,7 +871,7 @@ namespace IvyBus { domainbus = Properties.Settings.Default.IvyBus; } -#endif +#endif if (domainbus == null || domainbus.Length == 0) domainbus = DEFAULT_DOMAIN; return domainbus; -- cgit v1.1