before patch, when you want to access struct ethhdr you have to define a new struct ethhdr and cast pkt->pkt_buf to struct ethhdr, which is pretty annoying. Now ethhdr is in pkt_hdr struct and it's casted right away ARPHDR_ETHER/ARPHDR_LOOP packet arrives.
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/hostmon.c | 8 ++------ src/othptab.c | 6 ++---- src/packet.c | 1 + src/packet.h | 16 ++++++++++++---- 4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c index feeb629..c4c8fb1 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -980,12 +980,8 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr, /* get HW addresses */ switch (pkt.pkt_hatype) { case ARPHRD_ETHER: { - struct ethhdr *hdr_eth = - (struct ethhdr *)pkt.pkt_buf; - memcpy(scratch_saddr, hdr_eth->h_source, - ETH_ALEN); - memcpy(scratch_daddr, hdr_eth->h_dest, - ETH_ALEN); + memcpy(scratch_saddr, pkt.ethhdr->h_source, ETH_ALEN); + memcpy(scratch_daddr, pkt.ethhdr->h_dest, ETH_ALEN); list = elist; break; } case ARPHRD_FDDI: { diff --git a/src/othptab.c b/src/othptab.c index 62ce73f..831a907 100644 --- a/src/othptab.c +++ b/src/othptab.c @@ -183,10 +183,8 @@ struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt,
if ((table->mac) || (!is_ip)) { if (pkt->pkt_hatype == ARPHRD_ETHER) { - convmacaddr((char *) (((struct ethhdr *) packet)-> - h_source), new_entry->smacaddr); - convmacaddr((char *) (((struct ethhdr *) packet)-> - h_dest), new_entry->dmacaddr); + 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) { convmacaddr((char *) (((struct fddihdr *) packet)-> saddr), new_entry->smacaddr); diff --git a/src/packet.c b/src/packet.c index 20f20bf..b01c0ac 100644 --- a/src/packet.c +++ b/src/packet.c @@ -46,6 +46,7 @@ static int packet_adjust(struct pkt_hdr *pkt) switch (pkt->pkt_hatype) { case ARPHRD_ETHER: case ARPHRD_LOOPBACK: + cast_hdr(ethhdr, pkt); pkt->pkt_payload = pkt->pkt_buf; pkt->pkt_payload += ETH_HLEN; pkt->pkt_len -= ETH_HLEN; diff --git a/src/packet.h b/src/packet.h index 0bed4a0..561f74e 100644 --- a/src/packet.h +++ b/src/packet.h @@ -33,13 +33,21 @@ struct pkt_hdr { 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 ethhdr *ethhdr; char pkt_buf[MAX_PACKET_SIZE]; };
-#define PACKET_INIT(packet) \ - struct pkt_hdr packet = { \ - .pkt_bufsize = MAX_PACKET_SIZE, \ - .pkt_payload = NULL \ +#define pkt_cast_hdr(hdr, pkt) \ + do { \ + pkt.hdr = (struct hdr *) pkt.pkt_buf; \ + } while (0) + + +#define PACKET_INIT(packet) \ + struct pkt_hdr packet = { \ + .pkt_bufsize = MAX_PACKET_SIZE, \ + .pkt_payload = NULL, \ + .ethhdr = NULL, \ };
void open_socket(int *fd);
iptraf-ng@lists.fedorahosted.org