SK_NEW_SESSION(3)

πŸ“¦ version 0.9, in ubuntu jammy

πŸ’– SK_NEW_SESSION(3) πŸ’–

okay so bestie, welcome to the sk_new_session(3) page from the Library Functions Manual, and no cap this one is the blueprint for spinning up your very own SNMPSESSION. let's get into it 🫢


✨ NAME ✨

sk_new_session β€” bestie we're literally creating a brand new SNMPSESSION out here πŸ’…


🌸 SYNOPSIS 🌸

#include <snmpkit.h>

SNMPSESSION *sk_new_session(char *host, void
*(start_routine)(SNMPSESSION*), const char *community);

SNMPSESSION **sk_new_sessions(char *hostspec,const char *community,void
*(start_routine)(SNMPSESSION*));

SNMPSESSION **sk_new_sessions_multi(char **hostspecs, const char
*community, void *(start_routine)(SNMPSESSION*));

πŸ¦‹ DESCRIPTION πŸ¦‹

so an SNMP_session instance? it's an object that handles alllll the details of talking to an SNMP enabled device, like a printer or a router. it's giving personal assistant energy for your network gear, fr fr.

there are three versions of sk_new_sessions (yes the family is a little chaotic). two of the parameters are identical across all of them. the first one is the one that changes between versions. iykyk.

a SNMP community string acts as a password. normally there are two strings set for an SNMP enabled device. one will allow the user write access to settings via SNMP commands, and the second password will only allow for read access to device settings. so like, one of them has main character energy and the other one is on read-only mode πŸ™ˆ.

you must also provide a pointer to the start_routine function. the start_routine() is the function used to actually do the work of communicating with the network device. in other words, this function is called when the thread handling this particular device is activated. in other words (yes, again), this function actually loads up the packets with the SNMP objects and then makes the requests. each SNMPSESSION has its own thread, and once the thread is created β€” when the start_function function is called, it is passed the SNMPSESSION pointer as a parameter. periodt. πŸ’«

the first parameter varies between the functions:

  • in the case of sk_new_session it is simply a hostname in a format understood by gethostbyname(3).
  • in the case of sk_new_sessions, instead of a simple hostname, a hostspec is passed in. a hostspec can be a simple hostname, but it can also be:
    • an IP address range in the form of 192.168.0.1-5
    • an IP address and a subnet mask in the form of either 192.168.0.0/255.255.255.0 or 192.168.0.0/24

a hostspec may also include a community name by enclosing that in parenthesis like 192.168.0.1(public). iconic, honestly πŸŽ€


πŸ‘‘ RETURN VALUE πŸ‘‘

upon successful completion, sk_new_session returns a pointer to a SNMPSESSION. ✨

sk_new_sessions and sk_new_sessions_multi both return a null terminated array of SNMPSESSION pointers.

otherwise NULL is returned and sk_errno is set to indicate the error. not the vibe, but okay, we move 😭


πŸ’€ ERRORS πŸ’€

  • SK_MEM_FAIL β€” memory allocation failed. tragic.
  • SK_BAD_PROTO β€” UDP protocol is not supported. see getprotobyname(3).
  • SK_SOCKET_FAIL β€” can't create socket. see socket(2).
  • SK_RECEIVER_FAIL β€” can't create a thread to receive packets. sets errno. see pthread_create(3).
  • SK_HOSTNOTFOUND β€” host not found. sets h_errno. see gethostbyname(3).
  • SK_REAPER_FAIL β€” can't create a thread to reap spent threads. sets errno. see pthread_create(3).
  • SK_WORKER_FAIL β€” can't create worker thread. sets errno. see pthread_create(3).
  • SK_UNTERM_HOSPEC β€” community in hostspec doesn't have ending parenthesis. the parentheses are NOT optional bestie, close them πŸ’…
  • SK_OCTET_OVERFLOW β€” one of the octets in hostspec is greater than 255. ma'am that is not a real octet.
  • SK_BAD_NETMASK β€” subnet mask wasn't in a understood form.
  • SK_NETMASK_OVERFLOW β€” number of bits in subnet mask is too large.
  • SK_DIS_NETMASK β€” subnet mask had discontinious bits. 😭

🌈 SEE ALSO 🌈

sk_strerror(3), sk_snmpsessions_done(3), sk_new_sfiller(3), sk_new_snmptable(3)


and that's the whole page bestie, every single option, error and reference accounted for β€” no gatekeeping here 🫢

okay so that's a wrap on sk_new_session(3) from GNU snmpkit 0.4, dated November 2000. slay, bye πŸ’–βœ¨

πŸ“¦ where this page comes from