-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug_tools.c
91 lines (74 loc) · 2.57 KB
/
debug_tools.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
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
/*
Copyright (C) 2013
Fabien Gaud <[email protected]>, Baptiste Lepers <[email protected]>,
Fabien Mottet <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 or later, as published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "debug_tools.h"
unsigned long compare_time(struct timeval* start_time, struct timeval *stop_time){
unsigned long sec_res = stop_time->tv_sec - start_time->tv_sec;
unsigned long usec_res = stop_time->tv_usec - start_time->tv_usec;
return 1000000*sec_res + usec_res;
}
char* getCurrentTime(){
time_t timeseconds;
timeseconds = time(NULL);
char *timestring = ctime(×econds);
timestring[strlen(timestring)-1] = '\0';
return timestring;
}
void do_proc_info(FILE* output, char *proc_file)
{
char proc_info[256];
FILE *fp;
if ((fp = fopen(proc_file,"r")) == NULL){
DEBUG_TMP("Error while opening %s\n",proc_file);
exit(EXIT_FAILURE);
}
// Per proc_file rules
if(strncmp(proc_file,"/proc/sys/net/ipv4/ip_local_port_range",strlen(proc_file)) == 0 ){
char proc_info2[256];
if(fscanf (fp,"%s\t%s",proc_info,proc_info2)){};
#ifndef USE_RST
fprintf(output,"* %-50s\t\e[01;31m%s %s\e[m\n", proc_file, proc_info, proc_info2);
#else
fprintf(output,"* %-50s\t%s %s\n", proc_file, proc_info, proc_info2);
#endif
}
else if(strncmp(proc_file,"/proc/sys/net/ipv4/tcp_fin_timeout",strlen(proc_file)) == 0 ){
if(fscanf (fp,"%s",proc_info)){};
#ifndef USE_RST
fprintf(output,"* %-50s\t\e[01;31m%s\e[m\n", proc_file, proc_info);
#else
fprintf(output,"* %-50s\t%s\n", proc_file, proc_info);
#endif
}
else if(strncmp(proc_file,"/proc/sys/net/ipv4/tcp_tw_recycle",strlen(proc_file)) == 0 ){
if(fscanf (fp,"%s",proc_info)){};
#ifndef USE_RST
fprintf(output,"* %-50s\t\e[01;31m%s\e[m\n", proc_file, proc_info);
#else
fprintf(output,"* %-50s\t%s\n", proc_file, proc_info);
#endif
}
else{
if(fscanf (fp,"%s",proc_info)){};
fprintf(output,"* %-50s\t%s\n", proc_file, proc_info);
}
fclose(fp);
}