1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/*
* jnettop, network online traffic visualiser
* Copyright (C) 2002-2006 Jakub Skopal
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Header: /cvsroot/jnettop/jnettop/jtxtdisplay.c,v 1.2 2006/04/11 15:21:05 merunka Exp $
*
*/
#include "jbase.h"
#include "jdevice.h"
#include "jprocessor.h"
#include "jconfig.h"
#include "jutil.h"
#include "jtxtdisplay.h"
int secondsToRun;
GPtrArray *lastStreamsArray;
#define CSV_FORMATSTRING "\"$src$\",\"$dst$\",\"$proto$\",\"$srcport$\",\"$dstport$\",\"$srcname$\",\"$dstname$\",\"$srcbytes$\",\"$dstbytes$\",\"$totalbytes$\",\"$srcpackets$\",\"$dstpackets$\",\"$totalpackets$\",\"$srcbps$\",\"$dstbps$\",\"$totalbps$\",\"$srcpps$\",\"$dstpps$\",\"$totalpps$\",\"$filterdata$\",\"$uid\""
#define TSV_FORMATSTRING "$src$\t$dst$\t$proto$\t$srcport$\t$dstport$\t$srcname$\t$dstname$\t$srcbytes$\t$dstbytes$\t$totalbytes$\t$srcpackets$\t$dstpackets$\t$totalpackets$\t$srcbps$\t$dstbps$\t$totalbps$\t$srcpps$\t$dstpps$\t$totalpps$\t$filterdata$\t$uid$"
gchar *formatString = NULL;
static void processStreamsFunc(GPtrArray * streamArray) {
lastStreamsArray = streamArray;
}
static void displayLoop() {
g_usleep(500000);
while (jcapture_IsRunning && secondsToRun--) {
g_usleep(1000000);
}
}
static gboolean jtxtdisplay_PreSetup() {
return TRUE;
}
static void jtxtdisplay_Setup() {
jprocessor_SetProcessStreamsFunc((ProcessStreamsFunc) processStreamsFunc);
if (formatString == NULL)
formatString = strdup(TSV_FORMATSTRING);
}
static gboolean jtxtdisplay_PreRunSetup() {
return TRUE;
}
static void jtxtdisplay_PreRun() {
}
static gboolean jtxtdisplay_Run() {
displayLoop();
return FALSE;
}
static void jtxtdisplay_Shutdown() {
int i;
GString *str;
str = g_string_new("");
for (i=0; i<lastStreamsArray->len; i++) {
jbase_stream *s = (jbase_stream *)g_ptr_array_index(lastStreamsArray, i);
g_string_truncate(str, 0);
jutil_InterpretStreamFormat(str, formatString, s);
printf("%s\n", str->str);
}
g_string_free(str, TRUE);
}
static void jtxtdisplay_DrawStatus(const gchar *msg) {
}
static int jtxtdisplay_ProcessArgument(const gchar **arg, int argc) {
if (!strcmp(*arg, "-t") || !strcmp(*arg, "--timeout")) {
if (argc<2) {
fprintf(stderr, "%s parameter needs one numeric argument\n", *arg);
exit(255);
}
secondsToRun = atoi(arg[1]);
return 2;
}
if (!strcmp(*arg, "--format")) {
if (argc<2) {
fprintf(stderr, "%s parameter needs one argument\n", *arg);
exit(255);
}
if (!strcmp(arg[1], "CSV"))
formatString = strdup(CSV_FORMATSTRING);
else if (!strcmp(arg[1], "TSV"))
formatString = strdup(TSV_FORMATSTRING);
else {
formatString = strdup(arg[1]);
}
return 2;
}
return 0;
}
jbase_display jtxtdisplay_Functions = {
TRUE,
jtxtdisplay_PreSetup,
jtxtdisplay_Setup,
jtxtdisplay_PreRunSetup,
jtxtdisplay_PreRun,
jtxtdisplay_Run,
jtxtdisplay_Shutdown,
jtxtdisplay_DrawStatus,
jtxtdisplay_ProcessArgument
};
|