You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Olivier DALET <od...@gmail.com> on 2007/01/13 01:35:58 UTC
BUG REPORT : IP Address parsing (.NET 2.0 and log4net 1.2.10) causes UdpAppender to crash
Hi,
I've detected a bug in IPAddressConverter.ConvertFrom
(log4net-1.2.10\src\Util\TypeConverters\IPAddressConverter.cs):
If compiled with .NET framework 2.0, the IP is resolved via dns using this code:
IPHostEntry host = Dns.GetHostEntry(str);
then the first address in the host.AddressList array is returned.
When executed on my computer, this array contains the following items:
+ [0] {::1} System.Net.IPAddress
+ [1] {192.168.0.2 } System.Net.IPAddress
+ [2] {192.168.206.1} System.Net.IPAddress
+ [3] {192.168.114.1} System.Net.IPAddress
So, with the existing code, the address ::1 is selected... and the
UdpAppender throws an Exception :-(
log4net:ERROR [UdpAppender] Unable to send logging event to remote
host ::1 on port 1234.
System.Net.Sockets.SocketException : Une adresse incompatible avec le
protocole demandé a été utilisée (*)
à System.Net.Sockets.Socket.SendTo(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
à System.Net.Sockets.UdpClient.Send (Byte[] dgram, Int32 bytes,
IPEndPoint endPoint)
à log4net.Appender.UdpAppender.Append(LoggingEvent loggingEvent)
To avoid this:
- first I added this property to IPAddressConverter:
public bool IsIPv6Supported { get { return false; } }
note that I'm not networking aware, and thus this may be replaced by
some code able to detect wether or not IP v6 is supported...
- then I replaced "return host.AddressList[0];" with:
foreach (IPAddress address in host.AddressList)
{
if ((address.AddressFamily ==
System.Net.Sockets.AddressFamily.InterNetworkV6) && !IsIPv6Supported)
continue;
return address;
}
This way, I return the first IPv4 address.
Hope this helps
(*) aproximatively translated from French into English: The used
address is incompatible with the requested protocol
PS: log4net is really fantastic a library. I knew it existed for a
long time but am just using it for a few months. I love it.
--
Olivier DALET
---------------------------------
http://odalet.wordpress.com
http://aspadvice.com/blogs/oliviers_net_blog