merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
[debian/gcpegg] / ipproto.c
1 /* PROGRAM:     eggsh
2  * FILE:        $Header: /home/egg/src/RCS/ipproto.c,v 1.1 1998/07/21 11:37:21 ghn Exp $
3  * PURPOSE:     Declarations/definitions of IP data protocols for Egg
4  * AUTHOR:      Greg Nelson
5  * DATE:        98-04-12
6  *
7  * REVISED:     $Log: ipproto.c,v $
8  * REVISED:     Revision 1.1  1998/07/21 11:37:21  ghn
9  * REVISED:     Initial revision
10  * REVISED:
11  * Copyright 1998 - Greg Nelson
12  * Redistributable under the terms of the GNU Public Licence (GPL)
13  */
14
15 #include <string.h>
16 #include "global.h"
17 #include "crc16.h"
18
19 int32 PackPacket(char *buf, uint32 bufsize, EggCarton *cart) {
20   int32 rec, ntrl, llen;
21   uint16 crc;
22
23   if (bufsize < sizeof(EggHeader)) return -1;
24
25   memcpy(buf, &(cart->hdr), sizeof(EggHeader));
26   buf += sizeof(EggHeader);
27
28   ntrl = card->hdr.reclen;
29   llen = sizeof(uint32) + ntrl * sizeof(trial);
30
31   for (rec = 0; rec < cart->hdr.numrec; rec++) {
32     memcpy(buf, &(card->records[rec].timestamp), sizeof(uint32));
33     memcpy(buf + sizeof(uint32),
34            &(card->records[rec].trials), ntrl * sizeof(trial));
35     crc = BlockCRC16((byte *)buf, llen);
36     memcpy(buf + llen, &crc, sizeof(uint16));
37     buf += llen + sizeof(uint16);
38   }
39 }