-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging new sniffing feature from marsan27/sniffer
Added network packet sniffing capabilities
- Loading branch information
Showing
10 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef HEADER_P_INTERPRETER | ||
#define HEADER_P_INTERPRETER | ||
|
||
#include "packetForger.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
packet_t parse_packet(char* buffer, int size); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "../include/packetInterpreter.h" | ||
|
||
/** | ||
* Function to get protocol of packet | ||
* | ||
*/ | ||
int get_packet_proto(char* buffer, int size){ | ||
struct iphdr *ipheader = (struct iphdr*)buffer; | ||
|
||
int protocol = ipheader->protocol; | ||
|
||
printf("Packet of protocol %i detected\n", protocol); | ||
return protocol; | ||
} | ||
|
||
/** | ||
* Obtain packet from byte stream | ||
* | ||
* NOTE: only accepts TCP packets for now | ||
* | ||
*/ | ||
packet_t parse_packet(char* buffer, int size){ | ||
int proto = get_packet_proto(buffer, size); | ||
packet_t packet; | ||
|
||
if(proto!=6){ | ||
build_null_packet(packet); | ||
fprintf(stderr, "Parsed packet of non-supported protocol. This should not have happened %i\n", proto); | ||
return packet; | ||
} | ||
|
||
//Constructing packet struct | ||
packet.ipheader = (struct iphdr*) buffer; | ||
int ip_header_length = packet.ipheader->ihl*4; | ||
|
||
packet.tcpheader = (struct tcphdr*) (buffer+ip_header_length); | ||
int tcp_header_length = packet.tcpheader->doff*4; | ||
|
||
packet.payload = (char*) buffer+ip_header_length+tcp_header_length; | ||
|
||
packet.payload_length = size - ip_header_length - tcp_header_length; | ||
|
||
packet.packet = buffer; | ||
|
||
return packet; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters