Index: lib/tftp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/tftp.c,v
retrieving revision 1.21
diff -u -r1.21 tftp.c
--- lib/tftp.c	4 May 2006 22:39:47 -0000	1.21
+++ lib/tftp.c	8 May 2006 13:28:43 -0000
@@ -122,23 +122,7 @@
 } tftp_error_t;
 
 typedef struct tftp_packet {
-  unsigned short  event;
-  union {
-    struct {
-      unsigned char   data[512];
-    } request;
-    struct {
-      unsigned short  block;
-      unsigned char   data[512];
-    } data;
-    struct {
-      unsigned short  block;
-    } ack;
-    struct {
-      unsigned short  code;
-      unsigned char   data[512];
-    } error;
-  } u;
+  unsigned char data[516];
 } tftp_packet_t;
 
 typedef struct tftp_state_data {
@@ -235,6 +219,29 @@
  *
  **********************************************************/
 
+static void setpacketevent(tftp_packet_t *packet, unsigned short num)
+{
+  packet->data[0] = (num >> 8);
+  packet->data[1] = (num & 0xff);
+}
+
+
+static void setpacketblock(tftp_packet_t *packet, unsigned short num)
+{
+  packet->data[2] = (num >> 8);
+  packet->data[3] = (num & 0xff);
+}
+
+static unsigned short getrpacketevent(tftp_packet_t *packet)
+{
+  return (packet->data[0] << 8) | packet->data[1];
+}
+
+static unsigned short getrpacketblock(tftp_packet_t *packet)
+{
+  return (packet->data[2] << 8) | packet->data[3];
+}
+
 static void tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
 {
   int sbytes;
@@ -260,18 +267,18 @@
 
     if(data->set.upload) {
       /* If we are uploading, send an WRQ */
-      state->spacket.event = htons(TFTP_EVENT_WRQ);
+      setpacketevent(&state->spacket, TFTP_EVENT_WRQ);
       filename = curl_easy_unescape(data, filename, 0, NULL);
-      state->conn->upload_fromhere = (char *)state->spacket.u.data.data;
+      state->conn->upload_fromhere = (char *)&state->spacket.data[2];
       if(data->set.infilesize != -1)
         Curl_pgrsSetUploadSize(data, data->set.infilesize);
     }
     else {
       /* If we are downloading, send an RRQ */
-      state->spacket.event = htons(TFTP_EVENT_RRQ);
+      setpacketevent(&state->spacket, TFTP_EVENT_RRQ);
     }
-    snprintf((char *)state->spacket.u.request.data,
-             sizeof(state->spacket.u.request.data),
+    snprintf((char *)&state->spacket.data[2],
+             512,
              "%s%c%s%c", filename, '\0',  mode, '\0');
     sbytes = 4 + (int)strlen(filename) + (int)strlen(mode);
     sbytes = sendto(state->sockfd, (void *)&state->spacket,
@@ -325,7 +332,7 @@
   case TFTP_EVENT_DATA:
 
     /* Is this the block we expect? */
-    rblock = ntohs(state->rpacket.u.data.block);
+    rblock = getrpacketblock(&state->rpacket);
     if ((state->block+1) != rblock) {
       /* No, log it, up the retry count and fail if over the limit */
       infof(data,
@@ -340,9 +347,9 @@
     /* This is the expected block.  Reset counters and ACK it. */
     state->block = rblock;
     state->retries = 0;
-    state->spacket.event = htons(TFTP_EVENT_ACK);
-    state->spacket.u.ack.block = htons(state->block);
-    sbytes = sendto(state->sockfd, (void *)&state->spacket,
+    setpacketevent(&state->spacket, TFTP_EVENT_ACK);
+    setpacketblock(&state->spacket, state->block);
+    sbytes = sendto(state->sockfd, (void *)state->spacket.data,
                     4, SEND_4TH_ARG,
                     (struct sockaddr *)&state->remote_addr,
                     state->remote_addrlen);
@@ -409,7 +416,7 @@
 
   case TFTP_EVENT_ACK:
     /* Ack the packet */
-    rblock = ntohs(state->rpacket.u.data.block);
+    rblock = getrpacketblock(&state->rpacket);
 
     if(rblock != state->block) {
       /* This isn't the expected block.  Log it and up the retry counter */
@@ -428,14 +435,14 @@
        block */
     state->block++;
     state->retries = 0;
-    state->spacket.event = htons(TFTP_EVENT_DATA);
-    state->spacket.u.ack.block = htons(state->block);
+    setpacketevent(&state->spacket, TFTP_EVENT_DATA);
+    setpacketblock(&state->spacket, state->block);
     if(state->block > 1 && state->sbytes < 512) {
       state->state = TFTP_STATE_FIN;
       return;
     }
     Curl_fillreadbuffer(state->conn, 512, &state->sbytes);
-    sbytes = sendto(state->sockfd, (void *)&state->spacket,
+    sbytes = sendto(state->sockfd, (void *)state->spacket.data,
                     4+state->sbytes, SEND_4TH_ARG,
                     (struct sockaddr *)&state->remote_addr,
                     state->remote_addrlen);
@@ -678,17 +685,17 @@
       } else {
 
 	/* The event is given by the TFTP packet time */
-	event = (tftp_event_t)ntohs(state->rpacket.event);
+	event = (tftp_event_t)getrpacketevent(&state->rpacket);
 
 	switch(event) {
 	case TFTP_EVENT_DATA:
 	  if (state->rbytes > 4)
 	    Curl_client_write(data, CLIENTWRITE_BODY,
-			  (char *)state->rpacket.u.data.data, state->rbytes-4);
+			  (char *)&state->rpacket.data[4], state->rbytes-4);
 	  break;
 	case TFTP_EVENT_ERROR:
-	  state->error = (tftp_error_t)ntohs(state->rpacket.u.error.code);
-	  infof(conn->data, "%s\n", (char *)state->rpacket.u.error.data);
+	  state->error = (tftp_error_t)getrpacketblock(&state->rpacket);
+	  infof(conn->data, "%s\n", (char *)&state->rpacket.data[4]);
 	  break;
 	case TFTP_EVENT_ACK:
 	  break;
