#include "global.h"
#include "genlib.h"
-int32 getzulutime(struct timeval *ztv) {
+uint32 getzulutime(struct timeval *ztv) {
struct timeval ttv;
if (ztv) {
/* Assemble header fields into data packet. */
- packShort(src->hdr.type = DATA_PACKET);
- packShort(src->hdr.pktsize = pktsize);
- packShort(src->hdr.eggid);
- packShort(src->hdr.samp_rec);
- packShort(src->hdr.sec_rec);
- packShort(src->hdr.rec_pkt);
- packByte(0); /* Pad byte in case we want to expand trialsz */
- packByte(src->hdr.trialsz);
- packShort(src->hdr.numrec);
+ pack16(src->hdr.type = DATA_PACKET);
+ pack16(src->hdr.pktsize = pktsize);
+ pack16(src->hdr.eggid);
+ pack16(src->hdr.samp_rec);
+ pack16(src->hdr.sec_rec);
+ pack16(src->hdr.rec_pkt);
+ pack8(0); /* Pad byte in case we want to expand trialsz */
+ pack8(src->hdr.trialsz);
+ pack16(src->hdr.numrec);
/* Append data records to packet. */
for (rec = 0; rec < src->hdr.numrec; rec++) {
- packLong(src->records[rec].timestamp);
- packBytes(&(src->records[rec].trials), src->hdr.samp_rec);
+ pack32(src->records[rec].timestamp);
+ pack8s(&(src->records[rec].trials), src->hdr.samp_rec);
}
+
/* Get CRC, pack into base(32,32,64) notation, and add tag byte (0xFF) */
lbuf = BlockCRC16((byte *) rbuf, pktP - rbuf);
lbuf = ((lbuf & 0xF800) << 13) |
((lbuf & 0x07C0) << 10) |
((lbuf & 0x003F) << 8) |
(0x00FF);
- packLong(lbuf);
+ pack32(lbuf);
+
if ((pktP - rbuf) != pktsize) {
- fprintf(stderr, "Length mismatch assembling packet. Computed: %d, actually packed: %d.\n",
+ fprintf(stderr, "Length mismatch assembling packet. Computed: %d, actually packed: %ld.\n",
pktsize, pktP - rbuf);
}
return rbuf;
/* Unpack the portable header into a host-order and aligned
EggHeader packet. */
- unpackShort(dst->hdr.type);
- unpackShort(dst->hdr.pktsize);
- unpackShort(dst->hdr.eggid);
- unpackShort(dst->hdr.samp_rec);
- unpackShort(dst->hdr.sec_rec);
- unpackShort(dst->hdr.rec_pkt);
- unpackByte(pad); /* Pad in case we later grow trialsz */
- unpackByte(dst->hdr.trialsz);
- unpackShort(dst->hdr.numrec);
+ unpack16(dst->hdr.type);
+ unpack16(dst->hdr.pktsize);
+ unpack16(dst->hdr.eggid);
+ unpack16(dst->hdr.samp_rec);
+ unpack16(dst->hdr.sec_rec);
+ unpack16(dst->hdr.rec_pkt);
+ unpack8(pad); /* Pad in case we later grow trialsz */
+ unpack8(dst->hdr.trialsz);
+ unpack16(dst->hdr.numrec);
if (dst->hdr.type != DATA_PACKET) {
#ifdef DEBUG
/* Unpack the data records from the file packet. */
for (rec = 0; rec < dst->hdr.numrec; rec++) {
- unpackLong(dst->records[rec].timestamp);
+ unpack32(dst->records[rec].timestamp);
/* Assumes sizeof(trial) = 1 */
- unpackBytes(&(dst->records[rec].trials), dst->hdr.samp_rec);
+ unpack8s(&(dst->records[rec].trials), dst->hdr.samp_rec);
}
/* Compute the CRC, reassemble into record terminator,
((lbuf & 0x003F) << 8) |
(0x00FF);
- unpackLong(filecrc);
+ unpack32(filecrc);
if (lbuf != filecrc) {
#ifdef DEBUG
- fprintf(stderr, "Bad CRC in packet read from file. Read 0x%08lX, computed 0x%08lX.\n", filecrc, lbuf);
+ fprintf(stderr, "Bad CRC in packet read from file. Read 0x%08X, computed 0x%08X.\n", filecrc, lbuf);
#endif
return -2;
}
if (dst->hdr.pktsize != (pktP - src)) {
#ifdef DEBUG
- fprintf(stderr, "Length mismatch decoding packet. Header: %d, length decoded: %d.\n",
+ fprintf(stderr, "Length mismatch decoding packet. Header: %d, length decoded: %ld.\n",
dst->hdr.pktsize, pktP - src);
#endif
return -1;
void dquad2sockaddr(struct sockaddr_in *sinp, int16 *mask, char *dquad) {
char *tp, *loser;
- long saddr;
+ uint32 saddr;
short qcount;
loser = mallocpy(dquad);
}
char *sockaddr2dquad(struct sockaddr_in *sinp) {
- long saddr;
+ uint32 saddr;
saddr = ntohl(sinp->sin_addr.s_addr);
return hl2dquad(saddr);
}
-char *hl2dquad(long addr) {
+char *hl2dquad(uint32 addr) {
static char resout[16];
- sprintf(resout, "%ld.%ld.%ld.%ld",
+ sprintf(resout, "%u.%u.%u.%u",
(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF);