Hi Dave,
 
Thank you for your response. For some reason I am not getting any E-mail from 
net-snmp mailing list any more. Neither in my in box nor spam box. That's why I 
posted my answer twice yesterday and today I check the archive in net-snmp 
forum and I saw my E-mail along with your response. I tried to re-register 
again but my E_mail address was already in the system.
I am not sure what is the issue but I appreciate if someone can give me some 
hints.
 
Back to my original question from you regarding Tables:
 
I don't have any get_first or get_next in my code.  I tried with snmpget and I 
realized that my TableHandler gets call twice per a single query.
 
I put the TableHandler( created by mib2c) below for your review: As you can see 
there is a call fill_Table()( I added).  This is the function I need to call to 
populate data into the table.
I would like to call it once( at the very beginning) to response to either 
snmpget or snmpwalk
 
Best Regards,
Reza
 
 int
athStatusTable_handler(netsnmp_mib_handler 
*handler,netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
structathStatusTable_entry *table_entry;int
ret;
switch(reqinfo->mode) {
/** Read-support (also covers GetNext requests)
*/
caseMODE_GET:
//We  fill the data here//fill_table();
for(request = requests; request; request = request->next) {table_entry = (
structathStatusTable_entry *)netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch(table_info->colnum) {
caseCOLUMN_ATHINDEX:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athIndex);
break;
caseCOLUMN_ATHNAMES:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
(u_char *) table_entry->athNames,
table_entry->athNames_len);
break;
caseCOLUMN_ATHSCANNINGPERIOD:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
(u_char *) table_entry->
athScanningPeriod,
table_entry->
athScanningPeriod_len);
break;
caseCOLUMN_ATHOUTPUT:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athOutput);
break;
caseCOLUMN_ATHINPUT:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athInput);
break;
caseCOLUMN_ATHCRC:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athCrc);
break;
caseCOLUMN_ATHPHY:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athPhy);
break;
caseCOLUMN_ATHLONGR:
if(!table_entry) {netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->athLongr);
break;
default:netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHOBJECT);
break;}
}
break;
/** Write-support
*/
caseMODE_SET_RESERVE1:
for(request = requests; request; request = request->next) {table_entry = (
structathStatusTable_entry *)netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch(table_info->colnum) {
caseCOLUMN_ATHSCANNINGPERIOD:
/** or possiblc 'netsnmp_check_vb_type_and_size' 
*/ret =
netsnmp_check_vb_type_and_max_size(request->requestvb,
ASN_OCTET_STR,
sizeof(table_entry->athScanningPeriod));
if(ret != SNMP_ERR_NOERROR) {netsnmp_set_request_error(reqinfo, request, ret);
returnSNMP_ERR_NOERROR;}
break;
default:netsnmp_set_request_error(reqinfo, request,
SNMP_ERR_NOTWRITABLE);
returnSNMP_ERR_NOERROR;}
}
break;
caseMODE_SET_RESERVE2:
break;
caseMODE_SET_FREE:
break;
caseMODE_SET_ACTION:
for(request = requests; request; request = request->next) {table_entry = (
structathStatusTable_entry *)netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch(table_info->colnum) {
caseCOLUMN_ATHSCANNINGPERIOD:memcpy(table_entry->old_athScanningPeriod,
table_entry->athScanningPeriod,
sizeof(table_entry->athScanningPeriod));table_entry->old_athScanningPeriod_len =
table_entry->athScanningPeriod_len;
memset(table_entry->athScanningPeriod, 0,
sizeof(table_entry->athScanningPeriod));memcpy(table_entry->athScanningPeriod,
request->requestvb->val.string,
request->requestvb->val_len);
table_entry->athScanningPeriod_len =
request->requestvb->val_len;
break;}
}
break;
caseMODE_SET_UNDO:
for(request = requests; request; request = request->next) {table_entry = (
structathStatusTable_entry *)netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch(table_info->colnum) {
caseCOLUMN_ATHSCANNINGPERIOD:memcpy(table_entry->athScanningPeriod,
table_entry->old_athScanningPeriod,
sizeof(table_entry->athScanningPeriod));memset(table_entry->old_athScanningPeriod,
 0,
sizeof(table_entry->athScanningPeriod));table_entry->athScanningPeriod_len =
table_entry->old_athScanningPeriod_len;
break;}
}
break;
caseMODE_SET_COMMIT:
break;}
returnSNMP_ERR_NOERROR;}
 
 
 
 
 
 
On 2 January 2013 18:59, Reza Salehi <rezsalehi@...> wrote:
> The only problem I have is  myTableHandler  gets call multiple times while
> it is iterating during the GET or SET. Can you be a bit more explicit about 
> exactly what is happening? For a single GET request, you should see: -  one 
> call of the 'get_first' hook routine -  multiple calls of the 'get_next' hook 
> routine (as many times as there are rows in the table -  followed by one call 
> of myTableHandler For a single SET request, I believe you should see something
similar, except with four calls to the myTableHandler. How does that compare 
with what you actually see?
(I suggest you try with a single "snmpget" command rather than walking the 
whole table - as that should give a clearer view of what is happening) > Is 
there anyway to define a call back function during table registration to
> gets call once  either before starting iteration the table or after
> finishing it? If you mean before/after walking the whole table, then no.
The agent doesn't know that the table is being walked - it simply
receives a sequence of GetNext requests, which is processes
individually. If you mean before/after the sequence of calls to the iterator
hooks that will run through the table, then that should be easy
('get_first' is called at the start, and the handler will be called at the 
end). But it's not clear to me exactly what you are trying to do here,
or what the underlying problem actually is. Dave
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to