|
@@ -14,8 +14,8 @@
|
|
void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
|
|
void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
|
|
void check_handshake(struct packet_info *info, flow f);
|
|
void check_handshake(struct packet_info *info, flow f);
|
|
void *sniff_packets(void *);
|
|
void *sniff_packets(void *);
|
|
-void process_packet(uint8_t *packet, struct packet_info *info);
|
|
|
|
-void extract_packet_headers(const uint8_t *packet, struct packet_info *info);
|
|
|
|
|
|
+void process_packet(struct packet_info *info);
|
|
|
|
+void extract_packet_headers(uint8_t *packet, struct packet_info *info);
|
|
|
|
|
|
/** Checks a handshake message to see if it is tagged or a
|
|
/** Checks a handshake message to see if it is tagged or a
|
|
* recognized flow.
|
|
* recognized flow.
|
|
@@ -106,7 +106,9 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa
|
|
//memcpy(modified_packet, packet, header->len);
|
|
//memcpy(modified_packet, packet, header->len);
|
|
|
|
|
|
struct packet_info *info = calloc(1, sizeof(struct packet_info));
|
|
struct packet_info *info = calloc(1, sizeof(struct packet_info));
|
|
- extract_packet_headers(packet, info);
|
|
|
|
|
|
+ uint8_t *tmp_packet = calloc(1, header->len);
|
|
|
|
+ memcpy(tmp_packet, packet, header->len);
|
|
|
|
+ extract_packet_headers(tmp_packet, info);
|
|
|
|
|
|
// Check to make sure it is an IP packet
|
|
// Check to make sure it is an IP packet
|
|
if(info->ip_hdr == NULL)
|
|
if(info->ip_hdr == NULL)
|
|
@@ -128,10 +130,10 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa
|
|
// TODO: handle errors
|
|
// TODO: handle errors
|
|
|
|
|
|
} else { //not a fragment, add to packet chain */
|
|
} else { //not a fragment, add to packet chain */
|
|
- process_packet(packet, info);
|
|
|
|
|
|
+ process_packet(info);
|
|
|
|
|
|
end:
|
|
end:
|
|
- if((pcap_inject(handle, packet, header->len)) < 0 ){
|
|
|
|
|
|
+ if((pcap_inject(handle, tmp_packet, header->len)) < 0 ){
|
|
fprintf(stderr, "Error: %s\n", pcap_geterr(handle));
|
|
fprintf(stderr, "Error: %s\n", pcap_geterr(handle));
|
|
}
|
|
}
|
|
free(info);//Note: don't free this while a thread is using it
|
|
free(info);//Note: don't free this while a thread is using it
|
|
@@ -248,7 +250,7 @@ void *sniff_packets(void *args){
|
|
* 2) adds the packet to the flow's data chain
|
|
* 2) adds the packet to the flow's data chain
|
|
* 3) updates the flow's state
|
|
* 3) updates the flow's state
|
|
*/
|
|
*/
|
|
-void process_packet(uint8_t *packet, struct packet_info *info){
|
|
|
|
|
|
+void process_packet(struct packet_info *info){
|
|
int index;
|
|
int index;
|
|
|
|
|
|
flow newFlow;
|
|
flow newFlow;
|
|
@@ -301,10 +303,10 @@ void process_packet(uint8_t *packet, struct packet_info *info){
|
|
* a packet_info struct
|
|
* a packet_info struct
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-void extract_packet_headers(const uint8_t *packet, struct packet_info *info){
|
|
|
|
|
|
+void extract_packet_headers(uint8_t *packet, struct packet_info *info){
|
|
|
|
|
|
/* First fill in IP header */
|
|
/* First fill in IP header */
|
|
- const uint8_t *p = packet;
|
|
|
|
|
|
+ uint8_t *p = packet;
|
|
p += ETHER_HEADER_LEN; //skip ethernet header
|
|
p += ETHER_HEADER_LEN; //skip ethernet header
|
|
info->ip_hdr = (struct ip_header*) p;
|
|
info->ip_hdr = (struct ip_header*) p;
|
|
info->size_ip_hdr = IP_HEADER_LEN(info->ip_hdr);
|
|
info->size_ip_hdr = IP_HEADER_LEN(info->ip_hdr);
|