Added get_port() method to socket_t to learn the listening port.
This commit is contained in:
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -467,6 +467,7 @@ METHOD(socket_t, sender, status_t,
|
||||
dst = packet->get_destination(packet);
|
||||
family = src->get_family(src);
|
||||
port = src->get_port(src);
|
||||
port = port ?: CHARON_UDP_PORT;
|
||||
skt = find_socket(this, family, port);
|
||||
if (!skt)
|
||||
{
|
||||
@@ -534,6 +535,14 @@ METHOD(socket_t, sender, status_t,
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
METHOD(socket_t, get_port, u_int16_t,
|
||||
private_socket_dynamic_socket_t *this, bool nat_t)
|
||||
{
|
||||
/* we return 0 here for users that have no explicit port configured, the
|
||||
* sender will default to the default port in this case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
METHOD(socket_t, destroy, void,
|
||||
private_socket_dynamic_socket_t *this)
|
||||
{
|
||||
@@ -567,6 +576,7 @@ socket_dynamic_socket_t *socket_dynamic_socket_create()
|
||||
.socket = {
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.get_port = _get_port,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -309,7 +309,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)
|
||||
{
|
||||
@@ -470,6 +470,12 @@ static int open_send_socket(private_socket_raw_socket_t *this,
|
||||
return skt;
|
||||
}
|
||||
|
||||
METHOD(socket_t, get_port, u_int16_t,
|
||||
private_socket_raw_socket_t *this, bool nat_t)
|
||||
{
|
||||
return nat_t ? CHARON_NATT_PORT : CHARON_UDP_PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* open a socket to receive packets
|
||||
*/
|
||||
@@ -616,6 +622,7 @@ socket_raw_socket_t *socket_raw_socket_create()
|
||||
.socket = {
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.get_port = _get_port,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user