Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Apr 2013 23:43:04 -0400
From:      Eitan Adler <lists@eitanadler.com>
To:        Sami Halabi <sodynet1@gmail.com>
Cc:        "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>, Luigi Rizzo <rizzo@iet.unipi.it>, Andreas Nilsson <andrnils@gmail.com>
Subject:   Re: using netmap
Message-ID:  <CAF6rxg=dQ_-MNNwtMBT%2BR=jjo5SN350d6hVAM0hecPceod8F-Q@mail.gmail.com>
In-Reply-To: <CAEW%2BogZo7Se1CcGz%2BXwK5v80ns0vrUif=WTwNwTGxv2jVaY1=Q@mail.gmail.com>
References:  <CAEW%2BogbOG1E8i88v%2B9ChJGHbstx6JQXMg82cEPqbbFvfDztM4A@mail.gmail.com> <CAPS9%2BSufmM7MM2wVs6hM8xipEess2PB3t-i39_S1XUo7aCosEA@mail.gmail.com> <CAEW%2BogZo7Se1CcGz%2BXwK5v80ns0vrUif=WTwNwTGxv2jVaY1=Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
[ please bottom post or reply inline ]

On 25 April 2013 17:48, Sami Halabi <sodynet1@gmail.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF6rxg=dQ_-MNNwtMBT%2BR=jjo5SN350d6hVAM0hecPceod8F-Q>