+
+
+static gboolean
+esc_write(wtap_dumper *wdh, const guint8 *buf, int len, int *err)
+{
+ int i;
+ guint8 byte;
+ static const guint8 esc = 0xfe;
+
+ for(i=0; i<len; i++) {
+ byte=buf[i];
+ if(byte == 0xff || byte == 0xfe) {
+ /*
+ * Escape the frame delimiter and escape byte.
+ */
+ if (!wtap_dump_file_write(wdh, &esc, sizeof esc, err))
+ return FALSE;
+ byte-=2;
+ }
+ if (!wtap_dump_file_write(wdh, &byte, sizeof byte, err))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean eyesdn_dump(wtap_dumper *wdh,
+ const struct wtap_pkthdr *phdr,
+ const union wtap_pseudo_header *pseudo_header _U_,
+ const guint8 *pd, int *err);
+
+gboolean eyesdn_dump_open(wtap_dumper *wdh, int *err)
+{
+ wdh->subtype_write=eyesdn_dump;
+ wdh->subtype_close=NULL;
+
+ if (!wtap_dump_file_write(wdh, eyesdn_hdr_magic,
+ EYESDN_HDR_MAGIC_SIZE, err))
+ return FALSE;
+ wdh->bytes_dumped += EYESDN_HDR_MAGIC_SIZE;
+ *err=0;
+ return TRUE;
+}
+
+int eyesdn_dump_can_write_encap(int encap)
+{
+ switch (encap) {
+ case WTAP_ENCAP_ISDN:
+ case WTAP_ENCAP_LAYER1_EVENT:
+ case WTAP_ENCAP_DPNSS:
+ case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
+ case WTAP_ENCAP_LAPB:
+ case WTAP_ENCAP_MTP2:
+ case WTAP_ENCAP_BACNET_MS_TP:
+ case WTAP_ENCAP_PER_PACKET:
+ return 0;
+
+ default:
+ return WTAP_ERR_UNSUPPORTED_ENCAP;
+ }
+}
+
+/* Write a record for a packet to a dump file.
+ * Returns TRUE on success, FALSE on failure. */
+static gboolean eyesdn_dump(wtap_dumper *wdh,
+ const struct wtap_pkthdr *phdr,
+ const union wtap_pseudo_header *pseudo_header _U_,
+ const guint8 *pd, int *err)
+{
+ static const guint8 start_flag = 0xff;
+ guint8 buf[EYESDN_HDR_LENGTH];
+ int usecs;
+ time_t secs;
+ int channel;
+ int origin;
+ int protocol;
+ int size;
+
+ usecs=phdr->ts.nsecs/1000;
+ secs=phdr->ts.secs;
+ size=phdr->caplen;
+ origin = pseudo_header->isdn.uton;
+ channel = pseudo_header->isdn.channel;
+
+ switch(phdr->pkt_encap) {
+
+ case WTAP_ENCAP_ISDN:
+ protocol=EYESDN_ENCAP_ISDN; /* set depending on decoder format and mode */
+ break;
+
+ case WTAP_ENCAP_LAYER1_EVENT:
+ protocol=EYESDN_ENCAP_MSG;
+ break;
+
+ case WTAP_ENCAP_DPNSS:
+ protocol=EYESDN_ENCAP_DPNSS;
+ break;
+
+#if 0
+ case WTAP_ENCAP_DASS2:
+ protocol=EYESDN_ENCAP_DASS2;
+ break;
+#endif
+
+ case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
+ protocol=EYESDN_ENCAP_ATM;
+ channel=0x80;
+ break;
+
+ case WTAP_ENCAP_LAPB:
+ protocol=EYESDN_ENCAP_LAPB;
+ break;
+
+ case WTAP_ENCAP_MTP2:
+ protocol=EYESDN_ENCAP_MTP2;
+ break;
+
+ case WTAP_ENCAP_BACNET_MS_TP:
+ protocol=EYESDN_ENCAP_BACNET;
+ break;
+
+ default:
+ *err=WTAP_ERR_UNSUPPORTED_ENCAP;
+ return FALSE;
+ }
+
+ phton24(&buf[0], usecs);
+
+ buf[3] = (guint8)0;
+ buf[4] = (guint8)(0xff & (secs >> 24));
+ buf[5] = (guint8)(0xff & (secs >> 16));
+ buf[6] = (guint8)(0xff & (secs >> 8));
+ buf[7] = (guint8)(0xff & (secs >> 0));
+
+ buf[8] = (guint8) channel;
+ buf[9] = (guint8) (origin?1:0) + (protocol << 1);
+ phtons(&buf[10], size);
+
+ /* start flag */
+ if (!wtap_dump_file_write(wdh, &start_flag, sizeof start_flag, err))
+ return FALSE;
+ if (!esc_write(wdh, buf, 12, err))
+ return FALSE;
+ if (!esc_write(wdh, pd, size, err))
+ return FALSE;
+ return TRUE;
+}