Browse Source

Add functions for converting binary IP addresses

NX 6 years ago
parent
commit
db9f4ca350
2 changed files with 27 additions and 5 deletions
  1. 24 2
      Source/Managed/ENet.cs
  2. 3 3
      Source/Native/enet.h

+ 24 - 2
Source/Managed/ENet.cs

@@ -137,6 +137,22 @@ namespace ENet {
 			}
 			}
 		}
 		}
 
 
+		public string GetIP() {
+			StringBuilder ip = new StringBuilder(1024);
+
+			if (Native.enet_address_get_host_ip(nativeAddress, ip, (IntPtr)ip.Capacity) != 0)
+				return String.Empty;
+
+			return ip.ToString();
+		}
+
+		public bool SetIP(string ip) {
+			if (ip == null)
+				throw new ArgumentNullException("ip");
+
+			return Native.enet_address_set_host_ip(ref nativeAddress, ip) == 0;
+		}
+
 		public string GetHost() {
 		public string GetHost() {
 			StringBuilder hostName = new StringBuilder(1024);
 			StringBuilder hostName = new StringBuilder(1024);
 
 
@@ -838,7 +854,7 @@ namespace ENet {
 		public const uint timeoutLimit = 32;
 		public const uint timeoutLimit = 32;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMaximum = 30000;
 		public const uint timeoutMaximum = 30000;
-		public const uint version = (2 << 16) | (2 << 8) | (4);
+		public const uint version = (2 << 16) | (2 << 8) | (5);
 
 
 		public static bool Initialize() {
 		public static bool Initialize() {
 			return Native.enet_initialize() == 0;
 			return Native.enet_initialize() == 0;
@@ -880,11 +896,17 @@ namespace ENet {
 		internal static extern uint enet_time_get();
 		internal static extern uint enet_time_get();
 
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_address_get_host(ENetAddress address, StringBuilder hostName, IntPtr nameLength);
+		internal static extern int enet_address_set_host_ip(ref ENetAddress address, string ip);
 
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
 		internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
 
 
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern int enet_address_get_host_ip(ENetAddress address, StringBuilder ip, IntPtr ipLength);
+
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern int enet_address_get_host(ENetAddress address, StringBuilder hostName, IntPtr nameLength);
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);
 		internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);
 
 

+ 3 - 3
Source/Native/enet.h

@@ -31,7 +31,7 @@
 
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MINOR 2
 #define ENET_VERSION_MINOR 2
-#define ENET_VERSION_PATCH 4
+#define ENET_VERSION_PATCH 5
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
@@ -4193,7 +4193,7 @@ extern "C" {
 		}
 		}
 	#endif
 	#endif
 
 
-	enet_uint32 enet_time_get() {
+	enet_uint32 enet_time_get(void) {
 		static enet_uint64 start_time_ns = 0;
 		static enet_uint64 start_time_ns = 0;
 
 
 		struct timespec ts;
 		struct timespec ts;
@@ -5084,4 +5084,4 @@ extern "C" {
 }
 }
 #endif
 #endif
 #endif
 #endif
-#endif
+#endif