0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-20 12:02:28 +02:00

Move is_proto function to the socket.h header

These functions are small enough to be inlined and also avoids
dependency on socket.c from unit_tests using those functions.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20210401131337.3684-10-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21950.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Arne Schwabe 2021-04-01 15:13:32 +02:00 committed by Gert Doering
parent 9eb285f42f
commit 72e1ecb5b5
2 changed files with 38 additions and 48 deletions

View File

@ -3101,42 +3101,6 @@ static const struct proto_names proto_names[] = {
{"tcp6", "TCPv6", AF_INET6, PROTO_TCP},
};
bool
proto_is_net(int proto)
{
if (proto < 0 || proto >= PROTO_N)
{
ASSERT(0);
}
return proto != PROTO_NONE;
}
bool
proto_is_dgram(int proto)
{
return proto_is_udp(proto);
}
bool
proto_is_udp(int proto)
{
if (proto < 0 || proto >= PROTO_N)
{
ASSERT(0);
}
return proto == PROTO_UDP;
}
bool
proto_is_tcp(int proto)
{
if (proto < 0 || proto >= PROTO_N)
{
ASSERT(0);
}
return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
}
int
ascii2proto(const char *proto_name)
{

View File

@ -474,18 +474,6 @@ socket_descriptor_t socket_do_accept(socket_descriptor_t sd,
struct link_socket_actual *act,
const bool nowait);
/*
* proto related
*/
bool proto_is_net(int proto);
bool proto_is_dgram(int proto);
bool proto_is_udp(int proto);
bool proto_is_tcp(int proto);
#if UNIX_SOCK_SUPPORT
socket_descriptor_t create_socket_unix(void);
@ -572,6 +560,44 @@ enum proto_num {
PROTO_N
};
static inline bool
proto_is_net(int proto)
{
ASSERT(proto >= 0 && proto < PROTO_N);
return proto != PROTO_NONE;
}
/**
* @brief Returns if the protocol being used is UDP
*/
static inline bool
proto_is_udp(int proto)
{
ASSERT(proto >= 0 && proto < PROTO_N);
return proto == PROTO_UDP;
}
/**
* @brief Return if the protocol is datagram (UDP)
*
*/
static inline bool
proto_is_dgram(int proto)
{
return proto_is_udp(proto);
}
/**
* @brief returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
*/
static inline bool
proto_is_tcp(int proto)
{
ASSERT(proto >= 0 && proto < PROTO_N);
return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
}
int ascii2proto(const char *proto_name);
sa_family_t ascii2af(const char *proto_name);