From owner-freebsd-net@FreeBSD.ORG Fri Jun 25 12:02:19 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B96A516A4CE for ; Fri, 25 Jun 2004 12:02:19 +0000 (GMT) Received: from tigra.ip.net.ua (tigra.ip.net.ua [82.193.96.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id BF84943D5C for ; Fri, 25 Jun 2004 12:02:18 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from heffalump.ip.net.ua (heffalump.ip.net.ua [82.193.96.213]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id i5PC7iiM076123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Jun 2004 15:07:46 +0300 (EEST) (envelope-from ru@ip.net.ua) Received: (from ru@localhost) by heffalump.ip.net.ua (8.12.11/8.12.11) id i5PC1rvs037085; Fri, 25 Jun 2004 15:01:53 +0300 (EEST) (envelope-from ru) Date: Fri, 25 Jun 2004 15:01:53 +0300 From: Ruslan Ermilov To: kamal kc Message-ID: <20040625120153.GA37003@ip.net.ua> References: <20040625104911.69479.qmail@web13004.mail.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9amGYk9869ThD9tj" Content-Disposition: inline In-Reply-To: <20040625104911.69479.qmail@web13004.mail.yahoo.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) cc: freebsd-net@freebsd.org Subject: Re: newbie: ethernet, ip header proble X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2004 12:02:19 -0000 --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 25, 2004 at 03:49:11AM -0700, kamal kc wrote: > Hi i am new to this mailing list. > =20 > I have written a program to capture packets using pcap library routines. = I have a FreeBSD 5.1. The problem I faced was I successfully captured packe= ts and parsed to ethernet header and ip header. > =20 > i present a section of code how i did it. > =20 > -- > char *ptr; > ptr=3Dpcap_next(.....); > =20 > struct ether_header *eth; > struct ip *ip; > =20 > eth=3D(struct ether_header *)ptr; // datalink type DLT_EN10MB > ptr+=3D14; // the size of the ether_header being 14 bytes;=20 > =20 > ip=3D(struct ip *)ptr; > =20 > printf("\n %s %s", ether_ntoa(eth->ether_dhost), ether_ntoa(eth->ether_sh= ost)); > printf("\n %s %s", inet_ntoa(ip->ip_src), inet_ntoa(ip->ip_dst)); > =20 > ---------------- > =20 > Now the problem is that the ethernet destination and sender host is print= ed the same. > it is equal to that of the sender MAC address(linux) when ICMP packets (b= y ping utility) > is sent to the host(FreeBSD) running the program. > =20 > Also that the ip adresses printed is the same as the sender ip address(ie= linux). > =20 > The program is run on host with FreeBSD. > =20 > The ip address of the computers are:=20 > 192.168.1.10 has Linux > 192.168.1.11 has FreeBSD > =20 > I couldn't think of a solution as i guess the coding was alright. > =20 > Anybody could help > =20 Sure, carefully read the BUGS sections of both ether_ntoa(3) and inet_ntoa(= 3) manpages. Cheers, --=20 Ruslan Ermilov ru@FreeBSD.org FreeBSD committer --9amGYk9869ThD9tj Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFA3BQwqRfpzJluFF4RAnZkAKCbIdz5laNFp8EFa2xpJg8V12IccwCfcSiP Q7fXrsR7FYqnXQEc3dATXFY= =KkzS -----END PGP SIGNATURE----- --9amGYk9869ThD9tj--