Hi Bryan
pfring_parse_pkt does not know the packet length, please set it into the hdr 
before calling pfring_parse_pkt.

hdr.len = hdr.caplen = buffers_array_[0]->len;

Alfredo

> On 15 Oct 2015, at 03:45, Bryan Fok <[email protected]> wrote:
> 
> Hi Alfredo
> 
> I did memset, and still receive 0 ip and 0 port at the print out. I dont know 
> whats going on. I put more detail on the code and printout here.
> 
> 
> This is how I initialize the cluster:
> 
>         std::cerr << "number of buffers: " << NBUFF << std::endl;
>         //start a new cluster
>         zc_ = pfring_zc_create_cluster(cluster_id, buffer_len_, 0, 
> MAX_CARD_SLOTS + NBUFF, numa_node_of_cpu(bind_core), NULL);
>         if (zc_ == NULL)
>         {
> 
>             char *s = NULL;
>             sprintf(s, "pfring_zc_create_cluster error [%s] Please check that 
> pf_ring.ko is loaded and hugetlb fs is mounted\n", strerror(errno));
>             std::string str_err(s);
>             _on_exception(str_err);
>         }
>         std::cerr << "cluster created." << std::endl;
>         //open device
>         zq_ = pfring_zc_open_device(zc_, device, rx_only, 0);
>         if (zq_ == NULL)
>         {
>             char *s = NULL;
>             sprintf(s, "pfring_zc_open_device error [%s] Please check that %s 
> is up and not already used\n", strerror(errno), device);
>             std::string str_err(s);
>             _on_exception(str_err);
>         }
>         std::cerr << "device " << device << " open." << std::endl;
>         //memory allocation
>         for (int i = 0; i < NBUFF; i++)
>         {
>             buffers_array_[i] = pfring_zc_get_packet_handle(zc_);
> 
>             if (buffers_array_[i] == NULL)
>             {
>                 char *s = NULL;
>                 sprintf(s, "pfring_zc_get_packet_handle error\n");
>                 std::string str_err(s);
>                 _on_exception(str_err);
>                 return;
>             }
>         }
>         std::cerr << "number of buffer allocated: " << NBUFF << std::endl;
> 
> 
> 
> 
> This is how I loop the receive method:
> 
> 
> while (start_)
> {
>             memset(&hdr, 0, sizeof(hdr));
> 
>             if (pfring_zc_recv_pkt(zq_, &buffers_array_[0], 0) > 0)
>             {
>                 pfring_parse_pkt(pfring_zc_pkt_buff_data(buffers_array_[0], 
> zq_), &hdr, 5, 0, 1);
>                 std::cout << "ip_src:" << 
> print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_src.v4)) << " l4_src_port: "
>                         << hdr.extended_hdr.parsed_pkt.l4_src_port << " 
> ip_dst:" << print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_dst.v4))
>                         << " l4_dst_port: " << 
> hdr.extended_hdr.parsed_pkt.l4_dst_port << std::endl;
>           
>             }
> }
> 
> This is the print out:
> 
> cluster created.
> #########################################################################
> # ERROR: You do not seem to have a valid PF_RING ZC license 6.1.1.150917 for 
> eth1 [Intel 1 Gbit e1000e family]
> # ERROR: Please get one at http://shop.ntop.org/ <http://shop.ntop.org/>.
> #########################################################################
> # We're now working in demo mode with packet capture and          
> # transmission limited to 5 minutes
> #########################################################################
> device zc:eth1 open.
> number of buffer allocated: 256
> init pfring completed.
> added channel ip: 266.1.1.6 port: 2116 ip int: 0
> add channel completed.
> initializing ping pong
> receiver aync listening started.
> #########################################################################
> # ERROR: You do not seem to have a valid PF_RING ZC license 6.1.1.150917 for 
> eth1 [Intel 1 Gbit e1000e family]
> # ERROR: Please get one at http://shop.ntop.org/ <http://shop.ntop.org/>.
> #########################################################################
> Using PF_RING v.6.0.3
> sender socket created.
> starting ping pong
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> 
> 
> B.R.
> Bryan
> 
> 
> From: [email protected]
> Date: Wed, 14 Oct 2015 11:52:11 +0200
> To: [email protected]
> Subject: Re: [Ntop-misc] Failed to extract ip and port by pfring_parse_pkt()  
> at ZC but ok at venilia pf_ring
> 
> Hi Bryan
> please try zero’ing hdr in order to make sure pfring_parse_pkt() does not 
> skip packet headers as optimisation (it avoids parsing the packet twice in 
> case hdr already contains valid parsing info)
> 
> Alfredo
> 
> On 14 Oct 2015, at 05:10, Bryan Fok <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> I am testing the ZC (without license, it print on screen) , it is receiving 
> the packets that I sent from the other host, but it always return 0 content 
> from the pfring_parse_pkt() .
> 
> 1) This is how I capture the packet, and extract the ip in ZC:
> 
> if (pfring_zc_recv_pkt(zq_, &buffers_array_[0], 0) > 0)
> {
>                 pfring_parse_pkt(pfring_zc_pkt_buff_data(buffers_array_[0], 
> zq_), &hdr, 5, 0, 1);
> 
>                 std::cout << "ip_src:" << 
> print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_src.v4)) << " l4_src_port: "
>                         << hdr.extended_hdr.parsed_pkt.l4_src_port << " 
> ip_dst:" << print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_dst.v4))
>                         << " l4_dst_port: " << 
> hdr.extended_hdr.parsed_pkt.l4_dst_port << std::endl;
> }
> 
> The output is always no matter where the message came from:
> ip_src:0.0.0.0 l4_src_port: 0 ip_dst:0.0.0.0 l4_dst_port: 0
> 
> 
> 2) In Venilia PF_RING, it work very well which mean it actually print out the 
> src and dst IPs properly:
> 
> if (pfring_recv(pd_, &buf, 0, &hdr, wait_for_packet_))
> {
>                 pfring_parse_pkt(buf, &hdr, 5, 0, 1);
> 
>                 std::cout << "ip_src:" << 
> print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_src.v4)) <<
>                          " l4_src_port: " << 
> hdr.extended_hdr.parsed_pkt.l4_src_port <<
>                          " ip_dst:" << 
> print_ip(byte_swap(hdr.extended_hdr.parsed_pkt.ip_dst.v4)) <<
>                          " l4_dst_port: " << 
> hdr.extended_hdr.parsed_pkt.l4_dst_port <<std::endl;
> }
> 
> 
> B.R
> Bryan
> _______________________________________________
> Ntop-misc mailing list
> [email protected] <mailto:[email protected]>
> http://listgateway.unipi.it/mailman/listinfo/ntop-misc 
> <http://listgateway.unipi.it/mailman/listinfo/ntop-misc>
> 
> _______________________________________________ Ntop-misc mailing list 
> [email protected] <mailto:[email protected]>  
> <http://listgateway.unipi.it/mailman/listinfo/ntop-misc>http://listgateway.unipi.it/mailman/listinfo/ntop-misc
>  <http://listgateway.unipi.it/mailman/listinfo/ntop-misc>
> 
> _______________________________________________
> Ntop-misc mailing list
> [email protected] <mailto:[email protected]>
> http://listgateway.unipi.it/mailman/listinfo/ntop-misc 
> <http://listgateway.unipi.it/mailman/listinfo/ntop-misc>
_______________________________________________
Ntop-misc mailing list
[email protected]
http://listgateway.unipi.it/mailman/listinfo/ntop-misc

Reply via email to