$NetBSD$

Fix session hang on 64-bit systems due to IFACE_CMDBUF struct misalignment.

There is no active upstream maintainer and no upstream bug tracker.
The original source is available via pkgsrc ham/dpbox and ham/tnt.

* src/ifacedef.h (tnt), source/ifacedef.h (dpbox): The IFACE_CMDBUF
  union contained a 'long file_id' member for CMD_BCCALLBACK.  On
  64-bit LP64 systems sizeof(long) is 8, which forces the union to
  require 8-byte alignment.  The compiler inserts 4 bytes of padding
  between the 'int command' field and the union, shifting 'data' from
  offset 4 (32-bit) to offset 8 (64-bit).

  The protocol uses length-prefixed writes that assume 'data' is at
  offset 4.  On 64-bit systems every command with a payload is
  transmitted incorrectly: the write covers only the command field and
  the padding, never reaching the actual payload.  The receiver reads
  'data' from offset 8 and gets uninitialised memory.  Affected
  commands include CMD_CSTATUS (frame count), CMD_CONNECT, CMD_ACT_RESP,
  and all other commands with data payloads.  The result is a session
  hang whenever dpbox sends enough data to exhaust the frame window,
  because the CMD_CSTATUS response from TNT is never correctly received
  by dpbox to reset the window.

  The BCAST_HEADINFO struct also contained 'long file_id', causing its
  size to differ between 32-bit and 64-bit, corrupting the temp file
  used to pass broadcast header information between dpbox and TNT.

  Fix by replacing both 'long file_id' declarations with 'int32_t
  file_id' and updating LEN_BCCALLBACK accordingly.  File IDs are
  BBS message sequence numbers that never approach 32-bit range.
  This restores IFACE_CMDBUF to 256 bytes with 'data' at offset 4
  on both 32-bit and 64-bit systems, matching the wire protocol
  assumptions throughout the codebase.  Add #include <stdint.h> for
  the int32_t type.

  This file is identical in both tnt and dpbox; the same patch must
  be applied to both packages.

--- src/ifacedef.h.orig	2026-05-23 13:36:15.111561277 +0000
+++ src/ifacedef.h	2026-05-23 13:36:15.121720675 +0000
@@ -6,6 +6,8 @@
    updated: Mark Wahl DL4YBG 96/09/23
 */
 
+#include <stdint.h>
+
 #define HEAD_LEN sizeof(IFACE_HEADER)
 #define IFACE_PACLEN 256
 #define MAX_LEN (HEAD_LEN + IFACE_PACLEN)
@@ -31,7 +33,7 @@
 #define LEN_BULLID (LEN_SIMPLE + sizeof(int) + BULLIDLEN + 1)
 #define LEN_SETRWMODE (LEN_SIMPLE + sizeof(int))
 #define LEN_BOXISBUSY (LEN_SIMPLE + sizeof(int))
-#define LEN_BCCALLBACK (LEN_SIMPLE + sizeof(long))
+#define LEN_BCCALLBACK (LEN_SIMPLE + sizeof(int32_t))
 #define LEN_SETUNPROTO (LEN_SIMPLE + 20)
 #define LEN_CONNECT (LEN_SIMPLE + sizeof(int) + 20)
 #define LEN_TNTRESPONSE (LEN_SIMPLE + sizeof(int))
@@ -76,7 +78,7 @@
     /* CMD_BOXISBUSY */
     int boxisbusy;
     /* CMD_BCCALLBACK */
-    long file_id; 
+    int32_t file_id; 
     /* CMD_SETUNPROTO */
     struct {
       char qrg[20];
@@ -166,7 +168,7 @@
   char tnc;
   char port;
   char qrg[20];
-  long file_id;
+  int32_t file_id;
   unsigned short file_type;
   char filename[256];
   char address[256];
