[comp.sys.mac.programmer] SUMMARY: Trying to use MacTCP with THINK LSC 3.02 - SOLVED - the winner is...

tony@rata.vuw.ac.nz (Tony Martindale) (01/11/91)

  "Yes folks,... you can stop calling us now, finally a winner has
been found.  Can I have the envelope please, (sterotypic net.hostess
delivers the SMTP envelope) ... the winner is, (a pause while the
envelope is opened and the From: line read) ... Pete Resnick aka
resnick@cogsci.uiuc.edu!  Congratulations! (Pete's mailbox is flooded
with congratulatory messages)..."

  And for those who are interested, an autopsy of the problem follows
(longish):


In article <1991Jan10.040350.20238@ux1.cso.uiuc.edu> resnick@cogsci.uiuc.edu (Pete Resnick) writes:
>tony@rata.vuw.ac.nz (Tony Martindale) writes:
>
>>>OSErr openMacTCPdriver()
>>>{
>>>	
>>>	OSErr PBOpen();
>        ^^^^^^^^^^^^^^^
>*********************This shouldn't be here*********************

Oh how right you are. I should have noticed this when this worked:

OSErr openMacTCPdriver()
{
	
	OSErr PBOpen();
	OSErr result;
	ioParam paramblock;
	
	
	/*bzero(&paramblock, sizeof(paramblock));
	
	paramblock.ioNamePtr = (StringPtr) DRIVERNAME;
	paramblock.ioPermssn = fsCurPerm;*/
	
	result = OpenDriver(DRIVERNAME, &refnum);
	/*result = PBOpen(&paramblock, 0);*/
	
	if (result != noErr) {
		printf("OpenDriver failed with return code:
%d.",result);
	}
	
	return(result);

}

But this didn't!

OSErr openMacTCPdriver()
{
	
	OSErr OpenDriver();
	OSErr result;
	ioParam paramblock;
	
	
	/*bzero(&paramblock, sizeof(paramblock));
	
	paramblock.ioNamePtr = (StringPtr) DRIVERNAME;
	paramblock.ioPermssn = fsCurPerm;*/
	
	result = OpenDriver(DRIVERNAME, &refnum);
	/*result = PBOpen(&paramblock, 0);*/
	
	if (result != noErr) {
		printf("OpenDriver failed with return code:
%d.",result);
	}
	
	return(result);

}

>>>	
>>>	UDPiopb paramblock;
>>>	Str255 drivername;
>>>	OSErr result;
>>>	boolean notasync = FALSE;
>>>	
>>>	strcpy(drivername, "\p.IPP");
>>>	
>>>	paramblock.ioCompletion = NULL;
>>>	paramblock.ioNamePtr = (char *) drivername;
>*********************Insert Here******************************
>	paramblock.csCode = 0;

Yeah, I switched to using ioParam instead of UDPiopb.

>>>	
>>>	result = PBOpen((ParmBlkPtr) &paramblock,notasync);
>>>	
>>>	if (result != noErr)
>>>		printf("PBOpen failed with return code: %d.",result);
>>>	
>>>	return(result);
>>>
>>>}
>
>I FOUND THE ANSWER!!! This was starting to bug me. There were two problems

                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Touche!

>with the code. The first, and most important, was your re-declaration of
>PBOpen. First, you don't need it since THINK C should take care of it for
>you, and second, you did it wrong: it's a Pascal procedure if it's in the
>Toolbox! When I commented it out in, I no longer got -35 as an error. But
>wait there's more....
>

This was it folks - I promise never to do it again :) I now can get
both PBOpen and OpenDriver to work successfully.

>Now I got a -23, which is bad permission code. In a real call to PBOpen,
>you'd be using the ioParam, not a csParam type parameter block. You are
>required to set ioPermssn to 0 (fsCurPerm). Since you are using the
>UDPiopb for your parameter block, csCode should be set to 0 since it is
>in the same position as ioPermssn. Once I did that, it worked fine.
>

Like I said above, fixed by using ioParam and bzero'ing the whole
thing.

>Like someone else said, the strcpy is probably not a good idea.
>

A lot of replies/responses thought this

	strcpy(drivername, "\p.IPP");

was the problem.  It was always null terminated when I peeked at it
using the debugger no matter how I allocated it, it is still a C
string. And once you pass the pointer to the Toolbox what does it
matter? It *is* a pascal string, all you need is the count at the
beginning (in the case of "\p.IPP", 4), the null is not used. I know
you have to be careful that you know what sort of strings you are
dealing with (what do ya mean that string starts with number?), but in
this case it was not the problem.

Again, many thanks to those who replied/responded. Almost everyone had
some useful information even if it did not win the grand prize :-).
The groovy net.folks were:

  "Michael A. Libes" <ml10+@andrew.cmu.edu
  Pete Resnick <resnick%cogsci.uiuc.edu@RELAY.CS.NET>	/* THE WINNER */
  davidp%calvin.usc.edu@usc.edu (David Peterson)
  Bill Cramer <cramer%iex@uunet.UU.NET>
  edmoy@violet.berkeley.edu				/* Runner up */
  eby@pegasus.att.com					/* Runner up */
  mattiasb@dront.nada.kth.se (Mattias Berglund)
  bernard@boulder.colorado.edu (Bernie Bernstein)


-- 
Tony Martindale                     Computing Services Centre,
email: tony@rata.vuw.ac.nz          Victoria University of Wellington,
phone: +64 4 721 000 x8453          P.O. Box 600, Wellington, NEW ZEALAND.