-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvis.h
138 lines (111 loc) · 2.78 KB
/
vis.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
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
/*
* vis.h
*
* Copyright (C) 2006-2012 B.A.T.M.A.N. contributors:
*
* Andreas Langer <[email protected]>, Marek Lindner
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA
*
*/
#include <pthread.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include "vis-types.h"
#include "hash.h"
#include "allocate.h"
#include "list-batman.h"
#ifndef SOURCE_VERSION
#define SOURCE_VERSION "0.4"
#endif
#define MAXCHAR 4096
#define VIS_PORT 4307
#define DOT_DRAW_PORT 2004
#define JSON_PORT 2005
#define ADDR_STR_LEN 16
extern struct list_head_first vis_if_list;
extern pthread_t udp_server_thread;
extern pthread_t master_thread;
extern pthread_mutex_t hash_mutex;
extern struct hashtable_t *node_hash;
extern struct hashtable_t *secif_hash;
extern uint8_t debug_level;
typedef enum { dot_draw = 1, json = 2, last = 4 } formats;
extern formats selected_formats;
struct thread_data {
int socket;
char ip[ADDR_STR_LEN];
formats format;
};
struct neighbour {
struct list_head list;
unsigned int addr;
uint16_t tq_avg;
unsigned char last_seen;
};
struct hna {
struct list_head list;
unsigned int addr;
unsigned char netmask;
unsigned char last_seen;
};
struct node {
unsigned int addr;
unsigned char last_seen;
unsigned char gw_class;
uint16_t tq_max;
struct list_head_first neigh_list;
struct list_head_first secif_list;
struct list_head_first hna_list;
};
struct secif {
unsigned int addr;
struct node *orig;
};
struct secif_lst {
struct list_head list;
unsigned int addr;
unsigned char last_seen;
};
typedef struct _buffer {
char *dot_buffer;
char *json_buffer;
int counter;
struct _buffer *next;
pthread_mutex_t mutex;
} buffer_t;
struct vis_if {
struct list_head list;
char *dev;
int32_t udp_sock;
int32_t dot_tcp_sock;
int32_t json_tcp_sock;
struct sockaddr_in udp_addr;
struct sockaddr_in dot_tcp_addr;
struct sockaddr_in json_tcp_addr;
};
void clean_secif_hash();
void clean_node_hash();
void clean_buffer();
void exit_error(char *format, ...);
int8_t is_aborted();
void debug_output(char *format, ...);
void addr_to_string(unsigned int addr, char *str, int len);
void *udp_server();