* [dpdk-dev] bytes order of ip header in dpdk 2.1
@ 2015-11-18 8:47 Moon-Sang Lee
2015-11-18 9:11 ` Moon-Sang Lee
0 siblings, 1 reply; 2+ messages in thread
From: Moon-Sang Lee @ 2015-11-18 8:47 UTC (permalink / raw)
To: dev
Once receiving a packet by rte_eth_rx_burst(), I printed IP header as
below.
It seems that length(uint16_t) is in big endian, but ip addresses are in
little endian.
I'm confused and appreciate any comment.
### print_ipv4_header src = 11.0.168.192, dst = 2.173.248.143, length = 60,
ttl = 64, proto = 6
This log was printed with these functions.
void print_ipv4_header(struct rte_mbuf *m) {
struct ether_hdr *eth_header;
struct ipv4_hdr *ipv4_header;
uint16_t length;
uint8_t ttl, proto;
uint32_t src_ip, dst_ip;
char src_ip_str[MAX_IP_STR_LEN], dst_ip_str[MAX_IP_STR_LEN];
eth_header = rte_pktmbuf_mtod(m, struct ether_hdr *);
ipv4_header = (struct ipv4_hdr*)(eth_header + 1);
* length = rte_be_to_cpu_16(ipv4_header->total_length);*
ttl = ipv4_header->time_to_live;
proto = ipv4_header->next_proto_id;
* src_ip = rte_be_to_cpu_32(ipv4_header->src_addr);*
* dst_ip = rte_be_to_cpu_32(ipv4_header->dst_addr);*
convert_ip_to_string(src_ip_str, src_ip);
convert_ip_to_string(dst_ip_str, dst_ip);
debug("### print_ipv4_header src = %s, dst = %s, length = %d, ttl = %d,
proto = %d", src_ip_str, dst_ip_str, length, ttl, proto);
}
void convert_ip_to_string(char *str, uint32_t ip) {
unsigned char *ptr = (unsigned char *)&ip;
sprintf(str, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]);
}
--
Moon-Sang Lee, SW Engineer
Email: sang0627@gmail.com
Wisdom begins in wonder. *Socrates*
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [dpdk-dev] bytes order of ip header in dpdk 2.1
2015-11-18 8:47 [dpdk-dev] bytes order of ip header in dpdk 2.1 Moon-Sang Lee
@ 2015-11-18 9:11 ` Moon-Sang Lee
0 siblings, 0 replies; 2+ messages in thread
From: Moon-Sang Lee @ 2015-11-18 9:11 UTC (permalink / raw)
To: dev
sorry, my code has a bug with regarding to byte order in
convert_ip_to_string().
On Wed, Nov 18, 2015 at 5:47 PM, Moon-Sang Lee <sang0627@gmail.com> wrote:
>
> Once receiving a packet by rte_eth_rx_burst(), I printed IP header as
> below.
> It seems that length(uint16_t) is in big endian, but ip addresses are in
> little endian.
> I'm confused and appreciate any comment.
>
> ### print_ipv4_header src = 11.0.168.192, dst = 2.173.248.143, length =
> 60, ttl = 64, proto = 6
>
> This log was printed with these functions.
>
> void print_ipv4_header(struct rte_mbuf *m) {
> struct ether_hdr *eth_header;
> struct ipv4_hdr *ipv4_header;
> uint16_t length;
> uint8_t ttl, proto;
> uint32_t src_ip, dst_ip;
> char src_ip_str[MAX_IP_STR_LEN], dst_ip_str[MAX_IP_STR_LEN];
>
> eth_header = rte_pktmbuf_mtod(m, struct ether_hdr *);
> ipv4_header = (struct ipv4_hdr*)(eth_header + 1);
> * length = rte_be_to_cpu_16(ipv4_header->total_length);*
> ttl = ipv4_header->time_to_live;
> proto = ipv4_header->next_proto_id;
> * src_ip = rte_be_to_cpu_32(ipv4_header->src_addr);*
> * dst_ip = rte_be_to_cpu_32(ipv4_header->dst_addr);*
> convert_ip_to_string(src_ip_str, src_ip);
> convert_ip_to_string(dst_ip_str, dst_ip);
>
> debug("### print_ipv4_header src = %s, dst = %s, length = %d, ttl =
> %d, proto = %d", src_ip_str, dst_ip_str, length, ttl, proto);
> }
>
> void convert_ip_to_string(char *str, uint32_t ip) {
> unsigned char *ptr = (unsigned char *)&ip;
>
> sprintf(str, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]);
> }
>
>
>
> --
> Moon-Sang Lee, SW Engineer
> Email: sang0627@gmail.com
> Wisdom begins in wonder. *Socrates*
>
--
Moon-Sang Lee, SW Engineer
Email: sang0627@gmail.com
Wisdom begins in wonder. *Socrates*
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-18 9:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-18 8:47 [dpdk-dev] bytes order of ip header in dpdk 2.1 Moon-Sang Lee
2015-11-18 9:11 ` Moon-Sang Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).