J'essaie de créer une application qui convertit mes anciens journaux Ethernet personnalisés (fichiers bin) en journaux de style winpcap standard.Winpcap sauvegarde les paquets bruts non d'un adaptateur
Le problème est que je n'arrive pas à trouver un exemple d'ouverture d'un pcap_t * sans utiliser un adaptateur (carte réseau). Le fichier temp.pkt n'a pas été créé.
J'ai regardé les exemples fournis avec Winpcap et tous utilisent un adaptateur en direct lors du déchargement de paquets. Cet exemple est le plus proche \ WpdPack \ Examples-pcap \ savedump \ savedump.c est le plus proche, voir l'exemple ci-dessous légèrement modifié.
#ifdef _MSC_VER
/*
* we do not want the warnings about the old deprecated and unsecure CRT functions
* since these examples can be compiled under *nix as well
*/
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "pcap.h"
int main(int argc, char **argv)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_dumper_t *dumpfile;
/* Open the adapter */
if ((adhandle= pcap_open(??????, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
1, // promiscuous mode (nonzero means promiscuous)
1000, // read timeout
errbuf // error buffer
)) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
/* Open the dump file */
dumpfile = pcap_dump_open(adhandle, argv[1]);
if(dumpfile==NULL) {
fprintf(stderr,"\nError opening output file\n");
return -1;
}
// ---------------------------
struct pcap_pkthdr header;
header.ts.tv_sec = 1 ; /* seconds */
header.ts.tv_usec = 1; /* and microseconds */
header.caplen = 100; /* length of portion present */
header.len = 100 ; /* length this packet (off wire) */
u_char pkt_data[100];
for(int i = 0 ; i < 100 ; i++) {
pkt_data[i] = i ;
}
pcap_dump((u_char *) dumpfile, &header, (u_char *) &pkt_data);
// ---------------------------
/* start the capture */
// pcap_loop(adhandle, 0, packet_handler, (unsigned char *)dumpfile);
pcap_close(adhandle);
return 0;
}
Fonctionne bien, avez-vous fait ce code vous-même ou a-t-il été référencé quelque part sur http://www.winpcap.org/docs/ et je ne l'ai pas remarqué? Merci –
Je l'ai fait l'année dernière quand j'avais besoin de faire quelque chose de similaire. – nos