Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/itrafmon.c | 58 +++++++++++++++++++++++++------------------------------
src/othptab.c | 22 +++++++++++---------
src/othptab.h | 11 +++++----
3 files changed, 44 insertions(+), 47 deletions(-)
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 9e8d75c..82fc1f0 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -566,10 +566,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
time_t facilitytime, char *ifptr)
{
int logging = options->logging;
- struct sockaddr_ll fromaddr; /* iface info */
- char tpacket[MAX_PACKET_SIZE]; /* raw packet data */
- char *packet = NULL; /* network packet ptr */
struct iphdr *ippacket;
struct ip6_hdr *ip6packet;
unsigned int protocol;
@@ -599,7 +596,6 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
int curwin = 0;
- int readlen;
char *ifname = ifptr;
unsigned long long total_pkts = 0;
@@ -752,6 +748,8 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
gettimeofday(&tv, NULL);
starttime = timeint = closedint = tv.tv_sec;
+ PACKET_INIT(pkt);
+
while (!exitloop) {
char ifnamebuf[IFNAMSIZ];
@@ -830,8 +828,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
rotate_flag = 0;
}
- getpacket(fd, tpacket, &fromaddr, &ch, &readlen,
- table.tcpscreen);
+ packet_get(fd, &pkt, &ch, table.tcpscreen);
if (ch == ERR)
goto no_key_ready;
@@ -1027,16 +1024,14 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
}
no_key_ready:
- if (readlen <= 0)
+ if (pkt.pkt_len <= 0)
continue;
total_pkts++;
show_stats(statwin, total_pkts);
pkt_result =
- processpacket((char *) tpacket, &packet,
- (unsigned int *) &readlen, &br,
- &sport, &dport, &fromaddr,
+ packet_process(&pkt, &br, &sport, &dport,
ofilter, MATCH_OPPOSITE_ALWAYS,
options->v6inv4asv6);
@@ -1047,7 +1042,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
/* 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; /* error getting interface name, get out! */
@@ -1055,33 +1050,32 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
ifname = ifnamebuf;
}
- switch(fromaddr.sll_protocol) {
+ switch(pkt.pkt_protocol) {
case ETH_P_IP:
- ippacket = (struct iphdr *) packet;
+ ippacket = (struct iphdr *) pkt.pkt_payload;
iphlen = ippacket->ihl * 4;
ip6packet = NULL;
protocol = ippacket->protocol;
frag_off = ippacket->frag_off;
break;
case ETH_P_IPV6:
- ip6packet = (struct ip6_hdr *) packet;
+ ip6packet = (struct ip6_hdr *) pkt.pkt_payload;
iphlen = 40;
ippacket = NULL;
protocol = ip6packet->ip6_nxt;
frag_off = 0;
break;
default:
- add_othp_entry(&othptbl, 0, 0, NULL,
+ add_othp_entry(&othptbl, &pkt, 0, 0, NULL,
NULL, NOT_IP,
- fromaddr.sll_protocol, fromaddr.sll_hatype,
- (char *) tpacket,
- (char *) packet, br, ifname, 0,
+ pkt.pkt_protocol,
+ pkt.pkt_payload, ifname, 0,
0, logging, logfile,
options->servnames, 0);
continue;
}
- transpacket = (struct tcphdr *) (packet + iphlen);
+ transpacket = (struct tcphdr *) (pkt.pkt_payload + iphlen);
if (protocol == IPPROTO_TCP) {
if (ippacket != NULL) {
@@ -1183,14 +1177,14 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
if (ippacket != NULL)
updateentry(&table, tcpentry, transpacket,
- tpacket, fromaddr.sll_hatype,
- readlen, br, ippacket->frag_off,
+ pkt.pkt_buf, pkt.pkt_hatype,
+ pkt.pkt_len, br, ippacket->frag_off,
logging, &revlook, rvnfd, options,
logfile);
else
updateentry(&table, tcpentry, transpacket,
- tpacket, fromaddr.sll_hatype,
- readlen, readlen, 0, logging,
+ pkt.pkt_buf, pkt.pkt_hatype,
+ pkt.pkt_len, pkt.pkt_len, 0, logging,
&revlook, rvnfd, options,
logfile);
/*
@@ -1207,7 +1201,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
strcat(msgstring, " (SYN)");
writetcplog(logging, logfile, tcpentry,
- readlen, options->mac,
+ pkt.pkt_len, options->mac,
msgstring);
}
@@ -1258,11 +1252,11 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
process_dest_unreach(&table, (char *) transpacket,
ifname);
}
- add_othp_entry(&othptbl, ippacket->saddr,
+ add_othp_entry(&othptbl, &pkt, ippacket->saddr,
ippacket->daddr, NULL, NULL, IS_IP,
- ippacket->protocol, fromaddr.sll_hatype,
- (char *) tpacket, (char *) transpacket,
- readlen, ifname, &revlook, rvnfd,
+ ippacket->protocol,
+ (char *) transpacket,
+ ifname, &revlook, rvnfd,
logging, logfile,
options->servnames, fragment);
@@ -1272,10 +1266,10 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
process_dest_unreach(&table, (char *) transpacket,
ifname);
- add_othp_entry(&othptbl, 0, 0, &ip6packet->ip6_src,
- &ip6packet->ip6_dst, IS_IP, ip6packet->ip6_nxt,
- fromaddr.sll_hatype, (char *) tpacket,
- (char *) transpacket, readlen, ifname,
+ add_othp_entry(&othptbl, &pkt, 0, 0,
+ &ip6packet->ip6_src, &ip6packet->ip6_dst,
+ IS_IP, ip6packet->ip6_nxt,
+ (char *) transpacket, ifname,
&revlook, rvnfd,
logging, logfile, options->servnames,
fragment);
diff --git a/src/othptab.c b/src/othptab.c
index 7ac58c0..008112a 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -29,6 +29,7 @@ details.
#include "rvnamed.h"
#include "servname.h"
#include "addproto.h"
+#include "packet.h"
#define MSGSTRING_MAX 240
#define SHORTSTRING_MAX 40
@@ -168,12 +169,12 @@ void process_dest_unreach(struct tcptable *table, char *packet, char
*ifname)
}
}
-struct othptabent *add_othp_entry(struct othptable *table,
+struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt,
unsigned long saddr,
unsigned long daddr, struct in6_addr *s6addr,
struct in6_addr *d6addr, int is_ip,
- int protocol, unsigned short linkproto,
- char *packet, char *packet2, unsigned int br,
+ int protocol,
+ char *packet2,
char *ifname, int *rev_lookup, int rvnfd,
int logging, FILE * logfile,
int servnames, int fragment)
@@ -181,6 +182,7 @@ struct othptabent *add_othp_entry(struct othptable *table,
struct othptabent *new_entry;
struct othptabent *temp;
struct in_addr isaddr, idaddr;
+ char *packet = pkt->pkt_buf;
new_entry = xmalloc(sizeof(struct othptabent));
memset(new_entry, 0, sizeof(struct othptabent));
@@ -189,19 +191,19 @@ struct othptabent *add_othp_entry(struct othptable *table,
new_entry->fragment = fragment;
if ((table->mac) || (!is_ip)) {
- if ((linkproto ==
- ARPHRD_ETHER) /* || (linkproto == LINK_PLIP) */ ) {
+ if ((pkt->pkt_hatype == ARPHRD_ETHER)
+ /* || (pkt->pkt_hatype == LINK_PLIP) */ ) {
convmacaddr((char *) (((struct ethhdr *) packet)->
h_source), new_entry->smacaddr);
convmacaddr((char *) (((struct ethhdr *) packet)->
h_dest), new_entry->dmacaddr);
- } else if (linkproto == ARPHRD_FDDI) {
+ } 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);
- } else if ((linkproto == ARPHRD_IEEE802)
- || (linkproto == ARPHRD_IEEE802_TR)) {
+ } else if ((pkt->pkt_hatype == ARPHRD_IEEE802)
+ || (pkt->pkt_hatype == ARPHRD_IEEE802_TR)) {
convmacaddr((char *) (((struct trh_hdr *) packet)->
saddr), new_entry->smacaddr);
convmacaddr((char *) (((struct trh_hdr *) packet)->
@@ -258,7 +260,7 @@ struct othptabent *add_othp_entry(struct othptable *table,
}
}
} else {
- new_entry->linkproto = linkproto;
+ new_entry->linkproto = pkt->pkt_hatype;
if (protocol == ETH_P_ARP) {
new_entry->un.arp.opcode =
@@ -280,7 +282,7 @@ struct othptabent *add_othp_entry(struct othptable *table,
new_entry->protocol = protocol;
strcpy(new_entry->iface, ifname);
- new_entry->pkt_length = br;
+ new_entry->pkt_length = pkt->pkt_len;
if (table->head == NULL) {
new_entry->prev_entry = NULL;
diff --git a/src/othptab.h b/src/othptab.h
index b894a87..48f9d29 100644
--- a/src/othptab.h
+++ b/src/othptab.h
@@ -9,6 +9,8 @@ Copyright (c) Gerard Paul Java 1997
***/
+#include "packet.h"
+
#define NONIP -1
#define IS_IP 1
#define NOT_IP 0
@@ -123,14 +125,13 @@ void init_othp_table(struct othptable *table, int mac);
void process_dest_unreach(struct tcptable *table, char *packet, char *ifname);
-struct othptabent *add_othp_entry(struct othptable *table,
+struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt,
unsigned long saddr,
unsigned long daddr, struct in6_addr *s6addr,
struct in6_addr *d6addr, int is_ip,
- int protocol, unsigned short linkproto,
- char *packet, char *netpacket,
- unsigned int br, char *ifname,
- int *rev_lookup, int rvnamedon,
+ int protocol,
+ char *packet2,
+ char *ifname, int *rev_lookup, int rvnamedon,
int logging, FILE * logfile,
int servnames, int fragment);
--
1.7.8.4