2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Copyright 2009, 2010 Emmanuel Roullit.
6 * Subject to the GPL, version 2.
15 #include <sys/socket.h>
17 #include <linux/ethtool.h>
19 #include <linux/wireless.h>
24 #include <sys/resource.h>
37 #define SMEM_SUG_MAX 104857600
38 #define SMEM_SUG_DEF 4194304
40 extern int af_socket(int af
);
41 extern int pf_socket(void);
42 extern int adjust_dbm_level(int in_dbm
, int dbm_val
);
43 extern int wireless_sigqual(const char *ifname
, struct iw_statistics
*stats
);
44 extern int wireless_rangemax_sigqual(const char *ifname
);
45 extern u32
wireless_bitrate(const char *ifname
);
46 extern u32
ethtool_bitrate(const char *ifname
);
47 extern u32
device_bitrate(const char *ifname
);
48 extern int ethtool_drvinf(const char *ifname
, struct ethtool_drvinfo
*drvinf
);
49 extern int ethtool_link(const char *ifname
);
50 extern int device_mtu(const char *ifname
);
51 extern int device_address(const char *ifname
, int af
,
52 struct sockaddr_storage
*ss
);
53 extern int device_irq_number(const char *ifname
);
54 extern int device_set_irq_affinity_list(int irq
, unsigned long from
,
56 extern int device_bind_irq_to_cpu(int irq
, int cpu
);
57 extern void sock_print_net_stats(int sock
, unsigned long skipped
);
58 extern int device_ifindex(const char *ifname
);
59 extern short device_get_flags(const char *ifname
);
60 extern void device_set_flags(const char *ifname
, const short flags
);
61 extern void drop_privileges(bool enforce
, uid_t uid
, gid_t gid
);
62 extern void xlockme(void);
63 extern void xunlockme(void);
64 extern int set_nonblocking(int fd
);
65 extern int set_nonblocking_sloppy(int fd
);
66 extern int set_reuseaddr(int fd
);
67 extern void set_sock_prio(int fd
, int prio
);
68 extern void set_tcp_cork(int fd
);
69 extern void set_tcp_uncork(int fd
);
70 extern void set_udp_cork(int fd
);
71 extern void set_udp_uncork(int fd
);
72 extern void set_sock_cork(int fd
, int udp
);
73 extern void set_sock_uncork(int fd
, int udp
);
74 extern void set_tcp_nodelay(int fd
);
75 extern void set_socket_keepalive(int fd
);
76 extern int set_ipv6_only(int fd
);
77 extern void set_mtu_disc_dont(int fd
);
78 extern int get_system_socket_mem(int which
);
79 extern void set_system_socket_mem(int which
, int val
);
80 extern void register_signal(int signal
, void (*handler
)(int));
81 extern void register_signal_f(int signal
, void (*handler
)(int), int flags
);
82 extern int get_tty_size(void);
83 extern short enter_promiscuous_mode(char *ifname
);
84 extern void leave_promiscuous_mode(char *ifname
, short oldflags
);
85 extern int device_up(char *ifname
);
86 extern int device_running(char *ifname
);
87 extern int device_up_and_running(char *ifname
);
88 extern int poll_error_maybe_die(int sock
, struct pollfd
*pfd
);
89 extern void set_epoll_descriptor(int fd_epoll
, int action
,
90 int fd_toadd
, int events
);
91 extern int set_epoll_descriptor2(int fd_epoll
, int action
,
92 int fd_toadd
, int events
);
93 extern void cpu_affinity(int cpu
);
94 extern int set_cpu_affinity(char *str
, int inverted
);
95 extern int set_proc_prio(int prio
);
96 extern int set_sched_status(int policy
, int priority
);
97 extern void ioprio_print(void);
98 extern void set_ioprio_rt(void);
99 extern void set_ioprio_be(void);
100 extern void xusleep(const struct timespec
*ts_delay
);
101 extern void xusleep2(long usecs
);
102 extern int xnanosleep(double seconds
);
103 extern int set_timeout(struct timeval
*timeval
, unsigned int msec
);
104 extern size_t strlcpy(char *dest
, const char *src
, size_t size
);
105 extern int slprintf(char *dst
, size_t size
, const char *fmt
, ...) __check_format_printf(3, 4);
106 extern int slprintf_nocheck(char *dst
, size_t size
, const char *fmt
, ...);
107 extern noinline
void *xmemset(void *s
, int c
, size_t n
);
108 extern char *getuint(char *in
, uint32_t *out
);
109 extern char *strtrim_right(register char *p
, register char c
);
110 extern char *strtrim_left(register char *p
, register char c
);
112 static inline int get_default_sched_policy(void)
117 static inline int get_default_sched_prio(void)
119 return sched_get_priority_max(get_default_sched_policy());
122 static inline int get_number_cpus(void)
124 return sysconf(_SC_NPROCESSORS_CONF
);
127 static inline int get_number_cpus_online(void)
129 return sysconf(_SC_NPROCESSORS_ONLN
);
132 static inline int get_default_proc_prio(void)
137 static inline struct timeval
tv_subtract(struct timeval time1
,
138 struct timeval time2
)
141 struct timeval result
;
143 if ((time1
.tv_sec
< time2
.tv_sec
) || ((time1
.tv_sec
== time2
.tv_sec
) &&
144 (time1
.tv_usec
<= time2
.tv_usec
))) {
145 result
.tv_sec
= result
.tv_usec
= 0;
147 result
.tv_sec
= time1
.tv_sec
- time2
.tv_sec
;
148 if (time1
.tv_usec
< time2
.tv_usec
) {
149 result
.tv_usec
= time1
.tv_usec
+ 1000000L -
153 result
.tv_usec
= time1
.tv_usec
- time2
.tv_usec
;
160 static inline char *skips(char *p
)
162 return strtrim_left(p
, ' ');
165 static inline char *skipchar(char *in
, char c
)
168 panic("Syntax error!\n");