Previous | Contents | Index |
Processes a pending message that sent by the master agent.
int esnmp_poll ()
This routine is called after the select() call has indicated data is ready on the eSNMP socket. (This socket was returned from the call to the esnmp_init routine.If a received message indicates a problem, an entry is made to the syslog file and an error status is returned.
If the received message is a request for eSNMP data, the object table is checked and the appropriate method routines are called.
ESNMP_LIB_OK The esnmp_poll routine completed successfully. ESNMP_LIB_BAD_REG The master agent failed in a previous registration attempt. See the log file. ESNMP_LIB_DUPLICATE An OPEN error occurred. A duplicate subagent identifier has already been received by the master agent. ESNMP_LIB_NO_CONNECTION The master agents OPEN request failed. Restart the connection after a delay. See the log file. ESNMP_LIB_CLOSE A CLOSE message was received. Restart the connection after a delay. ESNMP_LIB_NOTOK An eSNMP protocol error occurred and the packet was discarded. ESNMP_LIB_LOST_CONNECTION Communication with the master agent was lost. Restart the connection.
Sends ICMP ECHO_REQUEST packets (ping) to the master agent.
int esnmp_are_you_there ()
The esnmp_are_you_there routine does not block waiting for a response. It is intended to cause the master agent to reply immediately. The response should be processed by calling the esnmp_poll routine.If no response is received within the timeout period, the application code restarts the eSNMP protocol by calling the esnmp_init routine. There are no timers maintained by the eSNMP library.
ESNMP_LIB_OK The ICMP ECHO_REQUEST was sent. ESNMP_LIB_LOST_CONNECTION The ICMP ECHO_REQUEST packet cannot be sent because the master agent is down.
Sends a trap message to the master agent.
int esnmp_trap (int *generic_trap, int specific_trap, char *enterprise, varbind *vb)
generic_trap
A generic trap code.specific_trap
A specific trap code.enterprise
An enterprise OID string in dot notation.vb
A VARBIND list of data (a null pointer indicates no data).
This function can be called any time. If eSNMP has not initialized through the master agent, traps are queued and sent when communication is possible.The trap message is actually sent to the master agent after it responds to the esnmp_init routine. This occurs with every API call and for most esnmp_register routines. The quickest process to send traps to the master agent is to call the esnmp_init, esnmp_poll, and esnmp_trap routines.
The master agent formats the trap into an eSNMP trap message and sends it to management stations based on its current configuration.
The master agent does not respond to the content of the trap. However, the master agent does return a value that indicates whether the trap was received successfully.
ESNMP_LIB_OK The routine has completed successfully. ESNMP_LIB_LOST_CONNECTION Could not send the trap message to master agent. ESNMP_LIB_NOTOK Something failed and the message could not be generated.
Sends a close message to the master agent and shuts down eSNMP.
void esnmp_term (void)
Subagents should call this routine when terminating, so that the master agent can update its MIB registry more quickly.
ESNMP_LIB_OK The esnmp_term always returns ESNMP_LIB_OK even if the packet could not be sent.
Converts UNIX system time obtained from gettimeofday into a value with the same time base as sysUpTime.
unsigned int esnmp_sysuptime (struct timeval *timestamp)
*timestamp
A pointer to struct timeval contains a value obtained from the gettimeofday system call. The structure is defined in include/sys/time.h.A null pointer means return the current sysUpTime.
This routine provides a mechanism to convert UNIX timestamps into eSNMP TimeTicks. The function returns the value that sysUpTime held when the passed timestamp was now. Passing a null timestamp returns the current value of sysUpTime.This routine can be used as a TimeTicks data type (the time since the eSNMP master agent started) in units of 1/100 second. The time base is obtained from the master agent at OPEN time so calls to this function before that time will not be accurate.
0 An error occurred because a gettimeofday failed. Otherwise, timestamp time is 1/100 second since the eSNMP protocol started.
#include <include/sys/time.h> #include <esnmp.h> struct timeval timestamp; gettimeofday(×tamp, NULL); ... o_integer(vb, object, esnmp_sysuptime(×tamp));
5.2 Support Routines
The support routines are optional but are provided as a convenience to
developers writing method routines that handle specific management
information base (MIB) elements. The support routines provided include
the following:
Loads an integer value into the VARBIND structure with the appropriate type.
int o_integer (VARBIND *vb, OBJECT *obj, unsigned long value)
*vb
A pointer to the VARBIND structure that is supposed to receive the data. This function does not allocate the VARBIND structure.*obj
A pointer to the OBJECT structure for the MIB variable associated with the OID in the VARBIND structure.value
The value to be inserted into the VARBIND structure.The real type as defined in the object structure must be one of the following, otherwise an error is returned.
- ESNMP_TYPE_Integer32:
32-bit INTEGER- ESNMP_TYPE_Counter32:
32-bit Counter (unsigned)- ESNMP_TYPE_Gauge32:
32-bit Gauge (unsigned)- ESNMP_TYPE_TimeTicks:
32-bit TimeTicks (unsigned)- ESNMP_TYPE_UInteger32:
32-bit INTEGER (unsigned)- ESNMP_TYPE_Counter64:
64-bit Counter (unsigned)- ESNMP_TYPE_IpAddress:
"IMPLICIT OCTET STRING (4)"
Note
If the real type is IpAddress, then eSNMP assumes that the 4-byte integer is in network byte order and packaged it into an octet string.
ESNMP_MTHD_noError The routine completed successfully. ESNMP_MTHD_genErr An error has occurred.
include <esnmp.h> #include "ip_tbl.h" <-- for ipNetToMediaEntry_type definition VARBIND *vb = method->varbind; OBJECT *object = method->object; ipNetToMediaEntry_type *data; switch(arg) { case I_atIfIndex: return o_integer(vb, object, data->ipNetToMediaIfIndex);
Loads an octet value into the VARBIND structure with the appropriate type.
int o_octet (VARBIND *vb, OBJECT *obj, OCT *oct)
*vb
A pointer to the VARBIND structure that is supposed to receive the data. This function does not allocate the VARBIND structure.
Note
If the original value in the VARBIND structure is not null, this routine attempts to free it. So if you dynamically allocate memory or issue the malloc command. Fill the structure with zeros before using it.*obj
A pointer to the OBJECT structure for the MIB variable associated with the OID in the VARBIND structure.*oct
The value to be inserted into the VARBIND structure.The real type as defined in the object structure must be one of the following, otherwise an error is returned.
- ESNMP_TYPE_OCTET_STRING:
OCTET STRING (ASN.1)- ESNMP_TYPE_IpAddress
IMPLICIT OCTET STRING (4) - in octete form, network byte order- ESNMP_TYPE_DisplayString
DisplayString (Textual Con)- ESNMP_TYPE_NsapAddress
IMPLICIT OCTET STRING- ESNMP_TYPE_Opaque
IMPLICIT OCTET STRING- ESNMP_TYPE_BIT_STRING:
BIT STRING (ASN.1) - The first byte is the number of unused bits in the last byte.
ESNMP_MTHD_noError The routine completed successfully. ESNMP_MTHD_genErr An error occurred.
#include <esnmp.h> #include "ip_tbl.h" <-- for ipNetToMediaEntry_type definition VARBIND *vb = method->varbind; OBJECT *object = method->object; ipNetToMediaEntry_type *data; switch(arg) { case I_atPhysAddress: return o_octet(vb, object, &data->ipNetToMediaPhysAddress);
Loads an OID value into the VARBIND structure with the appropriate type.
int o_integer (VARBIND *vb, OBJECT *obj, OID *oid)
*vb
A pointer to the VARBIND structure that is supposed to receive the data. This function does not allocate the VARBIND structure.
Note
If the original value in the VARBIND structure is not null, this routine attempts to free it. So if you dynamically allocate memory or issue the malloc command. Fill the structure with zeros before using it.*obj
A pointer to the OBJECT structure for the MIB variable associated with the OID in the VARBIND structure.*oid
The value to be inserted into the VARBIND structure as data.The real type as defined in the object structure must be one of the following, otherwise an error is returned.
- ESNMP_TYPE_OBJECT_IDENTIFIER
- OBJECT IDENTIFIER (ASN.1)
ESNMP_MTHD_noError The routine completed successfully. ESNMP_MTHD_genErr An error occurred.
#include <esnmp.h> #include "ip_tbl.h" <-- for ipNetToMediaEntry_type definition VARBIND *vb = method->varbind; OBJECT *object = method->object; ipNetToMediaEntry_type *data; switch(arg) { case I_atObjectID: return o_oid(vb, object, &data->ipNetToMediaObjectID);
Loads a string value into the VARBIND structure with the appropriate type.
int o_string (VARBIND *vb, OBJECT *obj, unsigned character *ptr, int *len)
*vb
A pointer to the VARBIND structure that is supposed to receive the data. This function does not allocate the VARBIND structure.
Note
If the original value in the VARBIND structure is not null, this routine attempts to free it. So if you dynamically allocate memory or issue the malloc command. Fill the structure with zeros before using it.*obj
A pointer to the OBJECT structure for the MIB variable associated with the OID in the VARBIND structure.*ptr
The pointer to the buffer containing data to inserted into the VARBIND structure as data.*len
The length of the data in buffer pointed to by ptr.The real type as defined in the object structure must be one of the following, otherwise an error is returned.
- ESNMP_TYPE_OCTET_STRING:
OCTET STRING (ASN.1)- ESNMP_TYPE_IpAddress
IMPLICIT OCTET STRING (4) - in octete form, network byte order- ESNMP_TYPE_DisplayString
DisplayString (Textual Con)- ESNMP_TYPE_NsapAddress
IMPLICIT OCTET STRING- ESNMP_TYPE_Opaque
IMPLICIT OCTET STRING- ESNMP_TYPE_BIT_STRING:
BIT STRING (ASN.1) - The first byte is the number of unused bits in the last byte.
- ESNMP_TYPE_OBJECT_IDENTIFIER
OBJECT IDENTIFIER (ASN.1) - in dot notation, 1.3.4.6.3.
ESNMP_MTHD_noError The routine completed successfully. ESNMP_MTHD_genErr An error occurred.
#include <esnmp.h> #include "ip_tbl.h" <-- for ipNetToMediaEntry_type definition VARBIND *vb = method->varbind; OBJECT *object = method->object; ipNetToMediaEntry_type *data; switch(arg) { case I_atPhysAddress: return o_string(vb, object, data->ipNetToMediaPhysAddress.ptr, data->ipNetToMediaPhysAddress.len);
Converts a null-terminated string OID in dot notation to an OID structure.
oid *str2oid (oid *oid, char *s)
The routine dynamically allocates the buffer and inserts its pointer into the OID structure passed in. The caller is responsible to free this buffer. The OID can have a maximum of 128 elements.
Note
The str20id routine does not allocate an OID structure.
null An error occurred or the pointer to the OID structure (its first argument) has been returned.
include <esnmp.h> #define SOMETHING_BIG 1024 OID abc; char buffer[SOMETHING_BIG]; : : assume abc gets initialized with some value : printf("dots=%s\n", sprintoid(buffer, &abc));
Converts an OID into a null-terminated string.
char *sprintoid (char *buffer, oid *oid)
An OID can have up to 128 elements. A full-sized OID can require a large buffer.
The return values are its first argument.
#include <esnmp.h> #define SOMETHING_BIG 1024 OID abc; char buffer[SOMETHING_BIG]; : : assume abc gets initialized with some value : printf("dots=%s\n", sprintoid(buffer, &abc));
Copies the object's base OID and appends a copy of the instance array to make a complete OID for a value.
oid instance2oid (oid *new, obj *obj, unsigned int *instance, int *len)
*new
A pointer to OID that is to receive the new OID value.*obj
A pointer to the object table entry for the MIB variable being obtained. The first part of the new OID is the OID from this MIB object table entry.*instance
A pointer to an array of instance values. These values are appended to the base OID obtained from the MIB object table entry to construct the new OID.*len
The number of elements in the instance array.
The instance is an array of integers and len is the number of elements. The instance array may be created by oid2instance or constructed from key values as a result of a get_next search.This routine dynamically allocates the buffer and inserts its pointer into the OID structure passed in. It is the responsibility of the caller to free this buffer.
You should point to the OID structure receiving the new values and then call the instance2oid routine. Previous values in the OID structure are freed and the new values are dynamically allocated and inserted. Be sure the initail value of the new OID is all zeros. If you do not want the value freed, the instance2oid routine does not allocate an OID structure, only the array containing the elements.
null An error occurred or the pointer to the OID structure (its first argument) has been returned.
#include <esnmp.h> VARBIND *vb; <-- filled in OBJECT *object; <-- filled in unsigned int instance[6]; -- Construct the outgoing OID in a GETNEXT -- -- Instance is N.1.A.A.A.A where A's are IP address -- instance[0] = data->ipNetToMediaIfIndex; instance[1] = 1; for (i = 0; i < 4; i++) { instance[i+2]=((unsigned char *)(&data->ipNetToMediaNetAddress))[i]; } instance2oid(&vb->name, object, instance, 6);
Extracts the instance values from an OID and copies them to the specified array of integers. The routine then returns the number of elements in the array.
int oid2instance (oid *oid, obj *obj, unsigned int *instance, int *max_len)
*oid
An incoming OID containing an instance or part of an instance.*obj
A pointer to the object table entry for the MIB variable.*instance
A pointer to an array of unsigned integers where the index is placed.*max_len
The number of elements in the instance array.
The instance values are the elements of an OID beyond those that identify the MIB variable. These elements identify a specific instance of a MIB value.If there are more elements in the OID than specified by the max_len parameter, the function copies the number of elements specified by max_len only and returns the total number of elements that would have been copied had there been space.
LESS THAN ZERO An error occurred. This should not occur if the object was obtained by looking at this OID. ZERO No instance elements. GREATER THAN ZERO The number of index elements. This could be larger than the max_len parameter.
#include <esnmp.h> OID *incoming = &method->varbind->name; OBJECT *object = method->object; int instLength; unsigned int instance[6]; -- in a GET operation -- -- Expected Instance is N.1.A.A.A.A where A's are IP address -- instLength = oid2instance(incoming, object, instance, 6); if (instLength != 6) return ESNMP_MTHD_noSuchInstance;
Previous | Next | Contents | Index |