mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-05 06:39:52 +00:00
tftp client: pass 'mode' as an enum, not as a string constant
This commit is contained in:
parent
4edbec760a
commit
0ee4784d0c
@ -503,26 +503,45 @@ void tftp_cleanup(void)
|
||||
memset(&tftp_state, 0, sizeof(tftp_state));
|
||||
}
|
||||
|
||||
const char *
|
||||
mode_to_string(enum tftp_transfer_mode mode)
|
||||
{
|
||||
if (mode == TFTP_MODE_OCTET) {
|
||||
return "octet";
|
||||
}
|
||||
if (mode == TFTP_MODE_NETASCII) {
|
||||
return "netascii";
|
||||
}
|
||||
if (mode == TFTP_MODE_BINARY) {
|
||||
return "binary";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err_t
|
||||
tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, const char* mode)
|
||||
tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode)
|
||||
{
|
||||
LWIP_ERROR("TFTP client is not enabled (tftp_init)", (tftp_state.tftp_mode & LWIP_TFTP_MODE_CLIENT) != 0, return ERR_VAL);
|
||||
LWIP_ERROR("tftp_get: invalid file name", fname != NULL, return ERR_VAL);
|
||||
LWIP_ERROR("tftp_get: invalid mode", mode <= TFTP_MODE_BINARY, return ERR_VAL);
|
||||
|
||||
tftp_state.handle = handle;
|
||||
tftp_state.blknum = 1;
|
||||
tftp_state.mode_write = 1; /* We want to receive data */
|
||||
return send_request(addr, port, TFTP_RRQ, fname, mode);
|
||||
return send_request(addr, port, TFTP_RRQ, fname, mode_to_string(mode));
|
||||
}
|
||||
|
||||
err_t
|
||||
tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, const char* mode)
|
||||
tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode)
|
||||
{
|
||||
LWIP_ERROR("TFTP client is not enabled (tftp_init)", (tftp_state.tftp_mode & LWIP_TFTP_MODE_CLIENT) != 0, return ERR_VAL);
|
||||
LWIP_ERROR("tftp_put: invalid file name", fname != NULL, return ERR_VAL);
|
||||
LWIP_ERROR("tftp_put: invalid mode", mode <= TFTP_MODE_BINARY, return ERR_VAL);
|
||||
|
||||
tftp_state.handle = handle;
|
||||
tftp_state.blknum = 1;
|
||||
tftp_state.mode_write = 0; /* We want to send data */
|
||||
return send_request(addr, port, TFTP_WRQ, fname, mode);
|
||||
return send_request(addr, port, TFTP_WRQ, fname, mode_to_string(mode));
|
||||
}
|
||||
|
||||
#endif /* LWIP_UDP */
|
||||
|
@ -37,8 +37,14 @@
|
||||
|
||||
#include "lwip/apps/tftp_common.h"
|
||||
|
||||
enum tftp_transfer_mode {
|
||||
TFTP_MODE_OCTET,
|
||||
TFTP_MODE_NETASCII,
|
||||
TFTP_MODE_BINARY /* used in old versions only */
|
||||
};
|
||||
|
||||
err_t tftp_init_client(const struct tftp_context* ctx);
|
||||
err_t tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, const char* mode);
|
||||
err_t tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, const char* mode);
|
||||
err_t tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
|
||||
err_t tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
|
||||
|
||||
#endif /* LWIP_HDR_APPS_TFTP_CLIENT_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user