what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

tcpsee-1.1.c

tcpsee-1.1.c
Posted Apr 7, 2000
Authored by S

tcpsee is a tcpdump pipe written in C. It converts tcpdump's snarfed hex data to ASCII and has optional ANSI colors.

tags | tool, sniffer
SHA-256 | f87b03b194b80ebfd706405bdb319f02a5f85655b298e77077a0b816a8dcac19

tcpsee-1.1.c

Change Mirror Download
/* tcpsee by Derek Callaway <super@innu.org> -- S@IRC 
* $Id: tcpsee.c,v 1.1 2000/04/07 04:43:02 super Exp $
*/

#include<stdio.h>
#include<getopt.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

/* Default tcpdump pathname for popen()
* extra flags may also be provided here */
#define TCPDUMP_PATH "/usr/sbin/tcpdump"
/* Maximum Transfer Unit (How many bytes to snarf)
* Usually 1500 -- check ifconfig */
#define DEFAULT_MTU "1500"
#define HD(c) ((c>='A')?(toupper(c)-'A'+10):(c-'0'))
/* 1024 should be plenty. */
#define BUFSIZE 1024

void vexit (const char *);
void usage (char **);

static char counter;

char *ansc (void);

int
main (int argc, char **argv)
{
char *cmd, *realpath = TCPDUMP_PATH, *mtu = DEFAULT_MTU;
char buf[BUFSIZE], tcpflag, colflag, color = 1;
register char *p;
FILE *pipe;
int c;
while ((c = getopt (argc, argv, "t:m:n")) != EOF)
{
switch (c)
{
case 't':
realpath = optarg;
break;
case 'm':
mtu = optarg;
p = mtu;
while (*p)
{
if (!(isdigit (*p)))
usage (argv);
else
p++;
}
break;
case 'n':
color = 0;
break;
case '?':
usage (argv);
}
}
/* 7 = strlen(" -lxs ") plus null zero. */
if (!(cmd = (char *) malloc (strlen (realpath) + strlen (mtu) + 7)))
{
vexit ("malloc");
}
sprintf (cmd, "%s -lxs %s", realpath, mtu);
if (!(pipe = popen (cmd, "r")))
vexit ("popen");
setvbuf (stdout, (char *) NULL, _IONBF, 0);
while (fgets (buf, BUFSIZE, pipe))
{
if (buf[BUFSIZE] == '\0' && buf[BUFSIZE - 1] != '\n')
{
if (color)
printf ("\033[38m");
printf ("Line too long!");
if (color)
printf ("\033[m");
while ((c = fgetc (pipe)) != '\n')
{
if (c == EOF)
break;
}
if (c == EOF)
continue;
}
if (*(p = buf) != '\t')
{
counter = colflag = 1;
if (strstr (buf, " ack "))
{
tcpflag = 1;
}
if (color)
{
printf ("\n\n\033[39;7m");
while (*p != ' ')
{
if (*p)
putchar (*p);
else
break;
p++;
}
printf ("\033[33m");
while (*p)
{
switch (*p)
{
case '<':
if (!isspace (*(p + 1)))
{
printf ("\033[m\033[34m");
putchar ('<');
p++;
goto newcol;
}
case '>':
if (!isspace (*(p - 1)))
{
printf ("\033[m\033[34m");
putchar ('>');
p++;
goto newcol;
}
case ' ':
newcol:
if (colflag)
{
printf ("%s", ansc ());
colflag = 0;
}
default:
colflag = 1;
putchar (*p);
}
p++;
}
printf ("\033[m\n");
}
else
printf ("\n\n%s\n", buf);
continue;
}
if (tcpflag)
{
tcpflag = 0;
}
while (*p)
{
if (isxdigit (*p) && isxdigit (*p + 1))
{
c = HD (*p);
p++;
c = 16 * c + HD (*p);
p++;
if (isprint (c))
putchar (c);
}
else
p++;
}
}
exit (EXIT_SUCCESS);
}

void
vexit (const char *func)
{
perror (func);
exit (EXIT_FAILURE);
}

void
usage (char **argv)
{
printf ("%s [-n] [-t /path/to/tcpdump] [-m MTU]\n\n", argv[0]);
printf ("-n\tno color\n");
printf ("-t\ttcpdump path (default: %s)\n", TCPDUMP_PATH);
printf (" \tNote: extra tcpdump options may be provided with this flag\n");
printf ("-m\tMaximum Transfer Unit -- check ifconfig (default: %s)\n",
DEFAULT_MTU);
exit (EXIT_SUCCESS);
}

char *
ansc (void)
{
static char *codelist[] =
{ "\033[m\033[31m", "\033[m\033[32m", "\033[m\033[33m",
"\033[m\033[34;1m", "\033[m\033[35m", "\033[m\033[36m",
"\033[m\033[37m", "\033[m\033[38m"
};
if (counter == 8)
counter = 0;
return (codelist[counter++]);
}
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    16 Files
  • 26
    Apr 26th
    14 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close