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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/*
* Bump in the Host (BIH)
* http://code.google.com/p/bump-in-the-host/source/
* ----------------------------------------------------------
*
* Copyrighted (C) 2010,2011 by the China Mobile Communications
* Corporation <bih.cmcc@gmail.com>;
* See the COPYRIGHT file for full details.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
*/
#ifndef _VOSLIST_H
#define _VOSLIST_H
enum _listnode_status
{
LISTNODE_STATUS_ENABLE,
LISTNODE_STATUS_DISABLE
};
struct listnode
{
struct listnode *next;
struct listnode *prev;
unsigned int key;
char status;
void *data;
int datalen;
unsigned int datasp;
};
#define SHOW2BUF_DEF \
static char buff[1000],*p = NULL; \
int ret,len,size; \
#define SHOW2BUF_INIT() \
do \
{ \
ret=0; \
if(p&&p!=buff) \
vfree(p); \
size=sizeof(buff)-1; \
len=0; \
buff[0]=0; \
p=buff; \
} \
while(0)
#define SHOW2BUF_RET return(p)
#define SHOW2BUF(format,...) \
do \
{ \
ret=snprintf(p+len,size-len,format,##__VA_ARGS__); \
if (ret < 0 || ret >= (size-len)) \
{ \
while (1) \
{ \
p=vrealloc(p,2*size+1,size,p!=buff); \
if(!p) \
{ \
lprintf(0,"vrealloc error\n"); \
break; \
} \
size*=2; \
ret=snprintf(p+len,size-len,format,##__VA_ARGS__); \
if (ret > -1 && ret < (size-len)) \
break; \
} \
} \
len+=ret; \
if(p) \
*(p+len)=0; \
} \
while(0)
#define lprintf(level,format,...) \
do \
{ \
if(level==0) \
printk("%s(%d)%s: "format,__FILE__,__LINE__,(char *)__FUNCTION__,##__VA_ARGS__ ); \
else \
printk((format),##__VA_ARGS__ ); \
} \
while(0)
#define vmalloc(size) kmalloc((size),GFP_KERNEL)
#define vfree kfree
#define PKG_GET_STRING(val, cp) \
do \
{ \
while(*(cp)) \
*(val)++=*(cp)++; \
*(val)++=0; \
} \
while(0)
#define PKG_GET_BYTE(val, cp) ((val) = *(cp)++)
#define PKG_GET_SHORT(val, cp) \
do \
{ \
unsigned short Xv; \
Xv = (*(cp)++) << 8; \
Xv |= *(cp)++; \
(val) = Xv; \
} \
while(0)
#define PKG_GET_NETSHORT(val, cp) \
do \
{ \
unsigned char *Xvp; \
unsigned short Xv; \
Xvp = (unsigned char *) &Xv; \
*Xvp++ = *(cp)++; \
*Xvp++ = *(cp)++; \
(val) = Xv; \
} \
while(0)
#define PKG_GET_LONG(val, cp) \
do \
{ \
unsigned long Xv; \
Xv = (*(cp)++) << 24; \
Xv |= (*(cp)++) << 16; \
Xv |= (*(cp)++) << 8; \
Xv |= *(cp)++; \
(val) = Xv; \
} \
while(0)
#define PKG_GET_NETLONG(val, cp) \
do \
{ \
unsigned char *Xvp; \
unsigned long Xv; \
Xvp = (unsigned char *) &Xv; \
*Xvp++ = *(cp)++; \
*Xvp++ = *(cp)++; \
*Xvp++ = *(cp)++; \
*Xvp++ = *(cp)++; \
(val) = Xv; \
} \
while(0)
#define PKG_PUT_BUF(val, len, cp) \
do \
{ \
memcpy((cp),(val),(len)); \
(cp)+=(len); \
} \
while(0)
#define PKG_PUT_STRING(val, cp) \
do \
{ \
while(*(val)) \
*(cp)++=*(val)++; \
*(cp)++=0; \
} \
while(0)
#define PKG_PUT_BYTE(val, cp) (*(cp)++ = (unsigned char)(val))
#define PKG_PUT_SHORT(val, cp) \
do \
{ \
unsigned short Xv; \
Xv = (unsigned short)(val); \
*(cp)++ = (unsigned char)(Xv >> 8); \
*(cp)++ = (unsigned char)Xv; \
} \
while(0)
#define PKG_PUT_NETSHORT(val, cp) \
do \
{ \
unsigned char *Xvp; \
unsigned short Xv = (unsigned short)(val); \
Xvp = (unsigned char *)&Xv; \
*(cp)++ = *Xvp++; \
*(cp)++ = *Xvp++; \
} \
while(0)
#define PKG_PUT_LONG(val, cp) \
do \
{ \
unsigned long Xv; \
Xv = (unsigned long)(val); \
*(cp)++ = (unsigned char)(Xv >> 24); \
*(cp)++ = (unsigned char)(Xv >> 16); \
*(cp)++ = (unsigned char)(Xv >> 8); \
*(cp)++ = (unsigned char)Xv; \
} \
while(0)
#define PKG_PUT_NETLONG(val, cp) \
do \
{ \
unsigned char *Xvp; \
unsigned long Xv = (unsigned long)(val); \
Xvp = (unsigned char *)&Xv; \
*(cp)++ = *Xvp++; \
*(cp)++ = *Xvp++; \
*(cp)++ = *Xvp++; \
*(cp)++ = *Xvp++; \
} \
while(0)
int inet_pton4(char *src,unsigned char *dst);
int inet_pton6(char *src,unsigned char *dst);
char *inet_ntop4(unsigned char *src, char *dst, size_t size);
char *inet_ntop6(unsigned char *src, char *dst, size_t size);
unsigned int sk_inet_addr(char* ip_str);
char *buff2String(char *buff,int bufflen);
int msg_field2(char *linebuf,int linelen,int num,char **field,int *flen,char gech);
void *vrealloc(void *ptr,int newsize,int oldsize,char freeflag);
int listnode_tj(struct listnode *head);
void *listnode_pop(struct listnode **head);
int listnode_free(struct listnode *node,void (*func)(void *));
int listnode_clear(struct listnode **head,void (*func)(void *));
void listnode_show(struct listnode *head);
struct listnode *listnode_find(struct listnode *head,unsigned int key);
struct listnode *listnode_search(struct listnode *head,void *data,int len,int (*func)(void *,void *,int));
struct listnode *listnode_match(struct listnode *head,void *data,int len,int (*func)(void *,void *,int));
int listnode_insert(struct listnode **head,struct listnode *node);
struct listnode *listnode_uninsert(struct listnode **head,struct listnode *node);
struct listnode *listnode_uninsert2(struct listnode **head,unsigned int key);
struct listnode *listnode_add(struct listnode **head,unsigned int key,void *data,int datalen);
int listnode_del(struct listnode **head,unsigned int key,void (*func)(void *));
struct listnode *listnode_tail(struct listnode **head,void *data,int datalen);
int listnode_join(struct listnode **head,struct listnode **list);
#endif
|