aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Weil <weil@mail.berlios.de>2011-02-23 19:40:14 +0100
committerBlue Swirl <blauwirbel@gmail.com>2011-02-25 15:58:59 +0000
commit6a22a9c16907fe66b466b4d273b7fb887a45d1fc (patch)
tree911f4314e13053dc5f1fd6359c817c926315a731
parent1e0dd6b7f7a54afbe35f6cd028d864e8402be217 (diff)
downloadslirp-6a22a9c16907fe66b466b4d273b7fb887a45d1fc.zip
slirp-6a22a9c16907fe66b466b4d273b7fb887a45d1fc.tar.gz
slirp-6a22a9c16907fe66b466b4d273b7fb887a45d1fc.tar.bz2
slirp: Remove some type casts caused by bad declaration of x.tp_buf
x.tp_buf was declared as a uint8_t array, but always used as a char array (which needed a lot of type casts). The patch includes these changes: * Fix declaration of x.tp_buf and remove all type casts. * Use offsetof() to get the offset of x.tp_buf. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
-rw-r--r--tftp.c18
-rw-r--r--tftp.h2
2 files changed, 8 insertions, 12 deletions
diff --git a/tftp.c b/tftp.c
index fc34333..0e54105 100644
--- a/tftp.c
+++ b/tftp.c
@@ -136,12 +136,8 @@ static int tftp_send_oack(struct tftp_session *spt, const char *key,
m->m_data += sizeof(struct udpiphdr);
tp->tp_op = htons(TFTP_OACK);
- n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
- key) +
- 1;
- n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
- value) +
- 1;
+ n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", key) + 1;
+ n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", value) + 1;
saddr.sin_addr = recv_tp->ip.ip_dst;
saddr.sin_port = recv_tp->udp.uh_dport;
@@ -282,7 +278,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
/* skip header fields */
k = 0;
- pktlen -= ((uint8_t *)&tp->x.tp_buf[0] - (uint8_t *)tp);
+ pktlen -= offsetof(struct tftp_t, x.tp_buf);
/* prepend tftp_prefix */
prefix_len = strlen(slirp->tftp_prefix);
@@ -298,7 +294,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
tftp_send_error(spt, 2, "Access violation", tp);
return;
}
- req_fname[k] = (char)tp->x.tp_buf[k];
+ req_fname[k] = tp->x.tp_buf[k];
if (req_fname[k++] == '\0') {
break;
}
@@ -310,7 +306,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
return;
}
- if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
+ if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
return;
}
@@ -338,7 +334,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
while (k < pktlen) {
const char *key, *value;
- key = (const char *)&tp->x.tp_buf[k];
+ key = &tp->x.tp_buf[k];
k += strlen(key) + 1;
if (k >= pktlen) {
@@ -346,7 +342,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
return;
}
- value = (const char *)&tp->x.tp_buf[k];
+ value = &tp->x.tp_buf[k];
k += strlen(value) + 1;
if (strcasecmp(key, "tsize") == 0) {
diff --git a/tftp.h b/tftp.h
index 2663d1c..3412e81 100644
--- a/tftp.h
+++ b/tftp.h
@@ -26,7 +26,7 @@ struct tftp_t {
uint16_t tp_error_code;
uint8_t tp_msg[512];
} tp_error;
- uint8_t tp_buf[512 + 2];
+ char tp_buf[512 + 2];
} x;
};