[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tcpdump/oltr



If anyone is interested, this is a patch to P. Norton's patch to tcpdump.
(which is at ftp://ftp.cts.com/users/crash/p/pnorton/)
P. Norton's patch gets tcpdump working with ibmtr. After applying his patch
to tcpdump, this patch will then get tcpdump working with Olicom's Linux
driver, oltr.

It's just my first attempt. I think I did the ethertype all wrong, but it
seems to work. I can filter on MAC addresses and IP addresses.


*** print-tr.c.orig	Wed Apr 29 21:47:58 1998
--- print-tr.c	Wed May 13 11:22:52 1998
***************
*** 52,55 ****
--- 52,65 ----
  #include "ethertype.h"
  
+ /* Computes size of token ring header. Olicom card gives a variable-
+ 	length header; the routing information may not be there. */
+ static inline
+ int tr_hdr_len(const u_char* trhdr_p);
+ 
+ /* Computes size of token ring LLC. SNAP extensions (5 bytes after 
+ 	802.2 LLC) may not be there. */
+ static inline
+ int tr_llc_len(const u_char* trllc_p);
+ 
  const u_char *packetp;
  const u_char *snapend;
***************
*** 61,84 ****
  };
  
- #define TSRC(tp) ((tp)->th.saddr)
- #define TDST(tp) ((tp)->th.daddr)
- 
  static inline void
  tr_print(register const u_char *bp, u_int length)
  {
! 	register const struct tr_header *tp;
  
! 	tp = (const struct tr_header *)bp;
! 	if (qflag)
  		(void)printf("%s %s %d: ",
! 			     etheraddr_string(TSRC(tp)),
! 			     etheraddr_string(TDST(tp)),
  			     length);
! 	else
  		(void)printf("%s %s %s %d: ",
! 			     etheraddr_string(TSRC(tp)),
! 			     etheraddr_string(TDST(tp)),
  			     etherproto_string(tp->tl.ethertype),
! 			     length);
  }
  
--- 71,91 ----
  };
  
  static inline void
  tr_print(register const u_char *bp, u_int length)
  {
! 	register const struct trh_hdr *hdr;
  
! 	hdr = (const struct trh_hdr *)bp;
! /*	if (qflag)*/
  		(void)printf("%s %s %d: ",
! 			     etheraddr_string(hdr->saddr),
! 			     etheraddr_string(hdr->daddr),
  			     length);
! /*	else
  		(void)printf("%s %s %s %d: ",
! 			     etheraddr_string(TSRC(hdr)),
! 			     etheraddr_string(TDST(hdr)),
  			     etherproto_string(tp->tl.ethertype),
! 			     length);*/
  }
  
***************
*** 94,98 ****
  	u_int caplen = h->caplen;
  	u_int length = h->len;
! 	struct tr_header *tp;
  	u_short ether_type;
  	extern u_short extracted_ethertype;
--- 101,110 ----
  	u_int caplen = h->caplen;
  	u_int length = h->len;
! 	/*struct tr_header *tp;*/
! 	struct trh_hdr *v8025p;
! 	struct trllc *v8022p;
! 	int v8025_len;
! 	int v8022_len;
! 	const u_char *orig_p = p;
  	u_short ether_type;
  	extern u_short extracted_ethertype;
***************
*** 100,104 ****
  	ts_print(&h->ts);
  
! 	if (caplen < sizeof(struct tr_header)) {
  		printf("[|tokenring]");
  		goto out;
--- 112,118 ----
  	ts_print(&h->ts);
  
! 	/* The absolutle minimum packet is the trh_hdr minus the routing
! 		information */
! 	if (caplen < sizeof(struct trh_hdr) - 18) {
  		printf("[|tokenring]");
  		goto out;
***************
*** 116,127 ****
  	snapend = p + caplen;
  
! 	length -= sizeof(struct tr_header);
! 	caplen -= sizeof(struct tr_header);
! 	tp = (struct tr_header *)p;
! 	p += sizeof(struct tr_header);
  
  	/* TODO - print AC, FC, RCF, DSAP, SSAP */
  
! 	ether_type = ntohs(tp->tl.ethertype);
  
  	/*
--- 130,153 ----
  	snapend = p + caplen;
  
! 	v8025_len = tr_hdr_len(p);
! 	length -= v8025_len;
! 	caplen -= v8025_len;
! 
! 	v8025p = (struct trh_hdr *)p;
! 	p += v8025_len;
! 
! 	v8022_len = tr_llc_len(p);
! 	length -= v8022_len;
! 	caplen -= v8022_len;
! 
! 	v8022p = (struct trllc *)p;
! 	p += v8022_len;
  
  	/* TODO - print AC, FC, RCF, DSAP, SSAP */
  
! 	if (v8022_len == sizeof(struct trllc))
! 		ether_type = ntohs(v8022p->ethertype);
! 	else
! 		ether_type = 0;
  
  	/*
***************
*** 131,138 ****
  	if (ether_type < ETHERMTU) {
  		/* Try to print the LLC-layer header & higher layers */
! 		if (llc_print(p, length, caplen, TSRC(tp), TDST(tp)) == 0) {
  			/* ether_type not known, print raw packet */
  			if (!eflag)
! 				tr_print((u_char *)tp, length);
  			if (extracted_ethertype) {
  				printf("(LLC %s) ",
--- 157,164 ----
  	if (ether_type < ETHERMTU) {
  		/* Try to print the LLC-layer header & higher layers */
! 		if (llc_print(p, length, caplen, v8025p->saddr, v8025p->daddr) == 0) {
  			/* ether_type not known, print raw packet */
  			if (!eflag)
! 				tr_print(orig_p, length);
  			if (extracted_ethertype) {
  				printf("(LLC %s) ",
***************
*** 145,155 ****
  		/* ether_type not known, print raw packet */
  		if (!eflag)
! 			tr_print((u_char *)tp, length + sizeof(*tp));
  		if (!xflag && !qflag)
  			default_print(p, caplen);
  	}
  	if (xflag)
  		default_print(p, caplen);
   out:
  	putchar('\n');
  }
--- 171,207 ----
  		/* ether_type not known, print raw packet */
  		if (!eflag)
! 			tr_print(orig_p, length + v8025_len + v8022_len);
  		if (!xflag && !qflag)
  			default_print(p, caplen);
  	}
+ 	else {
+ 		default_print(p, caplen);
+ 	}
  	if (xflag)
  		default_print(p, caplen);
   out:
  	putchar('\n');
+ }
+ 
+ static inline
+ int tr_hdr_len(const u_char* trhdr_p) {
+ 
+ 	struct trh_hdr *hdr = (struct trh_hdr *) trhdr_p;
+ 	int hdr_len = sizeof(struct trh_hdr) - 18;
+ 
+     if (hdr->saddr[0] & TR_RII) /* RIF present */
+ 		hdr_len += ((ntohs(hdr->rcf) & TR_RCF_LEN_MASK)>>8);
+ 
+ 	return hdr_len;
+ }
+ 
+ static inline
+ int tr_llc_len(const u_char* trllc_p) {
+ 
+ 	struct trllc *llc = (struct trllc *) trllc_p;
+ 
+ 	if (llc->dsap == 0xAA && llc->ssap == 0xAA)
+ 		return sizeof(struct trllc);
+ 	else
+ 		return sizeof(struct trllc) - 5;
  }

--gilbert
-- 
_______________________________________________________________________
Gilbert Ramirez Jr.                     gram@merece.uthscsa.edu
University of Texas                     http://merece.uthscsa.edu/gram/
Health Science Center at San Antonio    University Health System