[cffi-devel] calling getifaddrs

Luís Oliveira luismbo at gmail.com
Sun Dec 12 01:45:39 UTC 2010


Hello,

On Sun, Dec 12, 2010 at 1:10 AM, pepone.onrez <pepone.onrez at gmail.com> wrote:
> (cffi:with-foreign-object (ifa 'ifaddrs)
>            (ice-cffi:getifaddrs ifa)
>            (cffi:foreign-string-to-lisp (cffi:foreign-slot-value ifa 'ifaddrs 'name)))

Here's getifaddrs's signature:
  int getifaddrs(struct ifaddrs **ifap);

getifaddrs() allocates the actual struct. Here's how it would be
called using C code:

  struct ifaddrs *p;
  getifaddrs(&p);
  // do something with p->name

The equivalent CFFI code would be something like:

  (with-foreign-object (p :pointer)
    (getifaddrs p)
    (foreign-slot-value (mem-ref p :pointer) 'ifaddrs 'name))

If you define NAME's type to be :STRING, that code will yield a Lisp string.

HTH,

-- 
Luís Oliveira
http://r42.eu/~luis/




More information about the cffi-devel mailing list