Novell Home

How to intercept EVENT PROTOCOL BIND (NetWare)

From Developer Community

This code demonstrates how to use RegisterForEvent() to install a handler for EVENT_PROTOCOL_BIND event.

Sample Code

#include <nwadv.h>
#include <nwerrno.h>
#include <nwthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

static unsigned int  volatile threadCount   = 0;
static          int  volatile exitRequested = 0;
static          int           mainThreadID;
static          int           mainThreadGroupID;

static void sigHandler( int sig_no) {
#ifdef __MWERKS__
#pragma unused( sig_no)
#endif
   int saved_thread_group_ID = SetThreadGroupID( mainThreadGroupID);
   signal( SIGTERM, sigHandler);
   exitRequested = !0;
   ResumeThread( mainThreadID);
   while ( threadCount) delay( 100);
   SetThreadGroupID( saved_thread_group_ID);
}
static void eventProc( unsigned long param, unsigned long user_param) {
#ifdef __MWERKS__
#pragma unused( param, user_param)
#endif
   int saved_thread_group_ID;
   ++threadCount;
   saved_thread_group_ID = SetThreadGroupID( mainThreadGroupID);
   puts( "eventProc called");
   SetThreadGroupID( saved_thread_group_ID);
   --threadCount;
}
int main() {
   unsigned long event_handle;
   ++threadCount;
   mainThreadID      = GetThreadID();
   mainThreadGroupID = GetThreadGroupID();
   signal( SIGTERM, sigHandler);
   event_handle = RegisterForEvent( EVENT_PROTOCOL_BIND, eventProc, NULL);
   if ( event_handle == EFAILURE) {
      signal( SIGTERM, SIG_DFL);
      puts( "RegisterForEvent failed");
      return EXIT_FAILURE;
   }
   puts( "Waiting...");
   SuspendThread( mainThreadID);
   UnregisterForEvent( event_handle);
   --threadCount;
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.