I've long-since been meaning to port some of the features from my iptstate software back to ipfstat's statetop function.
As a small start to get familiar with the code, I've done the easiest ones: added sorting my source port and destination port. Obviously useful if you're looking for a specific kind of traffic.
Hopefully I'll have enough time to add some other more interesting features soon.
Comments welcome. -- Phil Dibowitz [EMAIL PROTECTED] Freeware and Technical Pages Insanity Palace of Metallica http://www.phildev.net/ http://www.ipom.com/
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin, 1759
--- ipfstat.c.orig Wed Mar 30 00:45:13 2005 +++ ipfstat.c Wed Mar 30 01:08:54 2005 @@ -105,8 +105,10 @@ #define STSORT_BYTES 2 #define STSORT_TTL 3 #define STSORT_SRCIP 4 -#define STSORT_DSTIP 5 -#define STSORT_MAX STSORT_DSTIP +#define STSORT_SRCPT 5 +#define STSORT_DSTIP 6 +#define STSORT_DSTPT 7 +#define STSORT_MAX STSORT_DSTPT #define STSORT_DEFAULT STSORT_BYTES
@@ -151,7 +153,9 @@
static int sort_bytes __P((const void *, const void *));
static int sort_ttl __P((const void *, const void *));
static int sort_srcip __P((const void *, const void *));
+static int sort_srcpt __P((const void *, const void *));
static int sort_dstip __P((const void *, const void *));
+static int sort_dstpt __P((const void *, const void *));
#endif
@@ -1171,10 +1175,18 @@
qsort(tstable, tsentry + 1,
sizeof(statetop_t), sort_srcip);
break;
+ case STSORT_SRCPT:
+ qsort(tstable, tsentry +1,
+ sizeof(statetop_t), sort_srcpt);
+ break;
case STSORT_DSTIP:
qsort(tstable, tsentry + 1,
sizeof(statetop_t), sort_dstip);
break;
+ case STSORT_DSTPT:
+ qsort(tstable, tsentry + 1,
+ sizeof(statetop_t), sort_dstpt);
+ break;
default:
break;
}
@@ -1253,9 +1265,15 @@
case STSORT_SRCIP:
sprintf(str4, "src ip");
break;
+ case STSORT_SRCPT:
+ sprintf(str4, "src port");
+ break;
case STSORT_DSTIP:
sprintf(str4, "dest ip");
break;
+ case STSORT_DSTPT:
+ sprintf(str4, "dest port");
+ break;
default:
sprintf(str4, "unknown");
break;
@@ -1715,6 +1733,20 @@
return -1;
}
+static int sort_srcpt(a, b)
+const void *a;
+const void *b;
+{
+ register const statetop_t *ap = a;
+ register const statetop_t *bp = b;
+
+ if (htons(ap->st_sport) == htons(bp->st_sport))
+ return 0;
+ else if (htons(ap->st_sport) > htons(bp->st_sport))
+ return 1;
+ return -1;
+}
+
static int sort_dstip(a, b)
const void *a;
const void *b;
@@ -1740,4 +1772,19 @@
}
return -1;
}
+
+static int sort_dstpt(a, b)
+const void *a;
+const void *b;
+{
+ register const statetop_t *ap = a;
+ register const statetop_t *bp = b;
+
+ if (htons(ap->st_dport) == htons(bp->st_dport))
+ return 0;
+ else if (htons(ap->st_dport) > htons(bp->st_dport))
+ return 1;
+ return -1;
+}
+
#endif
signature.asc
Description: OpenPGP digital signature
