1

我有一个关于 openflow 数据包编程的问题。我建立了一个openflow网络,通过wireshark捕获控制器和交换机之间的数据包并将其保存在pcap文件中。现在我想在 C 程序中读取这个文件并分析 openflow 控制数据包头。我认为一种解决方案是逐字节读取文件并分离openflow数据包,但这似乎不是一种有用的方法。所以我的问题是:C 语言中是否有任何特殊的库(如 pcap)来提供一些工具来读取 openflow 数据包的标头并使用它们?为了更详细地解决我的问题,例如,我可以使用 libpcap 使用这些指令轻松找到数据包的 MAC 地址,

.........
#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 数据包标头?

4

1 回答 1

0

我使用 pcap 库来获取一些标头信息,以决定将数据包路由到何处。如果你真的想剖析你的 Openflow 消息,我建议你下载Openflow Wireshark Dissector。您还可以找到源代码,您可以在其中适应您的要求。

于 2015-05-18T01:24:05.253 回答