1) dissect declaration and initialization of struct pkt_hdr
2) rename PACKET_INIT_STRUCT() to packet_init()
3) un-inline packet_init(): it's not used on any fast path so there's no
need to be inlined
4) capture-pkt.c: rename p to pkt to have it consistent with other uses
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/capture-pkt.c | 10 ++++++----
src/detstats.c | 4 +++-
src/hostmon.c | 4 +++-
src/ifstats.c | 4 +++-
src/itrafmon.c | 4 +++-
src/packet.c | 13 +++++++++++++
src/packet.h | 16 +---------------
src/pktsize.c | 4 +++-
src/serv.c | 4 +++-
9 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/src/capture-pkt.c b/src/capture-pkt.c
index 6df4611..25e9f2b 100644
--- a/src/capture-pkt.c
+++ b/src/capture-pkt.c
@@ -47,20 +47,22 @@ int cmd_capture(int argc, char **argv)
die_errno("fopen");
}
- PACKET_INIT(p);
+ struct pkt_hdr pkt;
+ packet_init(&pkt);
+
int captured = 0;
for (;;) {
- if (packet_get(fd, &p, NULL, NULL) == -1)
+ if (packet_get(fd, &pkt, NULL, NULL) == -1)
die_errno("fail to get packet");
- if (!p.pkt_len)
+ if (!pkt.pkt_len)
continue;
printf(".");
fflush(stdout);
if (fp)
- fwrite(&p, sizeof(p), 1, fp);
+ fwrite(&pkt, sizeof(pkt), 1, fp);
if (++captured == cap_nr_pkt)
break;
diff --git a/src/detstats.c b/src/detstats.c
index 646893f..0f96e9b 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -290,6 +290,8 @@ void detstats(char *iface, time_t facilitytime)
int fd;
+ struct pkt_hdr pkt;
+
if (!dev_up(iface)) {
err_iface_down();
return;
@@ -378,7 +380,7 @@ void detstats(char *iface, time_t facilitytime)
exitloop = 0;
- PACKET_INIT(pkt);
+ packet_init(&pkt);
/*
* Data-gathering loop
diff --git a/src/hostmon.c b/src/hostmon.c
index 44dcf40..51267ef 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -758,6 +758,8 @@ void hostmon(time_t facilitytime, char *ifptr)
int fd;
+ struct pkt_hdr pkt;
+
if (ifptr && !dev_up(ifptr)) {
err_iface_down();
return;
@@ -821,7 +823,7 @@ void hostmon(time_t facilitytime, char *ifptr)
updtime = tv;
statbegin = startlog = tv.tv_sec;
- PACKET_INIT(pkt);
+ packet_init(&pkt);
do {
gettimeofday(&tv, NULL);
diff --git a/src/ifstats.c b/src/ifstats.c
index 2a5bba4..b7eeb7a 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -427,6 +427,8 @@ void ifstats(time_t facilitytime)
int fd;
+ struct pkt_hdr pkt;
+
struct timeval tv;
time_t starttime = 0;
time_t statbegin = 0;
@@ -491,7 +493,7 @@ void ifstats(time_t facilitytime)
updtime = tv;
starttime = startlog = statbegin = tv.tv_sec;
- PACKET_INIT(pkt);
+ packet_init(&pkt);
while (!exitloop) {
gettimeofday(&tv, NULL);
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 20c6f6c..8bf6c3a 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -588,6 +588,8 @@ void ipmon(time_t facilitytime, char *ifptr)
int fd;
+ struct pkt_hdr pkt;
+
int ch;
int keymode = 0;
char msgstring[80];
@@ -692,7 +694,7 @@ void ipmon(time_t facilitytime, char *ifptr)
updtime = tv;
starttime = timeint = closedint = tv.tv_sec;
- PACKET_INIT(pkt);
+ packet_init(&pkt);
while (!exitloop) {
char ifnamebuf[IFNAMSIZ];
diff --git a/src/packet.c b/src/packet.c
index 4556516..afa767f 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -329,6 +329,19 @@ again:
return PACKET_OK;
}
+int packet_init(struct pkt_hdr *pkt)
+{
+ pkt->pkt_bufsize = MAX_PACKET_SIZE;
+ pkt->pkt_payload = NULL;
+ pkt->ethhdr = NULL;
+ pkt->fddihdr = NULL;
+ pkt->iphdr = NULL;
+ pkt->ip6_hdr = NULL;
+ pkt->pkt_len = 0; /* signalize we have no packet prepared */
+
+ return 0; /* all O.K. */
+}
+
void pkt_cleanup(void)
{
destroyfraglist();
diff --git a/src/packet.h b/src/packet.h
index 895d63b..e8811e6 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -38,21 +38,6 @@ struct pkt_hdr {
char pkt_buf[MAX_PACKET_SIZE];
};
-static inline void PACKET_INIT_STRUCT(struct pkt_hdr *p)
-{
- p->pkt_bufsize = MAX_PACKET_SIZE;
- p->pkt_payload = NULL;
- p->ethhdr = NULL;
- p->fddihdr = NULL;
- p->iphdr = NULL;
- p->ip6_hdr = NULL;
- p->pkt_len = 0; /* signalize we have no packet prepared */
-}
-
-#define PACKET_INIT(packet) \
- struct pkt_hdr packet; \
- PACKET_INIT_STRUCT(&packet)
-
static inline __u8 pkt_iph_len(const struct pkt_hdr *pkt)
{
switch (pkt->pkt_protocol) {
@@ -80,6 +65,7 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win);
int packet_process(struct pkt_hdr *pkt, unsigned int *total_br,
in_port_t *sport, in_port_t *dport,
int match_opposite, int v6inv4asv6);
+int packet_init(struct pkt_hdr *pkt);
void pkt_cleanup(void);
#endif /* IPTRAF_NG_PACKET_H */
diff --git a/src/pktsize.c b/src/pktsize.c
index 54fb680..8206919 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -164,6 +164,8 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
int fd;
+ struct pkt_hdr pkt;
+
if (!dev_up(ifname)) {
err_iface_down();
goto err_unmark;
@@ -249,7 +251,7 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
goto err_close;
}
- PACKET_INIT(pkt);
+ packet_init(&pkt);
do {
gettimeofday(&tv, NULL);
diff --git a/src/serv.c b/src/serv.c
index c82bd3a..eecb34a 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -769,6 +769,8 @@ void servmon(char *ifname, time_t facilitytime)
struct porttab *ports;
+ struct pkt_hdr pkt;
+
if (!dev_up(ifname)) {
err_iface_down();
return;
@@ -842,7 +844,7 @@ void servmon(char *ifname, time_t facilitytime)
goto err_close;
}
- PACKET_INIT(pkt);
+ packet_init(&pkt);
while (!exitloop) {
gettimeofday(&tv, NULL);
--
1.9.1