comp.lang.ada
 help / color / mirror / Atom feed
* A suggestion about interfacing with C
@ 2016-05-02 16:45 mockturtle
  2016-05-02 18:46 ` Simon Wright
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mockturtle @ 2016-05-02 16:45 UTC (permalink / raw)


Dear all,
I need to interface with a C library (libnl, for using Netlink in Linux).  The library provides a "socket" represented by a struct nl_sock, but the user (the library user, that is, myself) sees only a pointer to nl_sock, since the library provides constructors, destructors and everything is needed to manipulate the socket. In a sense, the user can consider the pointer just as an "opaque handler" rather than a pointer. (I must say that my first impression of the API is definitively positive). 

In Ada I would like to provide a slightly thick package that hides the C type behind a, say, Netlink_Socket type that could be a record holding the pointer to nl_sock. Note that since libnl uses said pointer as an opaque handle, I just need to store the "bitstring" representing its value, in order to pass it to the C library.

I was wandering about the best way to implement the Ada "view"  of the pointer to nl_sock.  

* I could use Interfaces.C.Pointers, but it seems me an overkill since I do not need to do pointer arithmetic.  Moreover, I would need to define a record equivalento to struct nl_sock (although maybe in my case a null record could suffice)

* I could convert it in C to a char* and then using Interfaces.C.Strings.  (A bit dirty, but not too much...)

* I could convert it to an integer... (no, definitively too dirty)

* others? 

What would you suggest?

Keep in mind that the software will run on Linux only (Netlink is specific to Linux, as long as I know) and at 99.99% only on x86 and similar.

Thank you in advance for your help

Riccardo


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-05-03 21:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02 16:45 A suggestion about interfacing with C mockturtle
2016-05-02 18:46 ` Simon Wright
2016-05-02 19:07 ` Jeffrey R. Carter
2016-05-02 19:40 ` Per Sandberg
2016-05-02 20:14 ` Maciej Sobczak
2016-05-03 21:53 ` mockturtle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox