Commit 04456c72 authored by rswindell's avatar rswindell
Browse files

A new fidonet packet header structure definition (using a union for all the

header fields, not just the filler portion) - much more sane.
parent 48915e3b
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2013 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -38,7 +38,7 @@
#ifndef _FIDODEFS_H_
#define _FIDODEFS_H_
#include "gen_defs.h" /* uchar */
#include "gen_defs.h"
#define FIDO_NAME_LEN 36 /* Includes '\0' terminator */
#define FIDO_SUBJ_LEN 72 /* Includes '\0' terminator */
......@@ -76,45 +76,84 @@
#pragma pack(push,1) /* Disk image structures must be packed */
#endif
typedef struct _PACK { /* Fidonet Packet Header */
int16_t orignode, /* Origination Node of Packet */
destnode, /* Destination Node of Packet */
year, /* Year of Packet Creation e.g. 1995 */
month, /* Month of Packet Creation 0-11 */
day, /* Day of Packet Creation 1-31 */
hour, /* Hour of Packet Creation 0-23 */
min, /* Minute of Packet Creation 0-59 */
sec, /* Second of Packet Creation 0-59 */
baud, /* Max Baud Rate of Orig & Dest */
pkttype, /* Packet Type (-1 is obsolete) */
orignet, /* Origination Net of Packet */
destnet; /* Destination Net of Packet */
uchar prodcode, /* Product Code (00h is Fido) */
sernum, /* Binary Serial Number or NULL */
password[FIDO_PASS_LEN]; /* Session Password or NULL */
int16_t origzone, /* Origination Zone of Packet or NULL */
destzone; /* Destination Zone of Packet or NULL */
union {
char padding[20]; /* Fill Characters (Type 2.0) */
struct { /* OR Type 2+ Packet Header Info */
int16_t auxnet, /* Orig Net if Origin is a Point */
cwcopy; /* Must be Equal to cword */
uchar prodcode, /* Product Code */
revision; /* Revision */
int16_t cword, /* Compatibility Word */
origzone, /* Zone of Packet Sender or NULL */
destzone, /* Zone of Packet Receiver or NULL */
origpoint, /* Origination Point of Packet */
destpoint; /* Destination Point of Packet */
char empty[4];
} two_plus;
struct { /* OR Type 2.2 Packet Header Info */
char origdomn[8]; /* Origination Domain */
char destdomn[8]; /* Destination Domain */
char empty[4]; /* Product Specific Data */
} two_two;
} fill;
typedef struct _PACK { /* Fidonet Packet Header (types 2.0), FTS-1 */
uint16_t orignode; // Origination Node of Packet (all types)
uint16_t destnode; // Destination Node of Packet (all types)
uint16_t year; // Year of Packet Creation e.g. 1995
uint16_t month; // Month of Packet Creation 0-11
uint16_t day; // Day of Packet Creation 1-31
uint16_t hour; // Hour of Packet Creation 0-23
uint16_t min; // Minute of Packet Creation 0-59
uint16_t sec; // Second of Packet Creation 0-59
uint16_t baud; // Max Baud Rate of Orig & Dest
uint16_t pkttype; // Packet Type (2)
uint16_t orignet; // Origination Net of Packet
uint16_t destnet; // Destination Net of Packet
uint8_t prodcode; // Product Code (00h is Fido)
uint8_t sernum; // Binary Serial Number or NULL
uint8_t password[FIDO_PASS_LEN]; // Session Password or NULL
uint16_t origzone; // Origination Zone of Packet or NULL (added in rev 12 of FTS-1)
uint16_t destzone; // Destination Zone of Packet or NULL (added in rev 12 of FTS-1)
uint8_t fill[20]; // Unused (zeroed)
} fpkthdr2_t;
typedef struct _PACK { /* Fidonet Packet Header (types 2+), FSC-48 */
uint16_t orignode; // Origination Node of Packet (all types)
uint16_t destnode; // Destination Node of Packet (all types)
uint16_t year; // Year of Packet Creation e.g. 1995
uint16_t month; // Month of Packet Creation 0-11
uint16_t day; // Day of Packet Creation 1-31
uint16_t hour; // Hour of Packet Creation 0-23
uint16_t min; // Minute of Packet Creation 0-59
uint16_t sec; // Second of Packet Creation 0-59
uint16_t baud; // Max Baud Rate of Orig & Dest
uint16_t pkttype; // Packet Type (2)
uint16_t orignet; // Origination Net of Packet
uint16_t destnet; // Destination Net of Packet
uint8_t prodcodeLo; // Product Code (00h is Fido)
uint8_t revisionMaj; // Revision (major)
uint8_t password[FIDO_PASS_LEN]; // Session Password or NULL
uint16_t oldOrigZone; // Origination Zone in type 2.0 packet, unused in 2+
uint16_t oldDestZone; // Destination Zone in type 2.0 packet, unused in 2+
/* 2.0 Fill data area: */
uint16_t auxnet; // Orig Net if Origin is a Point
uint16_t cwcopy; // Must be Equal to cword (byte-swapped)
uint8_t prodcodeHi; // Product Code
uint8_t revisionMinor; // Revision (minor)
uint16_t cword; // Compatibility Word
uint16_t origzone; // Zone of Packet Sender or NULL
uint16_t destzone; // Zone of Packet Receiver or NULL
uint16_t origpoint; // Origination Point of Packet
uint16_t destpoint; // Destination Point of Packet
uint8_t proddata[4]; // Product Specific Data
} fpkthdr2plus_t;
typedef struct _PACK { /* Fidonet Packet Header (types 2.2), FSC-45 */
uint16_t orignode; // Origination Node of Packet (all types)
uint16_t destnode; // Destination Node of Packet (all types)
uint16_t origpoint; // Origination Point of Packet
uint16_t destpoint; // Destination Point of Packet
uint8_t reserved[8]; // Reserved, must be zero
uint16_t subversion; // Packet sub-version (2, indicates type 2.2 packet header)
uint16_t pkttype; // Packet Type (2)
uint16_t orignet; // Origination Net of Packet
uint16_t destnet; // Destination Net of Packet
uint8_t prodcode; // Product code (00h is Fido)
uint8_t prodrevision; // Product revision level
uint8_t password[FIDO_PASS_LEN]; // Session Password or NULL
uint16_t origzone; // Origination Zone of Packet or NULL (added in rev 12 of FTS-1)
uint16_t destzone; // Destination Zone of Packet or NULL (added in rev 12 of FTS-1)
/* 2.0 Fill data area: */
uint8_t origdomn[8]; // Origination Domain
uint8_t destdomn[8]; // Destination Domain
uint8_t proddata[4]; // Product Specific Data
} fpkthdr2_2_t;
typedef union _PACK { /* Fidonet Packet Header (types 2, 2+, and 2.2 */
fpkthdr2_t type2;
fpkthdr2plus_t type2plus;
fpkthdr2_2_t type2_2;
} fpkthdr_t;
#define FIDO_PACKET_HDR_LEN 58
......@@ -157,6 +196,15 @@ typedef struct _PACK { /* FidoNet Stored Message Header *.msg */
#define FIDO_STORED_MSG_HDR_LEN 190
#define FIDO_STORED_MSG_TERMINATOR '\0' /* 8-bits */
typedef struct _PACK { /* FidoNet 4D address (zone:net/node.point) */
uint16_t zone;
uint16_t net;
uint16_t node;
uint16_t point;
} faddr4d_t;
#if defined(PRAGMA_PACK)
#pragma pack(pop) /* original packing */
#endif
......
......@@ -3,8 +3,9 @@
/* $Id$ */
#include "fidodefs.h"
#include "sbbsdefs.h" /* faddr_t */
#include "xpendian.h" /* swap */
#include "dirwrap.h" /* _PATH_DEVNULL */
#include <stdio.h>
FILE* nulfp;
FILE* bodyfp;
......@@ -12,7 +13,7 @@ FILE* bodyfp;
/****************************************************************************/
/* Returns an ASCII string for FidoNet address 'addr' */
/****************************************************************************/
char *faddrtoa(faddr_t* addr, char* outstr)
char *faddrtoa(faddr4d_t* addr, char* outstr)
{
static char str[64];
char point[25];
......@@ -48,7 +49,7 @@ char* freadstr(FILE* fp, char* str, size_t maxlen)
int pktdump(FILE* fp, const char* fname)
{
int ch,lastch;
int ch,lastch=0;
char buf[128];
char origdomn[16]="";
char destdomn[16]="";
......@@ -56,12 +57,12 @@ int pktdump(FILE* fp, const char* fname)
char from[FIDO_NAME_LEN];
char subj[FIDO_SUBJ_LEN];
long offset;
faddr_t orig;
faddr_t dest;
faddr4d_t orig;
faddr4d_t dest;
fpkthdr_t pkthdr;
fpkdmsg_t pkdmsg;
if(fread(&pkthdr,sizeof(BYTE),sizeof(pkthdr),fp)!=sizeof(pkthdr)) {
if(fread(&pkthdr,sizeof(pkthdr),1,fp) != 1) {
fprintf(stderr,"%s !Error reading pkthdr (%u bytes)\n"
,fname,sizeof(pkthdr));
return(-1);
......@@ -75,39 +76,44 @@ int pktdump(FILE* fp, const char* fname)
// return(-2);
}
orig.zone=pkthdr.origzone;
orig.net=pkthdr.orignet;
orig.node=pkthdr.orignode;
printf("%s Packet Type ", fname);
if(pkthdr.type2.pkttype != 2) {
fprintf(stderr, "%u (unsupported packet type)\n", pkthdr.type2.pkttype);
return -3;
}
orig.zone=pkthdr.type2.origzone;
orig.net=pkthdr.type2.orignet;
orig.node=pkthdr.type2.orignode;
orig.point=0;
dest.zone=pkthdr.destzone;
dest.net=pkthdr.destnet;
dest.node=pkthdr.destnode;
dest.zone=pkthdr.type2.destzone;
dest.net=pkthdr.type2.destnet;
dest.node=pkthdr.type2.destnode;
dest.point=0; /* No point info in the 2.0 hdr! */
printf("%s Packet Type ", fname);
if(pkthdr.fill.two_plus.cword==BYTE_SWAP_16(pkthdr.fill.two_plus.cwcopy) /* 2+ Packet Header */
&& pkthdr.fill.two_plus.cword&1) {
if(pkthdr.type2plus.cword==BYTE_SWAP_16(pkthdr.type2plus.cwcopy) /* 2+ Packet Header */
&& pkthdr.type2plus.cword&1) {
fprintf(stdout,"2+");
dest.point=pkthdr.fill.two_plus.destpoint;
if(pkthdr.fill.two_plus.origpoint!=0 && orig.net==0xffff) { /* see FSC-0048 for details */
orig.net=pkthdr.fill.two_plus.auxnet;
orig.point=pkthdr.fill.two_plus.origpoint;
dest.point=pkthdr.type2plus.destpoint;
if(pkthdr.type2plus.origpoint!=0 && orig.net==0xffff) { /* see FSC-0048 for details */
orig.net=pkthdr.type2plus.auxnet;
orig.point=pkthdr.type2plus.origpoint;
}
} else if(pkthdr.baud==2) { /* Type 2.2 Packet Header */
} else if(pkthdr.type2_2.subversion==2) { /* Type 2.2 Packet Header (FSC-45) */
fprintf(stdout,"2.2");
dest.point=pkthdr.month;
sprintf(origdomn,"@%s",pkthdr.fill.two_two.origdomn);
sprintf(destdomn,"@%s",pkthdr.fill.two_two.destdomn);
dest.point=pkthdr.type2_2.destpoint;
sprintf(origdomn,"@%s",pkthdr.type2_2.origdomn);
sprintf(destdomn,"@%s",pkthdr.type2_2.destdomn);
} else
fprintf(stdout,"2.0");
printf(" from %s%s",faddrtoa(&orig,NULL),origdomn);
printf(" to %s%s\n" ,faddrtoa(&dest,NULL),destdomn);
if(pkthdr.password[0])
fprintf(stdout,"Password: '%.*s'\n",sizeof(pkthdr.password),pkthdr.password);
if(pkthdr.type2.password[0])
fprintf(stdout,"Password: '%.*s'\n",sizeof(pkthdr.type2.password),pkthdr.type2.password);
fseek(fp,sizeof(pkthdr),SEEK_SET);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment