+#include "interface.h"
+#include "extract.h" /* must come after interface.h */
+
+/* Compatibility */
+#ifndef IPPROTO_ND
+#define IPPROTO_ND 77
+#endif
+
+#ifndef IN_CLASSD
+#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
+#endif
+
+/* (following from ipmulti/mrouted/prune.h) */
+
+/*
+ * The packet format for a traceroute request.
+ */
+struct tr_query {
+ u_int tr_src; /* traceroute source */
+ u_int tr_dst; /* traceroute destination */
+ u_int tr_raddr; /* traceroute response address */
+ u_int tr_rttlqid; /* response ttl and qid */
+};
+
+#define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
+#define TR_GETQID(x) ((x) & 0x00ffffff)
+
+/*
+ * Traceroute response format. A traceroute response has a tr_query at the
+ * beginning, followed by one tr_resp for each hop taken.
+ */
+struct tr_resp {
+ u_int tr_qarr; /* query arrival time */
+ u_int tr_inaddr; /* incoming interface address */
+ u_int tr_outaddr; /* outgoing interface address */
+ u_int tr_rmtaddr; /* parent address in source tree */
+ u_int tr_vifin; /* input packet count on interface */
+ u_int tr_vifout; /* output packet count on interface */
+ u_int tr_pktcnt; /* total incoming packets for src-grp */
+ u_char tr_rproto; /* routing proto deployed on router */
+ u_char tr_fttl; /* ttl required to forward on outvif */
+ u_char tr_smask; /* subnet mask for src addr */
+ u_char tr_rflags; /* forwarding error codes */
+};
+
+/* defs within mtrace */
+#define TR_QUERY 1
+#define TR_RESP 2
+
+/* fields for tr_rflags (forwarding error codes) */
+#define TR_NO_ERR 0
+#define TR_WRONG_IF 1
+#define TR_PRUNED 2
+#define TR_OPRUNED 3
+#define TR_SCOPED 4
+#define TR_NO_RTE 5
+#define TR_NO_FWD 7
+#define TR_NO_SPACE 0x81
+#define TR_OLD_ROUTER 0x82
+
+/* fields for tr_rproto (routing protocol) */
+#define TR_PROTO_DVMRP 1
+#define TR_PROTO_MOSPF 2
+#define TR_PROTO_PIM 3
+#define TR_PROTO_CBT 4
+
+static void print_mtrace(register const u_char *bp, register u_int len)
+{
+ register struct tr_query *tr = (struct tr_query *)(bp + 8);
+
+ printf("mtrace %ld: %s to %s reply-to %s",
+ TR_GETQID(ntohl(tr->tr_rttlqid)),
+ ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst),
+ ipaddr_string(&tr->tr_raddr));
+ if (IN_CLASSD(ntohl(tr->tr_raddr)))
+ printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
+}
+
+static void print_mresp(register const u_char *bp, register u_int len)
+{
+ register struct tr_query *tr = (struct tr_query *)(bp + 8);
+
+ printf("mresp %ld: %s to %s reply-to %s",
+ TR_GETQID(ntohl(tr->tr_rttlqid)),
+ ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst),
+ ipaddr_string(&tr->tr_raddr));
+ if (IN_CLASSD(ntohl(tr->tr_raddr)))
+ printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid)));
+}