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.
19 #include <arpa/inet.h>
27 #include <sys/socket.h>
28 #include <sys/ioctl.h>
30 #include <sys/resource.h>
31 #include <sys/epoll.h>
32 #include <sys/syscall.h>
33 #include <asm/unistd.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>
50 void set_epoll_descriptor(int fd_epoll
, int action
, int fd_toadd
, int events
)
53 struct epoll_event ev
;
55 memset(&ev
, 0, sizeof(ev
));
57 ev
.data
.fd
= fd_toadd
;
59 ret
= epoll_ctl(fd_epoll
, action
, fd_toadd
, &ev
);
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
));
70 ev
.data
.fd
= fd_toadd
;
72 return epoll_ctl(fd_epoll
, action
, fd_toadd
, &ev
);
75 void register_signal(int signal
, void (*handler
)(int))
78 struct sigaction saction
;
80 sigfillset(&block_mask
);
82 saction
.sa_handler
= handler
;
83 saction
.sa_mask
= block_mask
;
84 saction
.sa_flags
= SA_RESTART
;
86 sigaction(signal
, &saction
, NULL
);
89 void register_signal_f(int signal
, void (*handler
)(int), int flags
)
92 struct sigaction saction
;
94 sigfillset(&block_mask
);
96 saction
.sa_handler
= handler
;
97 saction
.sa_mask
= block_mask
;
98 saction
.sa_flags
= flags
;
100 sigaction(signal
, &saction
, NULL
);
103 void set_itimer_interval_value(struct itimerval
*itimer
, unsigned long sec
,
106 itimer
->it_interval
.tv_sec
= sec
;
107 itimer
->it_interval
.tv_usec
= usec
;
109 itimer
->it_value
.tv_sec
= sec
;
110 itimer
->it_value
.tv_usec
= usec
;