🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by Chris Sedore Tue, 25 Mar 1997 00:00
TCPDump mods to watch protocol interaction
#16303
Author: Chris Sedore
Date: Tue, 25 Mar 1997 00:00
122 lines
3910 bytes
I posted a while ago about some mods to TCP dump I did to watch NNTP
protocol transactions.  This is a diff against tcpdump-3.3.  Note that this
could be used to watch most any human-readable protocol, including HTTP and
others.

It modifies the -q flag to print the TCP data in ASCII, terminating if it
finds a control character that is not \r or \n.  \r and \n are replaced
with '_' for reading ease.

You'll probably want to use -s to set the capture size.  I usually use 128.

I use it like:

tcpdump -q -s 128 host news.maxwell.syr.edu and host other.news.host.com

I'm also able to capture all NNTP traffic with my pentium 60 under FreeBSD
using the -w option to write to a file:

tcpdump -w outfile -s 128 host news.maxwell.syr.edu

then:

tcpdump -r outfile -q

Also, after the patch for tcpdump, I included a TCL script that creates
"conversation" files in /tmp, one for each connection so you can watch the
protocol interaction on a per-host per-connection basis.  Watch out when
using this where you expect many connections--it opens one file for each
connection--you may run out of file descriptors.

Feedback and improvements appreciated.

-Chris


*** tcpdump-3.3/print-tcp.c     Wed Dec 11 07:26:08 1996
--- tcpdump-3.3.local/print-tcp.c       Fri Mar 14 10:28:38 1997
*************** tcp_print(register const u_char *bp, reg
*** 104,109 ****
--- 104,111 ----
        register char ch;
        u_short sport, dport, win, urp;
        u_int32_t seq, ack;
+         char *dataptr;
+         int datalen;

        tp = (struct tcphdr *)bp;
        ip = (struct ip *)bp2;
*************** tcp_print(register const u_char *bp, reg
*** 127,132 ****
--- 129,149 ----

        if (qflag) {
                (void)printf("tcp %d", length - tp->th_off * 4);
+                 dataptr=(char *) tp +  tp->th_off * 4;
+                 datalen=length-(tp->th_off * 4);
+         if (datalen>0) {
+           char buf[300];
+           int x;
+           x=datalen;
+           if (x>299) { x=299; }
+           strncpy(buf,dataptr,x);
+           buf[x]=0;
+           while (--x>0) {
+             if ((buf[x]==13) || (buf[x]==10)) buf[x]='_';
+             if ((buf[x]>128) || (buf[x]<27)) buf[x]=0;
+           }
+           printf(" {%s} ",buf);
+         }
                return;
        }
        if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) {


----END PATCH FILE----

---simple TCL script

#!/usr/local/bin/tclsh
# send the output to this script via a pipe from tcpdump
#
# tcpdump -q -s 128 host news.maxwell.syr.edu and host other.news.peer.com
\
# |scriptname
# -or-
# tcpdump -q -r outfile |scriptname
#

while {![eof stdin]} {
  set s [gets stdin]

  set a [lsort [list [lindex $s 1] [string trimright [lindex $s 3] :]]]
  regsub -all " " $a "" a
  if {[lsearch -exact [array names conns] $a]>-1} {
    set fd $conns($a)
  } else {
    set fd [set conns($a) [open /tmp/$a w]]
  }
  switch -glob -- $s {
    *ihave* -
    *335* -
    *435* -
    *437* -
    *235* -
    *check* -
    *238* -
    *takethis* -
    *439* -
    *239* { puts $fd "[lindex $s 0] [lindex $s 1] [lindex $s 2] [lindex $s
3] [l
index $s 5] [lindex $s 6]" }
 }
  flush $fd
}

foreach a [array names $conns] {
  close $conns($a)
}


Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads