diff options
author | Antony Pavlov <antonynpavlov@gmail.com> | 2015-06-28 19:19:40 +0300 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-06-29 07:25:01 +0200 |
commit | 69957c548101c2c2a2e9cc5e588c610fb08d71a1 (patch) | |
tree | 04f8e5ba80ac557fa4f188128bb44bad16968f8e /fs/tftp.c | |
parent | fb6f3318de9eef90a9fc6bc7a7029ced221f78ac (diff) | |
download | barebox-69957c548101c2c2a2e9cc5e588c610fb08d71a1.tar.gz barebox-69957c548101c2c2a2e9cc5e588c610fb08d71a1.tar.xz |
tftp_recv(): handle opcode field in a more natural way
RFC1350 uses the 'opcode' term for the first 2-bytes field
of TFTP packet. But the U-boot tftp code uses the 'proto' term
for the same thing.
The patch takes back original term and makes opcode calculation
more clear.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs/tftp.c')
-rw-r--r-- | fs/tftp.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -256,22 +256,21 @@ static void tftp_timer_reset(struct file_priv *priv) static void tftp_recv(struct file_priv *priv, uint8_t *pkt, unsigned len, uint16_t uh_sport) { - uint16_t proto; - uint16_t *s; + uint16_t opcode; /* according to RFC1350 minimal tftp packet length is 4 bytes */ if (len < 4) return; - len -= 2; + opcode = ntohs(*(uint16_t *)pkt); - s = (uint16_t *)pkt; - proto = *s++; - pkt = (unsigned char *)s; + /* skip tftp opcode 2-byte field */ + len -= 2; + pkt += 2; - debug("%s: proto 0x%04x\n", __func__, proto); + debug("%s: opcode 0x%04x\n", __func__, opcode); - switch (ntohs(proto)) { + switch (opcode) { case TFTP_RRQ: case TFTP_WRQ: default: |