-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·726 lines (667 loc) · 24 KB
/
main.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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*****************************************************************************************
* NetMon - Network Monitor for Roadshow
* Based on sample from Olaf 'Ohlsen' Barthel
* Written by Sascha 'SieGeL' Pfalz
* $Id: main.c,v 1.3 2007/02/24 23:33:58 siegel Exp $
*****************************************************************************************/
#include "includes.h"
/*****************************************************************************************
* Global Variables:
*****************************************************************************************/
struct Library *MUIMasterBase = NULL;
struct Library *SocketBase = NULL;
struct Device *TimerBase = NULL;
#ifdef __amigaos4__
#define DoMethod IDoMethod
struct Library *IntuitionBase = NULL;
struct MUIMasterIFace *IMUIMaster = NULL;
struct IntuitionIFace *IIntuition = NULL;
struct SocketIFace *ISocket = NULL;
struct TimerIFace *ITimer = NULL;
#else
struct IntuitionBase *IntuitionBase = NULL;
#define PutErrStr(x) FPuts(Output(),x)
LONG __stack = 10240L; // MUI V3.x ABSOLUTLY REQUIRE THIS UNDER 68K!
#endif
// Timer related structs:
struct MsgPort *TimerMP = NULL;
struct timerequest *TimerIO = NULL;
ULONG sigs = 0;
ULONG timersigs = 0;
BOOL running = TRUE, // Main Loop var
WinGadgets = TRUE, // Close/Size/Depth gadget display
WriteStats = FALSE; // If NetMon should dump out stats every interval
APTR app = NULL,
mainwindow=NULL,strip,
aboutwin=NULL,
basegroup = NULL;
APTR mempool = NULL; // Memory pool allocated by AllocSysObject()
struct List *interface_list; // List of available interfaces
struct MinList *InterfaceList;
long RefreshInterval = 5; // Defaults to 5 seconds
char *tempbuf1 = NULL;
/**************************************************************************************************
* Prototypes:
**************************************************************************************************/
STATIC void ShowAbout(void); // Displays the About Window
STATIC void RemoveAboutWin(void); // Removes About Window
STATIC void OpenLibs(void); // Opens all required resources
STATIC void CloseLibs(void); // Removes all resources
STATIC void ReadOptions(char **argv); // Tries to read options from either Commandline or Icon
STRPTR GetRoadshowVersion(STRPTR buffer); // Reads TCP/IP Stack informations
APTR MyWinStyle(BOOL how); // Renders main frame either with or without text
#ifndef __amigaos4__
void __autoopenfail(void) { _XCEXIT(0);} // Dummy function for SAS
#endif
/**************************************************************************************************
* FUNCTION: main()
* PURPOSE: Entry Point of application
* INPUT: argc => Argument counter
* argv => Array of arguments
* RETURN: Exit Code
* NOTES: Arguments are ignored, if they are required ReadArgs() is used.
**************************************************************************************************/
int main(int argc, char **argv)
{
struct Node *node;
struct MInterfaces *in, *mi;
ULONG time_mask;
long status;
OpenLibs();
ReadOptions(argv);
for(node = interface_list->lh_Head ; node->ln_Succ != NULL ; node = node->ln_Succ)
{
in = AllocPooled(mempool,sizeof(struct MInterfaces));
if(!in)
{
fail(NULL,"Cannot allocate Memory for Node?",TRUE);
}
strcpy(in->Name,node->ln_Name);
in->FirstSample = in->CurrentSample = 0.00;
strcpy(in->NameBubble, "IP: 0.0.0.0");
strcpy(in->VolumeBubble,"IN: -\nOUT: -");
strcpy(in->SpeedRecord,"Max. IN: -\nMax. OUT: -");
AddTail((struct List *)InterfaceList, (struct Node *)in);
}
app = ApplicationObject,
MUIA_Application_Title , "NetMon",
MUIA_Application_Version , "$VER: "VERS" ("DATE")",
MUIA_Application_Copyright , "© 2004,2007 by Sascha 'SieGeL' Pfalz",
MUIA_Application_Author , "Sascha 'SieGeL' Pfalz",
MUIA_Application_Description, "Network Monitor for RoadShow ["CPU_TYPE"]",
MUIA_Application_Base , "NetMon",
MUIA_Application_Menustrip , strip = MenustripObject,
MUIA_Family_Child , MenuObjectT("Project"),
MUIA_Family_Child , MenuitemObject,
MUIA_Menuitem_Title , "About",
MUIA_Menuitem_Shortcut , "?",
MUIA_UserData , ID_ABOUT,
End,
MUIA_Family_Child , MenuitemObject,
MUIA_Menuitem_Title , NM_BARLABEL,
End,
MUIA_Family_Child , MenuitemObject,
MUIA_Menuitem_Title , "Quit",
MUIA_Menuitem_Shortcut , "Q",
MUIA_UserData , MUIV_Application_ReturnID_Quit,
End,
End,
MUIA_Family_Child , MenuObjectT("MUI"),
MUIA_Family_Child , MenuitemObject,
MUIA_Menuitem_Title , "About...",
MUIA_Menuitem_Shortcut , "!",
MUIA_UserData , ID_ABOUT_MUI,
End,
MUIA_Family_Child , MenuitemObject,
MUIA_Menuitem_Title , "Settings...",
MUIA_Menuitem_Shortcut , "M",
MUIA_UserData , ID_CONFIG_MUI,
End,
End,
End,
SubWindow, mainwindow = WindowObject,
MUIA_Window_ID , MAKE_ID('M','A','I','N'),
MUIA_Window_ScreenTitle , VERS" ["CPU_TYPE"] by Sascha 'SieGeL' Pfalz",
MUIA_Window_SizeRight , TRUE,
MUIA_Window_CloseGadget , WinGadgets,
MUIA_Window_DepthGadget , WinGadgets,
MUIA_Window_DragBar , WinGadgets,
MUIA_Window_SizeGadget , WinGadgets,
WindowContents, VGroup,
Child, basegroup = MyWinStyle(WinGadgets),
End,
End,
End;
if(!app)
{
fail(NULL,"Cannot create main MUI window!",TRUE);
}
DoMethod(mainwindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
DoMethod(basegroup,MUIM_Group_InitChange);
// Add the current socket data to the window:
for(mi=(struct MInterfaces *)InterfaceList->mlh_Head;mi->Node.mln_Succ!=NULL;mi=(struct MInterfaces *)mi->Node.mln_Succ)
{
mi->NamePtr = TextObject, MUIA_Text_PreParse,"\33l", MUIA_Text_Contents,mi->Name,End;
mi->StatePtr = TextObject, MUIA_Text_PreParse,"\33c", MUIA_Text_Contents,"---",End;
mi->SpeedPtr = TextObject, MUIA_Text_PreParse,"\33r", MUIA_Text_Contents,"---",End;
mi->VolumePtr = TextObject, MUIA_Text_PreParse,"\33r", MUIA_Text_Contents,"---",End;
mi->TimePtr = TextObject, MUIA_Text_PreParse,"\33r", MUIA_Text_Contents,"--:--:--",End;
set(mi->NamePtr,MUIA_ShortHelp,mi->NameBubble);
set(mi->VolumePtr,MUIA_ShortHelp,mi->VolumeBubble);
set(mi->SpeedPtr, MUIA_ShortHelp,mi->SpeedRecord);
DoMethod(basegroup,OM_ADDMEMBER,mi->NamePtr);
DoMethod(basegroup,OM_ADDMEMBER,mi->StatePtr);
DoMethod(basegroup,OM_ADDMEMBER,mi->SpeedPtr);
DoMethod(basegroup,OM_ADDMEMBER,mi->VolumePtr);
DoMethod(basegroup,OM_ADDMEMBER,mi->TimePtr);
}
DoMethod(basegroup,MUIM_Group_ExitChange);
if(WinGadgets == TRUE) set(mainwindow,MUIA_Window_Title, VERS" ("DATE")");
set(mainwindow,MUIA_Window_Open,TRUE);
get(mainwindow,MUIA_Window_Open,&status);
if(!status)
{
fail(NULL,"Unable to create Main Window!!",TRUE);
}
time_mask = PORT_SIG_MASK(TimerMP);
RetrieveSocketData();
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
#ifdef __NEWLIB_H__
TimerIO->tr_time.tv_sec = RefreshInterval;
TimerIO->tr_time.tv_usec = 0;
#else
TimerIO->tr_time.tv_secs = RefreshInterval;
TimerIO->tr_time.tv_micro = 0;
#endif
SendIO((struct IORequest *)TimerIO);
while (running)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{
case MUIV_Application_ReturnID_Quit:
running = FALSE;
break;
case ID_ABOUT:
ShowAbout();
break;
case ID_ABOUTCLOSE:
RemoveAboutWin();
break;
case ID_ABOUT_MUI:
if(!aboutwin)
{
aboutwin= AboutmuiObject,
MUIA_Aboutmui_Application,app,
End;
}
if(aboutwin) set(aboutwin,MUIA_Window_Open,TRUE);
else fail(app,"Unable to open MUI About window",TRUE);
break;
case ID_CONFIG_MUI:
DoMethod(app,MUIM_Application_OpenConfigWindow,0L);
break;
}
if (running && sigs)
{
sigs = Wait(sigs|time_mask|SIGBREAKF_CTRL_C);
}
if(sigs & time_mask)
{
WaitIO((struct IORequest *)TimerIO);
RetrieveSocketData();
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
#ifdef __NEWLIB_H__
TimerIO->tr_time.tv_sec = RefreshInterval;
TimerIO->tr_time.tv_usec = 0;
#else
TimerIO->tr_time.tv_secs = RefreshInterval;
TimerIO->tr_time.tv_micro = 0;
#endif
SendIO((struct IORequest *)TimerIO);
}
if(sigs & SIGBREAKF_CTRL_C) running = FALSE;
}
if(!CheckIO((struct IORequest *)TimerIO)) AbortIO((struct IORequest *)TimerIO);
WaitIO((struct IORequest *)TimerIO);
set(mainwindow,MUIA_Window_Open,FALSE);
MUI_DisposeObject(app);
CloseLibs();
exit(RETURN_OK);
}
/**************************************************************************************************
* FUNCTION: MyWinStyle()
* PURPOSE: Decides what kind of Frame Border the window should use.
* INPUT: TRUE => Full Textframe
* FALSE => Frame without text
* RETURN: APTR Pointer to group
**************************************************************************************************/
APTR MyWinStyle(BOOL how)
{
if(how == TRUE)
{
return(VGroup,GroupFrameT("Available Interfaces:"),MUIA_Group_Columns, 5,End);
}
else
{
return(VGroup,GroupFrame,MUIA_Group_Columns, 5, End);
}
}
/**************************************************************************************************
* FUNCTION: fail()
* PURPOSE: General failure function. Uses EasyRequest for warning infos if app is not loaded yet
* INPUT: app => Application Pointer
* *str => Error string
* withexit => TRUE = Exit after displaying message. FALSE = do not exit application
* RETURN: none
* REQUIRES: Open intuition.library!
**************************************************************************************************/
void fail(APTR thisapp,char *str,BOOL withexit)
{
if (*str)
{
if(thisapp) MUI_Request(app, mainwindow, 0,VERS" Warning:","Okay!","\33c%s", str);
else
{
struct EasyStruct MyES=
{
sizeof(struct EasyStruct),
0,
NULL,
"%s",
"Okay",
};
EasyRequest(NULL,&MyES,NULL,str);
}
printf("\nERROR: %s\n",str);
}
if(withexit==FALSE) return;
CloseLibs();
exit(RETURN_FAIL);
}
/**************************************************************************************************
* FUNCTION: OpenLibs()
* PURPOSE: Opens all required resources (Libraries, Interfaces, Memory)
* INPUT: none
* RETURN: none
* NOTES: In case of any error this function exists application with appropiate error message!
**************************************************************************************************/
STATIC void OpenLibs(void)
{
ULONG have_ifaces=FALSE;
char buffer[256],rsversion[128];
#ifdef __amigaos4__
if(!(DOSBase = OpenLibrary("dos.library",36)))
{
printf("ERROR: Cannot open dos.library v36+!\n");
exit(RETURN_FAIL);
}
if(!(IDOS = (struct DOSIFace *)GetInterface(DOSBase, "main",1,NULL)))
{
printf("ERROR: Cannot obtain DOS Interface!\n");
CloseLibs();
exit(RETURN_FAIL);
}
if (!(IntuitionBase=OpenLibrary("intuition.library",39)))
{
PutErrStr("ERROR: Cannot open intuition.library V39+!\n");
CloseLibs();
exit(RETURN_FAIL);
}
if((IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, "main", 1, NULL))==0)
{
PutErrStr("ERROR: Cannot obtain Intuition Interface!\n");
CloseLibs();
exit(RETURN_FAIL);
}
if (!(MUIMasterBase=OpenLibrary(MUIMASTER_NAME,19)) )
{
fail(NULL,"Cannot open MUIMaster.library V19+!",TRUE);
}
if((IMUIMaster = (struct MUIMasterIFace *)GetInterface(MUIMasterBase, "main", 1, NULL))==0)
{
fail(NULL,"Cannot obtain MUIMaster Interface!",TRUE);
}
if (!(SocketBase=OpenLibrary("bsdsocket.library",4)) )
{
fail(NULL,"Cannot open bsdsocket.library V4+!",TRUE);
}
if((ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL))==0)
{
fail(NULL,"Cannot obtain Socket Interface!",TRUE);
}
if(SocketBaseTags(SBTM_GETREF(SBTC_HAVE_INTERFACE_API),&have_ifaces, TAG_END)!=0)
{
sprintf(buffer,"Cannot query TCP/IP stack for featurelist?\n\nUsing %s",GetRoadshowVersion(rsversion));
fail(NULL,buffer,TRUE);
}
if(have_ifaces == FALSE)
{
sprintf(buffer,"This TCP/IP stack seems not to be Roadshow!\n\nDetected: %s",GetRoadshowVersion(rsversion));
fail(NULL,buffer,TRUE);
}
if(!(mempool = AllocSysObjectTags(ASOT_MEMPOOL, ASOPOOL_Puddle, 20480, ASOPOOL_Threshold, 20480, TAG_DONE)))
{
fail(NULL,"Cannot create memory pool?!",TRUE);
}
interface_list = ObtainInterfaceList();
if(interface_list == NULL || (IsListEmpty(interface_list)))
{
fail(NULL,"No configured Interfaces found?\nPlease start Roadshow first.",TRUE);
}
InterfaceList = (struct MinList *)AllocSysObjectTags(ASOT_LIST, ASOLIST_Min, TRUE, TAG_DONE);
if(!InterfaceList)
{
fail(NULL,"No memory left for Interface list??",TRUE);
}
TimerMP = AllocSysObject(ASOT_PORT,NULL);
if(!TimerMP)
{
fail(NULL,"Cannot create Timer message port!",TRUE);
}
TimerIO = AllocSysObjectTags(ASOT_IOREQUEST,ASOIOR_Size,sizeof(struct timerequest),ASOIOR_ReplyPort,TimerMP,TAG_DONE);
if(!TimerIO)
{
fail(NULL,"Cannot allocate timer request!",TRUE);
}
if(OpenDevice(TIMERNAME,UNIT_MICROHZ, (struct IORequest *)TimerIO, 0))
{
fail(NULL,"Cannot open timer.device!",TRUE);
}
TimerBase = (struct Device *)TimerIO->tr_node.io_Device;
ITimer = (struct TimerIFace *)GetInterface((struct Library *)TimerBase,"main",1,NULL);
if(!ITimer)
{
fail(NULL,"Cannot obtain Timer Interface!",TRUE);
}
#else
if(!(IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",39L)))
{
PutErrStr("Cannot Open intuition.library?!");
exit(20);
}
if(!(MUIMasterBase=OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
{
fail(NULL,"Failed to open "MUIMASTER_NAME" V12++ !",TRUE);
}
if(!(mempool = CreatePool(MEMF_PUBLIC|MEMF_CLEAR,20480L, 20480L)))
{
fail(NULL,"Cannot create memory pool?!",TRUE);
}
if(!(InterfaceList = AllocPooled(mempool,sizeof(struct MinList))))
{
fail(NULL,"Cannot allocate memory for interface list??",TRUE);
}
NewList((struct List *)InterfaceList);
if (!(SocketBase=OpenLibrary("bsdsocket.library",4)) )
{
fail(NULL,"Cannot open bsdsocket.library V4+!",TRUE);
}
if(SocketBaseTags(SBTM_GETREF(SBTC_HAVE_INTERFACE_API),&have_ifaces, TAG_END)!=0)
{
sprintf(buffer,"Cannot query TCP/IP stack for featurelist?\n\nUsing %s",GetRoadshowVersion(rsversion));
fail(NULL,buffer,TRUE);
}
if(have_ifaces == FALSE)
{
sprintf(buffer,"This TCP/IP stack seems not to be Roadshow!\n\nFound: %s",GetRoadshowVersion(rsversion));
fail(NULL,buffer,TRUE);
}
interface_list = ObtainInterfaceList();
if(interface_list == NULL || (IsListEmpty(interface_list)))
{
fail(NULL,"No configured Interfaces found?\nPlease start Roadshow first!",TRUE);
}
TimerMP = CreateMsgPort();
if(!TimerMP)
{
fail(NULL,"Cannot create Timer message port!",TRUE);
}
TimerIO = (struct timerequest *)CreateIORequest(TimerMP,sizeof(*TimerIO));
if(!TimerIO)
{
fail(NULL,"Cannot allocate timer request!",TRUE);
}
if(OpenDevice(TIMERNAME,UNIT_MICROHZ, (struct IORequest *)TimerIO, 0))
{
fail(NULL,"Cannot open timer.device!",TRUE);
}
TimerBase = (struct Device *)TimerIO->tr_node.io_Device;
#endif
if(!(tempbuf1 = AllocPooled(mempool,TEMPBUFSIZE)))
{
fail(NULL,"Cannot allocate 1k for buffers?",TRUE);
}
}
/**************************************************************************************************
* FUNCTION: CloseLibs()
* PURPOSE: Frees all allocated resources (Libraries, Interfaces, Memory)
* INPUT: none
* RETURN: none
**************************************************************************************************/
STATIC void CloseLibs(void)
{
#ifdef __amigaos4__
if(ITimer) DropInterface((struct Interface *)ITimer);
CloseDevice((struct IORequest *)TimerIO);
if(TimerIO!=NULL) FreeSysObject(ASOT_IOREQUEST,TimerIO);
if(TimerMP!=NULL) FreeSysObject(ASOT_PORT,TimerMP);
if(interface_list != NULL) ReleaseInterfaceList(interface_list);
if(InterfaceList!=NULL) FreeSysObject(ASOT_LIST,(APTR)InterfaceList);
if(mempool!=NULL) FreeSysObject(ASOT_MEMPOOL, (APTR)mempool);
if(ISocket!=NULL) DropInterface((struct Interface *)ISocket);
if(IMUIMaster!=NULL) DropInterface((struct Interface *)IMUIMaster);
if(IIntuition!=NULL) DropInterface((struct Interface *)IIntuition);
if(IDOS!=NULL) DropInterface((struct Interface *)IDOS);
if(SocketBase!=NULL) CloseLibrary(SocketBase);
if(MUIMasterBase!=NULL) CloseLibrary(MUIMasterBase);
if(IntuitionBase!=NULL) CloseLibrary(IntuitionBase);
if(DOSBase!=NULL) CloseLibrary(DOSBase);
#else
if(TimerIO!=NULL)
{
if(TimerIO->tr_node.io_Device != NULL) CloseDevice((struct IORequest *)TimerIO);
DeleteIORequest((struct IORequest *)TimerIO);
TimerIO = NULL;
}
if(TimerMP != NULL) DeleteMsgPort(TimerMP);
if(interface_list != NULL) ReleaseInterfaceList(interface_list);
if(mempool!=NULL) DeletePool(mempool);
if(SocketBase!=NULL) CloseLibrary(SocketBase);
if(MUIMasterBase!=NULL) CloseLibrary(MUIMasterBase);
if(IntuitionBase!=NULL) CloseLibrary((struct Library *)IntuitionBase);
#endif
}
/**************************************************************************************************
* FUNCTION: ShowAbout()
* PURPOSE: Opens the well-known About dialog :)
* INPUT: none
* RETURN: none
**************************************************************************************************/
STATIC void ShowAbout(void)
{
APTR titeltext;
LONG status;
char titlebuf[100],rsversion[256];
sprintf(titlebuf,"About %s [%s]",VERS,CPU_TYPE);
aboutwin = WindowObject,
MUIA_Window_Title , titlebuf,
MUIA_Window_NoMenus , TRUE,
MUIA_Window_SizeGadget, FALSE,
WindowContents, VGroup,
Child, HGroup,
Child, titeltext = TextObject, End,
End,
End,
End;
if(!aboutwin) fail(app, "Cannot open about window!",TRUE);
GetRoadshowVersion(rsversion);
DoMethod(aboutwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,ID_ABOUTCLOSE);
DoMethod(titeltext,MUIM_SetAsString,MUIA_Text_Contents,"\33c\33b%s (%s) [%s]\33n\n\nNetwork Monitor for Roadshow TCP/IP Stack\nwritten and (c) 2004,2007 by Sascha 'SieGeL' Pfalz\n\nUses codeparts from RoadShow examples written by Olaf 'Ohlsen' Barthel.\n\nBig thanks to Olaf for his great help and support and\nto Hyperion for making AmigaOS 4 finally possible!\n\nVisit http://www.saschapfalz.de for updates\n\n%s",VERS,DATE,CPU_TYPE,rsversion);
DoMethod(app, OM_ADDMEMBER, aboutwin);
set(app,MUIA_Application_Sleep,TRUE);
set(aboutwin,MUIA_Window_Open,TRUE);
get(aboutwin,MUIA_Window_Open,&status);
if(!status) fail(app,"Cannot open about window!!",TRUE);
}
/**************************************************************************************************
* FUNCTION: RemoveAboutWin()
* PURPOSE: Closes the About window
* INPUT: none
* RETURN: none
**************************************************************************************************/
STATIC void RemoveAboutWin(void)
{
set(aboutwin,MUIA_Window_Open,FALSE);
DoMethod(app,OM_REMMEMBER, aboutwin);
MUI_DisposeObject(aboutwin);aboutwin=NULL;
set(app,MUIA_Application_Sleep,FALSE);
aboutwin = NULL;
}
/**************************************************************************************************
* FUNCTION: ReadOptions()
* PURPOSE: Tries to read Config options from either Commandline or Icon. Commandline has precedence
* INPUT: none
* RETURN: none
**************************************************************************************************/
STATIC void ReadOptions(char **argv)
{
struct RDArgs *rda;
struct Process *pr;
STRPTR arg_template = "NOWINBORDER/S,WRITESTATS/S,INTERVAL/K/N";
STRPTR ttcheck;
LONG ArgArray[3] = {0L,0L,0L};
long check,check2 = 5;
struct Library *IconBase;
struct WBStartup *wst;
struct WBArg *wba;
#ifdef __amigaos4__
struct IconIFace *IIcon = NULL;
#endif
pr = (struct Process *)FindTask(NULL);
if(pr->pr_CLI == ZERO)
{
char fname[256];
BPTR myfile = GetProgramDir();
if(myfile)
{
memset(tempbuf1,'\0',TEMPBUFSIZE);
NameFromLock(myfile,tempbuf1,255);
wst = (struct WBStartup *)argv;
if(wst != NULL)
{
wba = &wst->sm_ArgList[0];
strcpy(fname,wba->wa_Name);
}
else strcpy(fname,"NetMon");
AddPart(tempbuf1,fname,255);
if(IconBase = OpenLibrary("icon.library",0L))
{
#ifdef __amigaos4__
if(IIcon = (struct IconIFace *)GetInterface(IconBase, "main", 1, NULL))
{
#endif
struct DiskObject *dobj;
dobj = GetDiskObject(tempbuf1);
if(dobj)
{
if(FindToolType((STRPTR *)dobj->do_ToolTypes,"NOWINBORDER")) WinGadgets = FALSE;
else WinGadgets = TRUE;
if(FindToolType((STRPTR *)dobj->do_ToolTypes,"WRITESTATS")) WriteStats = TRUE;
else WriteStats = FALSE;
ttcheck = FindToolType((STRPTR *)dobj->do_ToolTypes,"INTERVAL");
if(ttcheck != NULL) RefreshInterval = atoi(ttcheck);
if(RefreshInterval < 1) RefreshInterval = 5;
FreeDiskObject(dobj);
}
#ifdef __amigaos4__
DropInterface((struct Interface *)IIcon);
}
#endif
CloseLibrary(IconBase);
}
}
}
else
{
rda=ReadArgs(arg_template,ArgArray,NULL);
check = ArgArray[0];
if(check)
{
WinGadgets = FALSE;
}
if(ArgArray[2]) check2 = *(long *)ArgArray[2];
check = ArgArray[1];
if(check)
{
WriteStats = TRUE;
}
FreeArgs(rda);
if(check2 < 1) check2 = 5;
RefreshInterval = check2;
}
}
/**************************************************************************************************
* FUNCTION: GetRoadshowVersion()
* PURPOSE: Reads Version string from TCP/IP stack
* INPUT: buffer to hold version string
* RETURN: none
* NOTES: Taken from GetNetStatus.c written by Olaf Barthel
**************************************************************************************************/
STRPTR GetRoadshowVersion(STRPTR buffer)
{
char string[256],final[512],buf[128];
LONG len;
memset(string,'\0',sizeof(string));
memset(final,'\0',sizeof(final));
memset(buf,'\0',sizeof(buf));
if(SocketBase->lib_IdString != NULL)
{
strncpy(string,SocketBase->lib_IdString,sizeof(string)-1);
string[sizeof(string)-1] = '\0';
}
else
{
strcpy(string,"");
}
len = strlen(string);
while(len > 0 && (string[len-1] == '\r' || string[len-1] == '\n')) string[--len] = '\0';
if(len > 0)
{
STRPTR release_string = NULL;
BOOL need_line_feed = FALSE;
LONG i;
for(i = 0 ; i < len ; i++)
{
if(string[i] == '\n')
{
need_line_feed = TRUE;
break;
}
}
strcpy(final,string);
if(SocketBaseTags(SBTM_GETREF(SBTC_RELEASESTRPTR),&release_string,TAG_END) != 0)
{
release_string = NULL;
}
if(release_string != NULL)
{
strncpy(string,release_string,sizeof(string)-1);
string[sizeof(string)-1] = '\0';
}
else
{
strcpy(string,"");
}
len = strlen(string);
while(len > 0 && (string[len-1] == '\r' || string[len-1] == '\n')) string[--len] = '\0';
if(len > 0)
{
if(need_line_feed) strcat(final,"\n");
else strcat(final," ");
sprintf(buf,"[%s]",string);
strcat(final,buf);
}
strcpy(buffer,final);
}
return(buffer);
}