From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f170.google.com (mail-io0-f170.google.com [209.85.223.170]) by dpdk.org (Postfix) with ESMTP id CA98E58C3 for ; Wed, 18 Nov 2015 10:11:49 +0100 (CET) Received: by iouu10 with SMTP id u10so47829938iou.0 for ; Wed, 18 Nov 2015 01:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ubu3JpTAKYP1HKzwfwH+RsdqfwJD/A1nxudM1YQrvDY=; b=Re3KILK9nCLFtvneoMF908RPfFbMzN8hKKfYatwrMUbv0m+wtbyChMoOhVIYgDxyp+ IwEFtpM+o2doCB2yR/Q5M1QmVK17kFZMwv2Ke4iRjt30A8Mz1Y9ACtYMt0MZbF+ZCXja BL7gwE+f3irE7iyhd2SrxQNY8LE1r2IO+hoQmvoKrzijah1IJ99QwMWlNGx8PX397tJC bJYoxnTMptslvdFQ20Zua4yuShHvxb2TEi/0i8GXB2zvxOI2Qguq5X7zf23iovXepwHS B0GGS+kiZvfuUZC7Pz6QJyO1SOKCK7XDtC1cAmpVFPRpFvd/rtmJQptyoUyWybTCtQPr pQzA== MIME-Version: 1.0 X-Received: by 10.107.7.210 with SMTP id g79mr1824465ioi.81.1447837909223; Wed, 18 Nov 2015 01:11:49 -0800 (PST) Received: by 10.79.39.129 with HTTP; Wed, 18 Nov 2015 01:11:49 -0800 (PST) In-Reply-To: References: Date: Wed, 18 Nov 2015 18:11:49 +0900 Message-ID: From: Moon-Sang Lee To: dev@dpdk.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] bytes order of ip header in dpdk 2.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Nov 2015 09:11:50 -0000 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 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*