Browse Source

Fix length for a hostname with null-terminated character

NX 6 years ago
parent
commit
8becedcc7a
2 changed files with 23 additions and 23 deletions
  1. 11 11
      Source/Managed/ENet.cs
  2. 12 12
      Source/Native/enet.h

+ 11 - 11
Source/Managed/ENet.cs

@@ -138,9 +138,9 @@ namespace ENet {
 		}
 
 		public string GetIP() {
-			StringBuilder ip = new StringBuilder(1024);
+			StringBuilder ip = new StringBuilder(1025);
 
-			if (Native.enet_address_get_host_ip(nativeAddress, ip, (IntPtr)ip.Capacity) != 0)
+			if (Native.enet_address_get_ip(nativeAddress, ip, (IntPtr)ip.Capacity) != 0)
 				return String.Empty;
 
 			return ip.ToString();
@@ -150,13 +150,13 @@ namespace ENet {
 			if (ip == null)
 				throw new ArgumentNullException("ip");
 
-			return Native.enet_address_set_host_ip(ref nativeAddress, ip) == 0;
+			return Native.enet_address_set_ip(ref nativeAddress, ip) == 0;
 		}
 
 		public string GetHost() {
-			StringBuilder hostName = new StringBuilder(1024);
+			StringBuilder hostName = new StringBuilder(1025);
 
-			if (Native.enet_address_get_host(nativeAddress, hostName, (IntPtr)hostName.Capacity) != 0)
+			if (Native.enet_address_get_hostname(nativeAddress, hostName, (IntPtr)hostName.Capacity) != 0)
 				return String.Empty;
 
 			return hostName.ToString();
@@ -166,7 +166,7 @@ namespace ENet {
 			if (hostName == null)
 				throw new ArgumentNullException("hostName");
 
-			return Native.enet_address_set_host(ref nativeAddress, hostName) == 0;
+			return Native.enet_address_set_hostname(ref nativeAddress, hostName) == 0;
 		}
 	}
 
@@ -874,7 +874,7 @@ namespace ENet {
 		public const uint timeoutLimit = 32;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMaximum = 30000;
-		public const uint version = (2 << 16) | (3 << 8) | (0);
+		public const uint version = (2 << 16) | (3 << 8) | (1);
 
 		public static bool Initialize() {
 			return Native.enet_initialize() == 0;
@@ -916,16 +916,16 @@ namespace ENet {
 		internal static extern uint enet_time_get();
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_address_set_host_ip(ref ENetAddress address, string ip);
+		internal static extern int enet_address_set_ip(ref ENetAddress address, string ip);
 
 		[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_hostname(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);
+		internal static extern int enet_address_get_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);
+		internal static extern int enet_address_get_hostname(ENetAddress address, StringBuilder hostName, IntPtr nameLength);
 
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);

+ 12 - 12
Source/Native/enet.h

@@ -31,7 +31,7 @@
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MINOR 3
-#define ENET_VERSION_PATCH 0
+#define ENET_VERSION_PATCH 1
 #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_MINOR(version) (((version) >> 8) & 0xFF)
@@ -745,10 +745,10 @@ extern "C" {
 	ENET_API void enet_host_channel_limit(ENetHost*, size_t);
 	ENET_API void enet_host_bandwidth_limit(ENetHost*, enet_uint32, enet_uint32);
 
-	ENET_API int enet_address_set_host_ip(ENetAddress*, const char*);
-	ENET_API int enet_address_set_host(ENetAddress*, const char*);
-	ENET_API int enet_address_get_host_ip(const ENetAddress*, char*, size_t);
-	ENET_API int enet_address_get_host(const ENetAddress*, char*, size_t);
+	ENET_API int enet_address_set_ip(ENetAddress*, const char*);
+	ENET_API int enet_address_set_hostname(ENetAddress*, const char*);
+	ENET_API int enet_address_get_ip(const ENetAddress*, char*, size_t);
+	ENET_API int enet_address_get_hostname(const ENetAddress*, char*, size_t);
 
 	ENET_API ENetSocket enet_socket_create(ENetSocketType);
 	ENET_API int enet_socket_bind(ENetSocket, const ENetAddress*);
@@ -4329,7 +4329,7 @@ extern "C" {
 =======================================================================
 */
 
-		int enet_address_set_host_ip(ENetAddress* address, const char* ip) {
+		int enet_address_set_ip(ENetAddress* address, const char* ip) {
 			int type = AF_INET6;
 			void* destination = &address->ipv6;
 
@@ -4345,7 +4345,7 @@ extern "C" {
 			return 0;
 		}
 
-		int enet_address_set_host(ENetAddress* address, const char* name) {
+		int enet_address_set_hostname(ENetAddress* address, const char* name) {
 			struct addrinfo hints, *resultList = NULL, *result = NULL;
 
 			memset(&hints, 0, sizeof(hints));
@@ -4383,10 +4383,10 @@ extern "C" {
 			if (resultList != NULL)
 				freeaddrinfo(resultList);
 
-			return enet_address_set_host_ip(address, name);
+			return enet_address_set_ip(address, name);
 		}
 
-		int enet_address_get_host_ip(const ENetAddress* address, char* ip, size_t ipLength) {
+		int enet_address_get_ip(const ENetAddress* address, char* ip, size_t ipLength) {
 			if (inet_ntop(AF_INET6, &address->ipv6, ip, ipLength) == NULL)
 				return -1;
 
@@ -4396,7 +4396,7 @@ extern "C" {
 			return 0;
 		}
 
-		int enet_address_get_host(const ENetAddress* address, char* name, size_t nameLength) {
+		int enet_address_get_hostname(const ENetAddress* address, char* name, size_t nameLength) {
 			struct sockaddr_in6 sin;
 			int err;
 
@@ -4418,7 +4418,7 @@ extern "C" {
 			if (err != EAI_NONAME)
 				return -1;
 
-			return enet_address_get_host_ip(address, name, nameLength);
+			return enet_address_get_ip(address, name, nameLength);
 		}
 
 /*
@@ -5071,7 +5071,7 @@ extern "C" {
 		}
 
 		int enet_peer_get_ip(const ENetPeer* peer, char* ip, size_t ipLength) {
-			return enet_address_get_host_ip(&peer->address, ip, ipLength);
+			return enet_address_get_ip(&peer->address, ip, ipLength);
 		}
 
 		enet_uint16 enet_peer_get_port(const ENetPeer* peer) {