File: ipproto.c

package info (click to toggle)
gcpegg 5.1-7
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 324 kB
  • ctags: 437
  • sloc: ansic: 3,695; makefile: 94; sh: 27; csh: 21
file content (39 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* PROGRAM:     eggsh
 * FILE:        $Header: /home/egg/src/RCS/ipproto.c,v 1.1 1998/07/21 11:37:21 ghn Exp $
 * PURPOSE:     Declarations/definitions of IP data protocols for Egg
 * AUTHOR:      Greg Nelson
 * DATE:        98-04-12
 *
 * REVISED:     $Log: ipproto.c,v $
 * REVISED:     Revision 1.1  1998/07/21 11:37:21  ghn
 * REVISED:     Initial revision
 * REVISED:
 * Copyright 1998 - Greg Nelson
 * Redistributable under the terms of the GNU Public Licence (GPL)
 */

#include <string.h>
#include "global.h"
#include "crc16.h"

int32 PackPacket(char *buf, uint32 bufsize, EggCarton *cart) {
  int32 rec, ntrl, llen;
  uint16 crc;

  if (bufsize < sizeof(EggHeader)) return -1;

  memcpy(buf, &(cart->hdr), sizeof(EggHeader));
  buf += sizeof(EggHeader);

  ntrl = card->hdr.reclen;
  llen = sizeof(uint32) + ntrl * sizeof(trial);

  for (rec = 0; rec < cart->hdr.numrec; rec++) {
    memcpy(buf, &(card->records[rec].timestamp), sizeof(uint32));
    memcpy(buf + sizeof(uint32),
	   &(card->records[rec].trials), ntrl * sizeof(trial));
    crc = BlockCRC16((byte *)buf, llen);
    memcpy(buf + llen, &crc, sizeof(uint16));
    buf += llen + sizeof(uint16);
  }
}