Search code examples
c#cstructunions

converting C to C#


I'm trying to convert this C code to C#, is there a C# equivalent to the C union typedef?

struct sockaddr_in {
    short   sin_family;
    u_short sin_port;
    struct  in_addr sin_addr;
    char    sin_zero[8];
};

typedef struct in_addr {
  union {
    struct {
      u_char s_b1,s_b2,s_b3,s_b4;
    } S_un_b;
    struct {
      u_short s_w1,s_w2;
    } S_un_w;
    u_long S_addr;
  } S_un;
 } IN_ADDR, *PIN_ADDR, FAR *LPIN_ADDR;

Thanks.


Solution

  • You may check out the following page. This being said, in .NET you have classes that allows you to work directly with sockets and TCP/IP such as Socket, TcpListener, TcpClient and you don't need to translate C code blindly.