Sign in to follow this  
Afr0m@n

[.net] Updated way to get address in integer or long form for an IPAdress type? [Solved]

Recommended Posts

Afr0m@n    100
Ok, so after finally settling on what looks like a nice, suitable GUI for my client (BooGame), I decided I finally had found the strength to get back to my pet MMORPG project dubbed Nimdalin. However, now that I am on Vista RC1, I am getting an error that I did not get before when I was on WinXP. As it turns out, Vista is assigning IPv6 addresses to my network cards as well as the "standard" IP adresses (version 4?). This does not seem to go along well with my server, which craps out with an error message at a function in my code that is designed to return the IP adress in integer form from an IPAdress type. Here's the function:
		public static long GetLongAddressValue( IPAddress address )
		{
#pragma warning disable 618
			return address.Address;
#pragma warning restore 618
        }

I've checked out the Adress field of the IPAdress class, and as it turns out, it is deprecated in .NET2. I'm thinking this might have something to do with it, but I haven't been able to find a replacement field/function for it yet. Any suggestions? The error message looks like this: "The attempted operation is not supported for the type of object referenced". I also tried fixing the problem by myself by nullifying all the IPv6 adresses that my client might be trying to connecting from, like this:
        private void ConnectToHost()
        {
            for (int i = 0; i < m_IPs.Length; i++)
            {
                if (m_IPs[i].IsIPv6LinkLocal)
                    m_IPs[i] = null;
                else if (m_IPs[i].IsIPv6Multicast)
                    m_IPs[i] = null;
                else if (m_IPs[i].IsIPv6SiteLocal)
                    m_IPs[i] = null;
            }

            m_Socket.BeginConnect(m_IPs, m_Port, new AsyncCallback(OnConnect),
                                  m_Socket);
            m_AllDone.WaitOne();
            return;
        }

So far that hasn't gotten me anywhere though. If anyone has any suggestions at all, please share them! Thanks in advance! [smile] [Edited by - Afr0m@n on November 28, 2006 1:26:53 AM]

Share this post


Link to post
Share on other sites
Afr0m@n    100
I solved it! :)

If you ever get this error in Vista RC1/Vista yourself, you can make your program more Vista compatible by using the GetAddressBytes() function of the IPAddress type together with the System namespace's BitConverter. Here's how:

return BitConverter.ToInt32(IPAddress.GetAddressBytes(), 0);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this