timer: add time management functions
[netsniff-ng.git] / xutils.c
blob56b4c594297f5d5e589d703aff68a89ac98f8931
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2009, 2010 Emmanuel Roullit.
5 * Subject to the GPL, version 2.
6 */
8 #define _GNU_SOURCE
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stdint.h>
12 #include <fcntl.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <errno.h>
16 #include <stdarg.h>
17 #include <ctype.h>
18 #include <signal.h>
19 #include <arpa/inet.h>
20 #include <time.h>
21 #include <sched.h>
22 #include <limits.h>
23 #include <stdbool.h>
24 #include <netdb.h>
25 #include <ifaddrs.h>
26 #include <sys/time.h>
27 #include <sys/socket.h>
28 #include <sys/ioctl.h>
29 #include <sys/mman.h>
30 #include <sys/resource.h>
31 #include <sys/epoll.h>
32 #include <sys/syscall.h>
33 #include <asm/unistd.h>
34 #include <linux/if.h>
35 #include <linux/socket.h>
36 #include <linux/types.h>
37 #include <linux/if_ether.h>
38 #include <linux/if_packet.h>
39 #include <linux/sockios.h>
40 #include <netinet/tcp.h>
41 #include <netinet/udp.h>
43 #include "die.h"
44 #include "str.h"
45 #include "xutils.h"
46 #include "ring.h"
47 #include "sock.h"
48 #include "built_in.h"
50 void set_epoll_descriptor(int fd_epoll, int action, int fd_toadd, int events)
52 int ret;
53 struct epoll_event ev;
55 memset(&ev, 0, sizeof(ev));
56 ev.events = events;
57 ev.data.fd = fd_toadd;
59 ret = epoll_ctl(fd_epoll, action, fd_toadd, &ev);
60 if (ret < 0)
61 panic("Cannot add socket for epoll!\n");
64 int set_epoll_descriptor2(int fd_epoll, int action, int fd_toadd, int events)
66 struct epoll_event ev;
68 memset(&ev, 0, sizeof(ev));
69 ev.events = events;
70 ev.data.fd = fd_toadd;
72 return epoll_ctl(fd_epoll, action, fd_toadd, &ev);