packet_handler

函式名稱:packet_handler(u_char *param , const struct pcap_pkthdr *header , const u_char *pkt_data)   
函式功能:可進行包處理,與pcap_loop等回調函式聯合使用進行抓包   
參數說明:
u_char *param:數據包存儲的檔案指針   
struct pcap_pkthdr * header: 並非是數據包的指針,只是與數據包捕獲驅動有關的一個header ,是堆檔案包的結構體首部指針。可以得到時間值,數據包長度。   
const_char * pkt_data:指向數據包內容的指針,包括了協定頭,可以經過計算獲得IP數據包頭部的位置, UDP首部的位置。  
函式實現:
void packet_handler(u_char *param, const struct pcap_pkthdr *header,const u_char *pkt_data)   
{   
struct tm *ltime;   
char timestr[16];   
time_t local_tv_sec;   
/* 將時間戳轉換成可識別的格式 */   
local_tv_sec = header->ts->tv_sec;   
ltime=localtime(&local_tv_sec);   
strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);   
printf("%s,%.6d len:%d\n", timestr, header->ts->tv_usec,header->len);   
}

相關詞條

熱門詞條

聯絡我們