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
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"); }