This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 578db94ad netutils/ptpd: Bind the TX socket after reading the
interface address.
578db94ad is described below
commit 578db94ad261b240fa62e3382b251cf512c462eb
Author: raiden00pl <[email protected]>
AuthorDate: Sun Nov 15 18:00:11 2026 +0100
netutils/ptpd: Bind the TX socket after reading the interface address.
The TX socket was bound before SIOCGIFADDR filled interface_addr, so
it was bound to INADDR_ANY on the port the info socket already uses.
bind() now fails with EADDRINUSE for that, and ptpd does not start.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: raiden00pl <[email protected]>
---
netutils/ptpd/ptpd.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/netutils/ptpd/ptpd.c b/netutils/ptpd/ptpd.c
index db8fce137..559ce3951 100644
--- a/netutils/ptpd/ptpd.c
+++ b/netutils/ptpd/ptpd.c
@@ -741,19 +741,6 @@ static int ptp_initialize_state(FAR struct ptp_state_s
*state)
ptperr("Failed to bind to udp port %d\n", bind_addr.sin_port);
goto errout;
}
-
- /* Bind TX socket to interface address (local addr cannot be
- * multicast)
- */
-
- bind_addr.sin_addr = state->interface_addr.sin_addr;
- ret = bind(state->tx_socket, (FAR struct sockaddr *)&bind_addr,
- sizeof(bind_addr));
- if (ret < 0)
- {
- ptperr("Failed to bind tx to port %d\n", bind_addr.sin_port);
- goto errout;
- }
}
if (state->config->hardware_ts)
@@ -836,15 +823,32 @@ static int ptp_initialize_state(FAR struct ptp_state_s
*state)
state->interface_addr = *(FAR struct sockaddr_in *)&req.ifr_ifru.ifru_addr;
- /* Subscribe to PTP multicast address (AF_INET only).
- * Must be done after interface_addr is populated so the IGMP join
- * can locate the correct network device.
+ /* Bind the TX socket and subscribe to PTP multicast address (AF_INET
+ * only). Must be done after interface_addr is populated so the TX
+ * socket gets the interface address and the IGMP join can locate the
+ * correct network device.
*/
if (state->config->af == AF_INET)
{
+ struct sockaddr_in bind_addr;
struct in_addr mcast_addr;
+ /* Bind TX socket to interface address (local addr cannot be
+ * multicast)
+ */
+
+ bind_addr.sin_family = AF_INET;
+ bind_addr.sin_addr = state->interface_addr.sin_addr;
+ bind_addr.sin_port = HTONS(PTP_UDP_PORT_INFO);
+ ret = bind(state->tx_socket, (FAR struct sockaddr *)&bind_addr,
+ sizeof(bind_addr));
+ if (ret < 0)
+ {
+ ptperr("Failed to bind tx to port %d\n", bind_addr.sin_port);
+ goto errout;
+ }
+
mcast_addr.s_addr = HTONL(PTP_MULTICAST_ADDR);
ret = ipmsfilter(&state->interface_addr.sin_addr,
&mcast_addr, MCAST_INCLUDE);