Index: /branches/binary/server/memcached.c
===================================================================
--- /branches/binary/server/memcached.c (revision 759)
+++ /branches/binary/server/memcached.c (revision 760)
@@ -1085,17 +1085,24 @@
         assert(c->rsize >= MIN_BIN_PKT_LENGTH + 4);
 
-        /* This is a bit of magic.  I'm using wbuf as the header, so I'll place
-        this is int in far enough to cover the header */
-        flags = (int*)(c->wbuf + MIN_BIN_PKT_LENGTH);
-        *flags = htonl(strtoul(ITEM_suffix(it), NULL, 10));
-
         /* the length has two unnecessary bytes, and then we write four more */
         add_bin_header(c, 0, GET_RES_HDR_LEN, it->nbytes - 2 + GET_RES_HDR_LEN);
-        /* Flags */
+
+        /* Add the "extras" field: CAS-id followed by flags. The cas is a 64-
+           bit datatype and require alignment to 8-byte boundaries on some
+           architechtures. Verify that the size of the packet header is of
+           the correct size (if not the following code generates SIGBUS on
+           sparc hardware).
+        */
+        assert(MIN_BIN_PKT_LENGTH % 8 == 0);
+        identifier = (uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH);
+        *identifier = swap64(it->cas_id);
+        add_iov(c, identifier, 8);
+
+        /* Add the flags */
+        flags = (int*)(c->wbuf + MIN_BIN_PKT_LENGTH + 8);
+        *flags = htonl(strtoul(ITEM_suffix(it), NULL, 10));
         add_iov(c, flags, 4);
-        identifier = (uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH + 4);
-        *identifier = swap64((uint32_t)it->cas_id);
-        add_iov(c, identifier, 8);
-        /* bytes minus the CRLF */
+
+        /* Add the data minus the CRLF */
         add_iov(c, ITEM_data(it), it->nbytes - 2);
         conn_set_state(c, conn_mwrite);
@@ -1173,6 +1180,6 @@
     key[nkey] = 0x00;
 
-    flags = ntohl(*((int*)(c->rbuf)));
-    exptime = ntohl(*((int*)(c->rbuf + 4)));
+    flags = ntohl(*((int*)(c->rbuf + 8)));
+    exptime = ntohl(*((int*)(c->rbuf + 12)));
     vlen = c->bin_header[2] - (nkey + hdrlen);
 
@@ -1198,5 +1205,5 @@
     }
 
-    it->cas_id = (uint64_t)swap64(*((int64_t*)(c->rbuf + 8)));
+    it->cas_id = (uint64_t)swap64(*((int64_t*)(c->rbuf)));
 
     switch(c->cmd) {
@@ -1289,5 +1296,5 @@
             return;
         }
-    
+
         c->msgcurr = 0;
         c->msgused = 0;
@@ -1297,5 +1304,5 @@
             return;
         }
-    
+
         c->cmd = (c->bin_header[0] >> 16) & 0xff;
         c->keylen = c->bin_header[0] & 0xffff;
Index: /branches/binary/server/doc/binary-protocol-plan-v2.txt
===================================================================
--- /branches/binary/server/doc/binary-protocol-plan-v2.txt (revision 705)
+++ /branches/binary/server/doc/binary-protocol-plan-v2.txt (revision 760)
@@ -310,8 +310,8 @@
        |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
        +---------------+---------------+---------------+---------------+
-      0| Flags                                                         |
-       +---------------+---------------+---------------+---------------+
-      4| Data version check                                            |
-       |                                                               |
+      0| Data version check                                            |
+       |                                                               |
+       +---------------+---------------+---------------+---------------+
+      8| Flags                                                         |
        +---------------+---------------+---------------+---------------+
      Total 12 bytes
@@ -400,10 +400,10 @@
        |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
        +---------------+---------------+---------------+---------------+
-      0| Flags                                                         |
-       +---------------+---------------+---------------+---------------+
-      4| Expiration                                                    |
-       +---------------+---------------+---------------+---------------+
-      8| Data version check                                            |
-       |                                                               |
+      0| Data version check                                            |
+       |                                                               |
+       +---------------+---------------+---------------+---------------+
+      8| Flags                                                         |
+       +---------------+---------------+---------------+---------------+
+     12| Expiration                                                    |
        +---------------+---------------+---------------+---------------+
      Total 16 bytes
