1 /*
2  * os_dependens.h
3  *
4  *  Created on: 30.07.2009
5  *      Author: Chebotarev Roman
6  */
7 
8 #ifndef MAIN_INCLUDES_H_
9 #define MAIN_INCLUDES_H_
10 
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <errno.h>
16 #include <string.h>
17 #include <pcap.h>               /* if this gives you an error try pcap/pcap.h */
18 
19 #ifndef _WIN32
20 
21 #include <arpa/inet.h>
22 #include <sys/wait.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <signal.h>
26 #include <time.h>
27 #include <arpa/inet.h>
28 
29 #endif
30 
31 
32 
33 #ifdef	_WIN32
34 
35 #define bzero(x, y)						ZeroMemory(x, y)
36 #define	sleep(x)						Sleep(x * 1000)
37 #define	pcap_inject						pcap_sendpacket
38 #define set_timer_handler(on_timer)
39 #define	timer_start(ms, on_timer)		timeSetEvent(ms * 1000,\
40 								10, (LPTIMECALLBACK) on_timer,\
41 								0, TIME_ONESHOT )
42 #define timer_stop(t)					timeKillEvent(t)
43 #define	set_console_handler(handler)	SetConsoleCtrlHandler(handler, 1);
44 #define INTERRUPT_SIGNAL				CTRL_C_EVENT
45 #define	CHILDREN_TYPE					"threads"
46 
47 #else
48 
49 #define set_console_handler(handler) \
50 	if(signal(SIGINT, (void*)handler) == SIG_ERR) \
51 	{ \
52 		perror("signal"); \
53 		exit(ERR_SIGNAL); \
54 	}
55 
56 #define set_timer_handler(on_timer) \
57 	if(signal(SIGALRM, (void*)on_timer) == SIG_ERR) \
58 	{ \
59 		perror("signal"); \
60 		exit(ERR_SIGNAL); \
61 	}
62 #define	timer_start(x, on_timer)		alarm(x)
63 #define timer_stop(t)					alarm(0)
64 #define INTERRUPT_SIGNAL				SIGINT
65 #define	CHILDREN_TYPE					"children"
66 
67 #endif
68 
69 #endif /* MAIN_INCLUDES_H_ */
70