Browse Source

Add function for resolving a host name

NX 7 years ago
parent
commit
c5826882ed
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Source/Managed/ENet.cs

+ 12 - 0
Source/Managed/ENet.cs

@@ -137,6 +137,15 @@ namespace ENet {
 			}
 		}
 
+		public string GetHost() {
+			StringBuilder hostName = new StringBuilder(1024);
+
+			if (Native.enet_address_get_host(nativeAddress, hostName, (IntPtr)hostName.Capacity) != 0)
+				return null;
+
+			return hostName.ToString();
+		}
+
 		public bool SetHost(string hostName) {
 			if (hostName == null)
 				throw new ArgumentNullException("hostName");
@@ -836,6 +845,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern uint enet_time_get();
 
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern int enet_address_get_host(ENetAddress address, StringBuilder hostName, IntPtr nameLength);
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_address_set_host(ref ENetAddress address, byte[] hostName);