DPDK patches and discussions
 help / color / mirror / Atom feed
From: Moon-Sang Lee <sang0627@gmail.com>
To: dev@dpdk.org
Subject: [dpdk-dev] bytes order of ip header in dpdk 2.1
Date: Wed, 18 Nov 2015 17:47:37 +0900	[thread overview]
Message-ID: <CAACK=Xf7ZKOdXF6BiryiNFkDO0T1vfKKqcQxh-N=zkOr81EEcQ@mail.gmail.com> (raw)

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*

             reply	other threads:[~2015-11-18  8:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18  8:47 Moon-Sang Lee [this message]
2015-11-18  9:11 ` Moon-Sang Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAACK=Xf7ZKOdXF6BiryiNFkDO0T1vfKKqcQxh-N=zkOr81EEcQ@mail.gmail.com' \
    --to=sang0627@gmail.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).