|
Post by Lorenzo VBPCAP Founder on Nov 18, 2003 7:45:08 GMT -5
vbLong VBPCAPAPI vpCaptureMem(LPSAFEARRAY FAR *buffer,PCK_HEADER *phead){ //To avoid overhead this function do not perform //any error checking, so be sure to use in the proper way long res; struct tm *ltime; struct pcap_pkthdr *header; u_char *pkt_data;
//Call wincpap res= pcap_next_ex(Handle, &header,&pkt_data);// If Winpcap Fails then exit if (res<0) return VBPCAP_ERROR_FAILURE; //If winpcap is successfull and no timeout then process the data if (res > 0) {
ltime=localtime(&header->ts.tv_sec); phead->caplen=header->caplen; phead->len=header->len; phead->h=ltime->tm_hour; phead->m=ltime->tm_min; phead->s=ltime->tm_sec; phead->us=header->ts.tv_usec; //Lock the safearray (pvdata points to data) SafeArrayLock(*buffer);
//change num of elements in the safearray according to the buffer size (*buffer)->rgsabound[0].cElements=header->caplen+1; /* This is the HACK: Swapping Safearray PVDATA pointer with new allocated U_char pointer I really dont'know if it's the right way but is fast. For sure not is safe */ (*buffer)->pvData=pkt_data; //Unlock the array SafeArrayUnlock(*buffer); }
return res; }
|
|