Possible Duplicate:
converting C to C#
i have problem in converting by c code to c#
i hav two structers
struct sockaddr {
ushort sa_family;
char sa_data[14];
};
struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
and i use to cast it like this…
to get the ip address. from the sockaddr_in structure
ip = inet_ntoa((( sockaddr_in*)name)->sin_addr);
now i converted the structure in c# as
public struct sockaddr
{
public static ushort sa_family;
public static char[] sa_data = new char[14];
};
and..
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct sockaddr_in
{
public const int Size = 16;
public short sin_family;
public ushort sin_port;
public struct in_addr
{
public uint S_addr;
public struct _S_un_b
{
public byte s_b1, s_b2, s_b3, s_b4;
}
public _S_un_b S_un_b;
public struct _S_un_w
{
public ushort s_w1, s_w2;
}
public _S_un_w S_un_w;
}
public in_addr sin_addr;
}
can any one plz help me to get ip address from casting the sockaddr to sockaddr_in as i tried it in c… its working fine… how do i do the same in C#…
thanks u in Advance..
What you try to achieve is certainly possible in C#. Here is an example:
However as others have pointed out, such approaches lead to non-idiomatic C# code and cannot generally be recommended.