socket-default: refactor socket pair opening to a function
This commit is contained in:
@@ -614,6 +614,27 @@ static int open_socket(private_socket_default_socket_t *this,
|
|||||||
return skt;
|
return skt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a socket pair (normal an NAT traversal) for a given address family
|
||||||
|
*/
|
||||||
|
static void open_socketpair(private_socket_default_socket_t *this, int family,
|
||||||
|
int *skt, int *skt_natt, char *label)
|
||||||
|
{
|
||||||
|
*skt = open_socket(this, family, &this->port);
|
||||||
|
if (*skt == -1)
|
||||||
|
{
|
||||||
|
DBG1(DBG_NET, "could not open %s socket, %s disabled", label, label);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*skt_natt = open_socket(this, family, &this->natt);
|
||||||
|
if (*skt_natt == -1)
|
||||||
|
{
|
||||||
|
DBG1(DBG_NET, "could not open %s NAT-T socket", label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(socket_t, destroy, void,
|
METHOD(socket_t, destroy, void,
|
||||||
private_socket_default_socket_t *this)
|
private_socket_default_socket_t *this)
|
||||||
{
|
{
|
||||||
@@ -672,33 +693,8 @@ socket_default_socket_t *socket_default_socket_create()
|
|||||||
|
|
||||||
/* we allocate IPv6 sockets first as that will reserve randomly allocated
|
/* we allocate IPv6 sockets first as that will reserve randomly allocated
|
||||||
* ports also for IPv4 */
|
* ports also for IPv4 */
|
||||||
this->ipv6 = open_socket(this, AF_INET6, &this->port);
|
open_socketpair(this, AF_INET6, &this->ipv6, &this->ipv6_natt, "IPv6");
|
||||||
if (this->ipv6 == -1)
|
open_socketpair(this, AF_INET, &this->ipv4, &this->ipv4_natt, "IPv4");
|
||||||
{
|
|
||||||
DBG1(DBG_NET, "could not open IPv6 socket, IPv6 disabled");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->ipv6_natt = open_socket(this, AF_INET6, &this->natt);
|
|
||||||
if (this->ipv6_natt == -1)
|
|
||||||
{
|
|
||||||
DBG1(DBG_NET, "could not open IPv6 NAT-T socket");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->ipv4 = open_socket(this, AF_INET, &this->port);
|
|
||||||
if (this->ipv4 == -1)
|
|
||||||
{
|
|
||||||
DBG1(DBG_NET, "could not open IPv4 socket, IPv4 disabled");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->ipv4_natt = open_socket(this, AF_INET, &this->natt);
|
|
||||||
if (this->ipv4_natt == -1)
|
|
||||||
{
|
|
||||||
DBG1(DBG_NET, "could not open IPv4 NAT-T socket");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->ipv4 == -1 && this->ipv6 == -1)
|
if (this->ipv4 == -1 && this->ipv6 == -1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user