Chapter 9, Developing SMUX peers for SNMP agents
Syntax

Syntax

The syntax of MIB objects is modeled by the OS (Object Syntax) structure:

              typedef int (*IFP) ();

typedef struct object_syntax { char *os_name; /* syntax name */

int os_type; /* syntax type */ IFP os_decode; IFP os_free; /* free data */

} *OS; #define NULLOS ((OS) 0)

The syntaxes defined by the Internet-standard MIB are already implemented: 

Table 9-1 Internet-standard MIB defined syntaxes

 ---------------------------------------------------------------------
 Syntax             Structure type
 ---------------------------------------------------------------------
 INTEGER            integer
 OctetString        struct _OctetString
 ObjectID           struct OIDentifier
 NULL               char
 DisplayString      struct _OctetString
 IpAddress          struct sockaddr_in
 NetworkAddress     struct sockaddr_in
 Counter            integer
 Gauge              integer
 TimeTicks          integer
 ClnpAddress        struct _OctetString
where ``syntax'' is the name appearing in a compiled MIB module, and ``structure type'' is the C language data type corresponding to the object's syntax. The structure types are described below.

To take a syntax name and get back the structure, use the routine text2syn().

Here are the structures and routines used to implement some of these low-level MIB abstractions: Integer, OctetString, ObjectID, and IPAddress. 

INTEGER, Counter, Gauge, and TimeTicks

integer is used for the INTEGER, Counter, Gauge, and TimeTicks syntaxes. The definition is:

            typedef int integer;


OctetString, DisplayString, and ClnpAddress

struct _OctetString is used for the OctetString, DisplayString, and ClnpAddress syntaxes. The definition is:

               typedef struct _OctetString {
                   unsigned char *octet_ptr;   /* list of octets */
                   long     length;            /* number of elements */
               };


ObjectID

struct OIDentifier is used for the ObjectID syntax. The definition is:

typedef struct OIDentifier { int oid_nelem; /* number of sub-identifiers */

unsigned int *oid_elements; /* the (ordered) list of sub-identifiers */ } OIDentifier, *OID; #define NULLOID ((OID) 0)



IPAddress and NetworkAddress

struct sockaddr_in is used for the IpAddress and NetworkAddress syntaxes. It is assumed that you are familiar with this structure. If not, consult the file /usr/include/sys/netinet/in.h.