Re: working with tables...

This is a discussion on Re: working with tables... within the SNMP Coders forums, part of the Networking and Network Related category; --===============2051931462== Content-Type: multipart/alternative; boundary="----=_Part_1672_27823242.1208459770000" ------=_Part_1672_27823242.1208459770000 Content-Type: text/plain; charset=ISO-8859-1 ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Coders

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008
Alejandro Islas
 
Posts: n/a
Default Re: working with tables...

--===============2051931462==
Content-Type: multipart/alternative;
boundary="----=_Part_1672_27823242.1208459770000"

------=_Part_1672_27823242.1208459770000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Ok...using gdb I found where my code crashes. In the handler function that
follows

MonThreadsTable_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;
MonThreadsTable_entry *table_entry=NULL;
char arreglo[300];

switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request=requests; request; request=request->next) {
table_entry = (MonThreadsTable_entry *)
netsnmp_extract_iterator_context(request);
if(table_entry==NULL)
DEBUGMSGTL(("MonThreadsTable","NULL POINTER"));
.......

the function netsnmp_extract_iterator_context(request) returns a null
pointer instead of a pointer to the first
entry of my list. I checked and my linked list is being generated and
updated correctly (I'm printing each entry values constantly), so I guess
I'm missing something at initialization time....here's my initialization
function.

void
initialize_table_MonThreadsTable(void)
{
static oid MonThreadsTable_oid[] = {1,3,6,1,4,1,17723,2,1,1,19,1};
size_t MonThreadsTable_oid_len = OID_LENGTH(MonThreadsTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;

reg = netsnmp_create_handler_registration(
"MonThreadsTable", MonThreadsTable_handler,
MonThreadsTable_oid, MonThreadsTable_oid_len,
HANDLER_CAN_RONLY
);

table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info,
ASN_INTEGER, /* index: IdThread */
0);
table_info->min_column = 1;
table_info->max_column = 4;

iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
iinfo->get_first_data_point = MonThreadsTable_get_first_data_point;
iinfo->get_next_data_point = MonThreadsTable_get_next_data_point;
iinfo->table_reginfo = table_info;

netsnmp_register_table_iterator( reg, iinfo );

/* Initialise the contents of the table here */
}

Do you see someting wrong??? How do I link my table with the request info
used by the netsnmp_extract_iterator_context function??

Thanks again,

Alejandro


On Thu, Apr 17, 2008 at 11:00 AM, Alejandro Islas <alex.islas@gmail.com>
wrote:

>
>
> On Thu, Apr 17, 2008 at 3:47 AM, Dave Shield <D.T.Shield@liverpool.ac.uk>
> wrote:
>
> > On 17/04/2008, Alejandro Islas <alex.islas@gmail.com> wrote:
> > > I tried to use mib2c.container.conf file but mib2c
> > > wasn't able to found it

> >
> > Hmmm... what version of the toolkit are you using?
> > mib2c.container.conf has been around since the 5.2 release
> > (although the internals have changed significantly since then).
> >
> > I'm using NET-SNMP version: 5.2.1.2
> >
> >
> > > 1)After using mib2c my .c file only contains create/remove entries
> > > functions. As far as I understand, I need to implement a fetch entrie,

> > to
> > > avoid duplicate row entries..correct???

> >
> > Sorry - I don't understand what you're asking here.
> >

>
> After using mib2c to generate my code, I noticed that it created a
> create_row_entry and a
> remove_row_entry functions. I implemented a fetch_row_entry, so that
> my code would be able to check
> if it doesn't have a previously created entry for a particular index.
>
> >
> >
> > > 2) Besides including data reading functions (i'm using text files),

> >
> > What do you mean by "data reading functions"?
> > How are you storing the table contents within your module?

>
>
> I read a text file created by another process. Each line of such text
> file contains a row's info
> of my table, so my process checks for such entry(using the index) in
> the linked list and updated it or create a new entry
> if its the first time I received inf of such row.
>
> >
> >
> > > do I need to do anything else?? I did not do anything to the handler,
> > > get_first_data_point and get_next_data_point functions, I left them as

> > mib2
> > > generated them.

> >
> > The get_{first,next}_data_point routines need to step through the
> > rows of your table - in whatever way is appropriate for your module.
> > The template code assumes that the table is held as a linked list
> > of individual row entries - if this is how your data reading functions
> > store the table, then you probably don't need to change this code
> > much (if at all).
> > If you are storing the table in a different manner (or pulling it from
> > external sources), then you will need to amend these two routines
> > to match.

>
>
> Yes, I'm using the linked list of individual row entries created by
> mib2c.
>
> >
> >
> > > 3) Could you explain (or send me an info link) of how my table

> > handler is
> > > called by the system?? I don't see where my table list is called on

> > it.
> >
> > When you register the table, the agent includes this information in
> > a list of all the OIDs that it knows about. When it receives a
> > request,
> > it searches this list for the appropriate match(es), and calls the
> > corresponding handlers.
> >
> >
> > > 4) I used gdb...but didn't help me a lot, it only confirmed a

> > segmentation
> > > fault.

> >
> > But it should also indicate *where* this segmentation fault occurs.
> > This would help track down what is causing it.

>
>
> You're right, I think I need to play a little bit more with gbd
>
> >
> >
> > > I'm not compiling the whole project, only adding my so files using
> > > dlmod command. Can I still use dbg using this method or do I need to

> > compile
> > > the whole deamon including my handlers???

> >
> > Ummm... not sure.
> > It would probably be sensible to start by working with a "traditional"
> > approach,
> > at least until you get the module working. The same module code can be
> > embedded within the main agent, loaded dynamically, or used within a
> > subagent - with no changes to the code.
> >

>
> I'll try this and let you know.
>
> Alejandro
>
>


------=_Part_1672_27823242.1208459770000
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Ok...using gdb I found where my code crashes. In the handler function that follows<br><br>MonThreadsTable_handler(<br>&nbsp;& nbsp;&nbsp; netsnmp_mib_handler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp; *handler,<br>&nbsp;&nbsp;&nbsp; netsnmp_handler_registration&nbsp;&nbsp;&nbsp;&nbs p;&nbsp; *reginfo,<br>&nbsp;&nbsp;&nbsp; netsnmp_agent_request_info&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *reqinfo,<br>
&nbsp;&nbsp;&nbsp; netsnmp_request_info&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; *requests) {<br><br>&nbsp;&nbsp;&nbsp; netsnmp_request_info&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; *request;<br>&nbsp;&nbsp;&nbsp; netsnmp_table_request_info *table_info;<br>&nbsp;&nbsp;&nbsp; MonThreadsTable_entry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp; *table_entry=NULL;<br>&nbsp;&nbsp;&nbsp; char arreglo[300];<br>
<br>&nbsp;&nbsp;&nbsp; switch (reqinfo-&gt;mode) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp; * Read-support (also covers GetNext requests)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp; */<br>&nbsp;&nbsp;&nbsp; case MODE_GET:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp; for (request=requests; request; request=request-&gt;next) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp; table_entry = (MonThreadsTable_entry *)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; netsnmp_extract_iterator_context(request);<br>&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if(table_entry==NULL)<br>&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DEBUGMSGTL((&quot;MonThreadsTable&quot;,&quot;NULL POINTER&quot;));<br>......<br><br>&nbsp;the function netsnmp_extract_iterator_context(request) returns a null pointer instead of a pointer to the first<br>
entry of my list. I checked and my linked list is being generated and updated correctly (I'm printing each entry values constantly), so I guess I'm missing something at initialization time....here's my initialization function.<br>
<br>void<br>initialize_table_MonThreadsTable(void) <br>{<br>&nbsp;&nbsp;&nbsp; static oid MonThreadsTable_oid[] = {1,3,6,1,4,1,17723,2,1,1,19,1};<br>&nbsp;&nbsp;&nb sp; size_t MonThreadsTable_oid_len&nbsp;&nbsp; = OID_LENGTH(MonThreadsTable_oid);<br>&nbsp;&nbsp;&n bsp; netsnmp_handler_registration&nbsp;&nbsp;&nbsp; *reg;<br>
&nbsp;&nbsp;&nbsp; netsnmp_iterator_info&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *iinfo;<br>&nbsp;&nbsp;&nbsp; netsnmp_table_registration_info *table_info;<br><br>&nbsp;&nbsp;&nbsp; reg = netsnmp_create_handler_registration(<br>&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;MonThreadsTable&quot;,&nbsp;&nbsp;&nbsp;&nbs p; MonThreadsTable_handler,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp; MonThreadsTable_oid, MonThreadsTable_oid_len,<br>&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; HANDLER_CAN_RONLY<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; );<br><br>&nbsp;&nbsp;&nbsp; table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );<br>&nbsp;&nbsp;&nbsp; netsnmp_table_helper_add_indexes(table_info,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ASN_INTEGER,&nbsp; /* index: IdThread */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp; 0);<br>&nbsp;&nbsp;&nbsp; table_info-&gt;min_column = 1;<br>&nbsp;&nbsp;&nbsp; table_info-&gt;max_column = 4;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );<br>
&nbsp;&nbsp;&nbsp; iinfo-&gt;get_first_data_point = MonThreadsTable_get_first_data_point;<br>&nbsp;&nb sp;&nbsp; iinfo-&gt;get_next_data_point&nbsp; = MonThreadsTable_get_next_data_point;<br>&nbsp;&nbs p;&nbsp; iinfo-&gt;table_reginfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp; = table_info;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; netsnmp_register_table_iterator( reg, iinfo );<br>
<br>&nbsp;&nbsp;&nbsp; /* Initialise the contents of the table here */<br>}<br><br>Do you see someting wrong??? How do I link my table with the request info used by the netsnmp_extract_iterator_context function??<br><br>Thanks again,<br>
<br>Alejandro<br><br><br><div class="gmail_quote">On Thu, Apr 17, 2008 at 11:00 AM, Alejandro Islas &lt;<a href="mailto:alex.islas@gmail.com">alex.islas@gmai l.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="Ih2E3d">On Thu, Apr 17, 2008 at 3:47 AM, Dave Shield &lt;<a href="mailto:D.T.Shield@liverpool.ac.uk" target="_blank">D.T.Shield@liverpool.ac.uk</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">
<div>On 17/04/2008, Alejandro Islas &lt;<a href="mailto:alex.islas@gmail.com" target="_blank">alex.islas@gmail.com</a>&gt; wrote:<br>
&gt; I tried to use mib2c.container.conf file but mib2c<br>
&gt; wasn't able to found it<br>
<br>
</div>Hmmm... what version of the toolkit are you using?<br>
mib2c.container.conf has been around since the 5.2 release<br>
(although the internals have changed significantly since then).<br>
</div><div><br>
<font color="#cc33cc">I'm using NET-SNMP version:&nbsp; <a href="http://5.2.1.2" target="_blank">5.2.1.2</a><br></font><div class="Ih2E3d"><br>
<br>
&gt; &nbsp;1)After using mib2c my .c file only contains create/remove entries<br>
&gt; functions. As far as I understand, I need to implement a fetch entrie, to<br>
&gt; avoid duplicate row entries..correct???<br>
<br>
</div></div><div class="Ih2E3d">Sorry - I don't understand what you're asking here.</div></blockquote><div><br>&nbsp;&nbsp;&nbsp; <font color="#cc33cc">After using mib2c to generate my code, I noticed that it created a create_row_entry and a <br>
&nbsp;&nbsp;&nbsp; remove_row_entry functions. I implemented a fetch_row_entry, so that my code would be able to check<br>
&nbsp;&nbsp;&nbsp; if it doesn't have a previously created entry for a particular index.<br></font></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
<div><br>
&gt; 2) Besides including data reading functions (i'm using text files),<br>
<br>
</div>What do you mean by &quot;data reading functions&quot;?<br>
How are you storing the table contents within your module?</blockquote></div><div><br>&nbsp;&nbsp; <font color="#cc33cc">I read a text file created by another process. Each line of such text file contains a row's info<br>&nbsp;&nbsp; of my table, so my process checks for such entry(using the index) in the linked list and updated it or create a new entry<br>

&nbsp; if its the first time I received inf of such row.<br></font></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>

<div><br>
&gt; do I need to do anything else?? I did not do anything to the handler,<br>
&gt; get_first_data_point and get_next_data_point functions, I left them as mib2<br>
&gt; generated them.<br>
<br>
</div>The get_{first,next}_data_point routines need to step through the<br>
rows of your table - in whatever way is appropriate for your module.<br>
The template code assumes that the table is held as a linked list<br>
of individual row entries - if this is how your data reading functions<br>
store the table, then you probably don't need to change this code<br>
much (if at all).<br>
&nbsp; If you are storing the table in a different manner (or pulling it from<br>
external sources), then you will need to amend these two routines<br>
to match.</blockquote></div><div><br>&nbsp;&nbsp; <font color="#cc33cc">Yes, I'm using the linked list of individual row entries created by mib2c.</font><br></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
<div><br>
&gt; &nbsp;3) Could you explain (or send me an info link) of how my table handler is<br>
&gt; called by the system?? I don't see where my table list is called on it.<br>
<br>
</div>When you register the table, the agent includes this information in<br>
a list of all the OIDs that it knows about. &nbsp; When it receives a request,<br>
it searches this list for the appropriate match(es), and calls the<br>
corresponding handlers.<br>
<div><br>
<br>
&gt; 4) I used gdb...but didn't help me a lot, it only confirmed a segmentation<br>
&gt; fault.<br>
<br>
</div>But it should also indicate *where* this segmentation fault occurs.<br>
This would help track down what is causing it.</blockquote></div><div><br>&nbsp; &nbsp; <font color="#cc33cc">You're right, I think I need to play a little bit more with gbd</font> <br></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
<div><br>
&gt; &nbsp;I'm not compiling the whole project, only adding my so files using<br>
&gt; dlmod command. Can I still use dbg using this method or do I need to compile<br>
&gt; the whole deamon including my handlers???<br>
<br>
</div>Ummm... not sure.<br>
It would probably be sensible to start by working with a &quot;traditional&quot; approach,<br>
at least until you get the module working. &nbsp; The same module code can be<br>
embedded within the main agent, loaded dynamically, or used within a<br>
subagent - with no changes to the code.<br>
<font color="#888888"></font></blockquote></div><div>&nbsp;<br>&nbsp;<font color="#cc33cc">I'll try this and let you know.</font> <br></div><div><br><font color="#cc33cc">Alejandro</font> <br></div></div><br>
</blockquote></div><br>

------=_Part_1672_27823242.1208459770000--


--===============2051931462==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757...un.com/javaone
--===============2051931462==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

--===============2051931462==--

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:32 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0