I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock. snmp_synch_response requires a pointer to a pointer: snmp_synch_response(netsnmp_session *, netsnmp_pdu *, netsnmp_pdu **) Just how the heck do you code that? You can't just declare a System.Address. Would I need to drop into C and handle it there? B
On 06/06/2020 17:23, Bob Goddard wrote:
> I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock.
>
> snmp_synch_response requires a pointer to a pointer:
> snmp_synch_response(netsnmp_session *, netsnmp_pdu *, netsnmp_pdu **)
>
> Just how the heck do you code that? You can't just declare a System.Address.
>
> Would I need to drop into C and handle it there?
Yup, C's pointer crap is horrible in Ada.
Essentially, you need to create your types netsnmp_session and netsnmp_pdu.
Let's assume your package name is SNMP.
type Session is null record with
Convention => C; -- You may has this as an actual full record for al I
know.
You can probably get away with * parameters as "in out" parameters in
the Ada function.
You can do ** by creating a C convention access type to PDU and then
another to that.
On 2020-06-06 19:23, Bob Goddard wrote:
> I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock.
>
> snmp_synch_response requires a pointer to a pointer:
> snmp_synch_response(netsnmp_session *, netsnmp_pdu *, netsnmp_pdu **)
>
> Just how the heck do you code that? You can't just declare a System.Address.
Declare the parameter type as "access netsnmp_pdu" and its mode as
"access" or "in out" or "out", depending on what snmp_synch_response
actually does with the parameter. The mode gets you one C '*' and the
access type gets you the second '*'.
See RM B.3(68).
--
Niklas Holsti
niklas holsti tidorum fi
. @ .
On 06/06/2020 18:23, Bob Goddard wrote: > I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock. > > snmp_synch_response requires a pointer to a pointer: > snmp_synch_response(netsnmp_session *, netsnmp_pdu *, netsnmp_pdu **) > Just how the heck do you code that? You can't just declare a System.Address. That depends on the semantics because in C you cannot tell in from out. Assuming that snmp_synch_response returns a pointer to PDU and that netsnmp_session and netsnmp_pdu are record types: type netsnmp_pdu_Ptr is access all netsnmp_pdu; paragma Convention (C, netsnmp_pdu_Ptr); procedure snmp_synch_response ( Session : netsnmp_session; Request : netsnmp_pdu; Response : out netsnmp_pdu_Ptr -- Who manages the target? ); You must carefully read the documentation and probably the sources to determine who manages the returned object. Some libraries return pointers to internally allocated and freed memory others require the caller to deallocate the object at the returned point. C is a mess. > Would I need to drop into C and handle it there? P.S. Why do not you implement SNMP instead of using alien library? SNMP is not rocket science. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
On Saturday, 6 June 2020 18:01:41 UTC+1, Dmitry A. Kazakov wrote:
[...]
> > Would I need to drop into C and handle it there?
>
> P.S. Why do not you implement SNMP instead of using alien library? SNMP
> is not rocket science.
I think everyone feels my pain, and at the moment, life is too short to re-implement snmp. Net-snmp code can only be describe as how not to write an application and how not to write documentation.
Anyways... I had already done the following and created the pdu record:
function SNMP_Synch_Response (Session : access snmp_Session; PDU : access snmp_pdu; Response : System.Address) return Interfaces.C.int;
pragma Import (C, SNMP_Synch_Response, "snmp_synch_response");
I'll still look...
On 06/06/2020 19:34, Bob Goddard wrote: > On Saturday, 6 June 2020 18:01:41 UTC+1, Dmitry A. Kazakov wrote: > [...] >>> Would I need to drop into C and handle it there? >> >> P.S. Why do not you implement SNMP instead of using alien library? SNMP >> is not rocket science. > > I think everyone feels my pain, and at the moment, life is too short to re-implement snmp. Net-snmp code can only be describe as how not to write an application and how not to write documentation. And that is the reason to believe the rest of it is fine? > Anyways... I had already done the following and created the pdu record: > function SNMP_Synch_Response (Session : access snmp_Session; PDU : access snmp_pdu; Response : System.Address) return Interfaces.C.int; > pragma Import (C, SNMP_Synch_Response, "snmp_synch_response"); No need in access, C records are always passed by reference. No need in Address, use access to a named access: Session : snmp_Session; PDU : snmp_pdu; Response : access snmp_pdu_Ptr or (in Ada 2012 with function out parameters support) Response : out snmp_pdu_Ptr The rules of thumb when writing C bindings: Type Mode Ada C non-scalar any T *T scalar in T T scalar out T *T scalar in out T *T So, if you want **T, define a named access type with C convention: type T_Ptr is access all T; pragma Convention (C, T_Ptr); This is a scalar type, so **T would be Response : out T_Ptr or Response : access T_Ptr or you can declare a yet another access type: type T_Ptr_Ptr is access all T_Ptr; pragma Convention (C, T_Ptr_Ptr); and then use Response : T_Ptr_Ptr -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
On 6/6/20 6:23 PM, Bob Goddard wrote:
> I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock.
I'm pretty sure that AWS and maybe Kazakov's Simple Components have support for
SNMP. Why not look at them?
--
Jeff Carter
"I like it when the support group complains that they have
insufficient data on mean time to repair bugs in Ada software."
Robert I. Eachus
91
Den 2020-06-06 kl. 22:20, skrev Jeffrey R. Carter:
> On 6/6/20 6:23 PM, Bob Goddard wrote:
>> I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a
>> roadblock.
>
> I'm pretty sure that AWS and maybe Kazakov's Simple Components have
> support for SNMP. Why not look at them?
>
I think AWS has SMTP - not SNMP
--
Björn
On 6/6/20 10:20 PM, Jeffrey R. Carter wrote:
>
> I'm pretty sure that AWS and maybe Kazakov's Simple Components have support for
> SNMP. Why not look at them?
Sorry, I realize I misread your post (even though I typed what you had and not
what I thought I'd read). Please ignore.
--
Jeff Carter
"I like it when the support group complains that they have
insufficient data on mean time to repair bugs in Ada software."
Robert I. Eachus
91
On 06/06/2020 22:55, Jeffrey R. Carter wrote: > On 6/6/20 10:20 PM, Jeffrey R. Carter wrote: >> >> I'm pretty sure that AWS and maybe Kazakov's Simple Components have >> support for SNMP. Why not look at them? > > Sorry, I realize I misread your post (even though I typed what you had > and not what I thought I'd read). Please ignore. I do not have SNMP implemented. Though I have an implementation of OIDs. SNMP v1/2 is basically a single read request. SNMP v3 adds some sort of authentication with views to provide security I did not look at this. P.S. SNMP represents a dilema. It is either primitive low level: read garbage deal with that yourself, or a huge monstrosity if you wanted the client to understand millions of predefined OIDs and map them onto properly typed Ada variables. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de