--- /dev/null
+Description: <short summary of the patch>
+ TODO: Put a short summary on the line above and replace this paragraph
+ with a longer explanation of this change. Complete the meta-information
+ with other relevant fields (see below for details). To make it easier, the
+ information below has been extracted from the changelog. Adjust it or drop
+ it.
+ .
+ gcpegg (5.1-15) unstable; urgency=medium
+ .
+ * stop trying to force which VT eggsh is launched on
+Author: Bdale Garbee <bdale@gag.com>
+
+---
+The information above should follow the Patch Tagging Guidelines, please
+checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
+are templates for supplementary fields that you might want to add:
+
+Origin: <vendor|upstream|other>, <url of original patch>
+Bug: <url in upstream bugtracker>
+Bug-Debian: https://bugs.debian.org/<bugnumber>
+Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
+Forwarded: <no|not-needed|url proving that it has been forwarded>
+Reviewed-By: <name and email of someone who approved the patch>
+Last-Update: 2019-10-26
+
+--- gcpegg-5.1.orig/basket.c
++++ gcpegg-5.1/basket.c
+@@ -42,6 +42,7 @@
+ #include <sys/socket.h>
+ #include <netdb.h>
+ #include <netinet/in.h>
++#include <time.h>
+ #include "global.h"
+ #include "genlib.h"
+ #include "storage.h"
+@@ -90,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";
+
+@@ -113,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\
+@@ -146,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;
+@@ -181,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,
+@@ -213,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
+ }
+ }
+@@ -436,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
+
+@@ -617,14 +625,14 @@ static int32 BasketReceiveDataPacket(cha
+ 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
+@@ -647,7 +655,7 @@ static int32 BasketReceiveDataPacket(cha
+ 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",
+@@ -659,19 +667,20 @@ static int32 BasketReceiveDataPacket(cha
+ 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
+ }
+
+@@ -748,10 +757,10 @@ static int32 BasketReceiveDataPacket(cha
+ 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,
+@@ -761,14 +770,14 @@ static void MakeRequest(ReqPacket *pkt,
+ 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
+@@ -827,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,
+--- gcpegg-5.1.orig/byteorder.h
++++ gcpegg-5.1/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; \
+ }
+--- gcpegg-5.1.orig/egg.c
++++ gcpegg-5.1/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; /* Pri
+
+ /* 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, EggC
+
+ /* 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.
+--- gcpegg-5.1.orig/eggrc.sample
++++ gcpegg-5.1/eggrc.sample
+@@ -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,16 @@ 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
++
+--- gcpegg-5.1.orig/eggui.c
++++ gcpegg-5.1/eggui.c
+@@ -37,6 +37,8 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <curses.h>
++#include <time.h>
++#include <string.h>
+
+ /* Curses takes it upon itself to define TRUE and FALSE,
+ incompatibly, as it happens, with the definitions in
+@@ -55,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) {
+@@ -110,10 +112,10 @@ int32 UIUpdate(int32 cres, CollectRecord
+
+ 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();
+ }
+
+@@ -124,17 +126,20 @@ int32 UIUpdate(int32 cres, CollectRecord
+ printw("EGG %s ID %d REG %s %s", eggtable[0].name, eggtable[0].id,
+ configuredREG->reg_name, Version);
+
+- tmstr = ctime(&inittm); tmstr[strlen(tmstr)-1] = 0;
++ time_t inittm_val = inittm;
++ tmstr = ctime(&inittm_val); tmstr[strlen(tmstr)-1] = 0;
+ move(line++, 5);
+ printw("Up since %25s", tmstr);
+
+ move(line++, 5);
+ now = getzulutime(NULL);
+- tmstr = ctime(&now); tmstr[strlen(tmstr)-1] = 0;
++ time_t now_val = now;
++ tmstr = ctime(&now_val); tmstr[strlen(tmstr)-1] = 0;
+ printw("Last sample at %25s", tmstr);
+
+ move(line++, 5);
+- tmstr = ctime(&lastDataSent);
++ time_t lastDataSent_val = lastDataSent;
++ tmstr = ctime(&lastDataSent_val);
+ tmstr[strlen(tmstr)-1] = 0;
+ printw("Last packet at %25s", lastDataSent == 0 ? "Never" : tmstr);
+
+--- gcpegg-5.1.orig/genlib.c
++++ gcpegg-5.1/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 *
+ /* 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 *
+ /* 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 *
+ ((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 *
+ }
+
+ 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);
+
+--- gcpegg-5.1.orig/genlib.h
++++ gcpegg-5.1/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
+ 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(). */
+--- gcpegg-5.1.orig/global.h
++++ gcpegg-5.1/global.h
+@@ -32,13 +32,35 @@
+ #include "byteorder.h" /* Build byte-order independent version */
+
+ /* Good for i386, but be careful... */
+-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;
++/*
++#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;
++#else
++ 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.
+@@ -157,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 */
+--- gcpegg-5.1.orig/hw_pear.c
++++ gcpegg-5.1/hw_pear.c
+@@ -87,7 +87,7 @@ int32 OpenDev(DevOpts *opts) {
+ designating /dev/term/a. */
+ sprintf(ttydev, "/dev/term/%c", 'a' + (opts->port - 1));
+ #else
+- sprintf(ttydev, "/dev/ttyS%d", opts->port);
++ sprintf(ttydev, "/dev/REG", opts->port);
+ #endif
+
+ switch(opts->baud) {
+--- gcpegg-5.1.orig/network.c
++++ gcpegg-5.1/network.c
+@@ -237,7 +237,7 @@ int NetListen(int sd, char **pktbuf,
+
+ size = sizeof(*sin);
+ count = recvfrom(sd, buffer, MAXBUFSIZE, 0,
+- (struct sockaddr *)sin, (int *)&size);
++ (struct sockaddr *)sin, (socklen_t *)&size);
+ if (count < 0) {
+ /* Don't wait for it. */
+ if (errno == EWOULDBLOCK) return ERR_COMM_TMOUT;
+@@ -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;
+--- gcpegg-5.1.orig/reg_orion.c
++++ gcpegg-5.1/reg_orion.c
+@@ -97,7 +97,7 @@ static int32 OpenDev(DevOpts *opts) {
+ sprintf(ttydev, "/dev/term/%c", 'a' + (opts->port - 1));
+ #endif
+ #else
+- sprintf(ttydev, "/dev/ttyS%d", opts->port);
++ sprintf(ttydev, "/dev/REG", opts->port);
+ #endif
+
+ switch(opts->baud) {
+@@ -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
+@@ -147,8 +147,10 @@ fprintf(stderr, "Error in open(%s)\n", t
+ #else
+ res = cfsetospeed(&tt, baudcon);
+ cfmakeraw(&tt);
++#if !defined(__FreeBSD_kernel__)
+ tt.c_oflag &= (~(TABDLY | ONLCR));
+ #endif
++#endif
+ res = tcsetattr(TTY_fd, TCSANOW, &tt);
+
+ oldbits[TTY_fd] = bitsleft[TTY_fd] = 0;
+--- gcpegg-5.1.orig/reg_pear.c
++++ gcpegg-5.1/reg_pear.c
+@@ -77,7 +77,7 @@ static int32 OpenDev(DevOpts *opts) {
+ sprintf(ttydev, "/dev/term/%c", 'a' + (opts->port - 1));
+ #endif
+ #else
+- sprintf(ttydev, "/dev/ttyS%d", opts->port);
++ sprintf(ttydev, "/dev/REG", opts->port);
+ #endif
+
+ switch(opts->baud) {
+@@ -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
+@@ -122,8 +122,10 @@ static int32 OpenDev(DevOpts *opts) {
+ #else
+ res = cfsetospeed(&tt, baudcon);
+ cfmakeraw(&tt);
++#if !defined(__FreeBSD_kernel__)
+ tt.c_oflag &= (~(TABDLY | ONLCR));
+ #endif
++#endif
+ res = tcsetattr(TTY_fd, TCSANOW, &tt);
+
+ oldbits[TTY_fd] = bitsleft[TTY_fd] = 0;
+--- gcpegg-5.1.orig/reg_pseudo.c
++++ gcpegg-5.1/reg_pseudo.c
+@@ -27,6 +27,7 @@
+
+ #include <stdio.h>
+ #include <unistd.h>
++#include <time.h>
+
+ #include "global.h"
+ #include "genlib.h"
+--- gcpegg-5.1.orig/regtest.c
++++ gcpegg-5.1/regtest.c
+@@ -10,6 +10,10 @@
+ #define __USE_BSD
+ #include <errno.h>
+ #undef __USE_BSD
++#if defined(__FreeBSD_kernel__)
++/* Not patching the code directly, used once, in a "|" context */
++#define O_NDELAY 0
++#endif
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
+@@ -49,14 +53,16 @@ int main(int argc, char *argv[]) {
+ }
+
+ if ((TTY_fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
+- fprintf(stderr, "%s: %s\n", argv[1], sys_errlist[errno]);
++ fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
+
+ res = tcgetattr(TTY_fd, &tt);
+ res = cfsetospeed(&tt, baud);
+ cfmakeraw(&tt);
++#if !defined(__FreeBSD_kernel__)
+ tt.c_oflag &= (~(TABDLY | ONLCR));
++#endif
+ res = tcsetattr(TTY_fd, TCSANOW, &tt);
+
+ mean = 0;
+--- gcpegg-5.1.orig/sample.eggrc
++++ gcpegg-5.1/sample.eggrc
+@@ -38,6 +38,9 @@
+ # this time. Port is serial port number (e.g. 1 for /dev/ttyS1);
+ # <baud> is baud rate.
+ #
++# NOTE: in Debian, the device opened is always /dev/REG!
++# Symlink that to whatever your actual serial device is.
++#
+ # NETUP <script> <args> ...
+ # NETDOWN <script> <args> ...
+ #
+@@ -58,8 +61,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 +81,16 @@ 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
++
+--- gcpegg-5.1.orig/storage.c
++++ gcpegg-5.1/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, uint
+ 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 ti
+ 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,
+ 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,
+ 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,
+ #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
+ 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, uin
+ 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, uint
+ 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
+
+--- gcpegg-5.1.orig/xdsub.c
++++ gcpegg-5.1/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