From owner-freebsd-net@FreeBSD.ORG Thu Apr 25 21:48:37 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B160D16D for ; Thu, 25 Apr 2013 21:48:37 +0000 (UTC) (envelope-from sodynet1@gmail.com) Received: from mail-pd0-f177.google.com (mail-pd0-f177.google.com [209.85.192.177]) by mx1.freebsd.org (Postfix) with ESMTP id 8E53C1DFD for ; Thu, 25 Apr 2013 21:48:37 +0000 (UTC) Received: by mail-pd0-f177.google.com with SMTP id p11so2030229pdj.8 for ; Thu, 25 Apr 2013 14:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=rz4nfSo9nIax6srUnZB4e+jL6qfC1tGHaVKNxEtSUSA=; b=xTc+0lL/5DI8hukJw7io009D4KwGN08bte1n/o7++jLqWiJAe2FmA/1XKQ1lnXurFt Rbzl7PVLvTvna7Ryqr3BGgnCsLw2ZLjHWx049jJVKySDuilOonV6RgNZE1EKPqM9Kk+x IfzoAdt08BjrWKBpK6oIfWXcJeNEYmIUAgWIFp0CTirGKwgBJLyfyGJ7q6EOwwrBVVvt P6msccnIA7TPY1kuhthXqxoEt8WtzXcGcETU1+kqu5xKcwgdOy20I5HCQAKh4SHIbTOR IAzY9PPXuXskVJNLV6hv9tQ1DYsS2h0R/WhhJ7N1hdEzhaUq/Vyzg+CJWQUOvWjBMIQl 3qyw== MIME-Version: 1.0 X-Received: by 10.66.220.104 with SMTP id pv8mr26921061pac.72.1366926516981; Thu, 25 Apr 2013 14:48:36 -0700 (PDT) Received: by 10.70.100.132 with HTTP; Thu, 25 Apr 2013 14:48:36 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Apr 2013 00:48:36 +0300 Message-ID: Subject: Re: using netmap From: Sami Halabi To: Andreas Nilsson Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: "freebsd-net@freebsd.org" , Luigi Rizzo 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: Thu, 25 Apr 2013 21:48:37 -0000 Okay, i figured out the includes, now it runs and seg faults: root@fbsd1:~/netmap # ./n Starting... em0 registered... sysctl passed mem mapped... nifp mapped...32766 rx ring def... rx ring start... Segmentation fault (core dumped) root@fbsd1:~/netmap # so apparently it faults at the initialization ring = NETMAP_RXRING(nifp, 0); 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 printf("sysctl passed\n"); 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); 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); 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); ring->cur = NETMAP_RING_NEXT(ring, i); } } return 0; } On Mon, Apr 15, 2013 at 9:15 PM, Andreas Nilsson wrote: > > > > On Mon, Apr 15, 2013 at 7:52 PM, Sami Halabi wrote: > >> Hi, >> I would like to start using netmap. >> >> as a start i copied the example from netmap >> page: >> >> #include >> #include >> #include >> #include >> >> int main() { >> >> struct netmap_if *nifp; >> struct nmreq req; >> int i, len; >> char *buf; >> FILE* fd; >> >> fd = open("/dev/netmap", 0); >> strcpy(req.nr_name, "em1"); // register the interface >> ioctl(fd, NIOCREG, &req); // offset of the structure >> mem = mmap(NULL, req.nr_memsize, PROT_READ|PROT_WRITE, 0, fd, 0); >> nifp = NETMAP_IF(mem, req.nr_offset); >> for (;;) { >> struct pollfd x[1]; >> struct netmap_ring *ring = NETMAP_RX_RING(nifp, 0); >> >> x[0].fd = fd; >> x[0].events = POLLIN; >> poll(x, 1, 1000); >> for ( ; ring->avail > 0 ; ring->avail--) { >> i = ring->cur; >> buf = NETMAP_BUF(ring, i); >> use_data(buf, ring->slot[i].len); >> ring->cur = NETMAP_NEXT(ring, i); >> } >> } >> >> return 0; >> } >> >> >> and tried to compile: >> root@fbsd1:~/netmap # gcc -O2 -pipe -Werror -Wall -I ../sys -Wextra -c >> n.c >> In file included from n.c:4: >> /usr/include/net/netmap.h:139: error: expected specifier-qualifier-list >> before 'uint32_t' >> /usr/include/net/netmap.h:228: error: expected ':', ',', ';', '}' or >> '__attribute__' before 'num_slots' >> /usr/include/net/netmap.h:255: error: 'IFNAMSIZ' undeclared here (not in a >> function) >> /usr/include/net/netmap.h:256: error: expected ':', ',', ';', '}' or >> '__attribute__' before 'ni_version' >> /usr/include/net/netmap.h:292: error: expected specifier-qualifier-list >> before 'uint32_t' >> cc1: warnings being treated as errors >> n.c: In function 'main': >> n.c:14: warning: implicit declaration of function 'open' >> n.c:14: warning: assignment makes pointer from integer without a cast >> n.c:15: warning: implicit declaration of function 'strcpy' >> n.c:15: warning: incompatible implicit declaration of built-in function >> 'strcpy' >> n.c:16: warning: implicit declaration of function 'ioctl' >> n.c:16: error: 'NIOCREG' undeclared (first use in this function) >> n.c:16: error: (Each undeclared identifier is reported only once >> n.c:16: error: for each function it appears in.) >> n.c:17: error: 'mem' undeclared (first use in this function) >> n.c:17: error: 'struct nmreq' has no member named 'nr_memsize' >> n.c:17: error: 'PROT_READ' undeclared (first use in this function) >> n.c:17: error: 'PROT_WRITE' undeclared (first use in this function) >> n.c:17: warning: passing argument 5 of 'mmap' makes integer from pointer >> without a cast >> n.c:18: error: 'struct nmreq' has no member named 'nr_offset' >> n.c:20: error: array type has incomplete element type >> n.c:21: warning: implicit declaration of function 'NETMAP_RX_RING' >> n.c:21: warning: initialization makes pointer from integer without a cast >> n.c:24: error: 'POLLIN' undeclared (first use in this function) >> n.c:25: warning: implicit declaration of function 'poll' >> n.c:26: error: 'struct netmap_ring' has no member named 'avail' >> n.c:26: error: 'struct netmap_ring' has no member named 'avail' >> n.c:27: error: 'struct netmap_ring' has no member named 'cur' >> n.c:28: error: 'struct netmap_ring' has no member named 'nr_buf_size' >> n.c:29: warning: implicit declaration of function 'use_data' >> n.c:29: error: 'struct netmap_ring' has no member named 'slot' >> n.c:30: error: 'struct netmap_ring' has no member named 'cur' >> n.c:30: warning: implicit declaration of function 'NETMAP_NEXT' >> n.c:20: warning: unused variable 'x' >> n.c:10: warning: unused variable 'len' >> root@fbsd1:~/netmap # >> >> >> can you help me figure it out? >> >> Thanks in advance, >> >> -- >> Sami Halabi >> Information Systems Engineer >> NMS Projects Expert >> FreeBSD SysAdmin Expert >> _______________________________________________ >> freebsd-net@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-net >> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >> > > Hello Sami, > > First, I'm by no means an expert on NETMAP, but the url you provided says > that it's a snapshot, not a ready progam. There are a few fully working > examples in tools/tools/netmap/ subdir of at least 9-STABLE and 10-CURRENT. > Maybe you can find an example to start with there instead? > > Quite a few of the errors are from regular syscalls, and each of them have > a manpage that says which files to include, and compiling stuff with > -Werror assumes you can deal with "picky" compilers. > > Hope you come up with a working example. > > Best regards > Andreas > -- Sami Halabi Information Systems Engineer NMS Projects Expert FreeBSD SysAdmin Expert