Advertisement

IP->UINT

Started by September 03, 2001 12:31 AM
2 comments, last by Galileo430 23 years, 4 months ago
I was just wondering if anyone knows how to convert a IP to UINT when the IP is in a SOCKADDR_IN struct? I tried
  
memcpy(&adrIP->sin_addr, &dwTempIP, 4);
  
But it corrupts the IP.. Any ideas?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
I think that IP addresses in the SOCKADDR_IN struct are stored in little endian, which basically means that the ip is stored backwards in memory...

maybe...

NickW
Advertisement
Like this:

  unsigned int ip = ntohl( addr.sin_addr.S_addr );  


codeka.com - Just click it.
Or if you dont want to call a function which can be replaced with one line of code then its :
(Note code is in Delphi but easy to convert )
  result := IntToStr(Ord(pRemoteAddress.sin_addr.S_un_b.s_b1)) + '.' + IntToStr(Ord(pRemoteAddress.sin_addr.S_un_b.s_b2))+ '.' + IntToStr(Ord(pRemoteAddress.sin_addr.S_un_b.s_b3))+ '.' + IntToStr(Ord(pRemoteAddress.sin_addr.S_un_b.s_b4));   


note : Ord just casts a Char as an Int

~ Tim

Edited by - wrathgame on September 4, 2001 9:09:40 AM
~ Tim

This topic is closed to new replies.

Advertisement