C# and inet_addr

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hi,

I have to pass a serialized structure in a byte array to a win32 api
function.

the structure in C++ has the following:

typedef struct
{
...
unsigned long IPAddr;
...
}HEADER_MSG_REC;


The way that I was converting my IP address before (in C++) from string to
long was inet_addr. I can't seem to find an equivilant function in C# that
will allow me to do the same.

The win32api is using inet_ntoa to convert the long back into the string
representation.

thanks in advance.
 
The IPAddress class is available in .NET 1.1. Some of the constructors take
a byte array representation of the address as an argument and construct the
corresponding IPAddress object. There is also an IPAddress(long)
constructor. The IPAddress.Parse converts an IP address string into an
IPAddress object.

Orlin

www.ppstec.com
 
Well the problem that I am now facing is that the inet_addr returns an
unsigned long in C++ (4 bytes, 0 to 4,294,967,295), however, it's also of
type long in .net (which is 8 bytes). Can I simply cast this as a unit or
will it exception on me.

thoughts?
 
Back
Top