merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
authorBdale Garbee <bdale@gag.com>
Mon, 2 Jul 2012 20:51:44 +0000 (14:51 -0600)
committerBdale Garbee <bdale@gag.com>
Mon, 2 Jul 2012 20:51:44 +0000 (14:51 -0600)
14 files changed:
.eggprotocolrc
.eggrc
basket.c
byteorder.h
egg.c
eggui.c
genlib.c
genlib.h
global.h
network.c
reg_orion.c
reg_pear.c
storage.c
xdsub.c

index 10007d767d0005bd44dc89a42e2068d2c29dd811..a048ddb7e72576c119fde3803e19eb47cce4d5bc 100644 (file)
@@ -2,4 +2,4 @@
 #  Current protocol for egg
 #
 #   PROTOCOL <samp_rec> <sec_rec> <rec_pkt> <trialsz>
-PROTOCOL 10 10 6 200
+PROTOCOL 10 10 30 200
diff --git a/.eggrc b/.eggrc
index b8c44bcdd45f6b1533b8b2a64df0f33c6eb222e0..78df6e7eff4edd5f70ccdc0611df6d624c8615f5 100644 (file)
--- 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
index 487072bf798dd3b75fb5e1d57a7d984ae883dedc..5d20c66b39b02a9f3d94b6b97a7da13c3937ec69 100644 (file)
--- 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, "\
 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n\
@@ -147,8 +150,10 @@ static void updateHTML(void)
                   strcpy(udate, "<td colspan=2 align=center><em>Never contacted</em>");
                   strcpy(ustime, "");
              } else {
-                  strftime(udate, sizeof udate, "<td align=center>%Y-%m-%d %T", gmtime((time_t *) &eggtable[i].lastupd));
-                  strftime(ustime, sizeof ustime, "<td align=center>%Y-%m-%d %T", gmtime((time_t *) &eggStatistics[i].firstPacket));
+                  time_t lastupd_val = eggtable[i].lastupd;
+                  strftime(udate, sizeof udate, "<td align=center>%Y-%m-%d %T", gmtime(&lastupd_val));
+                  time_t firstPacket_val = eggStatistics[i].firstPacket;
+                  strftime(ustime, sizeof ustime, "<td align=center>%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, "<td align=center>%ld<td align=center>%ld<td align=center>%ld%%<td align=center>%.3f\n",
+                  fprintf(hf, "<td align=center>%d<td align=center>%d<td align=center>%d%%<td align=center>%.3f\n",
                          eggStatistics[i].trials,
                          eggStatistics[i].missing,
                          coverage,
@@ -214,8 +219,9 @@ static void updateHTML(void)
 </html>\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(&timestamp_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 <eggname> <eggid> <lastupdzulu> <setupvalid>\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,
index 6071e53628796e9063736d940e6b53837676e271..783e904c0432e6109dcf737b54ce15fa15acdcd9 100644 (file)
     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; \
                        }
     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 84786c586c4e0bcf819e19caa12e34edfa91a11f..47bef4a36614a43ae6042b8122fef892a8680590 100644 (file)
--- a/egg.c
+++ b/egg.c
@@ -49,6 +49,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <time.h>
 
 #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 80a1270d20b7348eccd7a1ab8a065bc7d0340a7c..e3eb431fd3451681939b1df96c6df2dff0848e96 100644 (file)
--- a/eggui.c
+++ b/eggui.c
 #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();
   }
 
index de328ff54aea1c22a02528f55421fe87e665fc78..094941e8051a5ae22335d149d45fc900e789be21 100644 (file)
--- 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);
   
index b176de667fa5345b70591eb1e162592fe4c99c69..e05d1c2d244df5ca9a5f6b18e779838cd2bd00f7 100644 (file)
--- 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(). */
index 09d20052ff5ab97fc6529d36f3ee1c5a911c7e91..d771cef75da6331fb73cca1781d8fac502e2c83b 100644 (file)
--- a/global.h
+++ b/global.h
 #include "byteorder.h"         /* Build byte-order independent version */
 
 /* Good for i386, but be careful... */
+/*
 #ifdef linux
 #include <sys/types.h>
-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 <stdint.h>
+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 */
index f68d02b4b9e0696231d5ac07e31b7e77ae546450..fe87a7d90f4464cc67d6ffd8e6d3cddda2463c93 100644 (file)
--- 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;
index ccb1189562b18b1f3d213bc33c45be86d2c1a991..c88ac38d0eb2cfa9a5167b4b4c04bbea75b4d324 100644 (file)
@@ -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
index 87755378b88f195e698d6e2e2655c666faf96f8d..7bb7c5ca25a658ccbdbbf1aa82fe2d93094f44a2 100644 (file)
@@ -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
index ac36436e8ff40c3f384bdd2a9df0c0d72e7003ca..2abe2de973e1aeb61f61d28a56658634fe60047a 100644 (file)
--- 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 3bcd022c400ff1fa5eafef040ebb2fb412464f06..b4fa71c52af9fbecb1214b8412ac8cf3ef0bb615 100644 (file)
--- 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