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 InternetGetLocalZones
function 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 theGetZoneList
function 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 eitherGetLocalZones
orGetZoneList
until 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'szipBuffPtr
parameter 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
zipNumZones
field returns the actual number of zone names that ZIP placed in the buffer. You must set thezipLastFlag
field to 0 before you execute theGetZoneList
orGetLocalZones
function. If thezipLastFlag
parameter 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 theGetZoneList
orGetLocalZones
function again immediately. When there are no more zone names to return, ZIP sets thezipLastFlag
field to a nonzero value. ThezipInfoField
field 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
DoGetZoneList
function, which illustrates how to use theGetZoneList
function. TheGetLocalZones
function operates in exactly the same fashion.This
DoGetZoneList
function allocates a buffer for zone names and repeatedly calls theGetZoneList
function to get a list of zone names. IfGetZoneList
returns a function result ofnoErr
, then theDoGetZoneList
code calls the application-definedMyZIPExtract
function, shown in Listing 4-3, to remove a zone name from theGetZoneList
buffer and place it in the application's buffer. TheDoGetZoneList
code in Listing 4-2 does not show the application-definedMyAddToZoneList
that writes the zone name to the application's buffer.
Listing 4-2 Using
GetZoneList
to 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 theGetZoneList
function or theGetLocalZones
function 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
MyZipExtract
that extracts
a particular zone name from the buffer of packed zone names returned by eitherGetZoneList
orGetLocalZones
.The
MyZipExtract
function takes anumInBuf
input parameter that specifies the number of zone names in the buffer pointed to by thetheBuffer
parameter. For thenumInBuf
parameter, you specify the value that ZIP returned in thezipNumZones
field of the XPP parameter block used for theGetZoneList
orGetLocalZones
function.You use the
whichOne
input parameter to identify the zone name to extract. TheMyZIPExtract
function returns the zone name in thezoneName
string parameter.The
MyZIPExtract
function returns a result ofparamErr
ifwhichOne
is 0 orwhichOn
e 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;