From a39e2d17ad9824dc69f678fb0e652467655ad7a0 Mon Sep 17 00:00:00 2001 From: Tautvilis Date: Tue, 1 Sep 2026 07:37:54 +0000 Subject: [PATCH] modbus-tcp: check if response slave id matches request slave id --- src/modbus-tcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index e84dc6028..37695b02e 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -225,6 +225,18 @@ static int _modbus_tcp_pre_check_confirmation(modbus_t *ctx, return -1; } + /* Check if response slave ID matches request slave ID*/ + if (req[6] != rsp[6]) { + if (ctx->debug) { + fprintf(stderr, + "The responding slave %d isn't the requested slave %d\n", + rsp[6], + req[6]); + } + errno = EMBBADSLAVE; + return -1; + } + return 0; }