(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);
}