Code Coverage by Clover.NET

IPV6-Bug

View: New views
1 Messages — Rating Filter:   Alert me  

IPV6-Bug

by Ruben-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I got an error while trying to log to chainsaw or nlog-viewer; I have
some IPV6-stuff on my system, that apparently confuses the
NLog.Internal.NetworkSenders.TcpNetworkSender:

When connectiong to localhost, the Dns.GetHostEntry-AddressList has on
index 0 an wired entry (::1) that can't be used to connect to the
network-logger.

I atteched a patch that was manly inspired by
http://odalet.wordpress.com/2007/01/

This patch solves the problem and should not conflict with other
network-configurations...

Tschö
    Ruben


Index: src/NLog/Internal/NetworkSenders/TcpNetworkSender.cs
===================================================================
--- src/NLog/Internal/NetworkSenders/TcpNetworkSender.cs (revision 507)
+++ src/NLog/Internal/NetworkSenders/TcpNetworkSender.cs (working copy)
@@ -46,6 +46,14 @@
         private Socket _socket;
 
         /// <summary>
+        /// Gets a value indicating whether this instance supports IPV6.
+        /// </summary>
+        /// <value>
+        /// <c>true</c> if this instance supports IPV6; otherwise, <c>false</c>.
+        /// </value>
+        public bool IsIPv6Supported { get { return false; } }
+
+        /// <summary>
         /// Creates a new instance of <see cref="TcpNetworkSender"/> and initializes
         /// it with the specified URL. Connects to the server specified in the URL.
         /// </summary>
@@ -62,12 +70,23 @@
 #endif
             int port = parsedUri.Port;
 
+            //IPAddress address = host.AddressList[0];
+
+            foreach (IPAddress address in host.AddressList)
+            {
+                if ((address.AddressFamily ==
+                    System.Net.Sockets.AddressFamily.InterNetworkV6) &&
+                    !IsIPv6Supported)
+                    continue;
 #if NETCF_1_0
-            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 #else
-            _socket = new Socket(host.AddressList[0].AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+                _socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 #endif
-            _socket.Connect(new IPEndPoint(host.AddressList[0], port));
+                _socket.Connect(new IPEndPoint(address, port));
+
+                return;
+            }
         }
 
         /// <summary>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nlog-list mailing list
Nlog-list@...
https://lists.sourceforge.net/lists/listinfo/nlog-list
LightInTheBox - Buy quality products at wholesale price