Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 6 +++++-
src/hostmon.c | 6 +++++-
src/ifstats.c | 6 +++++-
src/itrafmon.c | 6 +++++-
src/packet.c | 7 +++++--
src/packet.h | 2 +-
src/pktsize.c | 6 +++++-
src/serv.c | 6 +++++-
8 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index e3de9a0..8a07dc0 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -508,7 +508,11 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
&& (((now - statbegin) / 60) >= facilitytime))
exitloop = 1;
- packet_get(fd, &pkt, &ch, statwin);
+ if (packet_get(fd, &pkt, &ch, statwin) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
switch (ch) {
case ERR:
diff --git a/src/hostmon.c b/src/hostmon.c
index e9f3dc0..76ac805 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -908,7 +908,11 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
&& (((now - statbegin) / 60) >= facilitytime))
exitloop = 1;
- packet_get(fd, &pkt, &ch, table.tabwin);
+ if (packet_get(fd, &pkt, &ch, table.tabwin) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
if (ch != ERR) {
if (keymode == 0) {
diff --git a/src/ifstats.c b/src/ifstats.c
index 8b336bc..0e0bf49 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -563,7 +563,11 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
&& (((now - statbegin) / 60) >= facilitytime))
exitloop = 1;
- packet_get(fd, &pkt, &ch, table.statwin);
+ if (packet_get(fd, &pkt, &ch, table.statwin) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
switch (ch) {
case ERR:
diff --git a/src/itrafmon.c b/src/itrafmon.c
index ebe053b..02a4626 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -820,7 +820,11 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
rotate_flag = 0;
}
- packet_get(fd, &pkt, &ch, table.tcpscreen);
+ if (packet_get(fd, &pkt, &ch, table.tcpscreen) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
if (ch == ERR)
goto no_key_ready;
diff --git a/src/packet.c b/src/packet.c
index b48e98f..e7f8371 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -130,7 +130,7 @@ static int packet_adjust(struct pkt_hdr *pkt)
}
/* IPTraf input function; reads both keystrokes and network packets. */
-void packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
+int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
{
fd_set set;
int ss;
@@ -172,12 +172,15 @@ void packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
pkt->pkt_ifindex = from.sll_ifindex;
pkt->pkt_hatype = from.sll_hatype;
pkt->pkt_pkttype = from.sll_pkttype;
- }
+ } else
+ ss = len;
}
*ch = ERR; /* signalize we have no key ready */
if (!daemonized && (ss > 0) && FD_ISSET(0, &set))
*ch = wgetch(win);
+
+ return ss;
}
int packet_process(struct pkt_hdr *pkt, unsigned int *total_br,
diff --git a/src/packet.h b/src/packet.h
index 185a229..dd24533 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -46,7 +46,7 @@ struct pkt_hdr {
};
void open_socket(int *fd);
-void packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win);
+int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win);
int packet_process(struct pkt_hdr *pkt, unsigned int *total_br,
unsigned int *sport, unsigned int *dport,
struct filterstate *filter, int match_opposite,
diff --git a/src/pktsize.c b/src/pktsize.c
index 7dfcb92..8ec0a2c 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -299,7 +299,11 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname,
&& (((now - starttime) / 60) >= facilitytime))
exitloop = 1;
- packet_get(fd, &pkt, &ch, win);
+ if (packet_get(fd, &pkt, &ch, win) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
if (ch != ERR) {
switch (ch) {
diff --git a/src/serv.c b/src/serv.c
index 7bbcdf7..b9f1f59 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -961,7 +961,11 @@ void servmon(char *ifname, struct porttab *ports, const struct
OPTIONS *options,
&& (((now - starttime) / 60) >= facilitytime))
exitloop = 1;
- packet_get(fd, &pkt, &ch, list.win);
+ if (packet_get(fd, &pkt, &ch, list.win) == -1) {
+ write_error("Packet receive failed");
+ exitloop = 1;
+ break;
+ }
if (ch == ERR)
goto no_key_ready;
--
1.7.8.4