From 9c19f1c350c5d075a47a193c1b5b2d9f8fa41f04 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 2 Jul 2012 14:51:44 -0600 Subject: [PATCH] merge 64-bit fixes from Fernando Lucas Rodriguez --- .eggprotocolrc | 2 +- .eggrc | 23 +++++++++++---- basket.c | 78 ++++++++++++++++++++++++++++---------------------- byteorder.h | 42 +++++++++++++-------------- egg.c | 60 +++++++++++++++++++------------------- eggui.c | 14 ++++----- genlib.c | 66 +++++++++++++++++++++--------------------- genlib.h | 4 +-- global.h | 43 +++++++++++++++++----------- network.c | 4 +-- reg_orion.c | 4 +-- reg_pear.c | 4 +-- storage.c | 51 +++++++++++++++++++-------------- xdsub.c | 2 +- 14 files changed, 220 insertions(+), 177 deletions(-) diff --git a/.eggprotocolrc b/.eggprotocolrc index 10007d7..a048ddb 100644 --- a/.eggprotocolrc +++ b/.eggprotocolrc @@ -2,4 +2,4 @@ # Current protocol for egg # # PROTOCOL -PROTOCOL 10 10 6 200 +PROTOCOL 10 10 30 200 diff --git a/.eggrc b/.eggrc index b8c44bc..78df6e7 100644 --- a/.eggrc +++ b/.eggrc @@ -58,8 +58,8 @@ #BASKET diesse 193.8.230.134 # noosphere -> diesse -EGG noosphere 28 128.112.35.133 diesse PERM 1 -BASKET diesse 193.8.230.134 +#EGG noosphere 28 128.112.35.133 diesse PERM 1 +#BASKET diesse 193.8.230.134 # throop -> diesse #EGG throop 1003 193.8.230.132 diesse PERM 1 http://www.fourmilab.ch/ @@ -78,9 +78,20 @@ BASKET diesse 193.8.230.134 #BASKET tonga 209.157.90.137 #BASKET tonga1 209.157.90.138 -PROTOCOL 10 10 6 200 +#PROTOCOL 10 10 6 200 #REG PEAR 2 9600 -REG PSEUDO 1 9600 +#REG PSEUDO 1 9600 #REG ORION 1 9600 -NETUP pppscript up -NETDOWN pppscript down +#NETUP pppscript up +#NETDOWN pppscript down + +#egg.host.name ID# IP_address noosphere PERM 1 +#BASKET noosphere 128.112.35.133 +#PROTOCOL 10 10 30 200 +#REG ORION 0 9600 +#REG PEAR 0 9600 + +EGG egg.almadaria.es 1066 195.57.79.136 noosphere PERM 1 http://egg.almadaria.es +BASKET noosphere 128.112.35.133 +PROTOCOL 10 10 30 200 +REG ORION 0 9600 diff --git a/basket.c b/basket.c index 487072b..5d20c66 100644 --- a/basket.c +++ b/basket.c @@ -91,6 +91,7 @@ static void updateHTML(void) int i; static uint32 lastHtml = 0; uint32 now = getzulutime(NULL); + time_t now_val; char udate[256], ustime[256]; static char timeFormat[] = "%Y-%m-%d %T"; @@ -114,9 +115,11 @@ static void updateHTML(void) htmlFile[0] = 0; /* Suppress further updates */ return; } - - strftime(udate, sizeof udate, timeFormat, gmtime((time_t *) &now)); - strftime(ustime, sizeof ustime, timeFormat, gmtime((time_t *) &upsince)); + + now_val = now; + strftime(udate, sizeof udate, timeFormat, gmtime(&now_val)); + time_t upsince_val = upsince; + strftime(ustime, sizeof ustime, timeFormat, gmtime(&upsince_val)); fprintf(hf, "\ \n\ @@ -147,8 +150,10 @@ static void updateHTML(void) strcpy(udate, "Never contacted"); strcpy(ustime, ""); } else { - strftime(udate, sizeof udate, "%Y-%m-%d %T", gmtime((time_t *) &eggtable[i].lastupd)); - strftime(ustime, sizeof ustime, "%Y-%m-%d %T", gmtime((time_t *) &eggStatistics[i].firstPacket)); + time_t lastupd_val = eggtable[i].lastupd; + strftime(udate, sizeof udate, "%Y-%m-%d %T", gmtime(&lastupd_val)); + time_t firstPacket_val = eggStatistics[i].firstPacket; + strftime(ustime, sizeof ustime, "%Y-%m-%d %T", gmtime(&firstPacket_val)); } if (eggtable[i].url == NULL) { url1[0] = url2[0] = 0; @@ -182,7 +187,7 @@ static void updateHTML(void) coverage = 100; } - fprintf(hf, "%ld%ld%ld%%%.3f\n", + fprintf(hf, "%d%d%d%%%.3f\n", eggStatistics[i].trials, eggStatistics[i].missing, coverage, @@ -214,8 +219,9 @@ static void updateHTML(void) \n"); fclose(hf); #ifdef DEBUG + now_val = now; fprintf(stderr, "Updating HTML file %s at %s", - htmlFile, asctime(gmtime((time_t *) &now))); + htmlFile, asctime(gmtime(&now_val))); #endif } } @@ -437,9 +443,10 @@ int main(int argc, char *argv[]) { memcpy(&egg_now_time, pktbuf + 6, sizeof egg_now_time); egg_now_time = ntohl(egg_now_time); - fprintf(stderr, "Awake egg %d (%s) at its %lu: %s", + time_t egg_now_time_val = egg_now_time; + fprintf(stderr, "Awake egg %d (%s) at its %u: %s", pkt_eggid, eggtable[thisegg].name, egg_now_time, - asctime(gmtime((time_t *) &egg_now_time))); + asctime(gmtime(&egg_now_time_val))); } #endif @@ -618,14 +625,14 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg, EggHeader packet. */ dpktp = &dpk; - unpackShort(dpk.type); - unpackShort(dpk.pktsize); - unpackShort(dpk.eggid); - unpackShort(dpk.samp_rec); - unpackShort(dpk.sec_rec); - unpackShort(dpk.rec_pkt); - unpackByte(dpk.trialsz); - unpackShort(dpk.numrec); + unpack16(dpk.type); + unpack16(dpk.pktsize); + unpack16(dpk.eggid); + unpack16(dpk.samp_rec); + unpack16(dpk.sec_rec); + unpack16(dpk.rec_pkt); + unpack8(dpk.trialsz); + unpack16(dpk.numrec); /* This spoofing test is probably completely redundant now. */ #ifndef EGG_DYNAMIC @@ -648,7 +655,7 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg, char *spktp = pktP; if (result.hdr.numrec > 0) { - unpackLong(stamp); + unpack32(stamp); } pktP = spktp; fprintf(stderr, "Received packet: %d records from egg %d (%s).\n", @@ -660,19 +667,20 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg, transcribe to the result EggCarton. */ for (latest = 0, rec = 0; rec < result.hdr.numrec; rec++) { - unpackLong(result.records[rec].timestamp); /* Record timestamp */ + unpack32(result.records[rec].timestamp); /* Record timestamp */ if (result.records[rec].timestamp > latest) latest = result.records[rec].timestamp; #ifdef DEBUG - fprintf(stderr, " %10lu ", result.records[rec].timestamp); + fprintf(stderr, " %10u ", result.records[rec].timestamp); #endif /* Assumes sizeof(trial) = 1 */ - unpackBytes(&(result.records[rec].trials), result.hdr.samp_rec); + unpack8s(&(result.records[rec].trials), result.hdr.samp_rec); #ifdef DEBUG for (i = 0; i < result.hdr.samp_rec; i++) { fprintf(stderr, "%3d ", result.records[rec].trials[i]); } - fprintf(stderr, "%s", asctime(gmtime((time_t *) &result.records[rec].timestamp))); + time_t timestamp_val = result.records[rec].timestamp; + fprintf(stderr, "%s", asctime(gmtime(×tamp_val))); #endif } @@ -749,10 +757,10 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg, static void MakeRequest(ReqPacket *pkt, uint16 eggid, uint32 whence) { char *pktP = (char *) pkt; - packShort(REQ_PACKET); - packShort((4 * sizeof(uint16)) + sizeof(uint32)); - packShort(eggid); - packLong(whence); + pack16(REQ_PACKET); + pack16((4 * sizeof(uint16)) + sizeof(uint32)); + pack16(eggid); + pack32(whence); } /* MakeSettings -- Create a settings packet. This packet, @@ -762,14 +770,14 @@ static void MakeRequest(ReqPacket *pkt, uint16 eggid, uint32 whence) { static void MakeSettings(SettingsPacket *pkt, uint16 eggid) { char *pktP = (char *) pkt; - packShort(SETTINGS_PACKET); - packShort((7 * sizeof(uint16)) + sizeof(uint32) + sizeof(trial)); - packShort(eggid); - packLong(getzulutime(NULL)); - packShort(protocol.samp_rec); - packShort(protocol.sec_rec); - packShort(protocol.rec_pkt); - packByte(protocol.trialsz); + pack16(SETTINGS_PACKET); + pack16((7 * sizeof(uint16)) + sizeof(uint32) + sizeof(trial)); + pack16(eggid); + pack32(getzulutime(NULL)); + pack16(protocol.samp_rec); + pack16(protocol.sec_rec); + pack16(protocol.rec_pkt); + pack8(protocol.trialsz); } /* LoadEggStats -- Initialise in-memory egg status table @@ -828,7 +836,7 @@ static void SaveEggStats(void) { fprintf(fp, "# Status lines of form:\n"); fprintf(fp, "# STAT \n"); for (i = 0; i < numeggs; i++) { - fprintf(fp, "STAT %s %d %ld %d\n", + fprintf(fp, "STAT %s %d %u %d\n", eggtable[i].name, eggtable[i].id, eggtable[i].lastupd, diff --git a/byteorder.h b/byteorder.h index 6071e53..783e904 100644 --- a/byteorder.h +++ b/byteorder.h @@ -12,25 +12,25 @@ on RISC machines which typically require values to be aligned at an even multiple of their length. */ -#define packShort(x) { \ - short s = htons((short) (x)); \ - memcpy(pktP, &s, sizeof(short)); \ - pktP += sizeof(short); \ +#define pack16(x) { \ + uint16 s = htons((uint16) (x)); \ + memcpy(pktP, &s, sizeof(uint16)); \ + pktP += sizeof(uint16); \ } -#define packLong(x) { \ - long l = htonl((long) (x)); \ - memcpy(pktP, &l, sizeof(long)); \ - pktP += sizeof(long); \ +#define pack32(x) { \ + uint32 i = htonl((uint32) (x)); \ + memcpy(pktP, &i, sizeof(uint32)); \ + pktP += sizeof(uint32); \ } -#define packByte(x) { \ +#define pack8(x) { \ char c = (x); \ memcpy(pktP, &c, sizeof(char)); \ pktP += sizeof(char); \ } -#define packBytes(x, n) { \ +#define pack8s(x, n) { \ memcpy(pktP, x, n); \ pktP += n; \ } @@ -40,25 +40,25 @@ pktP. Note that the argument of these macros must be an lvalue. */ -#define unpackShort(x) { \ - short s; \ - memcpy(&s, pktP, sizeof(short)); \ - pktP += sizeof(short); \ +#define unpack16(x) { \ + uint16 s; \ + memcpy(&s, pktP, sizeof(uint16)); \ + pktP += sizeof(uint16); \ x = ntohs(s); \ } -#define unpackLong(x) { \ - long l; \ - memcpy(&l, pktP, sizeof(long)); \ - pktP += sizeof(long); \ - x = ntohl(l); \ +#define unpack32(x) { \ + uint32 i; \ + memcpy(&i, pktP, sizeof(uint32)); \ + pktP += sizeof(uint32); \ + x = ntohl(i); \ } -#define unpackByte(x) { \ +#define unpack8(x) { \ *((char *) &x) = (char) *pktP++; \ } -#define unpackBytes(x, n) { \ +#define unpack8s(x, n) { \ memcpy(x, pktP, n); \ pktP += n; \ } diff --git a/egg.c b/egg.c index 84786c5..47bef4a 100644 --- a/egg.c +++ b/egg.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "global.h" #include "genlib.h" @@ -94,7 +95,7 @@ static EggCarton savebuffer; char *pgmname; /* Program name from argv[0] */ char *myaddr; /* Interface to bind */ int16 myport; /* Service port to bind */ -int32 lastDataSent = 0; /* Time last packet sent to basket */ +uint32 lastDataSent = 0; /* Time last packet sent to basket */ /* If no priority increment has been specified at compile time, set to our default of ±10. [+/- 10, for folks without 8bit editors] */ @@ -106,7 +107,7 @@ static int niceness = NICE; /* Priority increment/decrement for collection /* Status exported to user interface. */ -int32 time_latency = 0, time_housekeeping = 0; +uint32 time_latency = 0, time_housekeeping = 0; #ifdef ALT_UI static double mean_Packet = 0.0, mean_Grand = 0.0; @@ -292,7 +293,7 @@ int main(int argc, char *argv[]) { } #ifdef DEBUG else { - printf("REG configured: %s = %d, %d, %ld\n", configuredREG ->reg_name, + printf("REG configured: %s = %d, %d, %d\n", configuredREG ->reg_name, devopts.type, devopts.port, devopts.baud); } #endif @@ -463,7 +464,7 @@ int main(int argc, char *argv[]) { totalTrials += ptrials; mean_Grand = totalGrand / totalTrials; total_Packets++; - printf("Packets sent: %ld Packet mean: %6.2f Grand mean: %6.2f\n", + printf("Packets sent: %d Packet mean: %6.2f Grand mean: %6.2f\n", total_Packets, mean_Packet, mean_Grand); #endif } @@ -489,7 +490,7 @@ int main(int argc, char *argv[]) { /* But let's be sure it really *is* in the interval. */ if (t.tv_sec < savebuffer.records[0].timestamp || t.tv_sec >= (savebuffer.records[0].timestamp + savebuffer.hdr.sec_rec * savebuffer.hdr.rec_pkt)) { - fprintf(stderr, "***Sample, collected at %ld, is not within packet starting at %ld.\n", + fprintf(stderr, "***Sample, collected at %ld, is not within packet starting at %u.\n", t.tv_sec, savebuffer.records[0].timestamp); exit(-1); } @@ -605,11 +606,12 @@ int main(int argc, char *argv[]) { uint32 stime; char *pktP = pktbuf + (2 * sizeof(uint16)); - unpackShort(reggid); - unpackLong(stime); + unpack16(reggid); + unpack32(stime); #ifdef PACKETDUMP - fprintf(stderr, "Request: eggid = %d, starttm = %ld: %s", - reggid, stime, asctime(gmtime((time_t *) &stime))); + time_t stime_val = stime; + fprintf(stderr, "Request: eggid = %d, starttm = %u: %s\n", + reggid, stime, asctime(gmtime(&stime_val))); #endif res = LoadPacket(stime, reggid, &retrcart); } @@ -639,10 +641,10 @@ int main(int argc, char *argv[]) { { char *pktP = pktbuf + (3 * sizeof(uint16)) + sizeof(uint32); - unpackShort(protocol.samp_rec); - unpackShort(protocol.sec_rec); - unpackShort(protocol.rec_pkt); - unpackByte(protocol.trialsz); + unpack16(protocol.samp_rec); + unpack16(protocol.sec_rec); + unpack16(protocol.rec_pkt); + unpack8(protocol.trialsz); } #ifdef PACKETDUMP fprintf(stderr, "Settings: samp_rec = %d, sec_rec = %d, rec_pkt = %d, trialsz = %d\n", @@ -672,12 +674,12 @@ int main(int argc, char *argv[]) { usec = time_latency; msec = usec / 1000; usec %= 1000; - printf("Sampling latency: %ld.%03ld msec", msec, usec); + printf("Sampling latency: %d.%03d msec", msec, usec); usec = time_housekeeping; msec = usec / 1000; usec %= 1000; - printf(" Housekeeping time: %ld.%03ld msec\n", msec, usec); + printf(" Housekeeping time: %d.%03d msec\n", msec, usec); #endif lt = ct; sleeptime = ((1000000 - SLACK) - ct.tv_usec); @@ -845,10 +847,10 @@ static void LoadRCFile(char *filename) { static void MakeAwake(AwakePacket *pkt) { char *pktP = (char *) pkt; - packShort(AWAKE_PACKET); - packShort((4 * sizeof(uint16)) + sizeof(uint32)); - packShort(eggtable[0].id); - packLong(getzulutime(NULL)); + pack16(AWAKE_PACKET); + pack16((4 * sizeof(uint16)) + sizeof(uint32)); + pack16(eggtable[0].id); + pack32(getzulutime(NULL)); } /* MakeDataPkt -- Build a canonical network byte order data packet @@ -866,20 +868,20 @@ static void MakeDataPkt(char **pkt, 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(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(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); } /* No need to calculate CRC -- NetTalk does that for us. diff --git a/eggui.c b/eggui.c index 80a1270..e3eb431 100644 --- a/eggui.c +++ b/eggui.c @@ -57,11 +57,11 @@ #include "version.h" #ifndef NO_UI -static int32 inittm = 0; +static uint32 inittm = 0; #endif -extern int32 lastDataSent; -extern int32 time_latency, time_housekeeping; +extern uint32 lastDataSent; +extern uint32 time_latency, time_housekeeping; /* Initialize user interface, as needed. */ int32 UIInit(void) { @@ -112,10 +112,10 @@ int32 UIUpdate(int32 cres, CollectRecord *coll) { if (coll->sampct == 1) { line = 11; - move(line++, 5); printw("Samples per record: %3d", (int)coll->opts.samp_rec); - move(line++, 5); printw("Seconds per record: %3d", (int)coll->opts.sec_rec); - move(line++, 5); printw("Records per packet: %3d", (int)coll->opts.rec_pkt); - move(line++, 5); printw("Bits per trial: %3d", (int)coll->opts.trialsz); + move(line++, 5); printw("Samples per record: %3d", coll->opts.samp_rec); + move(line++, 5); printw("Seconds per record: %3d", coll->opts.sec_rec); + move(line++, 5); printw("Records per packet: %3d", coll->opts.rec_pkt); + move(line++, 5); printw("Bits per trial: %3d", coll->opts.trialsz); refresh(); } 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); diff --git a/genlib.h b/genlib.h index b176de6..e05d1c2 100644 --- a/genlib.h +++ b/genlib.h @@ -37,7 +37,7 @@ /* Get time in GMT reference frame. If ztv is NULL, simply returns seconds. Otherwise, returns complete timeval in ztv as well. */ -extern int32 getzulutime(struct timeval *ztv); +extern uint32 getzulutime(struct timeval *ztv); /* Get difference in msec between two tvs. */ extern int32 deltams(struct timeval *tv1, struct timeval *tv2); @@ -59,7 +59,7 @@ extern void Parse(char *input, int *argc, char *argv[]); extern char *mallocpy(char *input); extern void dquad2sockaddr(struct sockaddr_in *sinp, int16 *mask, char *dquad); extern char *sockaddr2dquad(struct sockaddr_in *sinp); /* Static buffer! */ -extern char *hl2dquad(long addr); /* Static buffer! */ +extern char *hl2dquad(uint32 addr); /* Static buffer! */ /* Access to system or emulated usleep(). */ diff --git a/global.h b/global.h index 09d2005..d771cef 100644 --- a/global.h +++ b/global.h @@ -32,24 +32,35 @@ #include "byteorder.h" /* Build byte-order independent version */ /* Good for i386, but be careful... */ +/* #ifdef linux #include -typedef __u8 byte; -typedef __u8 uint8; -typedef __u16 uint16; -typedef __u32 uint32; -typedef __s8 int8; -typedef __s16 int16; -typedef __s32 int32; + typedef __u8 byte; + typedef __u8 uint8; + typedef __u16 uint16; + typedef __u32 uint32; + typedef __s8 int8; + typedef __s16 int16; + typedef __s32 int32; #else -typedef unsigned char byte; -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned long uint32; -typedef char int8; -typedef short int16; -typedef long int32; -#endif /* linux */ + typedef unsigned char byte; + typedef unsigned char uint8; + typedef unsigned ushort uint16; + typedef unsigned uint uint32; + typedef char int8; + typedef short int16; + typedef int int32; +#endif +*/ + +#include +typedef uint8_t byte; +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; /* Some fixed assumptions: Trial type is always bitsum. @@ -168,7 +179,7 @@ typedef struct eggentry { char *primbasket; int16 conntype; int16 connival; /* Connect interval in minutes */ - int32 lastupd; /* Zulutime of last update received */ + uint32 lastupd; /* Zulutime of last update received */ int16 setup; /* Does setup match config file? */ char *upcmd; /* Command to bring net up (req if conntype == DND) */ char *dncmd; /* Command to bring net down */ diff --git a/network.c b/network.c index f68d02b..fe87a7d 100644 --- a/network.c +++ b/network.c @@ -246,7 +246,7 @@ int NetListen(int sd, char **pktbuf, } #ifdef HEXDUMP - fprintf(stderr, "Received %ld bytes from %s\n", count, + fprintf(stderr, "Received %d bytes from %s\n", count, inet_ntoa(sin->sin_addr)); xd(stderr, buffer, count, FALSE); #endif @@ -274,7 +274,7 @@ int NetListen(int sd, char **pktbuf, pktsize = ntohs(rpktsize); if (pktsize != count) { #ifdef DEBUG - fprintf(stderr, "** Bad packet length: pktsize = %d, count = %ld.\n", + fprintf(stderr, "** Bad packet length: pktsize = %d, count = %d.\n", pktsize, count); #endif return ERR_PKT_BADLEN; diff --git a/reg_orion.c b/reg_orion.c index ccb1189..c88ac38 100644 --- a/reg_orion.c +++ b/reg_orion.c @@ -111,11 +111,11 @@ static int32 OpenDev(DevOpts *opts) { case 115200: baudcon = B115200; break; #endif default: - printf("%s: Baud rate %ld not supported.\n", pgmname, opts->baud); + printf("%s: Baud rate %d not supported.\n", pgmname, opts->baud); return -1; } - fprintf(stderr, "Opening %s at %ld\n", ttydev, opts->baud); + fprintf(stderr, "Opening %s at %d\n", ttydev, opts->baud); if ((TTY_fd = open(ttydev, O_RDONLY #ifdef CPU_BOUND | O_NDELAY diff --git a/reg_pear.c b/reg_pear.c index 8775537..7bb7c5c 100644 --- a/reg_pear.c +++ b/reg_pear.c @@ -91,11 +91,11 @@ static int32 OpenDev(DevOpts *opts) { case 115200: baudcon = B115200; break; #endif default: - printf("%s: Baud rate %ld not supported.\n", pgmname, opts->baud); + printf("%s: Baud rate %d not supported.\n", pgmname, opts->baud); return -1; } - fprintf(stderr, "Opening %s at %ld\n", ttydev, opts->baud); + fprintf(stderr, "Opening %s at %d\n", ttydev, opts->baud); if ((TTY_fd = open(ttydev, O_RDONLY #ifdef CPU_BOUND | O_NDELAY diff --git a/storage.c b/storage.c index ac36436..2abe2de 100644 --- a/storage.c +++ b/storage.c @@ -43,7 +43,7 @@ an error on the following declaration, disable it for your platform. */ -extern char *strdup (const char *s1); +/*extern char *strdup (const char *s1);*/ /* Eventually, these might deal with making a safe copy or mounting and unmounting a partition. Until such time as we actually do @@ -77,7 +77,7 @@ static int32 next_poss_fn(char *fn, uint32 tindex, int16 eggid); struct seekopt { char filename[256]; uint32 last_time; - long next_packet; + int32 next_packet; }; static struct seekopt seekOpt[SEEK_OPT_MAX]; @@ -217,11 +217,12 @@ int32 InitStorage(char *path) { int32 SavePacket(EggCarton *cart) { FILE *fp; char *packet, datatmp[255], datafile[255], *sp; - int32 pktime, res; + uint32 pktime, res; pktime = cart->records[0].timestamp; #ifdef STORAGE_DEBUG - fprintf(stderr, "SavePacket for %lu: %s", pktime, asctime(gmtime((time_t *) &pktime))); + time_t pktime_val = pktime; + fprintf(stderr, "SavePacket for %u: %s", pktime, asctime(gmtime(&pktime_val))); #endif /* Generate the file name corresponding to the date of @@ -285,8 +286,9 @@ int32 OpenDatabase(DBRec *dbp, uint32 tindex, int16 eggid) { int32 res; #ifdef STORAGE_DEBUG - fprintf(stderr, "OpenDatabase: Egg = %d, tindex = %ld %s", - eggid, tindex, asctime(gmtime((time_t *) &tindex))); + time_t tindex_val = tindex; + fprintf(stderr, "OpenDatabase: Egg = %d, tindex = %u %s", + eggid, tindex, asctime(gmtime(&tindex_val))); #endif dbp->eggind = 0; dbp->fp = NULL; @@ -344,7 +346,7 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c findex = PROJSTART; } #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket(%s, %lu, %d)\n", dbp->fn, tindex, eggid); + fprintf(stderr, "LoadNextPacket(%s, %u, %d)\n", dbp->fn, tindex, eggid); #endif /* See if the start address for this request is present @@ -364,20 +366,22 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c seekOpt[i].last_time == tindex) { fseek(dbp->fp, seekOpt[i].next_packet, SEEK_SET); #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket; Seek optimised [%ld] to %ld for\n file %s at %lu %s", + time_t last_time_val = seekOpt[i].last_time; + fprintf(stderr, "LoadNextPacket; Seek optimised [%d] to %d for\n file %s at %u %s", i, seekOpt[i].next_packet, seekOpt[i].filename, seekOpt[i].last_time, - asctime(gmtime((time_t *) &(seekOpt[i].last_time)))); + asctime(gmtime(&last_time_val))); #endif break; } if (i == seekOptIndex) { #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket; Cannot optimise seek in file %s\n at %lu %s", - dbp->fn, tindex, asctime(gmtime((time_t *) &(tindex)))); + time_t tindex_val = tindex; + fprintf(stderr, "LoadNextPacket; Cannot optimise seek in file %s\n at %u %s", + dbp->fn, tindex, asctime(gmtime(&tindex_val))); #endif break; /* Search wrapped table--cannot optimise */ } @@ -396,13 +400,15 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c #define SECONDS_PER_DAY (24L * 60 * 60) findex = ((findex / SECONDS_PER_DAY) + 1) * SECONDS_PER_DAY; #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket; EOF, CloseDatabase, findex = %lu: %s", - findex, asctime(gmtime((time_t *) &findex))); + time_t findex_val = findex; + fprintf(stderr, "LoadNextPacket; EOF, CloseDatabase, findex = %u: %s", + findex, asctime(gmtime(&findex_val))); #endif if (findex > now) { #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket; EOF findex = %lu > now = %lu %s", - findex, now, asctime(gmtime((time_t *) &now))); + time_t now_val = now; + fprintf(stderr, "LoadNextPacket; EOF findex = %u > now = %u %s", + findex, now, asctime(gmtime(&now_val))); #endif return ERR_EOF; } @@ -427,12 +433,13 @@ fprintf(stderr, "Eggid = %d Packet.eggid = %d\n", eggid, pktbuf.hdr.eggid); seekOpt[seekOptIndex].last_time = pktbuf.records[pktbuf.hdr.numrec - 1].timestamp; seekOpt[seekOptIndex].next_packet = ftell(dbp->fp); #ifdef STORAGE_DEBUG - fprintf(stderr, "LoadNextPacket; Seek optimisation[%d] for %s\n to address %ld for time %lu %s", + time_t last_time_val = seekOpt[seekOptIndex].last_time; + fprintf(stderr, "LoadNextPacket; Seek optimisation[%d] for %s\n to address %d for time %u %s", seekOptIndex, seekOpt[seekOptIndex].filename, seekOpt[seekOptIndex].next_packet, seekOpt[seekOptIndex].last_time, - asctime(gmtime((time_t *) &(seekOpt[seekOptIndex].last_time)))); + asctime(gmtime(&last_time_val))); #endif seekOptIndex = (seekOptIndex + 1) % SEEK_OPT_MAX; return ERR_NONE; @@ -495,8 +502,9 @@ static int32 next_filename(char *fn, uint32 tindex, int16 eggid, char ldf[255]; #ifdef STORAGE_DEBUG - fprintf(stderr, "next_filename: egg = %d, mustexist = %d, tindex = %lu %s", - eggid, mustexist, tindex, asctime(gmtime((time_t *) &tindex))); + time_t tindex_val = tindex; + fprintf(stderr, "next_filename: egg = %d, mustexist = %d, tindex = %u %s", + eggid, mustexist, tindex, asctime(gmtime(&tindex_val))); #endif if (eggid < 0 && !mustexist) { #ifdef STORAGE_DEBUG @@ -557,10 +565,11 @@ static int32 next_poss_fn(char *fn, uint32 tindex, int16 eggid) { int16 eggind; struct tm *tm; - tm = gmtime((time_t *) &tindex); + time_t time_index = tindex; + tm = gmtime(&time_index); strftime(datatmp, 255, datafmt, tm); #ifdef STORAGE_DEBUG - fprintf(stderr, "next_poss_fn: egg = %d, tindex = %lu %s", + fprintf(stderr, "next_poss_fn: egg = %d, tindex = %u %s", eggid, tindex, asctime(tm)); #endif diff --git a/xdsub.c b/xdsub.c index 3bcd022..b4fa71c 100644 --- a/xdsub.c +++ b/xdsub.c @@ -20,7 +20,7 @@ static char addrformat[80] = "%6X"; static char dataformat1[80] = "%02X"; static int bytesperline = 16, doublechar = 0, dflen = 2; -static unsigned long fileaddr; +static unsigned int fileaddr; static unsigned char lineecho[32]; /* OUTLINE -- Edit a line of binary data into the selected output -- 2.30.2