-------- Original Message --------
Subject: Re: Problem with sprint_realloc_iteger()
Date: Fri, 17 Mar 2006 10:53:10 +0530
From: Rashmi M Bangera <[EMAIL PROTECTED]>
To: Dave Shield <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>



getIndex method is as follows.


long* getIndex(void *data_context,int *len)
{
    udata *ud = data_context;
    *len = sizeof(ud->ifindex);
    return &ud->ifindex;
}

structure udata contains all the interface details fetched from ioctl call in get_first_data_item().Currently i am trying for only one
interface,so i am returning NULL in get_next_data_item.



dot3StatsTable_get_first_data_point(void **my_loop_context,
                                    void **my_data_context,
                                    netsnmp_variable_list * put_index_data,
                                    netsnmp_iterator_info *mydata)
{
    const char *itfName = "eth0";   
    ldata *ld;
    ld = SNMP_MALLOC_TYPEDEF(ldata);
    long index;
    if(!ld)
    return NULL;

    strncpy(ifr.ifr_name,itfName,5);
    ifr.ifr_name[4]= '\0';
   
    ld->sockdesc =  socket(AF_INET, SOCK_DGRAM, 0);
        if(ld->sockdesc < 0)
    {      
            return NULL;
    }

   
     
        ld->status = ioctl(ld->sockdesc,SIOCDEVPRIVATE,&ifr);

        if(ld->status < 0)
        {
            DEBUGMSGTL(("output","ioctl Error:SIOCDEVPRIVATE\n"));
            return NULL;
        }
        ld->es = (struct estats*)ifr.ifr_data;

        ld->status = ioctl(ld->sockdesc,SIOCGIFINDEX,&ifr);

        if(ld->status < 0)
        {
            DEBUGMSGTL(("output","ioctl Error:SIOCGIFINDEX \n"));
            return NULL;
        }
       
        ld->ifindex = (long)ifr.ifr_ifindex;
       
         snmp_set_var_value(put_index_data,(u_char *)&ld->ifindex,sizeof(long));
       
        close(ld->sockdesc);
        ld->sockdesc = 0;
        *my_loop_context =  ld;
        return put_index_data;
   
   
}

i am using context convert function to copy contents of structure ldata to udata.

Dave Shield wrote:
On Wed, 2006-03-15 at 12:11 +0530, Rashmi M Bangera wrote:

  
The problem is, when i use snmptable command, the code fails at
sprintf() statement in the sprint_realloc_integer() function.

case MODE_GET:
            switch (table_info->colnum) {
            case COLUMN_DOT3STATSINDEX:
        {
            long *index;
            size_t len;
            index = getIndex(data_context,&len);
    

And what value does 'index' receive?
There's no error checking here, and without seeing the
'getIndex' routine, it's impossible to tell what it
might be doing.

I would definitely suggest having some debugging code
within the getIndex routine, so you know exactly what
values it is returning (for both 'index' and 'len').

Dave
  

Reply via email to