Since we have struct sockaddr_ll in struct pkt_hdr now,
remove pkt_ifindex, pkt_hatype and pkt_pkttype members from
struct pkt_hdr and modify all their uses.
Leave pkt_protocol untouched, because it caches the protocol
number in host order (no need for another htons()/ntohs() in other
code).
Also remove pkt_halen and pkt_addr members, they are unused.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 4 ++--
src/hostmon.c | 12 ++++++------
src/ifstats.c | 2 +-
src/itrafmon.c | 6 +++---
src/othptab.c | 6 +++---
src/packet.c | 5 +----
src/packet.h | 5 -----
7 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index 7377161..6d8ca07 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -531,9 +531,9 @@ void detstats(char *iface, time_t facilitytime)
continue;
}
- outgoing = (pkt.pkt_pkttype == PACKET_OUTGOING);
+ outgoing = (pkt.from->sll_pkttype == PACKET_OUTGOING);
update_proto_counter(&ifcounts.total, outgoing, pkt.pkt_len);
- if (pkt.pkt_pkttype == PACKET_BROADCAST) {
+ if (pkt.from->sll_pkttype == PACKET_BROADCAST) {
update_proto_counter(&ifcounts.bcast, outgoing, pkt.pkt_len);
update_pkt_counter(&span_bcast, pkt.pkt_len);
}
diff --git a/src/hostmon.c b/src/hostmon.c
index 78315fe..71a1836 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -922,7 +922,7 @@ void hostmon(time_t facilitytime, char *ifptr)
/* we're capturing on "All interfaces", */
/* so get the name of the interface */
/* of this packet */
- int r = dev_get_ifname(pkt.pkt_ifindex, ifnamebuf);
+ int r = dev_get_ifname(pkt.from->sll_ifindex, ifnamebuf);
if (r != 0) {
write_error("Unable to get interface name");
break; /* can't get interface name, get out! */
@@ -931,7 +931,7 @@ void hostmon(time_t facilitytime, char *ifptr)
}
/* get HW addresses */
- switch (pkt.pkt_hatype) {
+ switch (pkt.from->sll_hatype) {
case ARPHRD_ETHER: {
memcpy(scratch_saddr, pkt.ethhdr->h_source, ETH_ALEN);
memcpy(scratch_daddr, pkt.ethhdr->h_dest, ETH_ALEN);
@@ -958,11 +958,11 @@ void hostmon(time_t facilitytime, char *ifptr)
}
/* Check source address entry */
- entry = in_ethtable(&table, pkt.pkt_hatype,
+ entry = in_ethtable(&table, pkt.from->sll_hatype,
scratch_saddr);
if (!entry)
- entry = addethentry(&table, pkt.pkt_hatype,
+ entry = addethentry(&table, pkt.from->sll_hatype,
ifname, scratch_saddr, list);
if (entry != NULL) {
@@ -975,10 +975,10 @@ void hostmon(time_t facilitytime, char *ifptr)
}
/* Check destination address entry */
- entry = in_ethtable(&table, pkt.pkt_hatype,
+ entry = in_ethtable(&table, pkt.from->sll_hatype,
scratch_daddr);
if (!entry)
- entry = addethentry(&table, pkt.pkt_hatype,
+ entry = addethentry(&table, pkt.from->sll_hatype,
ifname, scratch_daddr, list);
if (entry != NULL) {
diff --git a/src/ifstats.c b/src/ifstats.c
index cc1e2ad..097fde1 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -591,7 +591,7 @@ void ifstats(time_t facilitytime)
continue;
}
- ptmp = positionptr(table.head, pkt.pkt_ifindex);
+ ptmp = positionptr(table.head, pkt.from->sll_ifindex);
if (!ptmp)
continue;
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 2400e60..37c3229 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -964,7 +964,7 @@ void ipmon(time_t facilitytime, char *ifptr)
/* we're capturing on "All interfaces", */
/* so get the name of the interface */
/* of this packet */
- int r = dev_get_ifname(pkt.pkt_ifindex, ifnamebuf);
+ int r = dev_get_ifname(pkt.from->sll_ifindex, ifnamebuf);
if (r != 0) {
write_error("Unable to get interface name");
break; /* error getting interface name, get out! */
@@ -1052,13 +1052,13 @@ void ipmon(time_t facilitytime, char *ifptr)
if (pkt.iphdr)
updateentry(&table, tcpentry, transpacket,
- pkt.pkt_buf, pkt.pkt_hatype,
+ pkt.pkt_buf, pkt.from->sll_hatype,
pkt.pkt_len, br, pkt.iphdr->frag_off,
logging, &revlook, rvnfd,
logfile);
else
updateentry(&table, tcpentry, transpacket,
- pkt.pkt_buf, pkt.pkt_hatype,
+ pkt.pkt_buf, pkt.from->sll_hatype,
pkt.pkt_len, pkt.pkt_len, 0, logging,
&revlook, rvnfd,
logfile);
diff --git a/src/othptab.c b/src/othptab.c
index e23f39e..d4b21bd 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -182,10 +182,10 @@ struct othptabent *add_othp_entry(struct othptable *table, struct
pkt_hdr *pkt,
new_entry->fragment = fragment;
if (options.mac || !is_ip) {
- if (pkt->pkt_hatype == ARPHRD_ETHER) {
+ if (pkt->from->sll_hatype == ARPHRD_ETHER) {
convmacaddr((char *) pkt->ethhdr->h_source, new_entry->smacaddr);
convmacaddr((char *) pkt->ethhdr->h_dest, new_entry->dmacaddr);
- } else if (pkt->pkt_hatype == ARPHRD_FDDI) {
+ } else if (pkt->from->sll_hatype == ARPHRD_FDDI) {
convmacaddr((char *) pkt->fddihdr->saddr, new_entry->smacaddr);
convmacaddr((char *) pkt->fddihdr->daddr, new_entry->dmacaddr);
}
@@ -231,7 +231,7 @@ struct othptabent *add_othp_entry(struct othptable *table, struct
pkt_hdr *pkt,
}
}
} else {
- new_entry->linkproto = pkt->pkt_hatype;
+ new_entry->linkproto = pkt->from->sll_hatype;
if (protocol == ETH_P_ARP) {
new_entry->un.arp.opcode =
diff --git a/src/packet.c b/src/packet.c
index 555d6f1..047ca68 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -59,7 +59,7 @@ static int packet_adjust(struct pkt_hdr *pkt)
{
int retval = 0;
- switch (pkt->pkt_hatype) {
+ switch (pkt->from->sll_hatype) {
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK:
pkt_cast_hdrp_l2(ethhdr, pkt);
@@ -161,9 +161,6 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
pkt->pkt_caplen = pkt->pkt_bufsize;
pkt->pkt_payload = NULL;
pkt->pkt_protocol = ntohs(pkt->from->sll_protocol);
- pkt->pkt_ifindex = pkt->from->sll_ifindex;
- pkt->pkt_hatype = pkt->from->sll_hatype;
- pkt->pkt_pkttype = pkt->from->sll_pkttype;
} else
ss = len;
}
diff --git a/src/packet.h b/src/packet.h
index ddb570b..05afa68 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -25,12 +25,7 @@ struct pkt_hdr {
char *pkt_payload;
size_t pkt_caplen; /* bytes captured */
size_t pkt_len; /* bytes on-the-wire */
- int pkt_ifindex; /* Interface number */
unsigned short pkt_protocol; /* Physical layer protocol: ETH_P_* */
- unsigned short pkt_hatype; /* Header type: ARPHRD_* */
- unsigned char pkt_pkttype; /* Packet type: PACKET_OUTGOING, PACKET_BROADCAST, ... */
- unsigned char pkt_halen; /* Length of address */
- unsigned char pkt_addr[8]; /* Physical layer address */
struct iovec iov;
struct sockaddr_ll *from;
--
1.9.1