1

OK, this is a minor issue... but still irritating nonetheless.

In MSVS 2008 .NET 3.5 I IPAdress.Address was a long and I simply used

if(subnet == subnetmask.Address & addr.Address) { ... }

And then now i just installed MSVS 2010, still using .NET 3.5 but somehow it tells me the IPAddress.Address is obsolete.

I can still wrap a BitConvertor in BitConverter.ToInt64(subnet.GetAddressBytes(), 0) but it feels like i am going backwards. Is there a more elegant way or a built-in function to check for subnet?

Thanks.

Jake
  • 11,273
  • 21
  • 90
  • 147
  • This question has been asked a few times, please search next time. – leppie Nov 18 '11 at 07:45
  • @leppie: I can't find any duplicate question dealing with the obsolete marking and netmask/subnet calculation. If you can find one, please suggest the possible duplicate. – Anders Abel Nov 18 '11 at 07:54
  • I searched but could not find the answer I need. I just felt that the we did not manage to uphold the spirit and cleverness in subnet masking technique as it does not seem to be implemented in .NET. I was hoping we are not left with comparing byte blocks in a for-loop. – Jake Nov 18 '11 at 08:00
  • @Jake: What about http://stackoverflow.com/questions/1499269/how-to-check-if-an-ip-address-is-within-a-particular-subnet? – leppie Nov 18 '11 at 08:15
  • 1
    @leppie i saw that already. I found it via google first, not satisfied, I come over to SO and found that post which points to the same article. It is not immediately obvious that the method is the only justified viable method. – Jake Nov 18 '11 at 11:19

1 Answers1

4

The reason for IPAddress.Address to be marked as obsolete is:

This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. http://go.microsoft.com/fwlink/?linkid=14202

With IPv6 coming, depending on specific features of IPv4 should be regarded as obsolete. Your workaround has the same problem - dependency on IPv4. I think that you have two options:

  • Keep your application IPv4-only and supress the obsolete warning.
  • Find out how to make the functionality work in both IPv6 and IPv4.
Anders Abel
  • 67,989
  • 17
  • 150
  • 217