Skip to content

Commit b1edb77

Browse files
jforissieryarrick
authored andcommitted
tftp: bind to TFTP port only when in server mode
The TFTP app should not bind to the TFTP server port when configured as a client. Instead, the local port should be chosen from the dynamic range (49152 ~ 65535) so that if the application is stopped and started again, the remote server will not consider the new packets as part of the same context (which would cause an error since a new RRQ would be unexpected). Signed-off-by: Jerome Forissier <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
1 parent 56b29f8 commit b1edb77

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/apps/tftp/tftp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,12 @@ tftp_init_common(u8_t mode, const struct tftp_context *ctx)
454454
return ERR_MEM;
455455
}
456456

457-
ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
458-
if (ret != ERR_OK) {
459-
udp_remove(pcb);
460-
return ret;
457+
if (mode & LWIP_TFTP_MODE_SERVER) {
458+
ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
459+
if (ret != ERR_OK) {
460+
udp_remove(pcb);
461+
return ret;
462+
}
461463
}
462464

463465
tftp_state.handle = NULL;

0 commit comments

Comments
 (0)