Commit d31244ef authored by 's avatar
Browse files

Added test_packet_read


git-svn-id: file:///home/svn/mapi/trunk@222 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 04c51b55
#include <stdio.h>
#include <unistd.h>
#include <linux/if_ether.h>
#include "../mapi.h"
int main(MAPI_UNUSED int argc, char *argv[])
{
int fd;
int fid;
struct mapipkt *pkt;
int packet_no;
unsigned char *packet;
unsigned char *p;
int i, j;
if(argc!=3)
{
printf("\nWrong arguments\n");
return -1;
}
if((fd=mapi_create_flow(argv[1])) == -1)
{
printf("\nCould not create flow\n");
return -1;
}
fid=mapi_apply_function(fd,"BPF_FILTER", argv[2]);
fid=mapi_apply_function(fd, "TO_BUFFER");
mapi_connect(fd);
packet_no=0;
while(1)
{
// sleep(5);
if((pkt=mapi_get_next_pkt(fd, fid)) != NULL)
{
packet_no++;
if ((packet_no%1)==0)
printf("Got packet: %d\n", packet_no);
printf("ts: %llu, ifindex: %u, caplen: %u, wlen: %u\n", pkt->ts, pkt->ifindex, pkt->caplen, pkt->wlen);
packet=&(pkt->pkt);
/* Check Ethernet type */
p=packet;
p+=12;
p = packet;
p+=(ETH_HLEN+12);
printf("src IP: ");
for (j = 0; j < 4; j++) {
printf("%03d", *p++);
if (j<3)
printf(".");
}
printf(" dst IP: ");
for (j = 0; j < 4; j++) {
printf("%03d", *p++);
if (j<3)
printf(".");
else
printf("\n");
}
p=packet;
for (i=0; i<40; i++) {
printf("%02x", *p++);
if (((i+1)%4)==0)
printf(" ");
}
}
else
{
printf("\nError in mapi_get_next_packet\n");
}
}
mapi_close_flow(fd);
printf("\nmapi_get_next_packet OK\n");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment