From owner-freebsd-net@freebsd.org Thu Nov 26 10:35:40 2015 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B8102A39CFA for ; Thu, 26 Nov 2015 10:35:40 +0000 (UTC) (envelope-from ulric@siag.nu) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 976F4179A for ; Thu, 26 Nov 2015 10:35:40 +0000 (UTC) (envelope-from ulric@siag.nu) Received: by mailman.ysv.freebsd.org (Postfix) id 96542A39CF8; Thu, 26 Nov 2015 10:35:40 +0000 (UTC) Delivered-To: net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 95E05A39CF4 for ; Thu, 26 Nov 2015 10:35:40 +0000 (UTC) (envelope-from ulric@siag.nu) Received: from smtp.outgoing.loopia.se (smtp.outgoing.loopia.se [194.9.95.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 52FF71798 for ; Thu, 26 Nov 2015 10:35:39 +0000 (UTC) (envelope-from ulric@siag.nu) Received: from s314.loopia.se (localhost [127.0.0.1]) by s314.loopia.se (Postfix) with ESMTP id C7FAF162B579 for ; Thu, 26 Nov 2015 11:25:54 +0100 (CET) X-Loopia-Auth: webmail X-Loopia-User: ulric@siag.nu Received: from s498.loopia.se (unknown [172.21.200.96]) by s314.loopia.se (Postfix) with ESMTP id AA90220057FD; Thu, 26 Nov 2015 11:25:54 +0100 (CET) Received: from s405.loopia.se (unknown [172.21.200.105]) by s498.loopia.se (Postfix) with ESMTP id A30D245F912; Thu, 26 Nov 2015 11:25:54 +0100 (CET) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -0.331 X-Spam-Level: X-Spam-Status: No, score=-0.331 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, AWL=0.669] autolearn=disabled Received: from s498.loopia.se ([172.21.200.105]) by s405.loopia.se (s405.loopia.se [172.21.200.135]) (amavisd-new, port 10024) with LMTP id G0V0CYfB_os3; Thu, 26 Nov 2015 11:25:53 +0100 (CET) Received: from localhost (webmail.loopia.se [194.9.95.85]) (Authenticated sender: ulric@siag.nu) by s498.loopia.se (Postfix) with ESMTPA id 9E82A45EDB0; Thu, 26 Nov 2015 11:25:53 +0100 (CET) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 26 Nov 2015 11:25:53 +0100 From: ulric@siag.nu To: Hao Wu Cc: net@freebsd.org, owner-freebsd-net@freebsd.org Subject: Re: Can I send the Ethernet frames with particular payload via Netmap? In-Reply-To: References: Message-Id: <9b7b2eb25fd42295d3f2f8a46d2a3c1e@siag.nu> X-Sender: ulric@siag.nu User-Agent: Loopia Webmail/1.1.3 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Nov 2015 10:35:40 -0000 2015-11-25 15:30 skrev Hao Wu: > Hi all, > > I just start using Netmap. I want to know can I build the Ethernet > frames and send out via Netmap? I used to build the Ethernet frames via > Libnet, but it is too slow. So I turn to Netmap now. But I have no idea > on > how to write the code using Netmap or what functions should I call? > > Any replay is highly appreciated! It's crazy simple. To open a netmap descriptor: d = nm_open(ifname, NULL, 0, 0); To receive a frame: uint8_t *b = nm_nextpkt(d, &h); To send a frame: int n = nm_inject(d, b, len); Working example from Pen: https://github.com/UlricE/pen/blob/master/dsr.c Ulric