Compiling and Executing Browser Example
To compile Example 3-1, type:
% cc -o fnbrowse fnbrowse.c -lxfn |
To browse the namespace starting from the initial context, the program is invoked as:
% fnbrowse |
Or to browse a composite name and its descendents, type:
% fnbrowse composite_name |
Commands
The commands supported by the fnbrowse program are summarized in Table 3-1.
Table 3-1 Namespace Browser Commands
Command | Usage |
---|---|
down child | Sets the browser at the subcontext of the child |
up | Sets the browser at one level higher than the current context |
list | Lists the names bound within the current context |
show | Prints the reference of the current context |
show child | Prints the reference of the current context's child |
quit | Exits the browser |
Sample Output
Sample output for navigating the entire namespace is displayed here.
Note the following:
The first list command shows the initial context bindings.
The fnbrowse program lists all names it finds in the namespace, including names with underscores. These names are explained in "Initial Context Bindings".
The three dots (...) represent the global namespace.
% fnbrowse > list _myorgunit ... _myself thishost myself _orgunit _host _thisens myens thisens org orgunit thisuser _thishost myorgunit _user thisorgunit host _thisorgunit _myens user |
Navigating the namespace is accomplished with the up and down commands. In the following output, the down command brings the focus of the browser to the enterprise root of the namespace, thisens (can also be myens). The show command displays information about the reference and address type for thisens.
> down thisens > show Reference type: onc_fn_enterprise Address type: on_fn_nisplus length: 20 context type: enterprise root representation: normal version: 0 internal name: eng.wiz.com > up > down thisorgunit |
Continuing with the example, this list command shows the contexts for thisorgunit.
> list service _fs _host _service _site site _user host fs user > down usr Lookup failed: Name Not Found: 'usr' > down service > list printer > down printer |
The list command shows the printer names that are bound in the printer context. The show command displays the reference for the child, colorful.
> list celeste _default color colorful quartz nuttree puffin > show colorful printer Reference type: onc_printers Address type: onc_printers_bsdaddr length: 12 data: 0x00 0x00 0x00 0x08 0x62 0x6c 0x61 0x63 0x6b 0x63 ....blackc 0x61 0x74 at > down colorful Could not construct context handle: No Supported Address > quit % |
Printer Programming Example
Printer client and server software can take advantage of FNS to advertise and to browse the printers available with respect to organizations, sites, users, and hosts. The APIs used by the server and the client are XFN APIs, thereby ensuring that the application is portable across the different naming services used for storing printer bindings.
The programming example in this section shows how printer clients and servers obtain and store printer bindings. Users can then make use of the FNS commands, fnlist and fnlookup, to browse the printer context.
For example, use fnlist to look at the user printer context for jsmith:
% fnlist user/jsmith/service/printer celeste lp _default myprinter |
Similarly, you can look at the organization's printers:
% fnlist org/wiz.com/service/printer sales_printer mktg_printer eng_printer |
Alternatively, you can type:
% fnlist thisorgunit/service/printer |
You can look at the printers at a specific site, for example, the printers in the MTV site:
% fnlist thisorgunit/site/MTV/service/printer b1_printer b2_printer |
Client
The scenario for Example 3-2is a user who would like to print to a printer named colorful in his organization's context, thisorgunit/service/printer/colorful. The example printer client illustrates how the bindings for a specific printer are obtained.
The variable printer_binding contains the reference (the binding information) of the named printer. Using the binding information, the printer client can connect to the server and send the printer request. Note that the fn_ctx_lookup() function can be replaced by fn_ctx_list_name() or fn_ctx_list_bindings() to list all the names and their bindings.
Example 3-2 Print Client source