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 at 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 at gmail.com > Wisdom begins in wonder. *Socrates* > -- Moon-Sang Lee, SW Engineer Email: sang0627 at gmail.com Wisdom begins in wonder. *Socrates*