Merge branch 'multiplex' of https://gitlab.tuni.fi/cs/ultravideo/uvgrtp into multiplex

This commit is contained in:
Heikki Tampio 2023-04-12 10:56:12 +03:00
commit 66d4fe08f7
3 changed files with 34 additions and 2 deletions

View File

@ -19,6 +19,8 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <netdb.h>
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
@ -145,6 +147,29 @@ rtp_error_t uvgrtp::socket::bind_ip6(sockaddr_in6& local_address)
return RTP_OK;
}
int uvgrtp::socket::check_family(std::string addr)
{
// Use getaddrinfo() to determine whether we are using ipv4 or ipv6 addresses
struct addrinfo hint, * res = NULL;
memset(&hint, '\0', sizeof(hint));
hint.ai_family = PF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(addr.c_str(), NULL, &hint, &res) != 0) {
UVG_LOG_ERROR("Invalid IP address");
return RTP_GENERIC_ERROR;
}
if (res->ai_family == AF_INET6) {
UVG_LOG_DEBUG("Using an IPv6 address");
return 2;
}
else {
UVG_LOG_DEBUG("Using an IPv4 address");
return 1;
}
return -1;
}
sockaddr_in uvgrtp::socket::create_sockaddr(short family, unsigned host, short port) const
{
assert(family == AF_INET);

View File

@ -76,7 +76,6 @@ namespace uvgrtp {
/* Create socket using "family", "type" and "protocol"
*
* NOTE: Only family AF_INET (ie. IPv4) is supported
*
* Return RTP_OK on success
* return RTP_SOCKET_ERROR if creating the socket failed */
@ -90,6 +89,13 @@ namespace uvgrtp {
rtp_error_t bind(sockaddr_in& local_address);
rtp_error_t bind_ip6(sockaddr_in6& local_address);
/* Check if the given address is IPv4 or IPv6
*
* Return 1 for IPv4
* Return 2 for IPv6
* return -1 for error */
int check_family(std::string addr);
/* Same as setsockopt(2), used to manipulate the underlying socket object
*
* Return RTP_OK on success

View File

@ -9,6 +9,7 @@
#include <netinet/in.h>
#endif
#include <algorithm>
#include <cstring>
uvgrtp::socketfactory::socketfactory(int rce_flags) :
rce_flags_(rce_flags),
@ -23,7 +24,7 @@ uvgrtp::socketfactory::~socketfactory()
rtp_error_t uvgrtp::socketfactory::set_local_interface(std::string local_addr)
{
rtp_error_t ret;
//rtp_error_t ret;
local_address_ = local_addr;
// check IP address family