I'm working with libpcap in c / c + + and I have a problem when inserting pointers in a vector. This is my code:
typedef vector <u_char *>vPack;
...
vPack vect;
...
if (pcap_dispatch (p, 0, &mycallback, (u_char *) &vect) < 0){
cout << "Error" << endl;
pcap_perror (p, prestr);
}
....
void mycallback (u_char * args, const struct pcap_pkthdr *pkthdr, const u_char * packet){
u_char *pk;
pk = (u_char *)packet;
vPack *vec = (vPack *) args;
vec[0].push_back(pk);
}
The problem is that the elements are inserted in the same memory location, and the vector always contains the same element. Any suggestions?
PD: sorry for my english.