summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-03-01 14:40:32 +0100
committerHarald Welte <laforge@gnumonks.org>2018-03-01 14:42:25 +0100
commit0d3030c76405fbcf3d8cbcb61547eee53aec02b3 (patch)
tree13fec2319a05829620f2a2568d6e694d42baad19
parent380dc7e768c944ab0efc28f24205334a4c736a42 (diff)
trxcon: Fix '-i' to specify the "TRX IP address"
The command line help states '-i' is for 'TRX IP address', which is the remote IP address at which the TRX is to be found. Hoewever, it was used as the local (bind) IP address of the socket used towards the TRX. This is my attempt at fixing this. A more complete solution probably allows to specify both local (bind) and remote (connect) address, just to be clear. Change-Id: If0252b15e9c7942687c6dc470951d777f7af651c
-rw-r--r--src/host/trxcon/trx_if.c45
-rw-r--r--src/host/trxcon/trx_if.h3
-rw-r--r--src/host/trxcon/trxcon.c2
3 files changed, 15 insertions, 35 deletions
diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c
index 98e3cdd4..048b720c 100644
--- a/src/host/trxcon/trx_if.c
+++ b/src/host/trxcon/trx_if.c
@@ -83,42 +83,20 @@ static struct osmo_fsm trx_fsm = {
.event_names = trx_evt_names,
};
-static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host,
- uint16_t port_local, uint16_t port_remote,
+static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host_local,
+ uint16_t port_local, const char *host_remote, uint16_t port_remote,
int (*cb)(struct osmo_fd *fd, unsigned int what))
{
- struct sockaddr_storage sas;
- struct sockaddr *sa = (struct sockaddr *) &sas;
- socklen_t sa_len;
int rc;
ofd->data = priv;
ofd->fd = -1;
ofd->cb = cb;
- /* Init RX side for UDP connection */
- rc = osmo_sock_init_ofd(ofd, AF_UNSPEC, SOCK_DGRAM,
- 0, host, port_local, OSMO_SOCK_F_BIND);
- if (rc < 0)
- return rc;
-
- /* Init TX side for UDP connection */
- sa_len = sizeof(sas);
- rc = getsockname(ofd->fd, sa, &sa_len);
- if (rc)
- return rc;
-
- if (sa->sa_family == AF_INET) {
- struct sockaddr_in *sin = (struct sockaddr_in *) sa;
- sin->sin_port = htons(port_remote);
- } else if (sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
- sin6->sin6_port = htons(port_remote);
- } else {
- return -EINVAL;
- }
-
- rc = connect(ofd->fd, sa, sa_len);
+ /* Init UDP Connection */
+ rc = osmo_sock_init2_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, 0, host_local, port_local,
+ host_remote, port_remote,
+ OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT);
return rc;
}
@@ -641,7 +619,8 @@ int trx_if_tx_burst(struct trx_instance *trx, uint8_t tn, uint32_t fn,
* Open/close OsmoTRX connection
*/
-int trx_if_open(struct trx_instance **trx, const char *host, uint16_t port)
+int trx_if_open(struct trx_instance **trx, const char *local_host,
+ const char *remote_host, uint16_t port)
{
struct trx_instance *trx_new;
int rc;
@@ -659,13 +638,13 @@ int trx_if_open(struct trx_instance **trx, const char *host, uint16_t port)
INIT_LLIST_HEAD(&trx_new->trx_ctrl_list);
/* Open sockets */
- rc = trx_udp_open(trx_new, &trx_new->trx_ofd_ctrl, host,
- port + 101, port + 1, trx_ctrl_read_cb);
+ rc = trx_udp_open(trx_new, &trx_new->trx_ofd_ctrl, local_host,
+ port + 101, remote_host, port + 1, trx_ctrl_read_cb);
if (rc < 0)
goto error;
- rc = trx_udp_open(trx_new, &trx_new->trx_ofd_data, host,
- port + 102, port + 2, trx_data_rx_cb);
+ rc = trx_udp_open(trx_new, &trx_new->trx_ofd_data, local_host,
+ port + 102, remote_host, port + 2, trx_data_rx_cb);
if (rc < 0)
goto error;
diff --git a/src/host/trxcon/trx_if.h b/src/host/trxcon/trx_if.h
index dd84315e..6080dcee 100644
--- a/src/host/trxcon/trx_if.h
+++ b/src/host/trxcon/trx_if.h
@@ -52,7 +52,8 @@ struct trx_ctrl_msg {
int cmd_len;
};
-int trx_if_open(struct trx_instance **trx, const char *host, uint16_t port);
+int trx_if_open(struct trx_instance **trx, const char *local_host,
+ const char *remote_host, uint16_t port);
void trx_if_flush_ctrl(struct trx_instance *trx);
void trx_if_close(struct trx_instance *trx);
diff --git a/src/host/trxcon/trxcon.c b/src/host/trxcon/trxcon.c
index 60db8878..55422403 100644
--- a/src/host/trxcon/trxcon.c
+++ b/src/host/trxcon/trxcon.c
@@ -270,7 +270,7 @@ int main(int argc, char **argv)
goto exit;
/* Init transceiver interface */
- rc = trx_if_open(&app_data.trx, app_data.trx_ip, app_data.trx_base_port);
+ rc = trx_if_open(&app_data.trx, "0.0.0.0", app_data.trx_ip, app_data.trx_base_port);
if (rc)
goto exit;