-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathairhook-internal.h
73 lines (60 loc) · 1.87 KB
/
airhook-internal.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
/* Airhook protocol library, copyright 2001 Dan Egnor.
* This software comes with ABSOLUTELY NO WARRANTY. You may redistribute it
* under the terms of the GNU General Public License, version 2.
* See the file COPYING for more details. */
#ifndef AIRHOOK_INTERNAL_H
#define AIRHOOK_INTERNAL_H
#if AIRHOOK_DEBUG
# ifndef AIRHOOK_ASSERT
# include <assert.h>
# define AIRHOOK_ASSERT(t) assert(t)
# endif
#else
# define AIRHOOK_ASSERT(t)
#endif
typedef char airhook_type[4];
typedef union { void *pointer; char string[1]; } airhook_magic;
static inline void airhook_magic_init(airhook_magic *m,airhook_type t) {
#if AIRHOOK_DEBUG
int i;
m->pointer = m;
for (i = 0; i < sizeof(t) && i < sizeof(*m); ++i) m->string[i] ^= t[i];
#endif
}
static inline void airhook_magic_check(const airhook_magic *m,airhook_type t) {
#if AIRHOOK_DEBUG
int i;
airhook_magic k = *m;
for (i = 0; i < sizeof(k) && i < sizeof(t); ++i) k.string[i] ^= t[i];
AIRHOOK_ASSERT(k.pointer == m);
#endif
}
struct airhook_record {
struct airhook_time transmit;
unsigned char unsent,unseen;
};
struct airhook_socket {
airhook_magic magic;
struct airhook_status status;
/* synchronization */
unsigned short sequence,sequence_observed;
unsigned char sequence_confirmed,push_sequence;
/* incoming messages */
unsigned char missed[airhook_size],*missed_end;
struct airhook_data incoming[airhook_size],*incoming_end,*incoming_next;
/* outgoing messages */
unsigned char last_observed;
struct airhook_outgoing *waiting[airhook_size];
struct airhook_outgoing *last_changed;
struct airhook_outgoing *last_outgoing,*first_pending;
struct airhook_record current,log[airhook_size];
};
struct airhook_outgoing {
airhook_magic magic;
struct airhook_socket *socket;
struct airhook_outgoing_status status;
struct airhook_outgoing *next_changed;
struct airhook_outgoing *prev,*next;
unsigned char number;
};
#endif