-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaexcl_lib.h
110 lines (94 loc) · 2.41 KB
/
aexcl_lib.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <string.h>
#ifndef __AEXCL_LIB_H_
#define __AEXCL_LIB_H_
#ifdef USE_SYSLOG
#include <syslog.h>
#define ERRMSG(args...) syslog(LOG_ERR, args)
#define INFMSG(args...) syslog(LOG_INFO, args)
#define DBGMSG(args...) syslog(LOG_DEBUG, args)
#else
#define ERRMSG(args...) fprintf(stderr,"ERR: " args)
#define INFMSG(args...) fprintf(stderr,"INFO: " args)
#define DBGMSG(args...) fprintf(stderr,"DBG: " args)
#endif
#define SLEEP_SEC(val) sleep(val)
#define SLEEP_MSEC(val) usleep(val*1000)
#define SLEEP_USEC(val) usleep(val)
#undef BEGIN_C_DECLS
#undef END_C_DECLS
#ifdef __cplusplus
#define BEGIN_C_DECLS extern "C" {
#define END_C_DECLS }
#else
#define BEGIN_C_DECLS
#define END_C_DECLS
#endif
BEGIN_C_DECLS
static inline int get_10munit_time(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec&0x00FFFFFF)*100+tv.tv_usec/10000;
}
static inline int lf_to_null(char *sline, int linelen)
{
int i;
for(i=0;i<linelen;i++) {
if(sline[i]=='\n') {
sline[i]=0;
return i;
}else if(sline[i]==0){
return i;
}
}
return -1;
}
/*
* if newsize < 4096, align the size to power of 2
*/
static inline int realloc_memory(void **p, int newsize, const char *func)
{
void *np;
int i=0;
int n=16;
for(i=0;i<8;i++){
if(newsize<=n){
newsize=n;
break;
}
n=n<<1;
}
newsize=newsize;
//np=realloc(*p,newsize);
np = (void*) malloc( newsize );
if(!np){
ERRMSG("%s: realloc failed: %s\n",func,strerror(errno));
return -1;
}
*p=np;
return 0;
}
#define GET_BIGENDIAN_INT(x) (*(uint8_t*)(x)<<24)|(*((uint8_t*)(x)+1)<<16)|(*((uint8_t*)(x)+2)<<8)|(*((uint8_t*)(x)+3))
typedef struct key_data_t {
uint8_t *key;
uint8_t *data;
}key_data_t;
int open_tcp_socket(char *hostname, unsigned short *port);
int open_udp_socket(char *hostname, unsigned short *port);
int get_tcp_connect_by_host(int sd, char *host, uint16_t destport);
int get_tcp_connect(int sd, struct sockaddr_in dest_addr);
int bind_host(int sd, char *hostname, unsigned long ulAddr,unsigned short *port);
int read_line(int fd, char *line, int maxlen, int timeout, int no_poll);
char *kd_lookup(key_data_t *kd, char *key);
void free_kd(key_data_t *kd);
int remove_char_from_string(char *str, char rc);
int child_start(char* const argv[], int *infd, int *outfd, int *errfd);
END_C_DECLS
#endif