From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Tue, 19 Aug 2008 13:29:33 +0000 (+0000)
Subject: implemented an lhnetaddresstype_t enum instead of using #define's
X-Git-Tag: xonotic-v0.1.0preview~2123
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7f81dc664a496edf46a3cd537f2dc6dcb60ccf4c;p=xonotic%2Fdarkplaces.git

implemented an lhnetaddresstype_t enum instead of using #define's


git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8461 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/lhnet.c b/lhnet.c
index 9b190ce5..37d9c620 100644
--- a/lhnet.c
+++ b/lhnet.c
@@ -68,7 +68,7 @@
 
 typedef struct lhnetaddressnative_s
 {
-	int addresstype;
+	lhnetaddresstype_t addresstype;
 	int port;
 	union
 	{
@@ -91,13 +91,15 @@ static struct namecache_s
 namecache[MAX_NAMECACHE];
 static int namecacheposition = 0;
 
-int LHNETADDRESS_FromPort(lhnetaddress_t *vaddress, int addresstype, int port)
+int LHNETADDRESS_FromPort(lhnetaddress_t *vaddress, lhnetaddresstype_t addresstype, int port)
 {
 	lhnetaddressnative_t *address = (lhnetaddressnative_t *)vaddress;
 	if (!address)
 		return 0;
 	switch(addresstype)
 	{
+	default:
+		return 0;
 	case LHNETADDRESSTYPE_LOOP:
 		// local:port  (loopback)
 		memset(address, 0, sizeof(*address));
diff --git a/lhnet.h b/lhnet.h
index e4224c76..08850fb3 100644
--- a/lhnet.h
+++ b/lhnet.h
@@ -4,20 +4,24 @@
 #ifndef LHNET_H
 #define LHNET_H
 
-#define LHNETADDRESSTYPE_NONE 0
-#define LHNETADDRESSTYPE_LOOP 1
-#define LHNETADDRESSTYPE_INET4 2
-#define LHNETADDRESSTYPE_INET6 3
+typedef enum lhnetaddresstype_e
+{
+	LHNETADDRESSTYPE_NONE,
+	LHNETADDRESSTYPE_LOOP,
+	LHNETADDRESSTYPE_INET4,
+	LHNETADDRESSTYPE_INET6,
+}
+lhnetaddresstype_t;
 
 typedef struct lhnetaddress_s
 {
-	int addresstype;
+	lhnetaddresstype_t addresstype;
 	int port; // used by LHNETADDRESSTYPE_LOOP
 	unsigned char storage[256]; // sockaddr_in or sockaddr_in6
 }
 lhnetaddress_t;
 
-int LHNETADDRESS_FromPort(lhnetaddress_t *address, int addresstype, int port);
+int LHNETADDRESS_FromPort(lhnetaddress_t *address, lhnetaddresstype_t addresstype, int port);
 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
 int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address);