diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index badebe03f..a85b7ae6f 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2179,6 +2179,7 @@ typedef struct hamlib_port { int value; /*!< Toggle PTT ON or OFF */ } gpio; /*!< GPIO attributes */ } parm; /*!< Port parameter union */ + int client_port; /*!< client socket port for tcp connection */ } hamlib_port_t; //! @endcond diff --git a/src/network.c b/src/network.c index 2b837356b..2ab22561e 100644 --- a/src/network.c +++ b/src/network.c @@ -165,6 +165,7 @@ int network_open(hamlib_port_t *rp, int default_port) int status; struct addrinfo hints, *res, *saved_res; struct in6_addr serveraddr; + struct sockaddr_in client; char hoststr[256], portstr[6] = ""; ENTERFUNC; @@ -299,6 +300,11 @@ int network_open(hamlib_port_t *rp, int default_port) rp->fd = fd; + socklen_t clientLen = sizeof(client); + getsockname(rp->fd, (struct sockaddr *)&client, &clientLen); + rig_debug(RIG_DEBUG_ERR, "%s: client port=%d\n", __func__, client.sin_port); + rp->client_port = client.sin_port; + RETURNFUNC(RIG_OK); }