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

## Recommended Posts

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
#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++)
{
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 on other sites
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);

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627722
• Total Posts
2978804

• 10
• 9
• 21
• 14
• 12