1 /* ----------------------------------------------------------------------------
4 (C) 2007 Daniele Lacamera
7 NSTX -- tunneling network-packets over DNS
9 (C) 2000 by Florian Heinz and Julien Oster
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License version 2, as
13 published by the Free Software Foundation.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 -------------------------------------------------------------------------- */
25 #include <sys/types.h>
26 #include <netinet/in.h>
27 #include <sys/socket.h>
34 #include <vdecommon.h>
38 static struct nstxqueue
*qhead
= NULL
;
40 static int qtimeout
= QUEUETIMEOUT
;
42 struct nstxqueue
*finditem (unsigned short id
)
44 struct nstxqueue
*ptr
;
46 for (ptr
= qhead
; ptr
; ptr
= ptr
->next
)
54 queueitem(unsigned short id
, const char *name
, const struct sockaddr_in
*peer
)
56 struct nstxqueue
*ptr
, *tmp
;
62 ptr
= malloc(sizeof(struct nstxqueue
));
63 memset(ptr
, 0, sizeof(struct nstxqueue
));
67 for (tmp
= qhead
; tmp
->next
; tmp
= tmp
->next
)
73 strcpy(ptr
->name
, name
);
75 memcpy(&ptr
->peer
, peer
, sizeof(struct sockaddr_in
));
76 ptr
->timeout
= time(NULL
) + qtimeout
;
79 void queueid (unsigned short id
)
81 queueitem(id
, NULL
, NULL
);
84 struct nstxqueue
*dequeueitem (int id
)
86 static struct nstxqueue
*tmp
= NULL
, *ptr
;
93 if ((id
< 0) || (qhead
->id
== id
))
102 for (tmp
= qhead
->next
; tmp
; tmp
= tmp
->next
)
106 ptr
->next
= tmp
->next
;
117 void timeoutqueue (void (*timeoutfn
)(struct nstxqueue
*))
119 struct nstxqueue
*ptr
;
124 while (qhead
&& (qhead
->timeout
<= now
))
140 void qsettimeout (int timeout
)