Anonymous




Register
Login

Amiga Future

Community

Knowledge

Service

Search




Advanced search

Unanswered topics
Active topics

Last Magazine

The Amiga Future 146 was released on the September 3rd.

The Amiga Future 146 was released on the September 3rd.
The Amiga Future 146 was released on the September 3rd.

The Amiga Future 146 was released on the September 3rd.
More informations

Social Media

Twitter Amigafuture Facebook Amigafuture RSS-Feed [german] Amigafuture RSS-Feed [english] Instagram YouTube

Advertisement

Amazon

Partnerlinks

Amiga Future Aktion: Probeheft für 1 Cent
Im Augenblick gibt es im Shop unter https://www.amigashop.org die Möglichkeit ein Probeheft der Amiga Future für 1 Cent (+ Versandkosten, inkl. MwSt.) zu bestellen.

Amiga Future Promotion: Sample issue for 1 cent
We have a special offer for all of you who’ve gotten a taste of it: Right now you can order an Amiga Future issue for 1 cent (plus shipping costs and included VAT) at https://www.amigashop.org.

AddNetMonitorHookTagList example

Support Roadshow

Moderators: AndreasM, olsen

Post Reply
philippe
Grade reingestolpert
Grade reingestolpert
Posts: 4
Joined: 06.09.2020 - 12:57

AddNetMonitorHookTagList example

Post by philippe »

Hi RoadShow community,

(first time post, so hello to everybody)


I'm playing for the first time with the BSDSOCKET API, using SAS/C 6.58

I get freeze when trying to use Hook monitors (it is installed, but cpu crash when inside the hook).

Does someone have some how to example, please ?


Code: Select all

/**********************************************************
 * BSDSOCKET tests
 **********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <dos/dos.h>
#include <dos/stdio.h>
#include <exec/exec.h>
#include <exec/execbase.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/socket.h>

/**********************************************************
 * DEFINES
 **********************************************************/

#define REG(x) register __ ## x

/**********************************************************
 * GLOBALS
 **********************************************************/

struct Library *SocketBase;

extern struct ExecBase *SysBase;
extern struct DOSBase  *DOSBase;

/**********************************************************
 ** Test
 **********************************************************/

ULONG __asm hookEntry(REG(a0) struct Hook *h, REG(a2) VOID *o, REG(a1) VOID *msg) 
{
	return ((*(ULONG (*)(struct Hook *, VOID *, VOID *))(h->h_SubEntry))(h, o, msg));
}

VOID InitHook(struct Hook *h, ULONG (*func)(), VOID *data)
{
	if(h)
	{
		h->h_Entry    = (ULONG (*)()) hookEntry;
		h->h_SubEntry = func;
		h->h_Data     = data;
	}
}

ULONG MonitorPacket(struct Hook *h, APTR reserved, struct PacketMonitorMessage *pmm)
{
	//printf("** packet **\n");
	
	return(MA_Continue);
}

void test(void)
{
	if(SocketBase = OpenLibrary("bsdsocket.library", 4))
	{
		ULONG result;
		
		struct TagItem tags[2];
		
		tags[0].ti_Tag  = SBTM_GETREF(SBTC_HAVE_MONITORING_API);
		tags[0].ti_Data = (ULONG)&result;
		tags[1].ti_Tag  = TAG_END;
		tags[1].ti_Data = 0;
		
		if(SocketBaseTagList(tags) == 0)
		{
			struct Hook h;
			
			tags[0].ti_Tag  = TAG_END;
			tags[0].ti_Data = 0;
			
			InitHook(&h, MonitorPacket, NULL);
			
			if(AddNetMonitorHookTagList(MHT_Packet, &h, tags) == 0)
			{
				printf("Monitor Hook added.\n");
				
				Wait(SIGBREAKF_CTRL_C);
			}
		}
		
		CloseLibrary(SocketBase);
		SocketBase = NULL;
	}
}

int main(int argc, char *argv[])
{
	test();
	
	return(0);
}

philippe
Grade reingestolpert
Grade reingestolpert
Posts: 4
Joined: 06.09.2020 - 12:57

Re: AddNetMonitorHookTagList example

Post by philippe »

I also tried to use C function directely using __asm and reg(x) so that it can be linked in h_Entry rather than h_SubEntry. This is to avoid the hookEntry wrapper.

Unfortunately i get same results.


I used that CBM procedure :

http://amigadev.elowar.com/read/ADCD_2. ... e04A4.html

http://amigadev.elowar.com/read/ADCD_2. ... e05C5.html

And Lattice C remark here at bottom (which i assume to be same for SAS/C) :

http://amigadev.elowar.com/read/ADCD_2. ... tml#line22

philippe
Grade reingestolpert
Grade reingestolpert
Posts: 4
Joined: 06.09.2020 - 12:57

Re: AddNetMonitorHookTagList example

Post by philippe »

OK well,

To enlight my lantern, i checked using assembler,

it appears that all is ok, in assembly, in the $RC, i get an updated Counter.

So my issue is clearly C-related (maybe wrongly installed netinclude).

Code: Select all

;----------------------------------------------------------
; 
; Project  : AddNetMonitorHookTags
; Short    : Monitor the (bsd)socket.library (Send/Recv)
; Author   : Philippe CARPENTIER
; Date     : 07.09.2020
; 
;----------------------------------------------------------

	INCDIR  include:
	INCLUDE dos/dos_lib.i
	INCLUDE dos/dosextens.i
	INCLUDE exec/libraries.i
	INCLUDE exec/macros.i
	INCLUDE exec/exec_lib.i
	INCLUDE utility/hooks.i

;----------------------------------------------------------

MHT_ICMP         EQU  0
MHT_UDP          EQU  1
MHT_TCP_Connect  EQU  2
MHT_Connect      EQU  3
MHT_Send         EQU  4
MHT_Packet       EQU  5
MHT_Bind         EQU  6

MA_Continue      EQU  0
MA_Ignore        EQU -1
MA_Drop          EQU -2
MA_DropWithReset EQU -3

_LVOAddNetMonitorHookTags     EQU -498
_LVOAddNetMonitorHookTagList  EQU -498
_LVORemoveNetMonitorHook      EQU -504

;----------------------------------------------------------
	
	SECTION S_0,CODE

MAIN:
	
	move.l  $4.w,a6                    ; SysBase
	move.l  a6,_SysBase                ; SysBase
	
	lea.l   _DOSName(pc),a1            ; Name
	moveq.l #0,d0                      ; Version
	JSRLIB  OpenLibrary                ; SysBase -> OpenLibrary
	move.l  d0,_DOSBase                ; Base
	beq.s   .closeLibs                 ; Skip
	
	lea.l   _SocketName(pc),a1         ; Name
	moveq.l #0,d0                      ; Version
	JSRLIB  OpenLibrary                ; Exec -> OpenLibrary
	move.l  d0,_SocketBase             ; Base
	beq.s   .closeLibs                 ; Skip

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	move.l  #MHT_Packet,d0             ; Type
	lea.l   _Hook(pc),a0               ; Hook
	lea.l   _Tags(pc),a1               ; Tags
	lea.l   MonitorFunc(pc),a2         ; Func
	
	move.l  a2,h_Entry(a0)             ; h -> h_Entry
	move.l  #0,h_SubEntry(a0)          ; h -> h_SubEntry
	move.l  #0,h_Data(a0)              ; h -> h_Data
	
	move.l  _SocketBase(pc),a6         ; SocketBase
	JSRLIB  AddNetMonitorHookTagList   ; SocketBase -> func()
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	move.l  #SIGBREAKF_CTRL_C,d0       ; signals
	move.l  _SysBase(pc),a6            ; SysBase
	JSRLIB  Wait                       ; Exec -> Wait

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
	lea.l   _Hook(pc),a0               ; Hook
	move.l  _SocketBase(pc),a6         ; SocketBase
	JSRLIB  RemoveNetMonitorHook       ; SocketBase -> func()
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
.closeLibs

	move.l  _SocketBase(pc),d0         ; Base
	beq.s   .exit                      ; Skip
	move.l  d0,a1                      ; Base
	move.l  _SysBase(pc),a6            ; SysBase
	JSRLIB  CloseLibrary               ; Exec -> CloseLibrary

	move.l  _DOSBase(pc),d0            ; Base
	beq.s   .exit                      ; Skip
	move.l  d0,a1                      ; Base
	move.l  _SysBase(pc),a6            ; SysBase
	JSRLIB  CloseLibrary               ; Exec -> CloseLibrary
	
.exit
	moveq.l #0,d0                      ; Return code
	move.l  _Counter,d0                ; Return code
	rts                                ; Exit program

;----------------------------------------------------------

	EVEN

; A0: struct Hook *h
; A2: APTR reserved 
; A1: struct PacketMonitorMessage *pmm

MonitorFunc:
	addq.l  #1,_Counter                ; Counter++
	move.l  #MA_Continue,d0            ; Return Code
	rts                                ; Return

;----------------------------------------------------------

	EVEN

_Hook:
	ds.b h_SIZEOF

_Tags:
	dc.l 0
	dc.l 0
	dc.l 0

_Counter:
	dc.l 0

_SysBase:
	ds.l 1

_DOSBase:
	ds.l 1

_SocketBase:
	ds.l 1

_DOSName:
	dc.b "dos.library",0

_SocketName:
	dc.b "bsdsocket.library",0

;----------------------------------------------------------

VERSTRING:
	dc.b    "$VER: AddNetMonitorHookTags v0.1 (07.09.2020) ",10,0

;----------------------------------------------------------

	END

philippe
Grade reingestolpert
Grade reingestolpert
Posts: 4
Joined: 06.09.2020 - 12:57

Re: AddNetMonitorHookTagList example

Post by philippe »

One question please,

The documentation explain clearly that not all stacks supports some feature. So that we have to check availability of the feature. But, more generally, which stacks support them ?

For example, is SBTC_HAVE_MONITORING_API specific to RoadShow ?

There a number of tools in Aminet for Miami, to monitor the traffic such as :
http://aminet.net/package/comm/tcp/MiLoad
http://aminet.net/package/comm/tcp/MiamiGraph

Unfortunately, i see they are not provided with any source code, and are specifics to Miami. Which makes me think each stack seems provides own methodology. If those new tags/flags are Roadshow specific, at least, it is nice to see there is here a good attempt at trying to specify some (amiga) standard tech.

Also, i ve seen there are another approach, at a different level, per driver interface, the SANA api gives also some methodology.

Such as :
http://aminet.net/package/comm/net/sanamon11
http://aminet.net/package/comm/net/SANA2Meter

But i like the global one from the stack itself.

Post Reply