[
https://issues.apache.org/jira/browse/LOG4NET-112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12472360
]
Nicko Cadell commented on LOG4NET-112:
--------------------------------------
Details from an email on the log4net-dev list.
From: Olivier DALET
Subject: 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
> Add support to the UdpAppender for IP v6 remote addresses
> ---------------------------------------------------------
>
> Key: LOG4NET-112
> URL: https://issues.apache.org/jira/browse/LOG4NET-112
> Project: Log4net
> Issue Type: Improvement
> Components: Appenders
> Affects Versions: 1.2.10
> Reporter: Nicko Cadell
> Assigned To: Nicko Cadell
> Priority: Minor
> Fix For: 1.2.11
>
>
> The UdpClient object must be configured for either IP v4 or IP v6 when it is
> created. Once configured it cannot be used to send to remote addresses that
> are from a different network family.
> Specifying the network family is not supported on NET 1.0, NETCF 1.0, SSCLI
> 1.0
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.