Packet



Summary


#include <rssnmp/snmp.h>
Function Description
rssnmp_packet_New() Variable initializer.
rssnmp_packet_NewFromData() Variable initializer, using received packet.
rssnmp_packet_NewFromContainer() Variable initializer, using packet container.
rssnmp_packet_Free() Variable destructor.
rssnmp_packet_Print() Variable print method.
rssnmp_packet_PrintFull() Variable print method (detailed packet data).
rssnmp_packet_AddVarbind() Add a new varbind to the packet.
rssnmp_packet_Encode() Encode packet data.


Initializers, destructor and print methods

Synopsis

rssnmp_packet_t rssnmp_packet_New(uint8_t version, char *community, uint8_t pdu, uint32_t request_id);

rssnmp_packet_t rssnmp_packet_NewFromData(void *data, int datasize);

rssnmp_packet_t rssnmp_packet_NewFromContainer(rssnmp_field_t packet_container);

void rssnmp_packet_Free(rssnmp_packet_t p);

void rssnmp_packet_Print(rssnmp_packet_t p, FILE *fp, char *offset);

void rssnmp_packet_PrintFull(rssnmp_packet_t p, FILE *fp, char *offset);

Description

A new SNMP packet can be instanced using rssnmp_packet_New(), providing version, community, PDU and request ID. The rssnmp_packet_NewFromData() and rssnmp_packet_NewFromContainer() initializers create a new packet out of raw packet data, either directly from recv() data or from a rssnmp_field_t variable that represents the entire packet container.

Return Value

All initializers return NULL on error.



Packet PDU types


#define ASN_GETREQUEST 0xA0
#define ASN_GETNEXTREQUEST 0xA1
#define ASN_GETRESPONSE 0xA2
#define ASN_SETREQUEST 0xA3
#define ASN_TRAP 0xA4
#define ASN_BULKREQUEST 0xA5
#define ASN_INFORMREQUEST 0xA6
#define ASN_TRAP_V2 0xA7


SNMP version definitions


#define SNMP_VERSION_1 0
#define SNMP_VERSION_2c 1
#define SNMP_VERSION_3 3


Packet Handling

Synopsis

int rssnmp_packet_AddVarbind(rssnmp_packet_t p, rssnmp_varbind_t v);

uint8_t *rssnmp_packet_Encode(rssnmp_packet_t p, int *size);

Description

Once the packet is created, you need to add varbinds to it. To do so, you may use the rssnmp_packet_AddVariable() method.

In order to send the packet using the sendto() function, you must first encode it. Do so with the rssnmp_packet_Encode(). It will return the malloc'd area with packet data and its size will be written in size.

Return Value

rssnmp_packet_AddVarbind() will return 0 upon success.

The rssnmp_packet_Encode() method will return NULL on error.