|
Post by Lorenzo VBPCAP Founder on Nov 19, 2003 13:30:31 GMT -5
vbLong VBPCAPAPI vpCaptureMemSafe(LPSAFEARRAY FAR *buffer){
//Pointer to PVDATA member vbByte * tmp=(vbByte *) (*buffer)->pvData; /*Some nasty vars: res= return code from winpcap header=winpcap packet header pkt_data=raw packet data /*
long res; struct pcap_pkthdr *header; u_char *pkt_data; //If working flag not 1 than vpBegin must be called first if (!WORKING){ SetExtError(EXT_ERROR_INVALIDOPERATION); return VBPCAP_ERROR_FAILURE; } //Check for a valid DEVICE handle returned by WINPCAP after the pcap_open //And Get The Packets if (Handle==NULL) return VBPCAP_ERROR_FAILURE; res= pcap_next_ex(Handle, &header,&pkt_data);
// Erroro on res=-1 if (res<0) return VBPCAP_ERROR_FAILURE; if (res > 0) { //Lock the array SafeArrayLock(*buffer); //If array is too small for the captured packet report the error if ((*buffer)->rgsabound[0].cElements < header->caplen+1){ SetExtError(EXT_ERROR_BUFFSMALL); return VBPCAP_ERROR_FAILURE; } //Copy the buffer end exit memcpy(tmp,pkt_data,header->caplen+1); } SafeArrayUnlock(*buffer); return res;
}
|
|