IPAddress creation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MG

    IPAddress creation

    Hello,

    I try to create IPAddress object from array of bytes and it always throws
    exception,
    even when array of bytes is taken from proper IPAddress object:

    IPAddress lAddress=IPAddr ess.Parse("1.2. 3.4");
    byte[] lBytes=lAddress .GetAddressByte s();
    IPAddress lNewAddress=new IPAddress(lByte s);

    Has anyone encountered the problem?
    Am I doing something wrong ??
    (Im usingFramework 1.1)



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: IPAddress creation

    MG,

    What is the exception that is thrown? Also, what are the contents of
    the byte array that you are passing in? You should have a 16-element byte
    array. The reason for this is to account for the fact that IP addresses are
    being widened at some point in time.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "MG" <mgruber@elka.p w.edu.pl> wrote in message
    news:%23Fwvb3eq DHA.2064@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > Hello,
    >
    > I try to create IPAddress object from array of bytes and it always throws
    > exception,
    > even when array of bytes is taken from proper IPAddress object:
    >
    > IPAddress lAddress=IPAddr ess.Parse("1.2. 3.4");
    > byte[] lBytes=lAddress .GetAddressByte s();
    > IPAddress lNewAddress=new IPAddress(lByte s);
    >
    > Has anyone encountered the problem?
    > Am I doing something wrong ??
    > (Im usingFramework 1.1)
    >
    >
    >[/color]


    Comment

    • MG

      #3
      Re: IPAddress creation

      Nicholas,

      Thanks for help - passing array with 16 elements works.
      Is there any info about this topic - I looked at online MSDN at

      but found no info on format of the passed array.

      Thought that GetAddressBytes () method returns data that is sufficient to
      create another object.
      I will work it out with my own conversion.

      Thanks.

      MG


      Comment

      Working...