[dpdk-dev] Segmentation Fault on printf()

Chris Wright chrisw at redhat.com
Fri Mar 14 17:10:47 CET 2014


* sabu kurian (sabu2kurian at gmail.com) wrote:
> Hello friends,
> 
> I'm trying to print the ether_type for a packet that I captured from a port
> on my machine. Suppose 'm' holds the packet. 'm' is of type 'struct
> rte_mbuf'. Intels API reference for DPDK says 'ether_type' is of uint16_t.
> I used the following code to retrieve ether_type.
> 
> void * eth_type;
> struct ether_hdr *eth;
> 
> eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> eth_type = &eth->ether_type;
> 
> printf("\n Type is %" PRIu16 , *((uint16_t *)eth_type));

Looks ok, albeit slightly overly complicated.

struct ether_hdr *eth;
uint16_t eth_type;

eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
eth_type = eth->ether_type;
printf("\n Type is %" PRIu16 , eth_type));

This would remove all the extra casting.  Perhaps the mbuf is the problem
here.  And if so, the above snippet would segfault on eth->ether_type
showing you that mbuf is invalid.

You could try to (above mtod):

rte_pktmbuf_dump(m, sizeof(struct ether_hdr));

as that will show key contents of mbuf and packet data (and do some
basic validation along the way).

thanks,
-chris


More information about the dev mailing list