Apple Using Network Setup, Listing 2-15 Finding the active TCP/IP entity, Working with Sets

Models: Network Setup

1 184
Download 184 pages 5.56 Kb
Page 47
Image 47
Listing 2-15Finding the active TCP/IP entity

C H A P T E R 2

Using Network Setup

*activeEntity = (**entitiesInSet).fElements[entityIndex].fEntityRef; OTCfgChangeEntityArea(activeEntity, area);

}

 

if (entitiesInSet != nil) {

 

DisposeHandle( (Handle) entitiesInSet );

assert(MemError() ==

noErr);

 

}

 

return err;

 

}

 

The code in Listing 2-15 pulls together the process of finding an active set entity by finding the active TCP/IP set entity. It opens the database, calls MyFindFirstActiveEntity (Listing 2-14) with kOTCfgClassNetworkConnection and kOTCfgTypeTCPv4 as parameters, calls MyGetEntityUserVisibleName (Listing 2-9) to get and print the entity’s user visible name, and calls MyCloseDatabaseAfterReading (Listing 2-3) to close the database.

Listing 2-15Finding the active TCP/IP entity

static void PrintActiveTCPEntity(void)

{

OSStatus err;

CfgDatabaseRef dbRef;

CfgAreaID readArea;

CfgEntityRef activeTCPEntity;

Str255 userVisibleName;

err = MyOpenDatabaseForReading(&dbRef, &readArea); if (err == noErr) {

err = MyFindFirstActiveEntity(dbRef, readArea, kOTCfgClassNetworkConnection, kOTCfgTypeTCPv4, &activeTCPEntity);

if (err == noErr) {

err = MyGetEntityUserVisibleName(dbRef, &activeTCPEntity, userVisibleName);

}

if (err == noErr) {

Working with Sets

47

Page 47
Image 47
Apple manual Using Network Setup, Listing 2-15 Finding the active TCP/IP entity, Working with Sets