diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-19 09:43:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-19 09:43:50 +0000 |
commit | 71c9f015e9d83910ea3ae127944ef5d900c5a582 (patch) | |
tree | 13bead09efe6ab55a6ef5c2bb86f0b791dd4d9f4 | |
parent | dd9228b861e41c816b31035ce9c2dfa3e5b5dc97 (diff) | |
download | busybox-w32-71c9f015e9d83910ea3ae127944ef5d900c5a582.tar.gz busybox-w32-71c9f015e9d83910ea3ae127944ef5d900c5a582.tar.bz2 busybox-w32-71c9f015e9d83910ea3ae127944ef5d900c5a582.zip |
tftp(d): a bit more verbose error reporting
-rw-r--r-- | networking/tftp.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/networking/tftp.c b/networking/tftp.c index 83b0ef36f..e0f2b91cf 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -38,10 +38,12 @@ | |||
38 | #define TFTP_ERROR 5 | 38 | #define TFTP_ERROR 5 |
39 | #define TFTP_OACK 6 | 39 | #define TFTP_OACK 6 |
40 | 40 | ||
41 | /* error codes sent over network */ | 41 | /* error codes sent over network (we use only 0, 3 and 8) */ |
42 | /* generic (error message is included in the packet) */ | ||
42 | #define ERR_UNSPEC 0 | 43 | #define ERR_UNSPEC 0 |
43 | #define ERR_NOFILE 1 | 44 | #define ERR_NOFILE 1 |
44 | #define ERR_ACCESS 2 | 45 | #define ERR_ACCESS 2 |
46 | /* disk full or allocation exceeded */ | ||
45 | #define ERR_WRITE 3 | 47 | #define ERR_WRITE 3 |
46 | #define ERR_OP 4 | 48 | #define ERR_OP 4 |
47 | #define ERR_BAD_ID 5 | 49 | #define ERR_BAD_ID 5 |
@@ -71,7 +73,7 @@ | |||
71 | struct globals { | 73 | struct globals { |
72 | /* u16 TFTP_ERROR; u16 reason; both network-endian, then error text: */ | 74 | /* u16 TFTP_ERROR; u16 reason; both network-endian, then error text: */ |
73 | uint8_t error_pkt[4 + 32]; | 75 | uint8_t error_pkt[4 + 32]; |
74 | /* used in tftpd_main(), a bit big fro stack: */ | 76 | /* used in tftpd_main(), a bit big for stack: */ |
75 | char block_buf[TFTP_BLKSIZE_DEFAULT]; | 77 | char block_buf[TFTP_BLKSIZE_DEFAULT]; |
76 | }; | 78 | }; |
77 | #define G (*(struct globals*)&bb_common_bufsiz1) | 79 | #define G (*(struct globals*)&bb_common_bufsiz1) |
@@ -420,13 +422,13 @@ static int tftp_protocol( | |||
420 | 422 | ||
421 | if (CMD_GET(cmd) && (opcode == TFTP_DATA)) { | 423 | if (CMD_GET(cmd) && (opcode == TFTP_DATA)) { |
422 | if (recv_blk == block_nr) { | 424 | if (recv_blk == block_nr) { |
423 | len = full_write(local_fd, &rbuf[4], len - 4); | 425 | int sz = full_write(local_fd, &rbuf[4], len - 4); |
424 | if (len < 0) { | 426 | if (sz != len - 4) { |
425 | bb_perror_msg(bb_msg_write_error); | 427 | strcpy(error_pkt_str, bb_msg_write_error); |
426 | error_pkt_reason = ERR_WRITE; | 428 | error_pkt_reason = ERR_WRITE; |
427 | goto send_err_pkt; | 429 | goto send_err_pkt; |
428 | } | 430 | } |
429 | if (len != blksize) { | 431 | if (sz != blksize) { |
430 | finished = 1; | 432 | finished = 1; |
431 | } | 433 | } |
432 | continue; /* send ACK */ | 434 | continue; /* send ACK */ |
@@ -467,9 +469,10 @@ static int tftp_protocol( | |||
467 | return finished == 0; /* returns 1 on failure */ | 469 | return finished == 0; /* returns 1 on failure */ |
468 | 470 | ||
469 | send_read_err_pkt: | 471 | send_read_err_pkt: |
470 | bb_perror_msg(bb_msg_read_error); | ||
471 | strcpy(error_pkt_str, bb_msg_read_error); | 472 | strcpy(error_pkt_str, bb_msg_read_error); |
472 | send_err_pkt: | 473 | send_err_pkt: |
474 | if (error_pkt_str[0]) | ||
475 | bb_error_msg(error_pkt_str); | ||
473 | error_pkt[1] = TFTP_ERROR; | 476 | error_pkt[1] = TFTP_ERROR; |
474 | xsendto(socket_fd, error_pkt, 4 + 1 + strlen(error_pkt_str), | 477 | xsendto(socket_fd, error_pkt, 4 + 1 + strlen(error_pkt_str), |
475 | &peer_lsa->u.sa, peer_lsa->len); | 478 | &peer_lsa->u.sa, peer_lsa->len); |
@@ -652,9 +655,10 @@ int tftpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
652 | #if ENABLE_FEATURE_TFTP_GET | 655 | #if ENABLE_FEATURE_TFTP_GET |
653 | if (!ENABLE_FEATURE_TFTP_PUT || opcode == TFTP_WRQ) { | 656 | if (!ENABLE_FEATURE_TFTP_PUT || opcode == TFTP_WRQ) { |
654 | if (opt_r) { | 657 | if (opt_r) { |
655 | error_pkt_reason = ERR_WRITE; | 658 | /* This would mean "disk full" - not true */ |
656 | /* will just send error pkt */ | 659 | /*error_pkt_reason = ERR_WRITE;*/ |
657 | goto do_proto; | 660 | error_msg = bb_msg_write_error; |
661 | goto err; | ||
658 | } | 662 | } |
659 | USE_GETPUT(cmd = 1;) /* CMD_GET: we will receive file's data */ | 663 | USE_GETPUT(cmd = 1;) /* CMD_GET: we will receive file's data */ |
660 | open_mode = O_WRONLY | O_TRUNC; | 664 | open_mode = O_WRONLY | O_TRUNC; |
@@ -662,6 +666,7 @@ int tftpd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
662 | #endif | 666 | #endif |
663 | local_fd = open(filename, open_mode); | 667 | local_fd = open(filename, open_mode); |
664 | if (local_fd < 0) { | 668 | if (local_fd < 0) { |
669 | /*error_pkt_reason = ERR_NOFILE/ERR_ACCESS?*/ | ||
665 | error_msg = "can't open file"; | 670 | error_msg = "can't open file"; |
666 | err: | 671 | err: |
667 | strcpy(error_pkt_str, error_msg); | 672 | strcpy(error_pkt_str, error_msg); |