... to prevent use of uninitialized variables.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/hostmon.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c
index b217835..e55de19 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -928,13 +928,23 @@ void hostmon(time_t facilitytime, char *ifptr)
return;
}
+ initethtab(&table);
+
LIST_HEAD(promisc);
if (options.promisc) {
promisc_init(&promisc, ifptr);
promisc_set_list(&promisc);
}
- initethtab(&table);
+ fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if(fd == -1) {
+ write_error("Unable to obtain monitoring socket");
+ goto err;
+ }
+ if(ifptr && dev_bind_ifname(fd, ifptr) == -1) {
+ write_error("Unable to bind interface on the socket");
+ goto err_close;
+ }
if (logging) {
if (strcmp(current_logfile, "") == 0) {
@@ -960,15 +970,7 @@ void hostmon(time_t facilitytime, char *ifptr)
"******** LAN traffic monitor started ********");
}
- fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
- if(fd == -1) {
- write_error("Unable to obtain monitoring socket");
- goto err;
- }
- if(ifptr && dev_bind_ifname(fd, ifptr) == -1) {
- write_error("Unable to bind interface on the socket");
- goto err_close;
- }
+ packet_init(&pkt);
exitloop = 0;
gettimeofday(&tv, NULL);
@@ -976,8 +978,6 @@ void hostmon(time_t facilitytime, char *ifptr)
updtime = tv;
statbegin = startlog = tv.tv_sec;
- packet_init(&pkt);
-
do {
gettimeofday(&tv, NULL);
now = tv.tv_sec;
@@ -1025,14 +1025,7 @@ void hostmon(time_t facilitytime, char *ifptr)
} while (!exitloop);
-err_close:
- close(fd);
-
-err:
- if (options.promisc) {
- promisc_restore_list(&promisc);
- promisc_destroy(&promisc);
- }
+ packet_destroy(&pkt);
if (logging) {
signal(SIGUSR1, SIG_DFL);
@@ -1043,7 +1036,13 @@ err:
}
strcpy(current_logfile, "");
- packet_destroy(&pkt);
+err_close:
+ close(fd);
+err:
+ if (options.promisc) {
+ promisc_restore_list(&promisc);
+ promisc_destroy(&promisc);
+ }
destroyethtab(&table);
}
--
1.9.1