Added get_port() method to socket_t to learn the listening port.

This commit is contained in:
Tobias Brunner
2012-08-08 15:12:25 +02:00
parent 56d07af3be
commit a7babe25ee
6 changed files with 59 additions and 5 deletions
@@ -305,7 +305,7 @@ METHOD(socket_t, sender, status_t,
/* send data */
sport = src->get_port(src);
family = dst->get_family(dst);
if (sport == CHARON_UDP_PORT)
if (sport == 0 || sport == CHARON_UDP_PORT)
{
if (family == AF_INET)
{
@@ -405,6 +405,12 @@ METHOD(socket_t, sender, status_t,
return SUCCESS;
}
METHOD(socket_t, get_port, u_int16_t,
private_socket_default_socket_t *this, bool nat_t)
{
return nat_t ? CHARON_NATT_PORT : CHARON_UDP_PORT;
}
/**
* open a socket to send and receive packets
*/
@@ -533,6 +539,7 @@ socket_default_socket_t *socket_default_socket_create()
.socket = {
.send = _sender,
.receive = _receiver,
.get_port = _get_port,
.destroy = _destroy,
},
},