mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-12 22:14:25 +00:00
Fix macro name clash with windows headers in TFTP server
Reported by Gisle Vanem
This commit is contained in:
parent
87172d6d35
commit
fa211096c2
@ -58,20 +58,20 @@
|
||||
#define TFTP_MAX_PAYLOAD_SIZE 512
|
||||
#define TFTP_HEADER_LENGTH 4
|
||||
|
||||
#define RRQ 1
|
||||
#define WRQ 2
|
||||
#define DATA 3
|
||||
#define ACK 4
|
||||
#define ERROR 5
|
||||
#define TFTP_RRQ 1
|
||||
#define TFTP_WRQ 2
|
||||
#define TFTP_DATA 3
|
||||
#define TFTP_ACK 4
|
||||
#define TFTP_ERROR 5
|
||||
|
||||
enum tftp_error {
|
||||
ERROR_FILE_NOT_FOUND = 1,
|
||||
ERROR_ACCESS_VIOLATION = 2,
|
||||
ERROR_DISK_FULL = 3,
|
||||
ERROR_ILLEGAL_OPERATION = 4,
|
||||
ERROR_UNKNOWN_TRFR_ID = 5,
|
||||
ERROR_FILE_EXISTS = 6,
|
||||
ERROR_NO_SUCH_USER = 7
|
||||
TFTP_ERROR_FILE_NOT_FOUND = 1,
|
||||
TFTP_ERROR_ACCESS_VIOLATION = 2,
|
||||
TFTP_ERROR_DISK_FULL = 3,
|
||||
TFTP_ERROR_ILLEGAL_OPERATION = 4,
|
||||
TFTP_ERROR_UNKNOWN_TRFR_ID = 5,
|
||||
TFTP_ERROR_FILE_EXISTS = 6,
|
||||
TFTP_ERROR_NO_SUCH_USER = 7
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
@ -127,7 +127,7 @@ send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *
|
||||
}
|
||||
|
||||
payload = (u16_t*) p->payload;
|
||||
payload[0] = PP_HTONS(ERROR);
|
||||
payload[0] = PP_HTONS(TFTP_ERROR);
|
||||
payload[1] = htons(code);
|
||||
MEMCPY(&payload[2], str, str_length + 1);
|
||||
|
||||
@ -147,7 +147,7 @@ send_ack(u16_t blknum)
|
||||
}
|
||||
payload = (u16_t*) p->payload;
|
||||
|
||||
payload[0] = PP_HTONS(ACK);
|
||||
payload[0] = PP_HTONS(TFTP_ACK);
|
||||
payload[1] = htons(blknum);
|
||||
udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port);
|
||||
pbuf_free(p);
|
||||
@ -186,12 +186,12 @@ send_data(void)
|
||||
}
|
||||
|
||||
payload = (u16_t *) tftp_state.last_data->payload;
|
||||
payload[0] = PP_HTONS(DATA);
|
||||
payload[0] = PP_HTONS(TFTP_DATA);
|
||||
payload[1] = htons(tftp_state.blknum);
|
||||
|
||||
ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
|
||||
if (ret < 0) {
|
||||
send_error(&tftp_state.addr, tftp_state.port, ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
|
||||
send_error(&tftp_state.addr, tftp_state.port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
|
||||
close_handle();
|
||||
return;
|
||||
}
|
||||
@ -211,7 +211,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
|
||||
if (((tftp_state.port != 0) && (port != tftp_state.port)) ||
|
||||
(!ip_addr_isany_val(tftp_state.addr) && !ip_addr_cmp(&tftp_state.addr, addr))) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
@ -222,8 +222,8 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
tftp_state.retries = 0;
|
||||
|
||||
switch (opcode) {
|
||||
case PP_HTONS(RRQ): /* fall through */
|
||||
case PP_HTONS(WRQ):
|
||||
case PP_HTONS(TFTP_RRQ): /* fall through */
|
||||
case PP_HTONS(TFTP_WRQ):
|
||||
{
|
||||
const char tftp_null = 0;
|
||||
char filename[TFTP_MAX_FILENAME_LEN];
|
||||
@ -232,7 +232,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
u16_t mode_end_offset;
|
||||
|
||||
if(tftp_state.handle != NULL) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
/* find \0 in pbuf -> end of filename string */
|
||||
filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2);
|
||||
if((u16_t)(filename_end_offset-2) > sizeof(filename)) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
pbuf_copy_partial(p, filename, filename_end_offset-2, 2);
|
||||
@ -249,27 +249,27 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
/* find \0 in pbuf -> end of mode string */
|
||||
mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset+1);
|
||||
if((u16_t)(mode_end_offset-filename_end_offset) > sizeof(mode)) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
pbuf_copy_partial(p, mode, mode_end_offset-filename_end_offset, filename_end_offset+1);
|
||||
|
||||
tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(WRQ));
|
||||
tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(TFTP_WRQ));
|
||||
tftp_state.blknum = 1;
|
||||
|
||||
if (!tftp_state.handle) {
|
||||
send_error(addr, port, ERROR_FILE_NOT_FOUND, "Unable to open requested file.");
|
||||
send_error(addr, port, TFTP_ERROR_FILE_NOT_FOUND, "Unable to open requested file.");
|
||||
break;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(WRQ)) ? "write" : "read"));
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(TFTP_WRQ)) ? "write" : "read"));
|
||||
ip_addr_debug_print(TFTP_DEBUG | LWIP_DBG_STATE, addr);
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, (" for '%s' mode '%s'\n", filename, mode));
|
||||
|
||||
ip_addr_copy(tftp_state.addr, *addr);
|
||||
tftp_state.port = port;
|
||||
|
||||
if (opcode == PP_HTONS(WRQ)) {
|
||||
if (opcode == PP_HTONS(TFTP_WRQ)) {
|
||||
tftp_state.mode_write = 1;
|
||||
send_ack(0);
|
||||
} else {
|
||||
@ -280,18 +280,18 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
break;
|
||||
}
|
||||
|
||||
case PP_HTONS(DATA):
|
||||
case PP_HTONS(TFTP_DATA):
|
||||
{
|
||||
int ret;
|
||||
u16_t blknum;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.mode_write != 1) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a write connection");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a write connection");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
|
||||
ret = tftp_state.ctx->write(tftp_state.handle, p);
|
||||
if (ret < 0) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "error writing file");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "error writing file");
|
||||
close_handle();
|
||||
} else {
|
||||
send_ack(blknum);
|
||||
@ -312,24 +312,24 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
break;
|
||||
}
|
||||
|
||||
case PP_HTONS(ACK):
|
||||
case PP_HTONS(TFTP_ACK):
|
||||
{
|
||||
u16_t blknum;
|
||||
int lastpkt;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.mode_write != 0) {
|
||||
send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a read connection");
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a read connection");
|
||||
break;
|
||||
}
|
||||
|
||||
blknum = ntohs(sbuf[1]);
|
||||
if (blknum != tftp_state.blknum) {
|
||||
send_error(addr, port, ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16
|
||||
}
|
||||
|
||||
default:
|
||||
send_error(addr, port, ERROR_ILLEGAL_OPERATION, "Unknown operation");
|
||||
send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Unknown operation");
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user