File: cheops.h

package info (click to toggle)
cheops 0.61-12
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,264 kB
  • ctags: 1,312
  • sloc: ansic: 12,730; sh: 155; makefile: 152
file content (481 lines) | stat: -rw-r--r-- 12,035 bytes parent folder | download | duplicates (3)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/*
 * Cheops Network User Interface
 *
 * Copyright (C) 1999, Adtran, Inc.
 * 
 * Distributed under the terms of the GNU GPL
 *
 */

#include "config.h"

#ifdef SNMP
#ifdef HAVE_NET_SNMP
#define UCD_COMPATIBLE
#include "net-snmp/net-snmp-config.h"
#include "net-snmp/version.h"
#include "net-snmp/net-snmp-includes.h"
#include "net-snmp/definitions.h"
#else
#include <asn1.h>
#include <mib.h>
#include <parse.h>
#include <snmp_api.h>
#include <snmp_client.h>
#include <snmp.h>
#include <snmp_impl.h>
#endif
#endif

/* Here we choose whether to use GNOME_CANVAS or not */
#ifdef USE_GNOME
#include <gnome.h>
#define USE_CANVAS
#endif

#define VERSION "0.61"

#define SERVICES "services.conf"
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
#define QUESO_CONF "cheops.conf"

#define DEFAULT_ICON "desktop.h"

#define FIXED_WIDTH 640 * 2
#define FIXED_HEIGHT 480 * 2

#define DEFAULT_ICON_WIDTH 120
#define DEFAULT_ICON_HEIGHT 80

#define STATE_NONE 0
#define STATE_PING 1
#define STATE_UP   2
#define STATE_ID   3
#define STATE_DOWN 4

#define Zzz 10

#ifndef USE_CANVAS
#include "gtklink.h"
#endif

#include <stdio.h>

#if (GTK_MINOR_VERSION > 1) || ((GTK_MICRO_VERSION > 1) &&  (GTK_MINOR_VERSION > 0))
	#define USE_ITEM
	#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
#else
	#undef USE_ITEM
	typedef void (*_GTK_MENU_FUNC_T)(GtkWidget *, void *);
	#define GTK_MENU_FUNC(a) ((_GTK_MENU_FUNC_T)(a))
#endif


#include "plugins.h"

#define OBJECT_FONT "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"

struct link;
struct plink;
struct pcache;
struct pageedit;
struct alias;

struct net_page;
struct net_object
{
#ifdef USE_CANVAS
	GnomeCanvasItem *icon;
	GnomeCanvasItem *label;
	GnomeCanvasItem *otherbox;
	GnomeCanvasItem *rect;
	double xo, yo;
#else
	GtkWidget *label;
	GtkWidget *eventbox;
	GtkWidget *otherbox;
	GtkWidget *pixmap;
	int xo, yo;
#endif
	gint id;
	struct net_page *np;
	unsigned int ip_addr;
	char hostname[256];
	char os[256];
	char fn[256];
	int drag;
	int x, y;
	int state;
	int mapped;
	struct link *links;
	struct alias *aliases;
	struct net_object *next;
	/* For rendering the map */
	int visited;
	int count;
#ifdef SNMP
	int hassnmp;
	int snmp_reqcnt;
	void *snmp;
	void *ss;
	char sysName[256];
	char sysDescr[256];
	char sysObjectID[256];
	char sysContact[256];
#endif
	struct monitor_tag *mon;
};


struct net_win
{
	GtkWidget *window;
	GtkWidget *menu;
	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *cvbox;
	GtkWidget *container;
	GtkWidget *infobox;
	GtkWidget *notebook;
	GtkWidget *status;
	GtkWidget *namelabel;
	GtkWidget *iplabel;
	GtkWidget *oslabel;
#ifdef SNMP
	GtkWidget *snmplabel;
#endif
	GtkTooltips *tips;
#ifdef USE_ITEM
	GtkItemFactory *menuf;
#else
	GtkMenuFactory *menuf;
#endif
	struct net_win *next;
};

struct network 
{
	unsigned int net_addr;
	unsigned int net_mask;
	struct network *next;
};

struct domain
{
	char domain[256];
	int recursive;
	struct domain *next;
};

struct ping_request {
	unsigned int addr;
	void *data;
	time_t timeout;
	struct ping_request *next;
};


struct net_page {
#ifdef USE_CANVAS
	GtkWidget *canvas;
#else
	GtkWidget *fixed;
#endif
	GtkWidget *pane;
	GtkWidget *label;
	GtkWidget *notebook;
#ifdef USE_CANVAS
	GnomeCanvasItem *lasthand;
#else
	GtkWidget *lasthand;
#endif
	GtkWidget *eventbox;
	GtkWidget *list;
	int lastid;
	struct net_object *objs;
	struct net_object *last;
	struct net_object *sel;
	char laststr[256];
	int lastx;
	int lasty;
	int automap;
	int icon_height;
	int icon_width;
	int small_icons;
	struct network *ncontents;
	struct domain *dcontents;
	struct pcache *pos;
	struct plink *pending;
	struct pageedit *pe;
	/* For auto-refresh */
	int refid;
	int refsec;
};


#define FLAG_USERNAME 1


struct service {
	int port;
	char name[80];
	int (*connect)(struct service *svc, char *hostname, char *ip, char *username, int port);
	int flags;
	char format[256];
	struct service *next;
};

#ifdef USE_CANVAS 
struct pixmap_cache_r {
	struct pixmap_cache *next;
	char filename[256];
	GdkPixmap *pixmap;
	GdkBitmap *mask;
};
#else
struct pixmap_cache {
	struct pixmap_cache *next;
	char filename[256];
	GdkPixmap *pixmap;
	GdkBitmap *mask;
};
#define pixmap_cache_r pixmap_cache
#endif


struct port {
	/* A port to be scanned */
	unsigned short dport;
	unsigned short sport;
	int avail;
	struct port *next;
	struct service *svc;
};

struct link {
	/* A link between two objects */
	struct net_page *page;
	struct net_object *other;
#ifdef USE_CANVAS
	GnomeCanvasItem *linkw;
#else
	GtkWidget *linkw;
#endif
	struct link *next;
};

struct plink {
	/* A link we've discovered, but for which
	   no objects yet exist */
	unsigned int addr1;
	unsigned int addr2;
	struct plink *next;
};

struct pcache {
	/* Ones position on the screen */
	unsigned int addr;
	int x;
	int y;
	struct pcache *next;
};

struct pageedit {
	struct net_page *np;
	GtkWidget *window;
	GtkWidget *networks;
	GtkWidget *domains;
	GtkWidget *entry;
};

struct aliascache {
	struct aliascache *next;
	unsigned int addr;
	char hostname[256];
};

struct alias {
	struct alias *next;
	char hostname[256];
};

#define MAX_REQUEST_RETRIES 4
#define REQUEST_TIMEOUT     10

struct map_request {
	/* A request by the user to map an object */
	struct net_page *np;
	unsigned int dest;
	unsigned int last;
	char ttl;
	int retries;
	time_t sent;
	struct map_request *next;
};


/* Don't trace deeper than  this, to prevent infinite loops */
#define MAP_MAX	 	60

/* Don't retransmit more than this # every 100 ms */
#define MAP_TIMEOUT_MAX 5

/* Empty port for tracing routes */
#define EMPTY_PORT 33434

/* Max TCP port to scan */
#define MAX_TCP 8000

typedef void (*tcp_cb)(void *, int port); 
typedef int (*service_cb)(struct service *, char *, char *, char *, int);

/* Arranging */
#define BY_OS 	1
#define BY_NAME 2
#define BY_ADDR 3
#define BY_DOMAIN 4
#define BY_MAP 5

#ifndef GPOINTER_TO_INT
#define GPOINTER_TO_INT(x) ((gint)x)
#endif

#define HIGHLIGHT_NORMAL 0
#define HIGHLIGHT_SELECTED 1

extern int discover_network_a(struct net_page *, char *, char *, int);
extern int init_scan_host(unsigned int ip, void *data);
extern int net_init();
extern void add_object(struct net_page *, struct net_object *);
extern struct net_object *network_object(struct net_page *);
extern void set_icon(struct net_object *no, char *);
extern void init_tcpip(void);
extern struct net_object *get_object(struct net_page *, unsigned int);
extern struct net_win main_window;
extern struct net_page *current_page;
extern int examine_host_queue(unsigned int, unsigned short, struct net_page * );
extern unsigned short inet_checksum (void *, int);
extern void add_unique(unsigned int, char *,char *, struct net_page *);
extern void set_status(char *);
extern void show_service_menu(struct net_object *no, GdkEventButton *event);
extern int try_ports[];
extern int init_halfscan(void);
extern int scan_ports(unsigned int, unsigned int, struct port *, int);
extern struct in_addr getlocalip (unsigned int dest);
extern void immediate_setcursor(int c);
extern void generic_setcursor(GdkWindow *, int);
extern int load_interfaces();
extern struct net_page *add_network(struct net_win *n, char *title);
extern int valid_np(struct net_page *np);
extern int valid_no(struct net_page *np, struct net_object *no);
extern unsigned char *get_server(char *, int);
extern int gather_hosts(struct net_page *, char *, int, int);
extern void start_mapping(struct net_object *);
extern int handle_map(char *buf, int len, struct sockaddr_in *sin);
extern int seqno;
extern void sendicmp (int ttl, struct in_addr to, int rep);
extern void object_link(struct net_page *np, struct net_object *no, struct net_object *no2);
extern void check_connections(struct net_page *np, struct net_object *no);
extern int option_queso;
extern int option_trim;
extern int option_reverse_dns;
extern int option_port_scan;
extern int option_automap;
extern int option_remember_positions;
extern int option_add_routes;
extern int option_use_icmp;
extern int option_use_visible_area;
extern int option_update_release;
extern int option_remember_hosts;
extern int option_remember_connects;
extern int option_remember_aliases;
extern int option_need_logfile;
extern int option_send_email;
extern int option_verbose_display;
extern void show_options(void);
extern int load_options(void);
extern void show_about(void *, int);
extern void show_gpl(void);
extern int save_options(void);
extern char *gpl_text;
extern char *find_file(char *);
extern void show_edit(struct net_page *);
extern void build_edit(struct net_page *, GtkWidget *cont);
extern void do_network(GtkWidget *, int);
int append_network(struct pageedit *pe, struct network *);
int append_domain(struct pageedit *pe, struct domain *);
extern void reload_page(void);
extern void fix_icon(GdkWindow *);
extern void arrange(struct net_page *np, int how);
extern struct alias *build_aliases(unsigned int addr);
extern char *print_aliases(struct net_object *, char);
extern void fix_tooltip(struct net_object *);
extern void place_object(struct net_object *no, int xp, int yp);
extern void add_to_list(GtkWidget *, struct net_object *);
extern char *get_pm_name(char *fn, char *extn);
#ifdef USE_CANVAS
extern struct pixmap_cache_r *get_pixmap_r(char *filename);
#else
extern struct pixmap_cache *get_pixmap(char *filename);
#define get_pixmap_r(a) get_pixmap(a)
#endif
extern void port_scanner(struct net_object *no);
extern int full_scan(tcp_cb callback, unsigned int src_addr, unsigned int dst_addr, int timeout, void *data);
extern char *get_version(unsigned int addr, unsigned short port);
extern char *get_name(unsigned short port);
extern char xterm[];
extern void do_save(GtkWidget *, char *);
extern int do_load(char *fn);
extern char defname[256];
extern struct pcache *get_cache(struct net_page *, unsigned int);
extern struct pcache *check_cache(struct net_page *, unsigned int);\
extern void fix_label(struct net_object *);
extern void map_connect(struct net_page *np, unsigned int addr1, unsigned int addr2, int);
extern void shrink_pixmaps(void);
extern void init_services(void);
extern void save_services(void);
extern void register_service(char *name, int port, char *format, 
                      service_cb callback,
		      int flags);
extern void unregister_service(struct service *);
#ifdef SNMP
extern void do_snmp_close(void *data);
extern char *snmp_get(struct net_object *no, char *community, char **objid, int cnt, char **answers);
extern char *snmp_get_async(struct net_object *no, struct net_page *np, char *community, char **objid, int cnt, char **answers, void (*callback)(void *), void *);
extern int option_snmp;
extern int option_snmp_verbose;
extern int snmp_walk(struct net_object *no, char *community, void (*)(char *obj, char *value, void *), void *, int *);
extern void snmp_browser(struct net_object *no);
extern void cheops_snmp_init();
extern char *snmp_set(struct net_object *no, char *community, char **objid, char **values, int *type, int cnt, char **answers);
#endif
extern struct service *users;
extern void do_search();
extern void search_again();
extern void check_old_config(char *oldname, char *newname);
extern void generic_set_status(GtkWidget *bar, char *s);
extern void destroy_object(struct net_page *np, struct net_object *no);
extern void check_links(struct net_object *no);
extern void check_label(struct net_object *no);
extern void highlight_object(struct net_object *no, int type);
#ifdef USE_CANVAS
extern void move_object(struct net_object *, double, double);
#else
extern void move_object(struct net_object *, int, int);
#endif
extern void event_log();
extern void register_probes();
#include "monitor.h"
#include "logger.h"
extern FILE *open_connection(unsigned int addr, unsigned short port);
extern void save_geometry();
extern void set_geometry(GtkWidget *);

extern void show_status();
extern void select_page(struct net_page *np);
extern int do_refresh(void *data);
extern void delete_edit(GtkWidget *w);
extern void show_hide_verbose();
extern void set_infobox(struct net_object *no);