I am new to the SNMP protocol. I want to know how snmpd
processes SNMP requests. For example:
snmpget -v1 -c public localhost sysName
My understanding is it is implementing MIBs, e.g. SNMPv2-MIB, but is executing the uname -n
command?
I am new to the SNMP protocol. I want to know how snmpd
processes SNMP requests. For example:
snmpget -v1 -c public localhost sysName
My understanding is it is implementing MIBs, e.g. SNMPv2-MIB, but is executing the uname -n
command?
For the net-snmp snmpd mapping for the sysname OID see system_mib.c where it is sometimes indeed based on uname
, see code snippet below:
#ifdef HAVE_GETHOSTNAME
gethostname(sysName, sizeof(sysName));
#else
#ifdef HAVE_UNAME
strlcpy(sysName, utsName.nodename, sizeof(sysName));
#else
#if defined (HAVE_EXECV) && !defined (mingw32)
sprintf(extmp.command, "%s -n", UNAMEPROG);
/*
* setup defaults
*/
extmp.type = EXECPROC;
extmp.next = NULL;
exec_command(&extmp);
strlcpy(sysName, extmp.output, sizeof(sysName));
if (strlen(sysName) >= 1)
sysName[strlen(sysName) - 1] = 0; /* chomp new line */
#else
strcpy(sysName, "unknown");
#endif /* HAVE_EXECV */
#endif /* HAVE_UNAME */
#endif /* HAVE_GETHOSTNAME */
To understand how snmpd
internally works look at agent architecture page on net-snmp site.
It is detailed and also explains how to extend net-snmp with new MIBs.