

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.net-snmp.org/wiki/index.php?action=history&amp;feed=atom&amp;title=TUT%3Amib2c_scalar</id>
		<title>TUT:mib2c scalar - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.net-snmp.org/wiki/index.php?action=history&amp;feed=atom&amp;title=TUT%3Amib2c_scalar"/>
		<link rel="alternate" type="text/html" href="http://www.net-snmp.org/wiki/index.php?title=TUT:mib2c_scalar&amp;action=history"/>
		<updated>2026-05-05T04:26:47Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>http://www.net-snmp.org/wiki/index.php?title=TUT:mib2c_scalar&amp;diff=5534&amp;oldid=prev</id>
		<title>Rstory: Created page with &quot;The mib2c [http://net-snmp.git.sourceforge.net/git/gitweb.cgi?p=net-snmp/net-snmp;a=blob_plain;f=local/mib2c.scalar.conf;hb=HEAD scalar configuration file] generates a bare-bones...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.net-snmp.org/wiki/index.php?title=TUT:mib2c_scalar&amp;diff=5534&amp;oldid=prev"/>
				<updated>2012-04-18T14:07:14Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;The mib2c [http://net-snmp.git.sourceforge.net/git/gitweb.cgi?p=net-snmp/net-snmp;a=blob_plain;f=local/mib2c.scalar.conf;hb=HEAD scalar configuration file] generates a bare-bones...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The mib2c [http://net-snmp.git.sourceforge.net/git/gitweb.cgi?p=net-snmp/net-snmp;a=blob_plain;f=local/mib2c.scalar.conf;hb=HEAD scalar configuration file] generates a bare-bones skeleton handler for each scalar object. You must then write code to provide data for the object, handling each mode. For a complete example, see the [http://net-snmp.git.sourceforge.net/git/gitweb.cgi?p=net-snmp/net-snmp;a=blob_plain;f=agent/mibgroup/ip-mib/ip_scalars.c;hb=HEAD IP-MIB scalars implementation] in the source tree. Here is an excerpt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int ipAddressSpinLockValue;&lt;br /&gt;
&lt;br /&gt;
int&lt;br /&gt;
handle_ipAddressSpinLock(netsnmp_mib_handler *handler,&lt;br /&gt;
                         netsnmp_handler_registration *reginfo,&lt;br /&gt;
                         netsnmp_agent_request_info *reqinfo,&lt;br /&gt;
                         netsnmp_request_info *requests);&lt;br /&gt;
&lt;br /&gt;
/** Initializes the ip module */&lt;br /&gt;
void init_ip_scalars(void)&lt;br /&gt;
{&lt;br /&gt;
    static oid      ipAddressSpinLock_oid[] = { 1, 3, 6, 1, 2, 1, 4, 33 };&lt;br /&gt;
&lt;br /&gt;
    DEBUGMSGTL((&amp;quot;ip_scalar&amp;quot;, &amp;quot;Initializing\n&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
    netsnmp_register_scalar(netsnmp_create_handler_registration&lt;br /&gt;
                            (&amp;quot;ipAddressSpinLock&amp;quot;, handle_ipAddressSpinLock,&lt;br /&gt;
                             ipAddressSpinLock_oid,&lt;br /&gt;
                             OID_LENGTH(ipAddressSpinLock_oid),&lt;br /&gt;
                             HANDLER_CAN_RWRITE));&lt;br /&gt;
&lt;br /&gt;
    /* Initialize spin lock with random value */&lt;br /&gt;
    ipAddressSpinLockValue = (int) random();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int&lt;br /&gt;
handle_ipAddressSpinLock(netsnmp_mib_handler *handler,&lt;br /&gt;
                          netsnmp_handler_registration *reginfo,&lt;br /&gt;
                          netsnmp_agent_request_info   *reqinfo,&lt;br /&gt;
                          netsnmp_request_info         *requests)&lt;br /&gt;
{&lt;br /&gt;
    long   value;&lt;br /&gt;
&lt;br /&gt;
    /* We are never called for a GETNEXT if it&amp;#039;s registered as a&lt;br /&gt;
       &amp;quot;instance&amp;quot;, as it&amp;#039;s &amp;quot;magically&amp;quot; handled for us.  */&lt;br /&gt;
&lt;br /&gt;
    /* a instance handler also only hands us one request at a time, so&lt;br /&gt;
       we don&amp;#039;t need to loop over a list of requests; we&amp;#039;ll only get one. */&lt;br /&gt;
&lt;br /&gt;
    switch(reqinfo-&amp;gt;mode) {&lt;br /&gt;
&lt;br /&gt;
        case MODE_GET:&lt;br /&gt;
            snmp_set_var_typed_value(requests-&amp;gt;requestvb, ASN_INTEGER,&lt;br /&gt;
                                     (u_char *)&amp;amp;ipAddressSpinLockValue,&lt;br /&gt;
                                     sizeof(ipAddressSpinLockValue));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
#ifndef NETSNMP_NO_WRITE_SUPPORT&lt;br /&gt;
        /*&lt;br /&gt;
         * SET REQUEST&lt;br /&gt;
         *&lt;br /&gt;
         * multiple states in the transaction.  See:&lt;br /&gt;
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg&lt;br /&gt;
         */&lt;br /&gt;
        case MODE_SET_RESERVE1:&lt;br /&gt;
        case MODE_SET_RESERVE2:&lt;br /&gt;
            /* just check the value */&lt;br /&gt;
            value =  *(requests-&amp;gt;requestvb-&amp;gt;val.integer);&lt;br /&gt;
            if (value != ipAddressSpinLockValue)&lt;br /&gt;
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_INCONSISTENTVALUE);&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
        case MODE_SET_FREE:&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
        case MODE_SET_ACTION:&lt;br /&gt;
            /* perform the final spinlock check and increase its value */&lt;br /&gt;
            value =  *(requests-&amp;gt;requestvb-&amp;gt;val.integer);&lt;br /&gt;
            if (value != ipAddressSpinLockValue) {&lt;br /&gt;
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_INCONSISTENTVALUE);&lt;br /&gt;
            } else {&lt;br /&gt;
                ipAddressSpinLockValue++;&lt;br /&gt;
                /* and check it for overflow */&lt;br /&gt;
                if (ipAddressSpinLockValue &amp;gt; 2147483647 || ipAddressSpinLockValue &amp;lt; 0)&lt;br /&gt;
                    ipAddressSpinLockValue = 0;&lt;br /&gt;
            }&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
        case MODE_SET_COMMIT:&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
        case MODE_SET_UNDO:&lt;br /&gt;
             break;&lt;br /&gt;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */&lt;br /&gt;
&lt;br /&gt;
        default:&lt;br /&gt;
            /* we should never get here, so this is a really bad error */&lt;br /&gt;
            snmp_log(LOG_ERR, &amp;quot;unknown mode (%d) in handle_ipAddressSpinLock\n&amp;quot;, reqinfo-&amp;gt;mode );&lt;br /&gt;
            return SNMP_ERR_GENERR;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return SNMP_ERR_NOERROR;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{TUT:LIST}}&lt;/div&gt;</summary>
		<author><name>Rstory</name></author>	</entry>

	</feed>