aboutsummaryrefslogtreecommitdiffstats
path: root/com32/libupload
diff options
context:
space:
mode:
authorErwan Velu <erwanaliasr1@gmail.com>2011-04-18 23:07:39 +0200
committerErwan Velu <erwanaliasr1@gmail.com>2011-04-18 23:07:39 +0200
commit1b2b5c5e3a34bde8c3860dde5e4d1b6ea984540d (patch)
tree0a006cfdaf71b97c62443e0fe743b6ce80eaf647 /com32/libupload
parentdddbf87e6937b39ffc0986561298db7edfe5bd56 (diff)
downloadsyslinux-1b2b5c5e3a34bde8c3860dde5e4d1b6ea984540d.tar.gz
syslinux-1b2b5c5e3a34bde8c3860dde5e4d1b6ea984540d.tar.xz
syslinux-1b2b5c5e3a34bde8c3860dde5e4d1b6ea984540d.zip
libupload: Implementing error code on tftp
When using the tftp backend, let's return the errors we got on the server.
Diffstat (limited to 'com32/libupload')
-rw-r--r--com32/libupload/upload_backend.h1
-rw-r--r--com32/libupload/upload_tftp.c52
-rw-r--r--com32/libupload/zout.c9
3 files changed, 45 insertions, 17 deletions
diff --git a/com32/libupload/upload_backend.h b/com32/libupload/upload_backend.h
index 968e2c62..7ea03e46 100644
--- a/com32/libupload/upload_backend.h
+++ b/com32/libupload/upload_backend.h
@@ -6,6 +6,7 @@
#include <stdbool.h>
#include <zlib.h>
#include "serial.h"
+#include "tftp.h"
/* Backend flags */
#define BE_NEEDLEN 0x01
diff --git a/com32/libupload/upload_tftp.c b/com32/libupload/upload_tftp.c
index 091c193c..8c65c9bd 100644
--- a/com32/libupload/upload_tftp.c
+++ b/com32/libupload/upload_tftp.c
@@ -8,7 +8,6 @@
#include <syslinux/config.h>
#include <netinet/in.h>
#include <sys/times.h>
-
#include "upload_backend.h"
enum tftp_opcode {
@@ -19,6 +18,12 @@ enum tftp_opcode {
TFTP_ERROR = 5,
};
+struct tftp_error {
+ uint16_t opcode;
+ uint16_t errcode;
+ char errmsg[0];
+} __attribute__ (( packed ));
+
struct tftp_state {
uint32_t my_ip;
uint32_t srv_ip;
@@ -28,6 +33,21 @@ struct tftp_state {
uint16_t seq;
};
+const char *tftp_string_error_message[]={
+"",
+"File not found",
+"Access Denied",
+"Disk Full",
+"Illegal Operation",
+"Unknown Transfert ID",
+"File already exists",
+"Unknown User",
+"Negociation failed",
+"Unable to resolve hostname", // not in RFC
+"Unable to connect", // not in RFC
+"No Error",
+};
+
#define RCV_BUF 2048
static int send_ack_packet(struct tftp_state *tftp,
@@ -91,9 +111,14 @@ static int send_ack_packet(struct tftp_state *tftp,
if (ntohs(xb[0]) == TFTP_ACK &&
ntohs(xb[1]) == tftp->seq) {
tftp->srv_port = ur->s_port;
- err = 0; /* All good! */
+ err = TFTP_OK; /* All good! */
goto done;
- } else if (ntohs(xb[1]) == TFTP_ERROR) {
+ } else if (ntohs(xb[0]) == TFTP_ERROR) {
+ struct tftp_error *te = (struct tftp_error *)(ur+1);
+ if (te->errcode == TFTP_ERR_UNKNOWN_ERROR) {
+ tftp_string_error_message[TFTP_ERR_UNKNOWN_ERROR]=strdup(te->errmsg);
+ }
+ err=-ntohs(te->errcode); // Return the associated error code
goto done;
}
}
@@ -113,6 +138,7 @@ static int upload_tftp_write(struct upload_backend *be)
struct tftp_state tftp;
char buffer[512+4+6];
int nlen;
+ int err=0;
const union syslinux_derivative_info *sdi =
syslinux_derivative_info();
const char *data = be->outbuf;
@@ -129,30 +155,30 @@ static int upload_tftp_write(struct upload_backend *be)
if (be->argv[1]) {
tftp.srv_ip = pxe_dns(be->argv[1]);
if (!tftp.srv_ip) {
- printf("\nUnable to resolve hostname: %s\n", be->argv[1]);
- return -1;
+// printf("\nUnable to resolve hostname: %s\n", be->argv[1]);
+ return -TFTP_ERR_UNABLE_TO_RESOLVE;
}
} else {
tftp.srv_ip = sdi->pxe.ipinfo->serverip;
if (!tftp.srv_ip) {
- printf("\nNo server IP address\n");
- return -1;
+// printf("\nNo server IP address\n");
+ return -TFTP_ERR_UNABLE_TO_CONNECT;
}
}
- printf("server %u.%u.%u.%u... ",
+/* printf("server %u.%u.%u.%u... ",
((uint8_t *)&tftp.srv_ip)[0],
((uint8_t *)&tftp.srv_ip)[1],
((uint8_t *)&tftp.srv_ip)[2],
- ((uint8_t *)&tftp.srv_ip)[3]);
+ ((uint8_t *)&tftp.srv_ip)[3]);*/
buffer[0] = 0;
buffer[1] = TFTP_WRQ;
nlen = strlcpy(buffer+2, be->argv[0], 512);
memcpy(buffer+3+nlen, "octet", 6);
- if (send_ack_packet(&tftp, buffer, 2+nlen+1+6))
- return -1;
+ if ((err=send_ack_packet(&tftp, buffer, 2+nlen+1+6))!=TFTP_OK)
+ return err;
do {
chunk = len >= 512 ? 512 : len;
@@ -163,8 +189,8 @@ static int upload_tftp_write(struct upload_backend *be)
data += chunk;
len -= chunk;
- if (send_ack_packet(&tftp, buffer, chunk+4))
- return -1;
+ if ((err=send_ack_packet(&tftp, buffer, chunk+4))!=TFTP_OK)
+ return err;
} while (chunk == 512);
return 0;
diff --git a/com32/libupload/zout.c b/com32/libupload/zout.c
index b5575a9f..47c0d308 100644
--- a/com32/libupload/zout.c
+++ b/com32/libupload/zout.c
@@ -78,6 +78,7 @@ int write_data(struct upload_backend *be, const void *buf, size_t len)
int flush_data(struct upload_backend *be)
{
int rv = Z_OK;
+ int err=-1;
while (rv != Z_STREAM_END) {
rv = do_deflate(be, Z_FINISH);
@@ -85,15 +86,15 @@ int flush_data(struct upload_backend *be)
return -1;
}
- printf("Uploading data, %u bytes... ", be->zbytes);
+// printf("Uploading data, %u bytes... ", be->zbytes);
- if (be->write(be))
- return -1;
+ if ((err=be->write(be)) != 0)
+ return err;
free(be->outbuf);
be->outbuf = NULL;
be->dbytes = be->zbytes = be->alloc = 0;
- printf("done.\n");
+// printf("done.\n");
return 0;
}