From owner-freebsd-net@FreeBSD.ORG Fri Apr 26 03:43:35 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 298B9547 for ; Fri, 26 Apr 2013 03:43:35 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by mx1.freebsd.org (Postfix) with ESMTP id 015621ABB for ; Fri, 26 Apr 2013 03:43:34 +0000 (UTC) Received: by mail-pa0-f50.google.com with SMTP id bg4so2215379pad.23 for ; Thu, 25 Apr 2013 20:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ab0qoIerzi4rdM6POadH9BpDS7+FVuWpGQN/ER6Qn4c=; b=V8ZPMWd3DX5Sa6kao/TePNTj+sGZa3vJmHQQtj9u1pEYPnbJ1HZkU2WwNYhkoBlLzd 7ZovY6eyO0fSqy2B+LujhgAg5oF6AR9gP79ERcjtu42a/1Gn1gW/RhSTBIO5yw5eX6n0 aNbm3K2eTdPKWMOcgbr7LagSzjhuPyz39/nBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:x-gm-message-state; bh=ab0qoIerzi4rdM6POadH9BpDS7+FVuWpGQN/ER6Qn4c=; b=Ap0jlvXklhqnVms9YIvC6ZZvhEi0xVCB1yXGzw4sVKC9eaXA6MubvbWiIYIHDb5p8/ +abRNiEkR2AI8CQ2AccuIrCD9ZECgeYiRllNu/2XhOF+TMEcnPm45Zwaw5Izl42z9t4U C+lGujN338k1Fqb3KSICbJ7l2dO1IS8fXGrdJ2iOMdhKyew5lrGXz4nE8Rw4dlp5SZVz 78zVHIV3znJAhT5gexxBGGD5Lb1smQtwsZ5yDnFlnx8fi2DOVts5hDBrg7fEJscWy7zf 79DLnGrTGa4XW3EMiETeXVN/ezqRpsrsXxBUcgoFuzlASBwXk9UhfaXjH/SG04M7/m5o P5zA== X-Received: by 10.68.90.36 with SMTP id bt4mr56275532pbb.42.1366947814311; Thu, 25 Apr 2013 20:43:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.159.97 with HTTP; Thu, 25 Apr 2013 20:43:04 -0700 (PDT) In-Reply-To: References: From: Eitan Adler Date: Thu, 25 Apr 2013 23:43:04 -0400 Message-ID: Subject: Re: using netmap To: Sami Halabi Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQlsSjlknm4lInBDTp2cG6BWzDayrMRZfgLcK3gjLJweMI4YEYC0IGlLY9QnijrTd/Gvnoek Cc: "freebsd-net@freebsd.org" , Luigi Rizzo , Andreas Nilsson X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 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, 26 Apr 2013 03:43:35 -0000 [ please bottom post or reply inline ] On 25 April 2013 17:48, Sami Halabi wrote: > Okay, > i figured out the includes, now it runs and seg faults: Don't forget to show the working headers ;) > any ideas? > > here is the new code: > int main() { > > struct netmap_if *nifp = NULL; > struct nmreq req; > int i, len, fd; > char *buf, *mem, *txt; > > printf("Starting...\n"); > fd = open("/dev/netmap", 0); > strcpy(req.nr_name, "em0"); // register the interface > printf("em0 registered...\n"); > ioctl(fd, NIOCREGIF, &req); // offset of the structure is req fully initialized? I don't think this ioctl is correct. Everything goes wrong after this as a result. > printf("sysctl passed\n"); Things will not always crash if you make a wrong call. Try checking return codes before printing something like this. > mem = mmap(NULL, req.nr_memsize, PROT_READ|PROT_WRITE, 0, fd, 0); > printf("mem mapped...\n"); > > nifp = NETMAP_IF(mem, req.nr_offset); > printf("nifp mapped...%u\n",(long)nifp); this seems wrong: ^^ ^^^^^^ > for (;;) { > struct pollfd x[1]; > printf("rx ring def...\n"); > struct netmap_ring *ring; > printf("rx ring start...\n"); > ring = NETMAP_RXRING(nifp, 0); > printf("rx ring polled...\n"); > > x[0].fd = fd; > x[0].events = POLLIN; > poll(x, 1, 1000); > for ( ; ring->avail > 0 ; ring->avail--) { > i = ring->cur; > printf("i=%d\n",&i); I think this is wrong. > buf = NETMAP_BUF(ring, i); > printf("buff read...\n"); > //use_data(buf, ring->slot[i].len); > txt = malloc(sizeof(char) * ring->slot[i].len +1); > strncpy(txt,buf,ring->slot[i].len); > txt[ring->slot[i].len]='\0'; > printf("len is: %d\n",&ring->slot[i].len); Also this. > ring->cur = NETMAP_RING_NEXT(ring, i); > } > } > > return 0; > } -- Eitan Adler