Indention of code
[netsniff-ng.git] / src / include / rxtx_common.h
blobe7e4e979b97843f42cee460e3e8272028687f476
1 /*
2 * Copyright (C) 2009, 2010 Daniel Borkmann <daniel@netsniff-ng.org> and
3 * Emmanuel Roullit <emmanuel@netsniff-ng.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
20 #ifndef _NET_RXTX_COMMON_H_
21 #define _NET_RXTX_COMMON_H_
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <assert.h>
28 #include <sys/poll.h>
30 #include "macros.h"
31 #include "types.h"
32 #include "xmalloc.h"
34 #ifndef POLLRDNORM
35 # define POLLRDNORM 0x0040
36 #endif
37 #ifndef POLLWRNORM
38 # define POLLWRNORM 0x0100
39 #endif
41 /* Inline stuff */
43 /**
44 * prepare_polling - Sets params for ringbuff polling
45 * @sock: socket
46 * @pfd: file descriptor for polling
48 static inline void prepare_polling(int sock, struct pollfd *pfd)
50 assert(pfd);
52 memset(pfd, 0, sizeof(*pfd));
54 pfd->fd = sock;
55 pfd->revents = 0;
56 pfd->events = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLERR;
59 /**
60 * alloc_frame_buffer - Allocates frame buffer
61 * @rb: ring buff struct
63 static inline void alloc_frame_buffer(struct ring_buff *rb)
65 int i = 0;
67 assert(rb);
69 rb->frames = xzmalloc(rb->layout.tp_frame_nr * sizeof(*rb->frames));
71 for (i = 0; i < rb->layout.tp_frame_nr; ++i) {
72 rb->frames[i].iov_base = (uint8_t *) ((long)rb->buffer) +
73 (i * rb->layout.tp_frame_size);
74 rb->frames[i].iov_len = rb->layout.tp_frame_size;
78 #endif /* _NET_RXTX_COMMON_H_ */