-
Notifications
You must be signed in to change notification settings - Fork 0
/
netstat.c
48 lines (46 loc) · 1.11 KB
/
netstat.c
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
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
/*Program to get the network statistics and hash the retreived data*/
int main()
{
system("nstat > net.txt");
FILE *ifp=fopen("net.txt","r");
int test, i=0, a[100], n=0;
long long int highorder, h=0, g;
fscanf(ifp, "%*s");
while(fscanf(ifp, "%*s%d%*s", &test) == 1)
{
a[n++]=test;
}
system("rm net.txt");
time_t seconds = time (NULL);
clock_t tic = clock();
int num = (int)seconds/(int)tic;
/*Choose the hash to use*/
if(num%2==0)
{
/*CRC Hash*/
for(i=0;i<n;i++)
{
highorder = h & 0xf8000000;
h = h << 5;
h = h ^ (highorder >> 27);
h = h ^ a[i];
}
}
else
{
/*PJW Hash*/
for(i=0;i<n;i++)
{
h = (h << 4) + a[i];
g = h & 0xf0000000;
if (g != 0)
h = h ^ (g >> 24);
h = h ^ g;
}
}
ifp = fopen("hashed.txt", "a");
fprintf(ifp, "%lld\n", h);
}