OTLookupName
Finds and returns all addresses that correspond to a particular name or name pattern, or confirms that a name is registered.C INTERFACE
OSErr OTLookupName (MapperRef ref, TLookupRequest* req, TLookupReply* reply);C++ INTERFACES
OSErr TMapper::LookupName (TLookupRequest* req, TLookupReply* reply);PARAMETERS
ref- A mapper reference.
req- A
TLookupRequeststructure (page 4-13) that specifies the name to be looked up as well as some additional values that the mapper provider can use to circumscribe the search.reply- A
TLookupReplystructure (page 4-14) that specifies the size and location of a buffer containing the names found, and the number of names found.DESCRIPTION
You can use theOTLookupNamefunction to find out whether a name is registered and what address is associated with that name. You use thereqparameter to supply the information needed for the search: what name should be looked up and, optionally, what node contains that information, how many matches you expect to find, and how long the search should continue before the function returns. On return, thereplyparameter contains thenamesfield that points to the buffer where the matching entries are stored and therspcountfield that specifies the number of matching entries.For each registered name found, the
OTLookupNamefunction stores the following information in the buffer referenced by thenamesfield of thereplyparameter:
unsigned short addrLen; /* length of address that follows*/ unsigned short nameLen; /* length of name that follows */ unsigned char addr[]; /* address */ unsigned char name[]; /* name, padded to quad-word boundary*/If you are searching for names using a name pattern and you expect that more than one name will be returned to you, you need to parse the reply buffer to extract the matching names.If you call the
OTLookupNamefunction asynchronously, the mapper provider calls your notifier function passing one of two completion codes for thecodeparameter (T_LKUPNAMERESULTorT_LKUPNAMECOMPLETE) and passing thereplyparameter in thecookieparameter. The mapper provider passes theT_LKUPNAMERESULTcode each time it stores a name in the reply buffer, and it passes theT_LKUPNAMECOMPLETEcode when it is done. When you receive this event, examine therspcountfield to determine whether there is a last name to retrieve from the reply buffer. The use of both codes is a feature that gives you a choice about how to process multiple names when searching for names matching a pattern.
The
- If you decide to allocate a buffer that is large enough to contain all the names returned, you can ignore the
T_LKUPNAMERESULTcode and call a function that parses the buffer once theOTLookupNamefunction has completed--that is, once the provider calls your notifier function using theT_LKUPNAMECOMPLETEevent.- If you want to save memory or if you don't know how large a buffer to allocate, you can use the following method to process the names returned. Each time that the
T_LKUPNAMERESULTevent is passed, you must do something with the reply from the reply buffer. You can copy it somewhere, or you can delete it if it isn't a name you're interested in. Then, from inside your notifier you must set thereply->names.lenfield or thereply->rspcountfield back to 0 (thus allowing the mapper provider to overwrite the original name). This tells the mapper provider that you are ready to receive another name. Accordingly, when the mapper provider has inserted another name into your reply buffer, it calls your notifier passing theT_LKUPNAMERESULTcode, and you can process the new entry as you have processed the first entry. This method also saves you the trouble of having to parse through the buffer to extract name and address information.
cookieparameter to the notifier contains thereplyparameter.The format of the names and protocol addresses are specific to the underlying protocol. Consult the documentation supplied for your protocol for more information.
COMPLETION EVENT CODES
T_LKUPNAMECOMPLETE0x2000000 FThe OTLookupNamefunction has completed. Thecookieparameter of the notifier function points to thereplyparameter.SEE ALSO
You use theOTDeleteNamefunction (page 4-22) or theOTDeleteNameByIDfunction, (page 4-24) to delete a registered name.A sample program that parses the reply buffer to extract matching names is shown in the section "Searching for Names," beginning on page 4-7.
For information on how to use this function with a TCP/IP protocol, see page 8-20 in the TCP/IP chapter.
Notifier functions are described in the chapter "Providers" in this book.
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help