-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaprsstat.c
429 lines (330 loc) · 9.39 KB
/
aprsstat.c
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
/*
* APRS Services for JNOS 111x, TNOS 2.30 & TNOS 2.4x
*
* April,2001-June,2004 - Release (C-)1.16+
*
* Designed and written by VE4KLM, Maiko Langelaar
*
* For non-commercial use (Ham Radio) only !!!
*
*/
#include "global.h"
#ifdef APRSD
#include "mbuf.h"
/* 01Feb2002, Maiko, DOS compile for JNOS will complain without these */
#ifdef MSDOS
#include "iface.h"
#include "arp.h"
#include "slip.h"
#endif
#include "ax25.h"
#include <time.h>
#include "aprs.h" /* 16May2001, VE4KLM, Finally added prototypes */
static int maxaprshrd = 0;
typedef struct {
char callsign[AXALEN];
char dti;
int packets;
time_t last;
/* 16Aug2001, Maiko, Now track which port heard on */
const char *iface_name;
/* 20Aug2001, VE4KLM, Playing with digis, etc */
int ndigis;
/* 21Aug2001, VE4KLM, Added digi calls (would be nice to see) */
char digis[MAXDIGIS][AXALEN];
} APRSHRD;
/* static APRSHRD aprshrd[MAXAPRSHRD]; */
static APRSHRD *aprshrd;
static int topcnt = 0;
/*
* 31May2001, VE4KLM, Heard list can now be dynamically resized by the
* sysop while TNOS is running, and is now initialized in autoexec.nos
* file. Previously I had a hardcoded array of 20 entries max.
*/
void init_aprshrd (int hsize)
{
if (maxaprshrd)
{
free (aprshrd);
maxaprshrd = 0;
topcnt = 0;
}
/* 28Aug2001, VE4KLM, User should be allowed to
* disable the heard table on the fly.
*/
if (hsize == 0)
return;
aprshrd = (APRSHRD*)malloc (sizeof(APRSHRD) * hsize);
if (aprshrd == (APRSHRD*)0)
{
tprintf ("not enough memory for APRS heard list\n");
return;
}
maxaprshrd = hsize;
}
#ifdef APRS_14501
/*
* 03Aug2001, VE4KLM, To calculate the amount of memory to allocate
* for the 14501 page, we need to know the current number of entries
* in the APRS heard list.
*/
int get_topcnt (void)
{
return (topcnt);
}
#endif
/*
* 17Oct2001, Maiko, New Function returns a pointer to a string
* that identifies the name of the interface on which the passed
* call was last heard on. The passed call is in internal format.
*/
const char *iface_hrd_on (char *callsign)
{
register APRSHRD *ptr = aprshrd;
register int cnt;
for (cnt = 0; cnt < topcnt; cnt++, ptr++)
{
if (addreq (ptr->callsign, callsign))
return ptr->iface_name;
}
return NULL;
}
/*
* Function : display_aprshrd
*
* DISPLAY the APRS Heard table
*/
/* 31Jul2001, VE4KLM, New function for HTML and non-HTML statistics */
static int show_aprshrdlst (char *dptr, int html)
{
register APRSHRD *ptr = aprshrd;
char tmp[AXBUF], *sptr = dptr;
register int cnt, idx;
time_t curtime;
int dspflg;
char *tptr;
for (cnt = 0; cnt < topcnt; cnt++, ptr++)
{
dspflg = 0;
/* 17Aug2001, Display interface if different from main port */
if (strcmp (ptr->iface_name, aprs_port))
dspflg |= 0x01;
/* 20Aug2001, VE4KLM, Playing with digis */
if (ptr->ndigis)
dspflg |= 0x02;
/* 21Aug2001, Lowercase the callsigns (it takes up alot less room)
* when viewing an HTML page
*/
tptr = strlwr (pax25 (tmp, ptr->callsign));
#ifdef APRS_14501
if (html)
{
dptr += sprintf (dptr, "<tr><td>");
if (locator)
dptr += sprintf (dptr, "<a href=\"%s%s\">%s</a>", locator, tptr, tptr);
else
dptr += sprintf (dptr, "%s", tptr);
dptr += sprintf (dptr, "</td><td>");
/* 12Apr2002, Maiko, Cosmetics */
if (dtiheard)
dptr += sprintf (dptr, "%c", ptr->dti);
else
dptr += sprintf (dptr, "n/a");
dptr += sprintf (dptr, "</td><td>%s</td><td>%d</td><td>",
tformat ((int32)(time (&curtime) - ptr->last)), ptr->packets);
if (dspflg & 0x01)
dptr += sprintf (dptr, "I %s", ptr->iface_name);
if (dspflg & 0x02)
{
if (dspflg & 0x01)
dptr += sprintf (dptr, ", ");
dptr += sprintf (dptr, "P ");
for (idx = 0; idx < ptr->ndigis; idx++)
{
if (idx)
dptr += sprintf (dptr, " ");
/* 05Sept2001, Maiko, Added '*' repeated flags if present */
dptr += sprintf (dptr, "%s%s",
strlwr (pax25 (tmp, ptr->digis[idx])),
(ptr->digis[idx][ALEN] & REPEATED) ? "*" : "");
}
}
if (!dspflg)
*dptr++ = '-';
dptr += sprintf (dptr, "</td></tr>");
}
else
#else
if (1)
#endif
{
/* 12Apr2002, Maiko, More cosmetics */
if (dtiheard)
tprintf ("%-15.15s%c ", tptr, ptr->dti);
else
tprintf ("%-14.14sn/a ", tptr);
tprintf ("%s %-4d ", tformat ((int32)(time (&curtime) - ptr->last)), ptr->packets);
if (dspflg & 0x01)
tprintf ("I %s", ptr->iface_name);
if (dspflg & 0x02)
{
if (dspflg & 0x01)
tprintf (", ");
tprintf ("P ");
for (idx = 0; idx < ptr->ndigis; idx++)
{
if (idx)
tprintf (" ");
/* 05Sept2001, Maiko, Added '*' repeated flags if present */
tprintf ("%s%s", strlwr (pax25 (tmp, ptr->digis[idx])),
(ptr->digis[idx][ALEN] & REPEATED) ? "*" : "");
}
}
if (!dspflg)
tprintf ("-");
tprintf ("\n");
}
}
if (html)
return (dptr - sptr);
else
return 1;
}
#ifdef APRS_14501
/* 31Jul2001, VE4KLM, new function for the http 14501 port statistics */
int build_14501_aprshrd (char *dptr)
{
char *sptr = dptr;
if (maxaprshrd == 0)
{
dptr += sprintf (dptr, "<h4>APRS heard table not configured</h4>");
return (dptr - sptr);
}
/* 03Jan2001, Maiko, Might as well put this instead of empty table */
if (topcnt == 0)
{
dptr += sprintf (dptr, "<h4>No APRS traffic heard so far</h4>");
return (dptr - sptr);
}
/* 16Aug2001, Maiko, We now track the port user was heard on */
dptr += sprintf (dptr, "<h4>APRS Traffic Heard</h4><table border=1 cellpadding=3 bgcolor=\"#00ddee\"><tr><td>Callsign</td><td>DTI</td><td>Since</td><td>Pkts</td><td>Other Info (I=Interface, P=Path)</td></tr>");
dptr += show_aprshrdlst (dptr, 1);
dptr += sprintf (dptr, "</table><br>");
return (dptr - sptr);
}
#endif
/* this function is the regular aprsstat function, modified 31Jul2001
* to use above function
*/
void display_aprshrd (void)
{
if (maxaprshrd == 0)
{
tprintf ("\nAPRS heard table not configured\n\n");
return;
}
/* 03Jan2001, Maiko, Might as well put this instead of empty table */
if (topcnt == 0)
{
tprintf ("\nNo APRS traffic heard so far\n\n");
return;
}
/* 16Aug2001, Maiko, We now track the port user was heard on */
tprintf ("\nAPRS traffic heard:\nCallsign DTI Since Pkts Other Info (I=Interface, P=Path)\n");
show_aprshrdlst (NULL, 0);
tprintf ("\n");
}
/*
* Function : update_aprshrd
*
* Update the APRS Heard table
*
* 16Aug2001, Maiko, Changed parameters for this function, need more
* information for statistic purposes and for future enhancements.
*/
void update_aprshrd (struct ax25 *hdr, struct iface *iface, char dti)
{
register APRSHRD *ptr = aprshrd, *repptr = (APRSHRD*)0;
char *callsign = hdr->source;
time_t curtime, oldest;
register int cnt;
/* 31May2001, VE4KLM, If heard was not configured, then leave now !!! */
if (maxaprshrd == 0)
return;
/* first go through the entire list see if we can update */
for (cnt = 0; cnt < topcnt; cnt++, ptr++)
{
/*
* 02Apr2002, Maiko, now have option to include/exclude the DTI
* character from the tracking index, the heard table can get
* quite large, especially if one station is using a variety
* of different DTI types. New global variable, 'dtiheard'.
*/
if (addreq (ptr->callsign, callsign) && (!dtiheard || (dtiheard && ptr->dti == dti)))
{
ptr->packets++; /* increment # of packets received */
ptr->last = time (&curtime); /* save time heard */
/* 16Aug2001, Maiko, Now track which port it was heard on */
ptr->iface_name = iface->name;
ptr->ndigis = hdr->ndigis; /* 20Aug2001, Playing with digis */
/* 21Aug2001, VE4KLM, Okay, let's just save the digi info */
memcpy (ptr->digis, hdr->digis, hdr->ndigis * AXALEN);
return; /* that's it, let's get out of here */
}
}
if (topcnt < maxaprshrd)
{
memcpy (ptr->callsign, callsign, AXALEN);
/* 02Apr2002, Maiko, DTI tracking can now be excluded */
if (dtiheard)
ptr->dti = dti;
else
ptr->dti = ' ';
ptr->packets = 1;
ptr->last = time (&curtime);
/* 16Aug2001, Maiko, Now track which port it was heard on */
ptr->iface_name = iface->name;
ptr->ndigis = hdr->ndigis; /* 20Aug2001, Playing with digis */
/* 21Aug2001, VE4KLM, Okay, let's just save the digi info */
memcpy (ptr->digis, hdr->digis, hdr->ndigis * AXALEN);
topcnt++;
}
else
{
/*
* If we get here it means the table is full. At this point we
* have no choice but to start overwriting the oldest data with
* the newest stuff coming in. 31May2001, VE4KLM, completed !!!
*/
repptr = (APRSHRD*)0;
ptr = aprshrd;
/* locate the oldest record, save a pointer to it */
for (oldest = 0, cnt = 0; cnt < topcnt; cnt++, ptr++)
{
if (ptr->last > oldest)
{
oldest = ptr->last;
repptr = ptr; /* replacement pointer */
}
}
/* replace this record with the latest information */
if (repptr != (APRSHRD*)0)
{
memcpy (repptr->callsign, callsign, AXALEN);
/* 02Apr2002, Maiko, DTI tracking can now be excluded */
if (dtiheard)
repptr->dti = dti;
else
repptr->dti = ' ';
repptr->packets = 1;
repptr->last = time (&curtime);
/* 16Aug2001, Maiko, Now track which port it was heard on */
repptr->iface_name = iface->name;
repptr->ndigis = hdr->ndigis; /* 20Aug2001, Playing with digis */
/* 21Aug2001, VE4KLM, Okay, let's just save the digi info */
memcpy (repptr->digis, hdr->digis, hdr->ndigis * AXALEN);
}
}
return;
}
#endif