Important: The information in this document is obsolete and should not be used for new development.
Getting a List of Zone Names for Your Local Network
If your application is running on a node that belongs to an extended network, the application can use the
or Its InternetGetLocalZonesfunction to obtain a list of the names of the zones in its node's local network. An application running on a node that belongs to an extended network can also use theGetZoneListfunction to obtain a list of the names of the zones throughout the AppleTalk internet to which its node's local network belongs. These functions behave similarly.ZIP returns a single ATP response per request. Because the complete list of zone
names may not fit in a single ATP response, you need to make repeated calls to eitherGetLocalZonesorGetZoneListuntil you receive all of the zone names. You must allocate a buffer to hold the zone names data that the ZIP function returns and point
to that buffer from the function'szipBuffPtrparameter block field. This buffer must be 578 bytes in size, large enough to hold an entire ATP response. ZIP returns the zone names into this buffer as a packed array of packed Pascal strings.The
zipNumZonesfield returns the actual number of zone names that ZIP placed in the buffer. You must set thezipLastFlagfield to 0 before you execute theGetZoneListorGetLocalZonesfunction. If thezipLastFlagparameter is still 0 when the command has completed execution, then ZIP is waiting to return more zone names. In this case you must empty the buffer, or allocate a new one, and call theGetZoneListorGetLocalZonesfunction again immediately. When there are no more zone names to return, ZIP sets thezipLastFlagfield to a nonzero value. ThezipInfoFieldfield is a 70-byte data buffer that you must allocate for use by ZIP. The first time you call any of these functions, you must set the first word of this field to 0. You must not change any values in this field subsequently.Listing 4-2 shows the application-defined
DoGetZoneListfunction, which illustrates how to use theGetZoneListfunction. TheGetLocalZonesfunction operates in exactly the same fashion.This
DoGetZoneListfunction allocates a buffer for zone names and repeatedly calls theGetZoneListfunction to get a list of zone names. IfGetZoneListreturns a function result ofnoErr, then theDoGetZoneListcode calls the application-definedMyZIPExtractfunction, shown in Listing 4-3, to remove a zone name from theGetZoneListbuffer and place it in the application's buffer. TheDoGetZoneListcode in Listing 4-2 does not show the application-definedMyAddToZoneListthat writes the zone name to the application's buffer.Listing 4-2 Using
GetZoneListto retrieve names of zones throughout the AppleTalk internet
FUNCTION DoGetZoneList: OSErr; CONST kZoneBufferSize = 578; {required size of zone list buffer} VAR xppPB: XPPParamBlock; result: OSErr; zoneBuffer: Ptr; index: Integer; zoneName: Str32; BEGIN {Allocate buffer for returned zone names.} zoneBuffer := NewPtr(kZoneBufferSize); IF zoneBuffer = NIL THEN result := MemError ELSE BEGIN WITH xppPB DO BEGIN xppTimeout := 3; {timeout interval} xppRetry := 4; {retry count} zipBuffPtr := zoneBuffer; {zone names returned here} zipLastFlag := 0; {set to 0 first time through} zipInfoField[1] := 0; {first word of zipInfoField must be } zipInfoField[2] := 0; { initialized to 0 the first time} END; {Loop to get all of the zone names.} REPEAT result := GetZoneList(@xppPB, FALSE); IF (result = noErr) THEN FOR index := 1 TO xppPB.zipNumZones DO IF MyZIPExtract(zoneBuffer, xppPB.zipNumZones, index, zoneName) = noErr THEN MyAddToZoneList(zoneName); UNTIL (xppPB.zipLastFlag <> 0) OR (result <> noErr); DisposPtr(zoneBuffer); {release memory} END; DoGetZoneList := result; END;When you call theGetZoneListfunction or theGetLocalZonesfunction to obtain a list of zone names, ZIP returns the zone names as a packed array of packed Pascal strings. Your application must include a routine to extract the zone names that you want from the buffer.Listing 4-3 shows an application-defined function called
MyZipExtractthat extracts
a particular zone name from the buffer of packed zone names returned by eitherGetZoneListorGetLocalZones.The
MyZipExtractfunction takes anumInBufinput parameter that specifies the number of zone names in the buffer pointed to by thetheBufferparameter. For thenumInBufparameter, you specify the value that ZIP returned in thezipNumZonesfield of the XPP parameter block used for theGetZoneListorGetLocalZonesfunction.You use the
whichOneinput parameter to identify the zone name to extract. TheMyZIPExtractfunction returns the zone name in thezoneNamestring parameter.The
MyZIPExtractfunction returns a result ofparamErrifwhichOneis 0 orwhichOne is greater than the number of zones in the buffer. Otherwise, the function returns a function result ofnoErr.Listing 4-3 Extracting a zone name from the list of zone names returned in the buffer
FUNCTION MyZIPExtract (theBuffer: Ptr; numInBuf: Integer; whichOne: Integer; VAR zoneName: Str32): OSErr; VAR result: OSErr; zonePtr: Ptr; BEGIN {preflight the input parameters} IF (whichOne = 0) OR (whichOne > numInBuf) THEN result := paramErr ELSE BEGIN zonePtr := theBuffer; {Look for whichOne} REPEAT whichOne := whichOne - 1; IF whichOne <> 0 THEN {move pointer to next zone name} zonePtr := Ptr(ORD4(zonePtr) + Length(StringPtr(zonePtr)^) + 1); UNTIL whichOne = 0; {return the zone name} BlockMove(zonePtr, @zoneName, Length(StringPtr(zonePtr)^) + 1); result := noErr; END; MyZIPExtract := result; END;