term% ls -F
term% cat index.txt
NDB(2)                        System Calls Manual                       NDB(2)

       ndbopen,  ndbclose, ndbreopen, ndbsearch, ndbsnext, ndbgetval, ndbfree,
       ipattr, ipinfo, ndbhash, ndbparse, csgetval - network database

       #include <u.h>
       #include <libc.h>
       #include <bio.h>
       #include <ndb.h>

       Ndb*       ndbopen(char *file);

       int        ndbreopen(Ndb *db);

       void       ndbclose(Ndb *db);

       Ndbtuple*  ndbsearch(Ndb *db, Ndbs *s, char *attr, char *val);

       Ndbtuple*  ndbsnext(Ndbs *s, char *attr, char *val);

       Ndbtuple*  ndbgetval(Ndb *db, Ndbs *s, char *attr, char *val,
                  char *rattr, char *buf);

       Ndbtuple*  csgetval(char *attr, char *val, char *rattr, char *buf);

       void       ndbfree(Ndbtuple *db);

       char*      ipattr(char *name);

       int        ipinfo(Ndb *db, char *ether, char *ip, char *name,
                  Ipinfo *iip);

       ulong      ndbhash(char *val, int hlen);

       Ndbtuple*  ndbparse(Ndb *db);

       These routines are used by network administrative  programs  to  search
       the  network database.  They operate on the database files described in

       Ndbopen opens the database file and calls malloc(2) to allocate a  buf‐
       fer for it.  If file is zero, all network database files are opened.

       Ndbreopen  checks if the database files associated with db have changed
       and if so throws out any cached information and reopens the files.

       Ndbclose closes any database files associated with  db  and  frees  all
       storage associated with them.

       Ndbsearch  and  ndbsnext  search a database for an entry containing the
       attribute/value pair, attr=val.  Ndbsearch is used to  find  the  first
       match  and  ndbsnext  is used to find each successive match.  On a suc‐
       cessful search both return a linked list  of  Ndbtuple  structures  ac‐
       quired by malloc(2) that represent the attribute/value pairs in the en‐
       try.  On failure they return zero.

              typedef struct Ndbtuple Ndbtuple;
              struct Ndbtuple {
                      char      attr[Ndbalen];
                      char      val[Ndbvlen];
                      Ndbtuple  *entry;
                      Ndbtuple  *line;
                      ulong     ptr;    /* for the application; starts 0 */

       The entry pointers chain together all pairs in the entry in a null-ter‐
       minated  list.   The line pointers chain together all pairs on the same
       line in a circular list.  Thus, a program can  implement  2  levels  of
       binding  for pairs in an entry.  In general, pairs on the same line are
       bound tighter than pairs on different lines.

       The argument s of ndbsearch has type Ndbs  and  should  be  pointed  to
       valid  storage before calling ndbsearch, which will fill it with infor‐
       mation used by ndbsnext to link  successive  searches.   The  structure
       Ndbs looks like:

              typedef struct Ndbs Ndbs;
              struct Ndbs {
                      Ndb      *db;   /* data base file being searched */
                      Ndbtuple *t;    /* last attribute value pair found */

       The  t  field  points  to the pair within the entry matched by the ndb‐
       search or ndbsnext.

       Ndbgetval searches the database for an entry containing not only an at‐
       tribute/value pair, attr=val, but also a pair with the attribute rattr.
       If successful, it copies the value associated with rattr into buf.  Buf
       must  point to an area at least Ndbvlen long.  Csgetval is like ndbget‐
       val but queries the connection server instead of  looking  directly  at
       the database.

       Ndbfree frees a list of tuples returned by one of the other routines.

       Ipattr takes the name of an IP system and returns the attribute it cor‐
       responds to:

              dom    domain name

              ip     Internet number

              sys    system name

       Ipinfo searches the database for Internet Protocol information about  a
       system and returns it in the structure addressed by iip.  The arguments
       ether (textual Ethernet address), ip (textual  IP  address),  and  name
       identify  the system.  At least one must be non-zero.  Ipinfo returns 0
       if successful, -1 otherwise.  Both bootp(8) and ipconfig(8) use  ipinfo
       to search the database.

       The  last  three calls are used by programs that create the hash tables
       and database files.  Ndbhash computes a hash offset  into  a  table  of
       length hlen for the string val.  Ndbparse reads and parses the next en‐
       try from the database file.  Multiple calls to ndbparse  parse  sequen‐
       tial entries in the database file.  A zero is returned at end of file.


       ndb(6) ndb(8)

       These routines set errstr.