Skip to content

Commit b20d2f4

Browse files
committed
Use the correct type for running_connections.
Eliminate a few temporary variables and the associated type casting.
1 parent 691637b commit b20d2f4

4 files changed

Lines changed: 16 additions & 33 deletions

File tree

src/sn_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ char Plugin_Active[10];
165165
#ifdef INCLUDE_INTERFACE
166166

167167
/**** shared memory pointers ************************************************/
168-
char *SHARED, *connection_data, *running_connections,
169-
*logged_connections;
168+
char *SHARED, *connection_data, *logged_connections;
169+
struct shared_conn_data *running_connections;
170170
int *LISTlength, *DATAlength, memory_id;
171171
unsigned int *TCP_nr_of_packets, *ICMP_nr_of_packets, *UDP_nr_of_packets;
172172
extern unsigned int *IP_nr_of_packets;

src/sn_interface.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "sn_resolv.h"
2121

2222
/*** extern stuff ********/
23-
extern char *SHARED, *connection_data, *running_connections,
24-
*logged_connections;
23+
extern char *SHARED, *connection_data, *logged_connections;
24+
extern struct shared_conn_data *running_connections;
2525
extern int *LISTlength, *DATAlength, memory_id;
2626
extern unsigned int *TCP_nr_of_packets, *ICMP_nr_of_packets, *UDP_nr_of_packets; unsigned int *IP_nr_of_packets;
2727
extern unsigned long *TCP_bytes_in_packets, *UDP_bytes_in_packets;
@@ -133,12 +133,10 @@ doupdate();
133133

134134
static void data_window (struct box_window *Win, struct box_window *P_Win,
135135
int num_lines, int num_cols, int begy,int begx,
136-
char *buffer, int listitem)
136+
struct shared_conn_data *conn, int listitem)
137137
{
138138
int i=0, j=0;
139-
struct shared_conn_data *conn;
140139

141-
conn = (struct shared_conn_data *) buffer;
142140
while((j<listitem)&&(i<(CONNECTION_CAPACITY+1)))
143141
{
144142
if(conn[i].connection[0]!=0)
@@ -169,12 +167,10 @@ wnoutrefresh(Win->main_window);wnoutrefresh(Win->work_window);
169167
doupdate();
170168
}
171169

172-
static void data_device (char *buffer, int listitem)
170+
static void data_device (struct shared_conn_data *conn, int listitem)
173171
{
174172
int i=0, j=0;
175-
struct shared_conn_data *conn;
176173

177-
conn = (struct shared_conn_data *) buffer;
178174
while((j<listitem)&&(i<(CONNECTION_CAPACITY+1)))
179175
{
180176
if(conn[i].connection[0]!=0)
@@ -235,14 +231,12 @@ wnoutrefresh(Work_win->work_window);
235231
doupdate();
236232
}
237233

238-
static void fill_box_window (struct box_window *Work_win, char *buffer,
234+
static void fill_box_window (struct box_window *Work_win, struct shared_conn_data *conn,
239235
int begin_item, int boxlen, int rowlen)
240236
/* 0 is the first item */
241237
{
242238
int i=0, j=0, line=0;
243-
struct shared_conn_data *conn;
244239

245-
conn = (struct shared_conn_data *) buffer;
246240
while((j<begin_item)&&(i<(CONNECTION_CAPACITY+1)))
247241
{
248242
if(conn[i].connection[0]!=0)
@@ -286,18 +280,15 @@ for(i=line;i<boxlen;i++)
286280
wnoutrefresh(Work_win->work_window);
287281
}
288282

289-
static void point_item (struct box_window *Work_win, char *buffer,
283+
static void point_item (struct box_window *Work_win, struct shared_conn_data *conn,
290284
int item, int begin_item, int boxlen, int rowlen)
291285
{
292286
int i=0, j=0;
293-
struct shared_conn_data *conn;
294-
295287

296288
if(item<0) return; /* POINTpos 0 = first item -1 = no items */
297289
/* LISTlength 0 = 1 -1 = no items */
298290
/* DANGER - there should always be >= */
299291
/* connections than 'item' */
300-
conn = (struct shared_conn_data *) buffer;
301292
while((j<item)&&(i<(CONNECTION_CAPACITY+1)))
302293
{
303294
if(conn[i].connection[0] !=0)
@@ -468,11 +459,10 @@ sigaction(signum,&new_sigusr,NULL);
468459
static void interaction (int sig) /* invoked when data arrives */
469460
{
470461
int i;
471-
struct shared_conn_data *conn;
462+
struct shared_conn_data *conn = running_connections;
472463

473464

474465
/* timeout increase */
475-
conn = (struct shared_conn_data *) running_connections;
476466
for(i=0;i<CONNECTION_CAPACITY;i++)
477467
if(conn[i].connection[0]!=0)
478468
conn[i].timeout+=1;
@@ -566,14 +556,12 @@ delwin(packets_box.work_window), delwin(packets_box.main_window);
566556
forced_refresh();
567557
}
568558

569-
int add_itemlist(char *buffer, char *string, char *desc)
559+
int add_itemlist(struct shared_conn_data *conn, char *string, char *desc)
570560
{
571561
int i, to_help, to_item;
572-
struct shared_conn_data *conn;
573562

574563
/*invoked every time a packet comes in */
575564

576-
conn = (struct shared_conn_data *) buffer;
577565
for(i=0;i<CONNECTION_CAPACITY;i++)
578566
if(strcmp( conn[i].connection, string)==0)
579567
{
@@ -606,12 +594,10 @@ conn[to_item].timeout=0;
606594
return to_item;
607595
}
608596

609-
int del_itemlist(char *buffer, char *string)
597+
int del_itemlist(struct shared_conn_data *conn, char *string)
610598
{
611599
int i;
612-
struct shared_conn_data *conn;
613600

614-
conn = (struct shared_conn_data *) buffer;
615601
for(i=0;i<CONNECTION_CAPACITY;i++)
616602
if(strcmp( conn[i].connection, string)==0)
617603
{
@@ -632,7 +618,7 @@ void clear_shared_mem(char mode)
632618
/* keep packet count */
633619
{
634620
int i;
635-
struct shared_conn_data *conn;
621+
struct shared_conn_data *conn = running_connections;
636622

637623
*DATAlength=0;
638624
*LISTlength=-1;
@@ -646,7 +632,6 @@ if(mode==0)
646632
}
647633

648634
log_conn->log_enter[0]=0;
649-
conn = (struct shared_conn_data *) running_connections;
650635
for(i=0;i<CONNECTION_CAPACITY;i++)
651636
{
652637
conn[i].connection[0]=0;
@@ -656,14 +641,12 @@ for(i=0;i<CONNECTION_CAPACITY;i++)
656641
};
657642

658643
static void create_arguments(char *esource, char *es_port, char *edest,
659-
char *ed_port, char *buffer, int item)
644+
char *ed_port, struct shared_conn_data *conn, int item)
660645
{
661646
char e_dummy[CONN_NAMELEN];
662647
int i=0, j=0;
663-
struct shared_conn_data *conn;
664648

665649
if(item<0) return;
666-
conn = (struct shared_conn_data *) buffer;
667650
while((j<item)&&(i<(CONNECTION_CAPACITY+1)))
668651
{
669652
if(conn[i].connection[0] !=0)

src/sn_interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
typedef void (*sig_hand)(int ); /* sighandler_t gave errors, weird */
66

7-
extern int add_itemlist(char *, char *, char *);
7+
extern int add_itemlist(struct shared_conn_data *, char *, char *);
88
extern void child_exit (void);
99
extern void clear_shared_mem(char);
10-
extern int del_itemlist(char *, char *);
10+
extern int del_itemlist(struct shared_conn_data *, char *);
1111
extern void forced_refresh (void);
1212
extern char *input_field(char *, char *, int);
1313
extern void mem_exit (void);

src/sniffit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ if (Plugin_Active[9] == 1)
18831883
logged_connections = mask + sizeof (struct snif_mask);
18841884
log_conn = (struct shared_logged_conn *) logged_connections;
18851885
running_connections = logged_connections + sizeof (struct shared_logged_conn);
1886-
TCP_nr_of_packets = running_connections + (sizeof (struct shared_conn_data) * CONNECTION_CAPACITY);
1886+
TCP_nr_of_packets = (void *)running_connections + (sizeof (struct shared_conn_data) * CONNECTION_CAPACITY);
18871887
TCP_bytes_in_packets = TCP_nr_of_packets + sizeof (int);
18881888
ICMP_nr_of_packets = TCP_bytes_in_packets + sizeof (unsigned long);
18891889
UDP_nr_of_packets = ICMP_nr_of_packets + sizeof (int);

0 commit comments

Comments
 (0)