On Wed, 2005-09-14 at 09:36 -0400, rh wrote:

> struct c
> {
>     struct a ;
>     struct b ;
> } ;
> 
> Given a pointer to 'a' in 'struct c', as we all know you can
>  access / modify 'b' in 'struct c'.

With "in-line" structures as shown - yes, that's possible.
(incredibly ugly, but possible!).

But if struct c was tweaked to be:

   struct c
   {
        struct a *;
        struct b *;
   }

and all you've got is the *value* of the "struct a" pointer,
then you can't get from there to the "struct b" pointer.

That's the situation with the Net-SNMP suite:

> // snmp_api.c
> struct session_list {
>     struct session_list *next;
>     netsnmp_session     *session;      <=======
>     netsnmp_transport   *transport;
>     struct snmp_internal_session *internal;
> };



> and that snmp_open() apparently returns the necessary session
> pointer,

The (internal) "session" pointer, yes - *NOT* the (enclosing)
"session_list" pointer.
Two options:

  a) use 'snmp_sess_open()' instead of 'snmp_open()'
        (which actually returns an opaque pointer to the
         "struct session_list" structure)

  b) use 'snmp_sess_pointer()' 
         to get from the "netsnmp_session" pointer
         back to the enclosing "struct session_list"
         (again as an opaque pointer)



> >    There is already a defined API  (snmp_sess_transport) for
> > retrieving the transport structure associated with a particular
> > session,  and the socket is one of the top-level fields of this
> > transport structure.  It's probably not unreasonable to access
> > this field (and perhaps the transport flags field) directly.
> 
> That's exactly what I need !


Note that it's this 'snmp_sess_transport' API works with
the opaque (session_list) pointer - *NOT* the "netsnmp_session"
pointer returned by 'snmp_open()'.

So you probably want something like:

     netsnmp_session *sess = snmp_open(...);
     netsnmp_transport *t = snmp_sess_transport(
                               snmp_sess_pointer( sess ));
     int sock = t->socket;



Dave


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. 
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to