Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/hostmon.c | 59 +++++++++++++++++++++++++-------------------------------
1 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c
index 24633bc..342cb64 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -735,10 +735,7 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
int logging = options->logging;
struct ethtab table;
struct ethtabent *entry;
- struct sockaddr_ll fromaddr;
- int br;
- char buf[MAX_PACKET_SIZE];
char scratch_saddr[ETH_ALEN];
char scratch_daddr[ETH_ALEN];
unsigned int idx = 1;
@@ -761,7 +758,6 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
FILE *logfile = NULL;
int pkt_result;
- char *ipacket;
WINDOW *sortwin;
PANEL *sortpanel;
@@ -847,6 +843,8 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
gettimeofday(&tv, NULL);
starttime = statbegin = startlog = tv.tv_sec;
+ PACKET_INIT(pkt);
+
do {
gettimeofday(&tv, NULL);
now = tv.tv_sec;
@@ -879,7 +877,7 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
&& (((now - statbegin) / 60) >= facilitytime))
exitloop = 1;
- getpacket(fd, buf, &fromaddr, &ch, &br, table.tabwin);
+ packet_get(fd, &pkt, &ch, table.tabwin);
if (ch != ERR) {
if (keymode == 0) {
@@ -924,12 +922,11 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
keymode = 0;
}
}
- if (br > 0) {
+ if (pkt.pkt_len > 0) {
char ifnamebuf[IFNAMSIZ];
pkt_result =
- processpacket(buf, &ipacket, (unsigned int *) &br,
- NULL, NULL, NULL, &fromaddr,
+ packet_process(&pkt, NULL, NULL, NULL,
ofilter,
MATCH_OPPOSITE_USECONFIG,
0);
@@ -941,7 +938,7 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
/* we're capturing on "All interfaces", */
/* so get the name of the interface */
/* of this packet */
- int r = iface_get_ifname(fromaddr.sll_ifindex, ifnamebuf);
+ int r = iface_get_ifname(pkt.pkt_ifindex, ifnamebuf);
if (r != 0) {
write_error("Unable to get interface name");
break; /* can't get interface name, get out! */
@@ -949,14 +946,14 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
ifname = ifnamebuf;
}
- if ((fromaddr.sll_hatype == ARPHRD_ETHER)
- || (fromaddr.sll_hatype == ARPHRD_FDDI)
+ if ((pkt.pkt_hatype == ARPHRD_ETHER)
+ || (pkt.pkt_hatype == ARPHRD_FDDI)
/* fix me
|| (linktype == LINK_PLIP)
*/
- || (fromaddr.sll_hatype == ARPHRD_IEEE802_TR)
- || (fromaddr.sll_hatype == ARPHRD_IEEE802)) {
- switch(fromaddr.sll_protocol) {
+ || (pkt.pkt_hatype == ARPHRD_IEEE802_TR)
+ || (pkt.pkt_hatype == ARPHRD_IEEE802)) {
+ switch(pkt.pkt_protocol) {
case ETH_P_IP:
case ETH_P_IPV6:
is_ip = 1;
@@ -970,35 +967,31 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
* Check source address entry
*/
- if ((fromaddr.sll_hatype == ARPHRD_ETHER)
+ if ((pkt.pkt_hatype == ARPHRD_ETHER)
/* fix me
|| (linktype == LINK_PLIP)
*/
- || (fromaddr.sll_hatype ==
- ARPHRD_IEEE802_TR)
- || (fromaddr.sll_hatype == ARPHRD_IEEE802)) {
+ || (pkt.pkt_hatype == ARPHRD_IEEE802_TR)
+ || (pkt.pkt_hatype == ARPHRD_IEEE802)) {
struct ethhdr *hdr_eth =
- (struct ethhdr *) buf;
+ (struct ethhdr *) pkt.pkt_buf;
memcpy(scratch_saddr,
(hdr_eth)->h_source, ETH_ALEN);
memcpy(scratch_daddr, (hdr_eth)->h_dest,
ETH_ALEN);
list = elist;
- } else if (fromaddr.sll_hatype == ARPHRD_FDDI) {
+ } else if (pkt.pkt_hatype == ARPHRD_FDDI) {
struct fddihdr *hdr_fddi =
- (struct fddihdr *) buf;
+ (struct fddihdr *) pkt.pkt_buf;
memcpy(scratch_saddr, (hdr_fddi)->saddr,
FDDI_K_ALEN);
memcpy(scratch_daddr, (hdr_fddi)->daddr,
FDDI_K_ALEN);
list = flist;
- } else
- if ((fromaddr.sll_hatype ==
- ARPHRD_IEEE802_TR)
- || (fromaddr.sll_hatype ==
- ARPHRD_IEEE802)) {
+ } else if ((pkt.pkt_hatype == ARPHRD_IEEE802_TR)
+ || (pkt.pkt_hatype == ARPHRD_IEEE802)) {
struct trh_hdr *hdr_trh =
- (struct trh_hdr *) buf;
+ (struct trh_hdr *) pkt.pkt_buf;
memcpy(scratch_saddr, (hdr_trh)->saddr,
TR_ALEN);
memcpy(scratch_daddr, (hdr_trh)->daddr,
@@ -1007,16 +1000,16 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
}
entry =
- in_ethtable(&table, fromaddr.sll_hatype,
+ in_ethtable(&table, pkt.pkt_hatype,
scratch_saddr);
if (!entry)
entry =
- addethentry(&table, fromaddr.sll_hatype,
+ addethentry(&table, pkt.pkt_hatype,
ifname, scratch_saddr, list);
if (entry != NULL) {
- updateethent(entry, br, is_ip, 1);
+ updateethent(entry, pkt.pkt_len, is_ip, 1);
if (!entry->prev_entry->un.desc.printed)
printethent(&table,
entry->prev_entry,
@@ -1029,15 +1022,15 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
*/
entry =
- in_ethtable(&table, fromaddr.sll_hatype,
+ in_ethtable(&table, pkt.pkt_hatype,
scratch_daddr);
if (!entry)
entry =
- addethentry(&table, fromaddr.sll_hatype,
+ addethentry(&table, pkt.pkt_hatype,
ifname, scratch_daddr, list);
if (entry != NULL) {
- updateethent(entry, br, is_ip, 0);
+ updateethent(entry, pkt.pkt_len, is_ip, 0);
if (!entry->prev_entry->un.desc.printed)
printethent(&table,
entry->prev_entry,
--
1.7.8.4