From: leo mueller <llug.dan@googlemail.com>
To: linux-c-programming@vger.kernel.org
Subject: mmap() returns with -EINVAL
Date: Thu, 30 Jul 2009 15:19:05 +0200 [thread overview]
Message-ID: <c93f91ee0907300619q2dc38f49q1092b363ed28687@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 375 bytes --]
hi all,
in my attached code snippet i try to mmap the incoming socket data
accoring to the kernel documentation
which can also be found online:
http://lxr.linux.no/linux+v2.6.30/Documentation/networking/packet_mmap.txt
by doing a mmap() my program exits with -EINVAL and up to now i have
no clue why... parametes should be right.
do you have any idea?
big thanks,
daniel
[-- Attachment #2: err.txt --]
[-- Type: text/plain, Size: 1497 bytes --]
typedef unsigned char *ring_buff_t;
[...]
ring_buff_t create_virt_ring(int sock)
{
int ret;
ring_buff_t rb;
struct tpacket_req req;
memset(&req, 0, sizeof(req));
dbg("pagesize: %d\n", getpagesize());
req.tp_block_size = getpagesize();
req.tp_frame_size = TP_RX_FRAME_SIZ;
req.tp_block_nr = TP_RX_BLOCKS;
req.tp_frame_nr = req.tp_block_size / req.tp_frame_size * req.tp_block_nr;
ret = setsockopt(sock, SOL_SOCKET, PACKET_RX_RING, (void *) &req, sizeof(req));
if(ret < 0){
err("setsockopt: creation of rx ring failed: %d - ", errno);
perror("");
goto _out_err;
}
rb = mmap(0, (size_t) req.tp_block_nr * req.tp_block_size, PROT_READ | PROT_WRITE, MAP_SHARED, sock, 0);
if(rb == MAP_FAILED){
err("mmap: cannot mmap the rx ring: %d - ", errno);
perror("");
goto _out_mmap;
}
dbg("kernel ringbuff allocated\n");
return rb;
_out_mmap:
destroy_virt_ring(sock, rb);
_out_err:
close(sock);
exit(1);
}
[...]
void destroy_virt_ring(int sock, ring_buff_t rb)
{
int ret;
struct tpacket_req req;
memset(&req, 0, sizeof(req));
ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, (void *) &req, sizeof(req));
if(ret < 0){
err("setsockopt: destruction of rx ring failed: %d - ", errno);
perror("");
}
if(rb){
munmap(rb, TP_RX_BLOCKS * getpagesize());
rb = 0;
}
dbg("kernel ringbuff deallocated\n");
}
next reply other threads:[~2009-07-30 13:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-30 13:19 leo mueller [this message]
2009-08-16 14:11 ` mmap() returns with -EINVAL Reto Glauser
2009-08-16 14:47 ` LDB
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c93f91ee0907300619q2dc38f49q1092b363ed28687@mail.gmail.com \
--to=llug.dan@googlemail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).