diff options
author | Martin Willi <martin@revosec.ch> | 2013-04-11 20:19:57 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2013-05-06 16:10:11 +0200 |
commit | a30727fe2b0d1d4c83aae7b00351e529ddef536b (patch) | |
tree | fd9368d0bf77edbe20537171bd7dbecfa9b42345 /src/libcharon | |
parent | 6948df3220c98700a41e4c58cc29dd5292e2ff34 (diff) | |
download | strongswan-a30727fe2b0d1d4c83aae7b00351e529ddef536b.tar.bz2 strongswan-a30727fe2b0d1d4c83aae7b00351e529ddef536b.tar.xz |
socket-default: refactor socket pair opening to a function
Diffstat (limited to 'src/libcharon')
-rw-r--r-- | src/libcharon/plugins/socket_default/socket_default_socket.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/src/libcharon/plugins/socket_default/socket_default_socket.c b/src/libcharon/plugins/socket_default/socket_default_socket.c index 4e6217af3..9c1bce303 100644 --- a/src/libcharon/plugins/socket_default/socket_default_socket.c +++ b/src/libcharon/plugins/socket_default/socket_default_socket.c @@ -614,6 +614,27 @@ static int open_socket(private_socket_default_socket_t *this, 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, 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 * ports also for IPv4 */ - this->ipv6 = open_socket(this, AF_INET6, &this->port); - if (this->ipv6 == -1) - { - 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"); - } - } + open_socketpair(this, AF_INET6, &this->ipv6, &this->ipv6_natt, "IPv6"); + open_socketpair(this, AF_INET, &this->ipv4, &this->ipv4_natt, "IPv4"); if (this->ipv4 == -1 && this->ipv6 == -1) { |