Log4net
  1. Log4net
  2. LOG4NET-100

IPAddressConverter improvement for .NET 2 or .NET 3

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.10
    • Fix Version/s: 1.2.11
    • Component/s: Other
    • Labels:
      None
    • Environment:
      .NET 2.0 or .NET 3.0

      Description

      log4net.Util.TypeConverters.IPAddressConverter uses only DNS query to get the IP address.
      But it may not convert an IP-address text properly especially on .NET 3.0.
      (Try Dns.GetHostEntry("127.0.0.1") on Vista. It returns some IPv4 and IPv6 addresses.)

      If you want to convert IP-address text directly, you should use IPAddress.Parse() or IPAddress.TryParse().
      You can also use Dns.GetHostAddresses(). It converts IP address properly.
      It would be better on .NET3. In .NET2, it seems not recognize IPv6 address.

      Here is a patch.

      ===================================================================
      — IPAddressConverter.cs (revision 468656)
      +++ IPAddressConverter.cs (working copy)
      @@ -77,8 +77,12 @@
      try
      {
      #if NET_2_0
      + // Try to parse the string as an IP address.
      + IPAddress addr;
      + if (IPAddress.TryParse(str, out addr))
      + return addr;
      +
      // Try to resolve via DNS. This is a blocking call.

      • // GetHostEntry works with either an IPAddress string or a host name
        IPHostEntry host = Dns.GetHostEntry(str);
        if (host != null &&
        host.AddressList != null &&

        Activity

        Iwasa Kazmi created issue -
        Iwasa Kazmi made changes -
        Field Original Value New Value
        Attachment IPAddressConverter.patch [ 12343830 ]
        Iwasa Kazmi made changes -
        Description log4net.Util.TypeConverters.IPAddressConverter uses only DNS query to get the IP address.
        But it may not convert an IP-address text properly especially on .NET 3.0.
        (Try Dns.GetHostEntry("127.0.0.1") on Vista. It returns some IPv4 and IPv6 addresses.)

        If you want to convert IP-address text directly, you should use IPAddress.Parse() or IPAddress.TryParse().
        Here is a patch.

        ===================================================================
        --- IPAddressConverter.cs (revision 468656)
        +++ IPAddressConverter.cs (working copy)
        @@ -77,8 +77,12 @@
          try
          {
         #if NET_2_0
        + // Try to parse the string as an IP address.
        + IPAddress addr;
        + if (IPAddress.TryParse(str, out addr))
        + return addr;
        +
          // Try to resolve via DNS. This is a blocking call.
        - // GetHostEntry works with either an IPAddress string or a host name
          IPHostEntry host = Dns.GetHostEntry(str);
          if (host != null &&
          host.AddressList != null &&
        log4net.Util.TypeConverters.IPAddressConverter uses only DNS query to get the IP address.
        But it may not convert an IP-address text properly especially on .NET 3.0.
        (Try Dns.GetHostEntry("127.0.0.1") on Vista. It returns some IPv4 and IPv6 addresses.)

        If you want to convert IP-address text directly, you should use IPAddress.Parse() or IPAddress.TryParse().
        You can also use Dns.GetHostAddresses(). It converts IP address properly.
        It would be better on .NET3. In .NET2, it seems not recognize IPv6 address.

        Here is a patch.

        ===================================================================
        --- IPAddressConverter.cs (revision 468656)
        +++ IPAddressConverter.cs (working copy)
        @@ -77,8 +77,12 @@
          try
          {
         #if NET_2_0
        + // Try to parse the string as an IP address.
        + IPAddress addr;
        + if (IPAddress.TryParse(str, out addr))
        + return addr;
        +
          // Try to resolve via DNS. This is a blocking call.
        - // GetHostEntry works with either an IPAddress string or a host name
          IPHostEntry host = Dns.GetHostEntry(str);
          if (host != null &&
          host.AddressList != null &&
        Nicko Cadell made changes -
        Affects Version/s 1.2.11 [ 12310980 ]
        Hide
        Nicko Cadell added a comment -

        Added code to IPAddressConverter to explicitly try to convert the string into an IPAddress before trying to resolve it via DNS. This should have perfromance improvments for values specified as IP Addresses.

        Show
        Nicko Cadell added a comment - Added code to IPAddressConverter to explicitly try to convert the string into an IPAddress before trying to resolve it via DNS. This should have perfromance improvments for values specified as IP Addresses.
        Nicko Cadell made changes -
        Assignee Nicko Cadell [ nicko ]
        Fix Version/s 1.2.11 [ 12310980 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        107d 9h 34m 1 Nicko Cadell 12/Feb/07 17:55

          People

          • Assignee:
            Nicko Cadell
            Reporter:
            Iwasa Kazmi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development