SNMP_table(3)

πŸ“¦ version 0.9, in ubuntu jammy

πŸ’– SNMP_table(3) β€” the SNMP_table glow-up πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about SNMP_table β€” a C++ object for requesting and storing a table of SNMP settings. she's from the Library Functions Manual and she is serving structure. let's get into it πŸ¦‹


✨ NAME ✨

SNMP_table β€” a C++ object for requesting and storing a table of SNMP settings. that's it, that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

#include <snmpkit>

SNMP_table(SNMP_session &session, unsigned int slen);

void get(list<void*> &dest);

unsigned int stlen();

look at her. so compact. so iconic. πŸ’…


🫢 DESCRIPTION 🫢

so here's the tea: an SNMP_table is a derivation of the SNMP_structFiller(3) class, and her whole purpose β€” her main character mission, if you will β€” is to automate fetching all the rows within a SNMP table. πŸ”₯

how does she do it? she keeps firing off multiple get_next requests against a group of objects, over and over, until she literally falls off the end of the table. no cap. she just keeps going until there's nothing left. πŸ’€


🧚 SNMP_table::SNMP_table(SNMP_session &session, void *(new_funct)());

creates a brand new SNMP_table object. ✨

  • the session parameter = which SNMP-enabled device you're querying (who's getting the ask)
  • new_funct = a function that allocates and initializes the underlying data structure, and hands back a void* to it

🌈 the append methods

void SNMP_structFiller::append_int(const string &oidstr,void (*fp)(void*,long));
void SNMP_structFiller::append_counter (const string &oidstr, void (*fp)(void*,long));
void SNMP_structFiller::append_timetick (const string &oidstr, void (*fp)(void*,unsigned long));
void SNMP_structFiller::append_ipaddr (const string &oidstr, void (*fp)(void*,const unsigned char *));
void SNMP_structFilleri::append_string(const string &oidstr, void (*fp)(void*,const char *));

every single one of these append methods adds an SNMP object to the end of the underlying SNMP_structFiller instance. periodt. πŸ’…

each method needs two things:

  • the OID of the SNMP object you're adding
  • a function that'll insert it into the associated structure
⚠️ important, bestie: this library does not attempt to read MIBs. so you're gonna need to look up the OID string beforehand and hard code that OID string into your program. no shortcuts, no MIB magic, you're on your own for that part πŸ™ˆ

now, the job of that function pointer? it inserts whatever data it gets back into the data structure. and because you control it, you can do any kind of munging around you want with the data you get β€” which means your receiving structure can be as complicated as your heart desires. πŸ‘‘

want examples? go look at the example programs included with the SNMPkit documentation (snmptest*.C) β€” they show various uses of this. go, read, slay. πŸ“

πŸ’€ Exceptions

  • BerOidBadSubOidException β€” one of the OIDs could not be converted to a number.
  • BerNoOidsException β€” no OIDs were specified.

πŸ’œ void SNMP_structFiller::remove(const string &oidstr);

deletes an SNMP object from the underlying SNMP_structFiller instance. bye girl, we don't need you anymore πŸ‘‹

πŸ’€ Exceptions

  • FillerRemoveEmptyException β€” someone tried to remove from an empty SNMP_structFiller object; this is a programming error, not a you-did-nothing-wrong situation.
  • FillerRemoveNotFoundException β€” someone tried to remove an item that isn't currently in the container; also a programming error.
  • FillerCorruptException β€” the SNMP table entry got successfully removed, BUT the OID sequence was NULL; this is a programming error inside the library itself.
  • OidSeqRemoveNotFoundException β€” a programming error resulted in an attempt to remove something that was not there.
  • OidSeqBadLayoutException β€” the BER sequence did not follow the layout of an OID sequence.

πŸ”₯ void SNMP_table::get(list<void*> &dest);

this is the method: reads multiple rows of information from an SNMP device and inserts them into the destination list. she's the whole point of the operation, honestly. ⭐

πŸ’€ Exceptions

and listen, there are a LOT of them, because networking is chaos and we respect that:

  • SNMPNoResponseException β€” the SNMP_structFiller object did not receive a response from the remote SNMP Agent. this can be caused by many things: no agent running on the destination, a firewall sitting between you and the destination, etc. 😭
  • SNMPPacketNotSequenceException β€” the response received was not a valid SNMP response.
  • SNMPRespNotSequenceException β€” the packet received was a valid SNMP response, but the payload of the packet wasn't a sequence type.
  • SNMPNotResponseTagException β€” the type of the SNMP response received was invalid (not 0xa2).
  • SNMPSeqnoNotIntException β€” the sequence number of the response was not classified as a number.
  • SNMPStateNotIntException β€” the SNMP device sent back an improperly constructed response packet and the status was not classified as an integer.
  • SNMPFaultOidNotIntException β€” a response came back with an error, but the index to the problem OID was not classified as an integer.
  • OidSeqBadLayoutException β€” within a SNMP packet there's a substructure which is an OID sequence. if the packet was supposed to have an OID sequence in a particular location but for some reason one of the elements wasn't of the correct type, then this exception gets thrown.
  • SNMPBadOidException β€” an OID in the SNMP response packet was invalid.
  • SocketSendShortExecption β€” an error occurred while sending the SNMP request, resulting in an incomplete transmission of the query.
  • BerSequenceTagException, BerIntTagException, BerCounterTagException, BerStringTagException, BerNullTagException, BerOidTagException, BerTimeTickTagException β€” although this will result from an encoding error, it's caused by calling a BER object constructor on an invalid piece of data.
  • BerLengthException, BerIntLengthExecption, BerCounterLengthExecption, BerNullLengthExecption, BerTimeTickLengthExecption, BerIPAddrLengthExecption β€” the size of the data to be encoded (BER) will not fit into an unsigned long data type.
🫢 no fr, that list is long but every single one of those is a real thing that can happen to you. respect the exceptions, they're just trying to tell you what went wrong.

πŸ‘€ SEE ALSO πŸ‘€

SNMP_structFiller(3), SNMP_table(3)


πŸŽ€ AUTHOR πŸŽ€

the SNMPkit C/C++ library was originally developed by Ben Woodard <ben@users.sourceforge.net>. this man page was written by Gerald Carter <gcarter@valinux.com>. legends, honestly. πŸ‘‘


and that's the whole page, bestie!! πŸ’– this one's from GNU snmpkit 0.4, dated November 2000 β€” so yeah, she's vintage, she's retro, she's still out here fetching tables. iykyk. now go hard code those OIDs and slay. βœ¨πŸ¦‹πŸŒΈπŸ’…


πŸ“¦ where this page comes from