From ebd31cc72e5319ab1a823fccb40a808378d8122d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 5 Jul 2019 10:35:39 +0200 Subject: [PATCH] Improve code readability by using enum typedefs. --- src/rinetd.c | 4 ++-- src/rinetd.h | 4 ++-- src/types.h | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/rinetd.c b/src/rinetd.c index 2fd5cd3..8a5f949 100644 --- a/src/rinetd.c +++ b/src/rinetd.c @@ -248,8 +248,8 @@ static void readConfiguration(char const *file) { } } -void addServer(char *bindAddress, uint16_t bindPort, int bindProto, - char *connectAddress, uint16_t connectPort, int connectProto, +void addServer(char *bindAddress, uint16_t bindPort, protocolType bindProto, + char *connectAddress, uint16_t connectPort, protocolType connectProto, int serverTimeout, char *sourceAddress) { /* Turn all of this stuff into reasonable addresses */ diff --git a/src/rinetd.h b/src/rinetd.h index 9b0ef4c..d7de52c 100644 --- a/src/rinetd.h +++ b/src/rinetd.h @@ -46,7 +46,7 @@ extern FILE *logFile; /* Functions */ -void addServer(char *bindAddress, uint16_t bindPort, int bindProto, - char *connectAddress, uint16_t connectPort, int connectProto, +void addServer(char *bindAddress, uint16_t bindPort, protocolType bindProto, + char *connectAddress, uint16_t connectPort, protocolType connectProto, int serverTimeout, char *sourceAddress); diff --git a/src/types.h b/src/types.h index 9414267..6b836c7 100644 --- a/src/types.h +++ b/src/types.h @@ -11,12 +11,14 @@ #include #include -enum ruleType { +typedef enum _rule_type ruleType; +enum _rule_type { allowRule, denyRule, }; -enum protocolType { +typedef enum _protocol_type protocolType; +enum _protocol_type { protoTcp = 1, protoUdp = 2, }; @@ -25,7 +27,7 @@ typedef struct _rule Rule; struct _rule { char *pattern; - int type; + ruleType type; }; typedef struct _server_info ServerInfo; @@ -40,7 +42,7 @@ struct _server_info { /* In ASCII and local byte order, for logging purposes */ char *fromHost, *toHost; int16_t fromPort, toPort; - int fromProto, toProto; + protocolType fromProto, toProto; /* Offset and count into list of allow and deny rules. Any rules prior to globalAllowRules and globalDenyRules are global rules. */ @@ -54,7 +56,7 @@ typedef struct _socket Socket; struct _socket { SOCKET fd; - int proto; + protocolType proto; /* recv: received on this socket sent: sent through this socket from the other buffer */ int recvPos, sentPos;