openbsd-20021028
[openafs.git] / src / rx / rx_packet.c
index 5cdf7de..a8f00d5 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <afsconfig.h>
 #ifdef KERNEL
-#include "../afs/param.h"
+#include "afs/param.h"
 #else
 #include <afs/param.h>
 #endif
@@ -18,38 +18,41 @@ RCSID("$Header$");
 
 #ifdef KERNEL
 #if defined(UKERNEL)
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
-#include "../rx/rx_kcommon.h"
-#include "../rx/rx_clock.h"
-#include "../rx/rx_queue.h"
-#include "../rx/rx_packet.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
+#include "rx/rx_kcommon.h"
+#include "rx/rx_clock.h"
+#include "rx/rx_queue.h"
+#include "rx/rx_packet.h"
 #else /* defined(UKERNEL) */
-#include "../h/types.h"
+#include "h/types.h"
 #ifndef AFS_LINUX20_ENV
-#include "../h/systm.h"
+#include "h/systm.h"
 #endif
 #if defined(AFS_SGI_ENV) || defined(AFS_HPUX110_ENV)
-#include "../afs/sysincludes.h"
+#include "afs/sysincludes.h"
 #endif
-#include "../h/socket.h"
-#include "../netinet/in.h"
-#include "../afs/afs_osi.h"
-#include "../rx/rx_kmutex.h"
-#include "../rx/rx_clock.h"
-#include "../rx/rx_queue.h"
-#ifdef AFS_SUN5_ENV
-#include <sys/sysmacros.h>
+#if defined(AFS_OBSD_ENV)
+#include "h/proc.h"
 #endif
-#include "../rx/rx_packet.h"
+#include "h/socket.h"
 #if !defined(AFS_SUN5_ENV) &&  !defined(AFS_LINUX20_ENV)
 #if    !defined(AFS_OSF_ENV) && !defined(AFS_AIX41_ENV)
-#include "../sys/mount.h"   /* it gets pulled in by something later anyway */
+#include "sys/mount.h"   /* it gets pulled in by something later anyway */
+#endif
+#include "h/mbuf.h"
 #endif
-#include "../h/mbuf.h"
+#include "netinet/in.h"
+#include "afs/afs_osi.h"
+#include "rx_kmutex.h"
+#include "rx/rx_clock.h"
+#include "rx/rx_queue.h"
+#ifdef AFS_SUN5_ENV
+#include <sys/sysmacros.h>
 #endif
+#include "rx/rx_packet.h"
 #endif /* defined(UKERNEL) */
-#include "../rx/rx_globals.h"
+#include "rx/rx_globals.h"
 #else /* KERNEL */
 #include "sys/types.h"
 #include <sys/stat.h>
@@ -76,12 +79,11 @@ RCSID("$Header$");
 #include "rx_packet.h"
 #include "rx_globals.h"
 #include <lwp.h>
-#include "rx_internal.h"
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#else
 #ifdef HAVE_STRING_H
 #include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
 #endif
 #endif
 #ifdef HAVE_UNISTD_H
@@ -156,7 +158,7 @@ afs_int32 rx_SlowPutInt32(struct rx_packet *packet, size_t offset, afs_int32 dat
  *         all buffers are contiguously arrayed in the iovec from 0..niovecs-1
  */ 
 afs_int32 rx_SlowReadPacket(struct rx_packet *packet, unsigned int offset,
-                       int resid, char *out)
+       int resid, char *out)
 {
   unsigned int i, j, l, r;
   for (l=0, i=1; i< packet->niovecs ; i++ ) {
@@ -173,7 +175,7 @@ afs_int32 rx_SlowReadPacket(struct rx_packet *packet, unsigned int offset,
   r = resid;
   while ((resid > 0) && (i < packet->niovecs)) {
     j = MIN (resid, packet->wirevec[i].iov_len - (offset - l));
-    bcopy ((char *)(packet->wirevec[i].iov_base) + (offset - l), out, j);
+    memcpy(out, (char *)(packet->wirevec[i].iov_base) + (offset - l), j);
     resid -= j;
     l += packet->wirevec[i].iov_len;
     i++;  
@@ -189,7 +191,7 @@ afs_int32 rx_SlowReadPacket(struct rx_packet *packet, unsigned int offset,
  *        offset is an integral multiple of the word size.
  */ 
 afs_int32 rx_SlowWritePacket(struct rx_packet *packet, int offset, int resid,
-                        char *in)
+       char *in)
 {
   int i, j, l, r;
   char * b;
@@ -213,7 +215,7 @@ afs_int32 rx_SlowWritePacket(struct rx_packet *packet, int offset, int resid,
     
     b = (char*)(packet->wirevec[i].iov_base) + (offset - l);
     j = MIN (resid, packet->wirevec[i].iov_len - (offset - l));
-    bcopy (in, b, j);
+    memcpy(b, in, j);
     resid -= j;
     l += packet->wirevec[i].iov_len;
     i++;  
@@ -222,7 +224,7 @@ afs_int32 rx_SlowWritePacket(struct rx_packet *packet, int offset, int resid,
   return (resid ? (r - resid) : r);
 }
 
-static struct rx_packet * allocCBuf(int class)
+static struct rx_packet *allocCBuf(int class)
 {
   struct rx_packet *c;
   SPLVAR;
@@ -270,8 +272,9 @@ static struct rx_packet * allocCBuf(int class)
   rx_nFreePackets--;
   c = queue_First(&rx_freePacketQueue, rx_packet);
   queue_Remove(c);
-  if (c->header.flags != RX_FREE_PACKET)
+  if (!(c->flags & RX_PKTFLAG_FREE))
     osi_Panic("rxi_AllocPacket: packet not free\n");
+  c->flags = 0;                /* clear RX_PKTFLAG_FREE, initialize the rest */
   c->header.flags = 0;
   
 #ifdef KERNEL
@@ -307,9 +310,7 @@ void rxi_freeCBuf(struct rx_packet *c)
  * This isn't terribly general, because it knows that the packets are only
  * rounded up to the EBS (userdata + security header).
  */
-int rxi_RoundUpPacket(p, nb)
-     struct rx_packet * p;
-     unsigned int nb;
+int rxi_RoundUpPacket(struct rx_packet *p, unsigned int nb)
 {
   int i;
   i = p->niovecs - 1;
@@ -365,7 +366,7 @@ void rxi_MorePackets(int apackets)
   p = rx_mallocedP = (struct rx_packet *) osi_Alloc(getme);
 
   PIN(p, getme);       /* XXXXX */
-  bzero((char *)p, getme);
+  memset((char *)p, 0, getme);
   NETPRI;
   AFS_RXGLOCK();
   MUTEX_ENTER(&rx_freePktQ_lock);
@@ -375,7 +376,7 @@ void rxi_MorePackets(int apackets)
     p->wirevec[0].iov_len  = RX_HEADER_SIZE;
     p->wirevec[1].iov_base = (char *) (p->localdata);
     p->wirevec[1].iov_len  = RX_FIRSTBUFFERSIZE;
-    p->header.flags = RX_FREE_PACKET;
+    p->flags |= RX_PKTFLAG_FREE;
     p->niovecs = 2;
     
     queue_Append(&rx_freePacketQueue, p);
@@ -403,14 +404,14 @@ void rxi_MorePacketsNoLock(int apackets)
   getme = apackets * sizeof(struct rx_packet);
   p = rx_mallocedP = (struct rx_packet *) osi_Alloc(getme);
 
-  bzero((char *)p, getme);
+  memset((char *)p, 0, getme);
 
   for (e = p + apackets; p<e; p++) {
     p->wirevec[0].iov_base = (char *) (p->wirehead);
     p->wirevec[0].iov_len  = RX_HEADER_SIZE;
     p->wirevec[1].iov_base = (char *) (p->localdata);
     p->wirevec[1].iov_len  = RX_FIRSTBUFFERSIZE;
-    p->header.flags = RX_FREE_PACKET;
+    p->flags |= RX_PKTFLAG_FREE;
     p->niovecs = 2;
     
     queue_Append(&rx_freePacketQueue, p);
@@ -432,7 +433,7 @@ void rxi_FreeAllPackets(void)
 /* Allocate more packets iff we need more continuation buffers */
 /* In kernel, can't page in memory with interrupts disabled, so we
  * don't use the event mechanism. */
-void rx_CheckPackets()
+void rx_CheckPackets(void)
 {
   if (rxi_NeedMorePackets) {
     rxi_MorePackets(rx_initSendWindow); 
@@ -457,16 +458,14 @@ void rxi_FreePacketNoLock(struct rx_packet *p)
 {
   dpf(("Free %x\n", p));
 
-  if (p->header.flags & RX_FREE_PACKET)
+  if (p->flags & RX_PKTFLAG_FREE)
     osi_Panic("rxi_FreePacketNoLock: packet already free\n");
   rx_nFreePackets++;
-  p->header.flags = RX_FREE_PACKET;
+  p->flags |= RX_PKTFLAG_FREE;
   queue_Append(&rx_freePacketQueue, p);
 }
 
-int rxi_FreeDataBufsNoLock(p, first)
-     struct rx_packet * p;
-     int first;
+int rxi_FreeDataBufsNoLock(struct rx_packet *p, int first)
 {
   struct iovec *iov, *end;
   
@@ -514,9 +513,7 @@ void rxi_RestoreDataBufs(struct rx_packet *p)
     }
 }
 
-int rxi_TrimDataBufs(p, first)
-     struct rx_packet * p;
-     int first;
+int rxi_TrimDataBufs(struct rx_packet *p, int first)
 {
   int length;
   struct iovec *iov, *end;
@@ -579,8 +576,7 @@ void rxi_FreePacket(struct rx_packet *p)
  * bytes in the packet at this point, **not including** the header.
  * The header is absolutely necessary, besides, this is the way the
  * length field is usually used */
-struct rx_packet *rxi_AllocPacketNoLock(class)
-     int class;
+struct rx_packet *rxi_AllocPacketNoLock(int class)
 {
   register struct rx_packet *p;
   
@@ -624,12 +620,13 @@ struct rx_packet *rxi_AllocPacketNoLock(class)
   
   rx_nFreePackets--;
   p = queue_First(&rx_freePacketQueue, rx_packet);
-  if (p->header.flags != RX_FREE_PACKET)
+  if (!(p->flags & RX_PKTFLAG_FREE))
     osi_Panic("rxi_AllocPacket: packet not free\n");
   
   dpf(("Alloc %x, class %d\n", p, class));
   
   queue_Remove(p);
+  p->flags = 0;                /* clear RX_PKTFLAG_FREE, initialize the rest */
   p->header.flags = 0;
   
   /* have to do this here because rx_FlushWrite fiddles with the iovs in
@@ -645,8 +642,7 @@ struct rx_packet *rxi_AllocPacketNoLock(class)
   return p;
 }
 
-struct rx_packet *rxi_AllocPacket(class)
-     int class;
+struct rx_packet *rxi_AllocPacket(int class)
 {
     register struct rx_packet *p;
 
@@ -661,9 +657,7 @@ struct rx_packet *rxi_AllocPacket(class)
  * returning.  caution: this is often called at NETPRI
  * Called with call locked.
  */
-struct rx_packet *rxi_AllocSendPacket(call, want)
-register struct rx_call *call;
-int want;
+struct rx_packet *rxi_AllocSendPacket(register struct rx_call *call, int want)
 {
     register struct rx_packet *p = (struct rx_packet *) 0;
     register int mud;
@@ -727,8 +721,8 @@ int want;
 #ifndef KERNEL
 
 /* count the number of used FDs */
-static int CountFDs(amax)
-register int amax; {
+static int CountFDs(register int amax)
+{
     struct stat tstat;
     register int i, code;
     register int count;
@@ -754,11 +748,7 @@ register int amax; {
  * (host,port) of the sender are stored in the supplied variables, and
  * the data length of the packet is stored in the packet structure.
  * The header is decoded. */
-int rxi_ReadPacket(socket, p, host, port)
-     int socket;
-     register struct rx_packet *p;
-     afs_uint32 *host;
-     u_short *port;
+int rxi_ReadPacket(int socket, register struct rx_packet *p, afs_uint32 *host, u_short *port)
 {
     struct sockaddr_in from;
     int nbytes;
@@ -786,10 +776,10 @@ int rxi_ReadPacket(socket, p, host, port)
     * our problems caused by the lack of a length field in the rx header.
     * Use the extra buffer that follows the localdata in each packet
     * structure. */
-    savelen = p->wirevec[p->niovecs].iov_len;
-    p->wirevec[p->niovecs].iov_len += RX_EXTRABUFFERSIZE;
+    savelen = p->wirevec[p->niovecs-1].iov_len;
+    p->wirevec[p->niovecs-1].iov_len += RX_EXTRABUFFERSIZE;
 
-    bzero((char *)&msg, sizeof(msg));
+    memset((char *)&msg, 0, sizeof(msg));
     msg.msg_name = (char *) &from;
     msg.msg_namelen = sizeof(struct sockaddr_in);
     msg.msg_iov = p->wirevec;
@@ -797,7 +787,7 @@ int rxi_ReadPacket(socket, p, host, port)
     nbytes = rxi_Recvmsg(socket, &msg, 0);
 
    /* restore the vec to its correct state */
-    p->wirevec[p->niovecs].iov_len = savelen;
+    p->wirevec[p->niovecs-1].iov_len = savelen;
 
     p->length = (nbytes - RX_HEADER_SIZE);
     if ((nbytes > tlen) || (p->length  & 0x8000)) {  /* Bogus packet */
@@ -867,11 +857,8 @@ int rxi_ReadPacket(socket, p, host, port)
  * HACK: We store the length of the first n-1 packets in the
  * last two pad bytes. */
 
-struct rx_packet *rxi_SplitJumboPacket(p, host, port, first)
-     register struct rx_packet *p;
-     afs_int32 host;
-     short port;
-     int first;
+struct rx_packet *rxi_SplitJumboPacket(register struct rx_packet *p, afs_int32 host, 
+       short port, int first)
 {
     struct rx_packet *np;
     struct rx_jumboHeader *jp;
@@ -932,13 +919,8 @@ struct rx_packet *rxi_SplitJumboPacket(p, host, port, first)
 
 #ifndef KERNEL
 /* Send a udp datagram */
-int osi_NetSend(socket, addr, dvec, nvecs, length, istack)
-    osi_socket socket;
-    char * addr;
-    struct iovec *dvec;
-    int nvecs;
-    int length;
-    int istack;
+int osi_NetSend(osi_socket socket, void *addr, struct iovec *dvec, int nvecs, 
+       int length, int istack)
 {
     struct msghdr msg;
 
@@ -953,7 +935,7 @@ int osi_NetSend(socket, addr, dvec, nvecs, length, istack)
     return 0;
 }
 #elif !defined(UKERNEL)
-/* osi_NetSend is defined in afs/afs_osinet.c
+/*
  * message receipt is done in rxk_input or rx_put.
  */
 
@@ -965,10 +947,7 @@ int osi_NetSend(socket, addr, dvec, nvecs, length, istack)
  * Returns the number of bytes not transferred.
  * The message is NOT changed.
  */
-static int cpytoc(mp, off, len, cp)
-    mblk_t *mp;
-    register int off, len;
-    register char * cp;
+static int cpytoc(mblk_t *mp, register int off, register int len, register char *cp)
 {
     register int n;
 
@@ -977,7 +956,7 @@ static int cpytoc(mp, off, len, cp)
            return -1;
        }
        n = MIN(len, (mp->b_wptr - mp->b_rptr));
-       bcopy((char *)mp->b_rptr, cp, n);
+       memcpy(cp, (char *)mp->b_rptr, n);
        cp += n;
        len -= n;
        mp->b_rptr += n;
@@ -989,10 +968,7 @@ static int cpytoc(mp, off, len, cp)
  * but it doesn't really.  
  * This sucks, anyway, do it like m_cpy.... below 
  */
-static int cpytoiovec(mp, off, len, iovs, niovs)
-    mblk_t *mp;
-    int off, len, niovs;
-    register struct iovec *iovs;
+static int cpytoiovec(mblk_t *mp, int off, int len, register struct iovec *iovs, int niovs)
 {
     register int m,n,o,t,i;
 
@@ -1009,7 +985,7 @@ static int cpytoiovec(mp, off, len, iovs, niovs)
            t = iovs[i].iov_len;
          }
          m = MIN(n,t);
-         bcopy((char *)mp->b_rptr, iovs[i].iov_base + o, m);
+         memcpy(iovs[i].iov_base + o, (char *)mp->b_rptr, m);
          mp->b_rptr += m;
          o += m;
          t -= m;
@@ -1022,10 +998,7 @@ static int cpytoiovec(mp, off, len, iovs, niovs)
 #define m_cpytoiovec(a, b, c, d, e) cpytoiovec(a, b, c, d, e)
 #else
 #if !defined(AFS_LINUX20_ENV)
-static int m_cpytoiovec(m, off, len, iovs, niovs)
-     struct mbuf *m;
-     int off, len, niovs;
-     struct iovec iovs[];
+static int m_cpytoiovec(struct mbuf *m, int off, int len, struct iovec iovs[], int niovs)
 {
   caddr_t p1, p2;
   unsigned int l1, l2, i, t;
@@ -1052,7 +1025,7 @@ static int m_cpytoiovec(m, off, len, iovs, niovs)
   
   while (len) {
     t = MIN(l1, MIN(l2, (unsigned int)len));
-    bcopy (p1, p2, t);
+    memcpy(p2, p1, t);
     p1 += t;    p2 += t;
     l1 -= t;    l2 -= t;
     len -= t;
@@ -1101,12 +1074,8 @@ int hdr_len, data_len;
 
 /* send a response to a debug packet */
 
-struct rx_packet *rxi_ReceiveDebugPacket(ap, asocket, ahost, aport, istack)
-  osi_socket asocket;
-  afs_int32 ahost;
-  short aport;
-  register struct rx_packet *ap;
-  int istack;
+struct rx_packet *rxi_ReceiveDebugPacket(register struct rx_packet *ap, 
+       osi_socket asocket, afs_int32 ahost, short aport, int istack)
 {
     struct rx_debugIn tin;
     afs_int32 tl;
@@ -1135,7 +1104,7 @@ struct rx_packet *rxi_ReceiveDebugPacket(ap, asocket, ahost, aport, istack)
            struct rx_debugStats tstat;
 
            /* get basic stats */
-           bzero ((char *)&tstat, sizeof(tstat)); /* make sure spares are zero */
+           memset((char *)&tstat, 0, sizeof(tstat)); /* make sure spares are zero */
            tstat.version = RX_DEBUGI_VERSION;
 #ifndef        RX_ENABLE_LOCKS
            tstat.waitingForPackets = rx_waitingForPackets;
@@ -1176,7 +1145,7 @@ struct rx_packet *rxi_ReceiveDebugPacket(ap, asocket, ahost, aport, istack)
            if (tl > 0)
              return ap;
 
-           bzero ((char *)&tconn, sizeof(tconn)); /* make sure spares are zero */
+           memset((char *)&tconn, 0, sizeof(tconn)); /* make sure spares are zero */
            /* get N'th (maybe) "interesting" connection info */
            for(i=0;i<rx_hashTableSize;i++) {
 #if !defined(KERNEL)
@@ -1277,7 +1246,7 @@ struct rx_packet *rxi_ReceiveDebugPacket(ap, asocket, ahost, aport, istack)
            if (tl > 0)
              return ap;
 
-           bzero ((char *)&tpeer, sizeof(tpeer));
+           memset((char *)&tpeer, 0, sizeof(tpeer));
            for(i=0;i<rx_hashTableSize;i++) {
 #if !defined(KERNEL)
                /* the time complexity of the algorithm used here
@@ -1388,12 +1357,8 @@ struct rx_packet *rxi_ReceiveDebugPacket(ap, asocket, ahost, aport, istack)
     return ap;
 }
 
-struct rx_packet *rxi_ReceiveVersionPacket(ap, asocket, ahost, aport, istack)
-  osi_socket asocket;
-  afs_int32 ahost;
-  short aport;
-  register struct rx_packet *ap;
-  int istack;
+struct rx_packet *rxi_ReceiveVersionPacket(register struct rx_packet *ap, 
+       osi_socket asocket, afs_int32 ahost, short aport, int istack)
 {
     afs_int32 tl;
 
@@ -1406,8 +1371,8 @@ struct rx_packet *rxi_ReceiveVersionPacket(ap, asocket, ahost, aport, istack)
 
        ap->header.flags = ap->header.flags & ~RX_CLIENT_INITIATED;
        rxi_EncodePacketHeader(ap);
-       bzero(buf, sizeof(buf));
-       snprintf(buf, sizeof(buf), "%s", cml_version_number+4);
+       memset(buf, 0, sizeof(buf));
+       strncpy(buf, cml_version_number+4, sizeof(buf)-1);
        rx_packetwrite(ap, 0, 65, buf);
        tl = ap->length;
        ap->length = 65;
@@ -1435,7 +1400,9 @@ static void rxi_SendDebugPacket(struct rx_packet *apacket, osi_socket asocket,
     taddr.sin_family = AF_INET;
     taddr.sin_port = aport;
     taddr.sin_addr.s_addr = ahost;
-
+#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
+    taddr.sin_len = sizeof(struct sockaddr_in);
+#endif
 
     /* We need to trim the niovecs. */
     nbytes = apacket->length;
@@ -1578,10 +1545,8 @@ void rxi_SendPacket(struct rx_connection * conn, struct rx_packet *p,
 /* Send a list of packets to appropriate destination for the specified
  * connection.  The headers are first encoded and placed in the packets.
  */
-void rxi_SendPacketList(struct rx_connection * conn,
-                       struct rx_packet **list,
-                       int len,
-                       int istack)
+void rxi_SendPacketList(struct rx_connection * conn, struct rx_packet **list,
+       int len, int istack)
 {
 #if     defined(AFS_SUN5_ENV) && defined(KERNEL)
     int waslocked;
@@ -1752,14 +1717,9 @@ void rxi_SendPacketList(struct rx_connection * conn,
  * copied into the packet.  Type is the type of the packet, as defined
  * in rx.h.  Bug: there's a lot of duplication between this and other
  * routines.  This needs to be cleaned up. */
-struct rx_packet *
-rxi_SendSpecial(call, conn, optionalPacket, type, data, nbytes, istack)
-    register struct rx_call *call;
-    register struct rx_connection *conn;
-    struct rx_packet *optionalPacket;
-    int type;
-    char *data;
-    int nbytes, istack;
+struct rx_packet *rxi_SendSpecial(register struct rx_call *call, 
+       register struct rx_connection *conn, struct rx_packet *optionalPacket, 
+       int type, char *data, int nbytes, int istack)
 {
     /* Some of the following stuff should be common code for all
      * packet sends (it's repeated elsewhere) */
@@ -1827,12 +1787,11 @@ rxi_SendSpecial(call, conn, optionalPacket, type, data, nbytes, istack)
 /* Encode the packet's header (from the struct header in the packet to
  * the net byte order representation in the wire representation of the
  * packet, which is what is actually sent out on the wire) */
-void rxi_EncodePacketHeader(p)
-register struct rx_packet *p;
+void rxi_EncodePacketHeader(register struct rx_packet *p)
 {
     register afs_uint32 *buf = (afs_uint32 *)(p->wirevec[0].iov_base);      /* MTUXXX */
 
-    bzero((char *)buf, RX_HEADER_SIZE);
+    memset((char *)buf, 0, RX_HEADER_SIZE);
     *buf++ = htonl(p->header.epoch);
     *buf++ = htonl(p->header.cid);
     *buf++ = htonl(p->header.callNumber);
@@ -1846,39 +1805,47 @@ register struct rx_packet *p;
 }
 
 /* Decode the packet's header (from net byte order to a struct header) */
-void rxi_DecodePacketHeader(p)
-register struct rx_packet *p;
+void rxi_DecodePacketHeader(register struct rx_packet *p)
 {
     register afs_uint32 *buf = (afs_uint32*)(p->wirevec[0].iov_base);      /* MTUXXX */
     afs_uint32 temp;
 
-    p->header.epoch = ntohl(*buf++);
-    p->header.cid = ntohl(*buf++);
-    p->header.callNumber = ntohl(*buf++);
-    p->header.seq = ntohl(*buf++);
-    p->header.serial = ntohl(*buf++);
-    temp = ntohl(*buf++);
+    p->header.epoch = ntohl(*buf);
+    buf++;
+    p->header.cid = ntohl(*buf);
+    buf++;
+    p->header.callNumber = ntohl(*buf);
+    buf++;
+    p->header.seq = ntohl(*buf);
+    buf++;
+    p->header.serial = ntohl(*buf);
+    buf++;
+
+    temp = ntohl(*buf);
+    buf++;
+
     /* C will truncate byte fields to bytes for me */
     p->header.type = temp>>24;
     p->header.flags = temp>>16;
     p->header.userStatus = temp>>8;
     p->header.securityIndex = temp>>0;
-    temp = ntohl(*buf++);
+
+    temp = ntohl(*buf);
+    buf++;
+
     p->header.serviceId = (temp&0xffff);
     p->header.spare = temp>>16;
     /* Note: top 16 bits of this last word are the security checksum */
 }
 
-void rxi_PrepareSendPacket(call, p, last)
-    register struct rx_call *call;
-    register struct rx_packet *p;
-    register int last;
+void rxi_PrepareSendPacket(register struct rx_call *call, register struct rx_packet *p, 
+       register int last)
 {
     register struct rx_connection *conn = call->conn;
     int i, j;
     ssize_t len;       /* len must be a signed type; it can go negative */
 
-    p->acked = 0;
+    p->flags &= ~RX_PKTFLAG_ACKED;
     p->header.cid = (conn->cid | call->channel);
     p->header.serviceId = conn->serviceId;
     p->header.securityIndex = conn->securityIndex;