+#define CLNP_PDU_ER 1
+#define CLNP_PDU_DT 28
+#define CLNP_PDU_MD 29
+#define CLNP_PDU_ERQ 30
+#define CLNP_PDU_ERP 31
+
+static struct tok clnp_pdu_values[] = {
+ { CLNP_PDU_ER, "Error Report"},
+ { CLNP_PDU_MD, "MD"},
+ { CLNP_PDU_DT, "Data"},
+ { CLNP_PDU_ERQ, "Echo Request"},
+ { CLNP_PDU_ERP, "Echo Response"},
+ { 0, NULL }
+};
+
+struct clnp_header_t {
+ u_int8_t nlpid;
+ u_int8_t length_indicator;
+ u_int8_t version;
+ u_int8_t lifetime; /* units of 500ms */
+ u_int8_t type;
+ u_int8_t segment_length[2];
+ u_int8_t cksum[2];
+};
+
+/*
+ * clnp_print
+ * Decode CLNP packets. Return 0 on error.
+ */
+
+static int clnp_print (const u_int8_t *pptr, u_int length)
+{
+ const u_int8_t *optr,*source_address,*dest_address;
+ u_int li,source_address_length,dest_address_length, clnp_pdu_type;
+ const struct clnp_header_t *clnp_header;
+
+ clnp_header = (const struct clnp_header_t *) pptr;
+ li = clnp_header->length_indicator;
+ optr = pptr;
+
+ /*
+ * Sanity checking of the header.
+ */
+
+ /* FIXME */
+
+ clnp_pdu_type = clnp_header->type & CLNP_PDU_TYPE_MASK;
+
+ pptr += sizeof(struct clnp_header_t);
+ dest_address_length = *pptr;
+ dest_address = pptr + 1;
+
+ pptr += (1 + dest_address_length);
+ source_address_length = *pptr;
+ source_address = pptr +1;
+
+ pptr += (1 + source_address_length);
+
+ if (vflag < 1) {
+ printf(", %s > %s, length %u",
+ print_nsap(source_address, source_address_length),
+ print_nsap(dest_address, dest_address_length),
+ length);
+ return (1);
+ }
+ printf(", length %u", length);
+
+ printf("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, PDU length: %u, checksum: 0x%04x ",
+ tok2str(clnp_pdu_values,
+ "unknown (%u)",
+ clnp_pdu_type),
+ clnp_header->length_indicator,
+ clnp_header->version,
+ clnp_header->lifetime/2,
+ (clnp_header->lifetime%2)*5,
+ EXTRACT_16BITS(clnp_header->segment_length),
+ EXTRACT_16BITS(clnp_header->cksum));
+
+ /* do not attempt to verify the checksum if it is zero */
+ if (EXTRACT_16BITS(clnp_header->cksum) == 0)
+ printf("(unverified)");
+ else printf("(%s)", osi_cksum(optr, li) ? "incorrect" : "correct");
+
+ printf("\n\tsource address (length %u): %s\n\tdest address (length %u): %s",
+ source_address_length,
+ print_nsap(source_address, source_address_length),
+ dest_address_length,
+ print_nsap(dest_address, dest_address_length));
+
+ /* dump the remaining header data */
+ print_unknown_data(pptr,"\n\t",clnp_header->length_indicator-(pptr-optr));
+
+ switch (clnp_pdu_type) {
+
+ case CLNP_PDU_ER:
+ case CLNP_PDU_DT:
+ case CLNP_PDU_MD:
+ case CLNP_PDU_ERQ:
+ case CLNP_PDU_ERP:
+
+ default:
+ /* dump the PDU specific data */
+ print_unknown_data(optr+clnp_header->length_indicator,"\n\t ",length-clnp_header->length_indicator);
+
+ }
+
+ return (1);
+}
+
+