// An example that registers a node as print spooler,
// searches for any print spoolers registered on the network,
// and extracts the information for the first one found.
// Assuming inclusion of
#include <AppleTalk.h>
#include
#define mySocket 20
#define objstr "\pGene Station" // We are called "Gene Station
#define typestr "\pPrintSpooler" // and are of type "PrintSpooler
#define zonestr "\p*
#define numExpected 10 // The number of matches expected
void DoError (OSErr myErr); main ()
{
ATNBPRecHandle myABRecord;
short nbpNameBufSize;
if ( myErr)
DoError( myErr);
// Maybe serial port B isn't available for use by AppleTalk
else {
// Call Memory Manager to allocate ATNBPRec myABRecord = (ATNBPRecHandle) NewHandle (nbpSize); // Set up our entity name to register
// Allocate data space for the entity name (used by NBP)
nbpNameBufSize = *objstr + *typestr + *zonestr;
nbpNamePtr = NewPtr (nbpNameBufSize); (* myABRecord)->nbpEntityPtr = &myEntity;
(* myABRecord)->nbpBufPtr = nbpNamePtr;
// Buffer used by NBP internally
// Socket to register us on
(* myABRecord)->nbpBufSize = nbpNameBufSize;
(* myABRecord)->nbpAddress.aSocket = mySocket; // Retransmit every 64 ticks
// And try 3 times
if ( myErr)
DoError( myErr);
// Maybe the name is already registered somewhere
// else on the network
else {
// Now that we've registered our name, find others of
// type "PrintSpooler
// Any one of type "PrintSpooler" in our zone
(Ptr) "\pPrintSpooler", (Ptr) "\p*"); // Allocate space for return buffer which will contain
// a tuple for each match found
// Buffer to place responses in
(* myABRecord)->nbpEntityPtr = &searchEntity;
(* myABRecord)->nbpBufPtr = myBufPtr;
(* myABRecord)->nbpBufSize = sizeof (* myBufPtr);
// The field nbpDataField, before the NBPLookup call,
// represents an approximate number of responses. After the
// call, nbpDataField contains the actual number of responses
// received.
(* myABRecord)->nbpDataField = numExpected;
myErr = NBPLookup( myABRecord, async); // Make sync call if ( myErr)
DoError( myErr);
// Did the buffer overflow?
else {
// Get the first reply
(* myABRecord)->nbpDataField,1,
&myEntity, & entityAddr);
// The socket address and name of the entity are returned
// here. If we want all of them, we'll have to loop for
// each one in the buffer.
if ( myErr)
DoError( myErr);
// Maybe the one we wanted wasn't in the buffer
}
}
}
}