IPAddress.Parse(aIpAddress) returns a wrong IP Address

  • Thread starter Thread starter Rainer Queck
  • Start date Start date
R

Rainer Queck

Hello NG,

what is it I am doing wrong?
If I call IPAddress.Parse(aIpAddress) where the string aIpAddress =
"172.017.024.015" I get {172.15.20.13} as a result.

How can that be?

Regards
Rainer
 
Rainer,

It's the extra 0's in the last three parts of the address. Remove
those, and it works.

How did they get in there in the first place? I think that it is
screwing up because with the 0's in there at that place, it is trying to
figure out if it is a class A or a class B address.
 
Good job Nicholas.

Thanks,


Nicholas Paldino said:
Rainer,

Debugging the source code, I see that a call is eventually made to
inet_addr to parse the address. Looking at the documentation, it states
that with the leading 0, it is interpreted as an octal value.

http://msdn2.microsoft.com/en-us/library/ms738563.aspx

And that makes sense, as 017 in octal is 15, 024 is 20, and 015 is 13.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rainer Queck said:
Hello NG,

what is it I am doing wrong?
If I call IPAddress.Parse(aIpAddress) where the string aIpAddress =
"172.017.024.015" I get {172.15.20.13} as a result.

How can that be?

Regards
Rainer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top