aboutsummaryrefslogtreecommitdiffstats
path: root/com32/sysdump/be_tftp.c
diff options
context:
space:
mode:
authorFeng Tang <feng.tang@intel.com>2010-07-14 10:57:18 +0800
committerFeng Tang <feng.tang@intel.com>2010-07-20 11:10:04 +0800
commit3400a8754214f4cd69d49d85c0396665d7a6415f (patch)
tree8e6218d779196123eb368b136d91ae55ad2bc418 /com32/sysdump/be_tftp.c
parent967eb65904c0de527fccee529187bf0dcb4af989 (diff)
downloadsyslinux-3400a8754214f4cd69d49d85c0396665d7a6415f.tar.gz
syslinux-3400a8754214f4cd69d49d85c0396665d7a6415f.tar.xz
syslinux-3400a8754214f4cd69d49d85c0396665d7a6415f.zip
elflink: add more change as show below
com32/lib/chdir.c com32/lib/getcwd.c com32/lib/getopt.c com32/lib/pci/scan.c com32/lib/sys/farcall.c com32/lib/sys/times.c com32/lib/sys/vesa/background.c com32/lib/sys/vesa/screencpy.c com32/lib/vdprintf.c com32/rosh/rosh.c com32/rosh/rosh.h com32/sysdump/backend.h com32/sysdump/be_tftp.c com32/sysdump/main.c com32/sysdump/memmap.c com32/sysdump/sysdump.h com32/sysdump/vesa.c doc/comboot.txt doc/extlinux.txt doc/gpt.txt doc/memdisk.txt doc/menu.txt doc/syslinux.txt
Diffstat (limited to 'com32/sysdump/be_tftp.c')
-rw-r--r--com32/sysdump/be_tftp.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/com32/sysdump/be_tftp.c b/com32/sysdump/be_tftp.c
index 07fdb084..36a91eb8 100644
--- a/com32/sysdump/be_tftp.c
+++ b/com32/sysdump/be_tftp.c
@@ -3,6 +3,7 @@
*/
#include <string.h>
+#include <stdio.h>
#include <syslinux/pxe.h>
#include <syslinux/config.h>
#include <netinet/in.h>
@@ -21,23 +22,30 @@ enum tftp_opcode {
struct tftp_state {
uint32_t my_ip;
uint32_t srv_ip;
+ uint32_t srv_gw;
uint16_t my_port;
uint16_t srv_port;
uint16_t seq;
};
+#define RCV_BUF 2048
+
static int send_ack_packet(struct tftp_state *tftp,
const void *pkt, size_t len)
{
com32sys_t ireg, oreg;
- t_PXENV_UDP_WRITE *uw = __com32.cs_bounce;
- t_PXENV_UDP_READ *ur = __com32.cs_bounce;
+ t_PXENV_UDP_WRITE *uw;
+ t_PXENV_UDP_READ *ur;
clock_t start;
static const clock_t timeouts[] = {
2, 2, 3, 3, 4, 5, 6, 7, 9, 10, 12, 15, 18, 21, 26, 31,
37, 44, 53, 64, 77, 92, 110, 132, 159, 191, 229, 0
};
const clock_t *timeout;
+ int err = -1;
+
+ uw = lmalloc(sizeof *uw + len);
+ ur = lmalloc(sizeof *ur + RCV_BUF);
memset(&ireg, 0, sizeof ireg);
ireg.eax.w[0] = 0x0009;
@@ -46,6 +54,7 @@ static int send_ack_packet(struct tftp_state *tftp,
memset(uw, 0, sizeof uw);
memcpy(uw+1, pkt, len);
uw->ip = tftp->srv_ip;
+ uw->gw = tftp->srv_gw;
uw->src_port = tftp->my_port;
uw->dst_port = tftp->srv_port ? tftp->srv_port : htons(69);
uw->buffer_size = len;
@@ -65,7 +74,7 @@ static int send_ack_packet(struct tftp_state *tftp,
ur->dest_ip = tftp->my_ip;
ur->s_port = tftp->srv_port;
ur->d_port = tftp->my_port;
- ur->buffer_size = __com32.cs_bounce_size - sizeof *ur;
+ ur->buffer_size = RCV_BUF;
ur->buffer = FAR_PTR(ur+1);
ireg.ebx.w[0] = PXENV_UDP_READ;
@@ -82,15 +91,20 @@ 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;
- return 0; /* All good! */
+ err = 0; /* All good! */
+ goto done;
} else if (ntohs(xb[1]) == TFTP_ERROR) {
- return -1; /* All bad! */
+ goto done;
}
}
} while ((clock_t)(times(NULL) - start) < *timeout);
}
- return -1; /* No success... */
+done:
+ lfree(ur);
+ lfree(uw);
+
+ return err;
}
static int be_tftp_write(struct backend *be)
@@ -107,10 +121,31 @@ static int be_tftp_write(struct backend *be)
tftp.my_ip = sdi->pxe.myip;
tftp.my_port = htons(local_port++);
- tftp.srv_ip = pxe_dns(be->argv[1]);
+ tftp.srv_gw = ((tftp.srv_ip ^ tftp.my_ip) & sdi->pxe.ipinfo->netmask)
+ ? sdi->pxe.ipinfo->gateway : 0;
tftp.srv_port = 0;
tftp.seq = 0;
+ 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;
+ }
+ } else {
+ tftp.srv_ip = sdi->pxe.ipinfo->serverip;
+ if (!tftp.srv_ip) {
+ printf("\nNo server IP address\n");
+ return -1;
+ }
+ }
+
+ 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]);
+
buffer[0] = 0;
buffer[1] = TFTP_WRQ;
nlen = strlcpy(buffer+2, be->argv[0], 512);
@@ -137,7 +172,7 @@ static int be_tftp_write(struct backend *be)
struct backend be_tftp = {
.name = "tftp",
- .helpmsg = "filename tftp_server",
- .minargs = 2,
+ .helpmsg = "filename [tftp_server]",
+ .minargs = 1,
.write = be_tftp_write,
};