adnmaster666
Messages postés1Date d'inscriptionmercredi 14 mars 2007StatutMembreDernière intervention14 mars 2007
-
14 mars 2007 à 14:34
cs_rt15
Messages postés3874Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention 7 novembre 2014
-
15 mars 2007 à 19:08
Bonjour voici le code pour réaliser un sniffer mais le prob c'est qu'il ne fournit que l'IP, et le TCP, il me faudrait aussi l'UDP, l'ARM et l'éthernet est-ce que quelqu'un pourrait m'aider merci d'avance
Voici le code que je possède déjà :
/*
* Structures
*/
struct ethhdr // Ethernet header
{
unsigned char h_dest[6]; // Destination host address
unsigned char h_source[6]; // Source host address
unsigned short h_proto; // Packet type ID field (IP, ARP ...)
};
struct iphdr // structure IP Header
{
//Pour processeur de type little-endian
unsigned char ihl:4; // IP header length
unsigned char version:4;
unsigned char tos; // Type of service
unsigned short tot_len; // Total length
unsigned short id; // Identification
unsigned short frag_off; // Fragment Offset + Flags
unsigned char ttl; // Time to life
unsigned char protocol;
unsigned short check; // Checksum
unsigned int saddr; // Source address
unsigned int daddr; // Destination address
};
struct tcphdr // structure TCP Header
{
//Pour processeur de type little-endian
unsigned short source; // port source
unsigned short dest; // port de destination
unsigned int seq; // Sequence number
unsigned int ack_seq; // acknowledge sequence
unsigned short res1:4, // Reserved 1 : 4 bits
doff:4, // Data Offset
fin:1, // Flag FINISH
syn:1, // Flag SYNCHRONIZE
rst:1, // Flag RESET
psh:1, // Flag PUSH
ack:1, // Flag ACKNOLEDGE
urg:1, // Flag URGENT
res2:2; // Reserved 2 : 2 bits (res1 + res2 = 6 bits reserved)
unsigned short window;
unsigned short check; // checksum
unsigned short urg_ptr; // urgent
};
/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\r\n", errbuf);
return EXIT_FAILURE;
}
/* Print the list */
for(d= alldevs; d != NULL; d= d->next)
{
printf("%d.\r\nName:\r\n\t%s\r\n", ++i, d->name);
if (d->description)
printf("Descriptions:\r\n\t%s\r\n\r\n", d->description);
else
printf(" (No description available)\r\n");
}
if (i == 0)
{
printf("\r\nNo interfaces found! Make sure WinPcap is installed.\r\n");
return EXIT_FAILURE;
}else{
printf("Enter the interface number (1-%d):",i);
scanf("%d", &ifNum);
}
if(ifNum < 1 || ifNum > i)
{
printf("\nInterface number out of range.\r\n");
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
/* Jump to the selected adapter */
for(d=alldevs, i=0; i< ifNum-1 ;d=d->next, i++);
cs_rt15
Messages postés3874Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention 7 novembre 201413 15 mars 2007 à 19:08
Salut,
C'est vrai qu'il existe certainement des sources qui te faciliteraient le travail...
Mais WinPCAP à l'air de bien faire son boulot : c'est juste que le code
di-dessus n'affiche la description que des quelques protocoles les plus
courants -> Tu peux donc le complèter en te basant sur la doc de ces
protocoles.