1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <pcap.h>
#include <pcap-bpf.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/ip.h>
char **str_split(char *s, const char *ct)
{
char **tab=NULL;
int i;
char *cs=NULL;
size_t size=1;
void *temp=NULL;
if(s!=NULL && ct != NULL)
{
for(i=0; (cs=strtok(s,ct)); i++)
{
if(size <=i+1){
size <<=1;
temp=realloc(tab,sizeof(*tab) * size);
if(temp!=NULL){
tab=temp;
}
else{
fprintf(stderr,"mémoire insffisante\n");
free(tab);
tab=NULL;
exit(EXIT_FAILURE);
}
}
tab[i]=cs;
s=NULL;
}
tab[i]=NULL;
}
return tab;
}
char *rebuild_mac(char **mac_digit){
int index_temp=0;
char mac_address[20];
strcpy(mac_address,"\0");
while(index_temp <6)
{
if(index_temp!=0 && index_temp<6){
strcat(mac_address,":");
}
if(strlen(mac_digit[index_temp])<2)
{
strcat(mac_address,"0");
strcat(mac_address,mac_digit[index_temp]);
}else{
strcat(mac_address,mac_digit[index_temp]);
}
//printf("Temp : %s -> taille : %d index_temp : %d\n", mac_address,strlen(mac_address),index_temp);
index_temp++;
}
//printf("Fin dela boucle while\n");
return mac_address;
}
int main(int argc, char **argv)
{
//printf("Point d'arret");
pcap_t *desc;
pcap_t *desc_save;
struct pcap_pkthdr hdr;
struct bpf_program bp ;
struct ethhdr *EtherHdr;
struct ip *IpHeader;
bpf_u_int32 netmask=32;
FILE *fp;
const u_char *packet;
char **temp;
char errbuf[PCAP_ERRBUF_SIZE];
char * buff =NULL;
char *save_temp;
char *fichier_pcap = argv[1];
char mac_address_src_1[20];
char mac_address_dst_1[20];
char mac_address_src_2[20];
char mac_address_dst_2[20];
char previous_mac_address[20];
char mac_AP[20];
char ip_address_src_1[20];
char ip_address_dst_1[20];
char ip_address_src_2[20];
char ip_address_dst_2[20];
char directory[100];
int index_temp= 0;
int num_protocole= 0;
int mac_found= 0;
int host_found = 0;
int i = 0;
int size_tab=100;
int multiple_ip = 0;
struct info_host{
char mac_address[20];
char ip_address[20];
};
struct info_host connected_host[size_tab];
printf("répertoire courant : %s / nb argument ; %d", argv[2],argc);
if(argc<=0){
exit(EXIT_FAILURE);
} |
Partager