c++ - What is the inet_addr function equivalent in C# -


I should know how to use an IP address such as an IP address ("192.168.0.2"); In C ++ where it gives the DWORD in C #, does my wrapper consider this field as an int?

Can anyone help this misunderstanding?

You must use an IPAddress class. This will make you a little problem because it tries to stop you from taking dependency on the IP4 address. The address is declared as obsolete member. Here is the solution:

  using the system; Using System.Net; Class program {static zero main (string [] args) {var addr = IPAddress.Parse ("192.168.0.2"); Int ip4 = biton on. ToInt32 ((addr.GetAddressBytes ()), 0); Console.light line ("{0: X8}", ip4); Console.ReadLine (); }}  

Output: 0200A8C0

Note that the address is in the proper network order (Big Endian).


Comments