X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=genlib.c;h=094941e8051a5ae22335d149d45fc900e789be21;hb=9c19f1c350c5d075a47a193c1b5b2d9f8fa41f04;hp=de328ff54aea1c22a02528f55421fe87e665fc78;hpb=42336b017ba010d03c1db3c28c8549e5d97a1cd9;p=debian%2Fgcpegg diff --git a/genlib.c b/genlib.c index de328ff..094941e 100644 --- a/genlib.c +++ b/genlib.c @@ -38,7 +38,7 @@ #include "global.h" #include "genlib.h" -int32 getzulutime(struct timeval *ztv) { +uint32 getzulutime(struct timeval *ztv) { struct timeval ttv; if (ztv) { @@ -86,31 +86,33 @@ char *Packetize(EggCarton *src) { /* 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; @@ -125,15 +127,15 @@ int32 Unpacketize(EggCarton *dst, char *src) { /* 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 @@ -145,9 +147,9 @@ int32 Unpacketize(EggCarton *dst, char *src) { /* 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, @@ -159,18 +161,18 @@ int32 Unpacketize(EggCarton *dst, char *src) { ((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; @@ -210,7 +212,7 @@ char *mallocpy(char *input) { void dquad2sockaddr(struct sockaddr_in *sinp, int16 *mask, char *dquad) { char *tp, *loser; - long saddr; + uint32 saddr; short qcount; loser = mallocpy(dquad); @@ -237,16 +239,16 @@ void dquad2sockaddr(struct sockaddr_in *sinp, int16 *mask, char *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);