2015-05-14 15 views
1

我對openflow數據包編程有個疑問。我建立了一個openflow網絡,通過wireshark捕獲控制器和交換機之間的數據包並將其保存在pcap文件中。現在我想在C程序中讀取這個文件並分析openflow控制包頭。我認爲一種解決方案是逐字節讀取文件並分開openflow數據包,但這似乎不是一種有用的方法。所以我的問題是:在C語言中是否有任何特殊的庫(如pcap)提供一些工具來讀取openflow數據包的頭文件並使用它們?在我的問題更多的分辨率,例如,我可以很容易找到使用libpcap的這些指令的數據包的MAC地址,c語言中的Openflow數據包解析

......... 
#include "pcap.h" 
......... 
pcap_t* descr; 
const u_char *packet; 
struct pcap_pkthdr hdr;  /* pcap.h */ 
struct ether_header *eptr; /* net/ethernet.h */ 
u_char* args = NULL; 
u_char *ptr; /* printing out hardware header info */ 
.......... 
.......... 
/* grab a device to peak into... */ 
dev = pcap_lookupdev(errbuf); 

descr = pcap_open_live(dev,BUFSIZ,0,-1,errbuf); 
// we will get the packet here from the interface 
packet = pcap_next(descr,&hdr); 
if(packet == NULL) 
{ 
    printf("Didn't grab packet\n"); 
    exit(1); 
} 
eptr = (struct ether_header *) packet; 
ptr = eptr->ether_dhost; 
i = ETHER_ADDR_LEN; 
printf(" Source Address: "); 
do{ 
    printf("%s%x",(i == ETHER_ADDR_LEN) ? " " : ":",*ptr++); 
}while(--i>0); 

,所以我想知道,有沒有這樣的方法找到了OpenFlow的包頭?

回答

0

我使用pcap庫來獲取一些標題信息,以作出關於在哪裏路由我的數據包的一些決定。如果你真的想剖析你的Openflow消息,我建議你下載Openflow Wireshark Dissector。你也可以找到源代碼,在那裏你可以適應你的要求。