mike@shogun.cc.umich.edu (Michael Nowak) (01/30/89)
I originally posted this in comp.sys.mac...
I'm trying to experiment with AppleTalk with my shiny new Lightspeed C
compiler and I'm having trouble using the new "preferred interface" to
AppleTalk listed in Volume V. Specifically, I'm trying to write some
code to register an entity on the network, and then look for entities
of that type. I can't get it to work - it usually crashes big time
with a call to PLookupName().
Let me state specifically what I am doing, in hopes that someone will
see the error of my ways. Here's what the call to PLookupName() looks
like:
search_name.objStr[0] = 0x01;
search_name.objStr[1] = '=';
search_name.typeStr[0] = 0x01;
search_name.typeStr[1] = '=';
search_name.zoneStr[0] = 0x01;
search_name.zoneStr[1] = '*';
mpp_pb_ptr = (MPPPBptr)NewPtr(sizeof(MPPParamBlock));
if (mpp_pb_ptr == (MPPPBptr)0) {
err_code = app_memoryErr;
goto nomppptr;
}
mpp_pb_ptr->ioCompletion = (ProcPtr)0;
mpp_pb_ptr->NBPentityPtr = (Ptr)&search_name;
mpp_pb_ptr->NBPretBuffPtr = (Ptr)entity_buffer;
mpp_pb_ptr->NBPretBuffSize = 1080;
mpp_pb_ptr->NBPmaxToGet = 10;
mpp_pb_ptr->NBPinterval = 8;
mpp_pb_ptr->NBPcount = 3;
err_code = PLookupName(mpp_pb_ptr, false);
entity_buffer is defined as char entity_buffer[1080]. I originally
tried using NBPSetEntity to set up search_name but have used this
approach to cut down on places where I could mess up. The code crashes
in the PLookupName call, with an odd address exception at 0x4345a0.
Does anyone have any source code which might do such a thing that I can
use as an example? Or if someone can point me to an ftp server which
might have such an example, I'd appreciate that too. I looked at sumex
but only found an example using the "alternate" or old interface. If
you can send me mail, that'd be great.
Any advice would be appreciated.
-----------------------------------------------------------------------------
Michael Nowak ...mailrus!shogun!mike
Workstation Consultant mike@shogun.cc.umich.edu
U of M Computing Center User Services Mike_Nowak@um.cc.umich.edu
...working for but in no way representing the University of Michigan...
tim@hoptoad.uucp (Tim Maroney) (01/30/89)
In article <894@mailrus.cc.umich.edu> mike@shogun.cc.umich.edu () writes: >I'm trying to experiment with AppleTalk with my shiny new Lightspeed C >compiler and I'm having trouble using the new "preferred interface" to >AppleTalk listed in Volume V. Specifically, I'm trying to write some >code to register an entity on the network, and then look for entities >of that type. I can't get it to work - it usually crashes big time >with a call to PLookupName(). > > search_name.objStr[0] = 0x01; > search_name.objStr[1] = '='; > search_name.typeStr[0] = 0x01; > search_name.typeStr[1] = '='; > search_name.zoneStr[0] = 0x01; > search_name.zoneStr[1] = '*'; You haven't stated how search_name is declared, but my best guess is that it's your problem. First, the documentation of LookupName in Inside Mac II-323 is slightly misleading. It says "EntityPtr points to the entity's name (in the form shown in figure 13 above)." However, in fact the structure in figure 13 is a names table entry and you only want to use the trailing part of that structure, the entity name. Don't include the pointer to next entry, internet address, or "used internally" byte. Second, unless you have declared each of objStr, typeStr, and zoneStr as "char[2]", you are initializing incorrectly. The entity name is not three Str255's in a row, but three variable-size strings with no space between them. If you declared like "struct { char objStr[256], typeStr[256], zoneStr[256]; }" instead, the name will be parsed incorrectly; one string should start where the previous one ends. It is best just to use an unstructured character buffer for formatting entity names. > mpp_pb_ptr = (MPPPBptr)NewPtr(sizeof(MPPParamBlock)); > if (mpp_pb_ptr == (MPPPBptr)0) { > err_code = app_memoryErr; > goto nomppptr; > } Why not just put the parameter block on the stack? That is, in an auto variable? No sense risking running out of memory and imposing an extra allocation overhead. However, this code is not your crashing problem. > mpp_pb_ptr->ioCompletion = (ProcPtr)0; > mpp_pb_ptr->NBPentityPtr = (Ptr)&search_name; > mpp_pb_ptr->NBPretBuffPtr = (Ptr)entity_buffer; > mpp_pb_ptr->NBPretBuffSize = 1080; > mpp_pb_ptr->NBPmaxToGet = 10; > mpp_pb_ptr->NBPinterval = 8; > mpp_pb_ptr->NBPcount = 3; > err_code = PLookupName(mpp_pb_ptr, false); This looks fine, which is why I think the problem must be in the search_name parameter. One useful debugging technique in these situations is to look at the network with Peek and see if you are actually sending out any lookup packets and getting any response. This should provide you with useful information, particularly if the search name is formatted incorrectly. One afterthought: Why are you passing "=" in the type field if you want to look only for things of a particular type? The string you're using, if formatted correctly, will look for all entities of all types on every zone your bridges can reach. You need to fill in with a specific type string. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "Don't talk to me about disclaimers! I invented disclaimers!" - The Censored Hacker
duggie@Jessica.stanford.edu (Doug Felt) (01/31/89)
I could not tell from your original posting what the structure of search_name was. It should be packed (IM V2 refers somewhat cryptically to "the form shown in figure 13 above") with each pascal string immediately following the previous one. If you use NBPSetEntity you should get a valid entity name. Still, I don't think that would cause a crash. The rest of the code looks ok to me. I have LSC code at home that works, which I can send. I am myself trying to write up some routines for a generic server, so if anyone else has done this or has sample code perhaps they can post it. Doug Felt Courseware Authoring Tools Porject Stanford University