NOTE - If you link with the libnetmgt_db.so library, the libnetmgt.so library must also be used, wit hlibnetmgt_db.so being listed before libnetmgt.so in the command line. The libnetmgt.so library may be used without the libnetmgt_db.so library.
host% cc myprog.c -o myprog -R /opt/SUNWconn/snm/lib -L /opt/SUNWconn/snm/lib -lnetmgt_db |
8.2.1.2 Dynamic Linking for the Solaris 1.1.1 Environment
To dynamically link your application with the libraries
provided with the Solaris 1.1.1 version of this product, follow this format:
host% cc myprog.c -o myprog -L /usr/snm/lib -lnetmgt_db -lnetmgt -lnsl |
8.2.2 Static Linking
When you statically link your program, you can include the
following libnetmgt libraries:
NOTE - If you link with the libnetmgt_db.a library, the libnetmgt.a library must also be used, wit hlibnetmgt_db.a being listed before libnetmgt.a in the command line. The libnetmgt.a library may be used without the libnetmgt_db.a library.
host% cc myprog.c -o myprog -L /opt/SUNWconn/snm/lib -Bstatic -lnetmgt_db -lnetmgt -lnsl |
If you use the static method, you must specifically link in libdl.
8.2.2.2 Static Linking in a Solaris 1.1.1 Environment
To statically link your application with the
libraries provided for the Solaris 1.1 version of this product, follow this
format:
host% cc myprog.c -o myprog -L /usr/snm/lib -Bstatic -lnetmgt_db -lnetmgt -lnsl |
If you use the static method, you must specifically link in libdl.
The following is an example of how to call snmdb_open()
.
if (!snmdb_open()) exit(1); |
The snmdb_lock() and snmdb_unlock()
functions lock and unlock the database. Call snmdb_lock() to
lock the database before you make changes to the database. After the database
updates are done, you should call snmdb_unlock() to release the
lock.
NOTE - While the database is locked,
Console users cannot perform any operations (such as sending and viewing requests)
from the Console. Therefore, you should minimize the time that the database
is locked. snmdb_lock allows you the option of displaying a clock
on the Console while the database is locked.
The following is an example of how to call snmdb_lock()
and snmdb_unlock().
NOTE - The lock and unlock functions
cause low-priority trap reports to be generated when elements are added, changed,
or deleted in the database. These trap reports are sent to the event dispatcher,
which then forwards the reports to registered management applications. See
Section 2.4, "Trap Reports,"
on page 2-4
, for more information.
NOTE - The examples shown in the
following sections are program fragments only. A complete program example
is included in the product structure in thefile view_db.c
in the API_examples directory.
8.6.1 Retrieving Information for a Single Element
To retrieve information about a single element from
the database, you must first read the element cluster record into the cluster
record buffer by calling snmdb_read. You can then retrieve any
of the records contained in an element's cluster record. See the Administration
Guide for information on cluster records. For agent and membership (view)
records, you can either retrieve an enumerated list of the agent or view
records or you can retrieve a specific agent or view record for the element.
To retrieve a piece of element information for
a single element, do the following:
NOTE - A call to snmdb_read
initializes the cluster record buffer; therefore, you do not need to clear
the buffer before reading subsequent cluster records into the internal buffer.
In the header file netmgt_db.h
, the data type of the cluster record buffer is defined as:
typedef struct { |
The following code segment shows how to retrieve information on the element "andrew:"
8.6.2 Retrieving Elements of a Given Type
To retrieve the names of elements
of a given type in a particular view or in all views, do the following:
NOTE -
The element <type> for the element you are adding must be
defined in a schema file; there is no API for adding a new element <type>
.
To add a new element
into the database, do the following:
NOTE -
See the Administration Guide for
information on adding a new element types.
To modify an element, do the following: