before patch, when you want to access struct fddihdr you have to define
a new struct fddihdr and cast pkt->pkt_buf to struct fddihdr, which is
pretty annoying. Now fddihdr is in pkt_hdr struct and it's casted right
away ARPHDR_FDDI packet arrives.
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/hostmon.c | 8 ++------
src/othptab.c | 7 ++-----
src/packet.c | 1 +
src/packet.h | 2 ++
src/tcptable.c | 2 ++
5 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c
index c4c8fb1..092293c 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -985,12 +985,8 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
list = elist;
break; }
case ARPHRD_FDDI: {
- struct fddihdr *hdr_fddi =
- (struct fddihdr *)pkt.pkt_buf;
- memcpy(scratch_saddr, hdr_fddi->saddr,
- FDDI_K_ALEN);
- memcpy(scratch_daddr, hdr_fddi->daddr,
- FDDI_K_ALEN);
+ memcpy(scratch_saddr, pkt.fddihdr->saddr, FDDI_K_ALEN);
+ memcpy(scratch_daddr, pkt.fddihdr->daddr, FDDI_K_ALEN);
list = flist;
break; }
default:
diff --git a/src/othptab.c b/src/othptab.c
index 831a907..1d223ce 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -174,7 +174,6 @@ struct othptabent *add_othp_entry(struct othptable *table, struct
pkt_hdr *pkt,
struct othptabent *new_entry;
struct othptabent *temp;
struct in_addr isaddr, idaddr;
- char *packet = pkt->pkt_buf;
new_entry = xmallocz(sizeof(struct othptabent));
@@ -186,10 +185,8 @@ struct othptabent *add_othp_entry(struct othptable *table, struct
pkt_hdr *pkt,
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);
- convmacaddr((char *) (((struct fddihdr *) packet)->
- daddr), new_entry->dmacaddr);
+ convmacaddr((char *) pkt->fddihdr->saddr, new_entry->smacaddr);
+ convmacaddr((char *) pkt->fddihdr->daddr, new_entry->dmacaddr);
}
}
diff --git a/src/packet.c b/src/packet.c
index 1be23ec..60d40b5 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -76,6 +76,7 @@ static int packet_adjust(struct pkt_hdr *pkt)
pkt->pkt_len -= 4;
break;
case ARPHRD_FDDI:
+ pkt_cast_hdrp(fddihdr, pkt);
pkt->pkt_payload = pkt->pkt_buf;
pkt->pkt_payload += sizeof(struct fddihdr);
pkt->pkt_len -= sizeof(struct fddihdr);
diff --git a/src/packet.h b/src/packet.h
index 6c6e1be..dea4417 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -34,6 +34,7 @@ struct pkt_hdr {
unsigned char pkt_halen; /* Length of address */
unsigned char pkt_addr[8]; /* Physical layer address */
struct ethhdr *ethhdr;
+ struct fddihdr *fddihdr;
char pkt_buf[MAX_PACKET_SIZE];
};
@@ -48,6 +49,7 @@ struct pkt_hdr {
.pkt_bufsize = MAX_PACKET_SIZE, \
.pkt_payload = NULL, \
.ethhdr = NULL, \
+ .fddihdr = NULL, \
};
void open_socket(int *fd);
diff --git a/src/tcptable.c b/src/tcptable.c
index 9d4462e..ff85c9b 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -619,6 +619,8 @@ void updateentry(struct tcptable *table, struct tcptableent
*tableentry,
if (opts->mac) {
memset(newmacaddr, 0, sizeof(newmacaddr));
+
+ /* change updateentry to take struct pkt to remove this */
if (linkproto == ARPHRD_ETHER) {
convmacaddr((char *) (((struct ethhdr *) packet)->
h_source), newmacaddr);
--
1.7.10.2