-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
68 lines (61 loc) · 1.4 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef UTILS_H_
#define UTILS_H_
#include<iostream>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fstream>
#include <assert.h>
#ifdef LINUX
#include <pthread.h>
#include <netpacket/packet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/ether.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <linux/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netpacket/packet.h>
#include <linux/stddef.h>
#include <sys/select.h>
#include <sys/time.h>
typedef int SockInt;
#else
#include<winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
typedef SOCKET SockInt;
#endif
template<typename T>
inline void SafeDelete(T& p){
if (p){
delete p;
p = NULL;
}
}
#ifdef PTHREAD
//pthread functions
bool StartThread(pthread_t* thread_id, void* thread_func(void*), void* param);
void StopThread(pthread_t thread_id);
void JoinThread(pthread_t& );
#else
#include<thread>
bool StartThread(std::thread* t, void* thread_func(void*), void*param);
void JoinThread(std::thread&t);
#endif
//time
void GetTime(char* buffer);
//build socket addr
void BuildSockAddr(const char* ip, const uint16_t port, struct sockaddr_in* sock_addr);
uint32_t Hex2Dec(char c);
#endif