using netmap

Sami Halabi sodynet1 at gmail.com
Mon Apr 15 17:52:40 UTC 2013


Hi,
I would like to start using netmap.

as a start i copied the example from netmap
<http://info.iet.unipi.it/~luigi/netmap/>page:
#include <stdio.h>
#include <stdlib.h>
#include <net/netmap_user.h>
#include <net/netmap.h>

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 at 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 at fbsd1:~/netmap #


can you help me figure it out?

Thanks in advance,

-- 
Sami Halabi
Information Systems Engineer
NMS Projects Expert
FreeBSD SysAdmin Expert


More information about the freebsd-net mailing list