Hi,

I'm new to CFFI and also to Common Lisp, i trying to use CFFI to call getifaddrs function.

I have defined a cffi-grovel for ifaddrss struct

(cstruct ifaddrs "struct ifaddrs"
    (next "ifa_next" :type :pointer)
    (name "ifa_name" :type :pointer)
    (flags "ifa_flags" :type :unsigned-int)
    (address "ifa_addr" :type :pointer)
    (netmask "ifa_netmask" :type :pointer)
    (broadcast "ifa_broadaddr" :type :pointer)
    (point-to-point-destination "ifa_dstaddr" :type :pointer)
    (data "ifa_data" :type :pointer))

In my package i define getifaddrs

(cffi:defcfun "getifaddrs" :int
  ""
  (ifap :pointer))

I try to access the name slot of ifaddrs struct but nothing seems to work, not sure what i doing wrong

(cffi:with-foreign-object (ifa 'ifaddrs)                                                                                                           
           (ice-cffi:getifaddrs ifa)                                                                                                                        
           (cffi:foreign-string-to-lisp (cffi:foreign-slot-value ifa 'ifaddrs 'name)))

0: (SB-SYS:MEMORY-FAULT-ERROR)
  1: ("foreign function: call_into_lisp")
  2: ("foreign function: post_signal_tramp")
  3: (CFFI::FOREIGN-STRING-LENGTH #.(SB-SYS:INT-SAP #X00000060) :ENCODING :UTF-8 :OFFSET 0)
  4: (CFFI:FOREIGN-STRING-TO-LISP #.(SB-SYS:INT-SAP #X00000060) :OFFSET 0 :COUNT NIL :MAX-CHARS 536870908 :ENCODING NIL)

 (cffi:with-foreign-pointer (ifa (cffi:foreign-type-size :pointer))                                                                                 
           (ice-cffi:getifaddrs ifa)                                                                                                                        
           (cffi:foreign-string-to-lisp (cffi:foreign-slot-value ifa 'ifaddrs 'name)))
 0: ((LAMBDA (BABEL-ENCODINGS::SRC BABEL-ENCODINGS::START BABEL-ENCODINGS::END BABEL-ENCODINGS::DEST BABEL-ENCODINGS::D-START)) #.(SB-SYS:INT-SAP #X080819B8) 0 9 "^@^@^@^@^@^@^@^@^@" 0)
1: (CFFI:FOREIGN-STRING-TO-LISP #.(SB-SYS:INT-SAP #X080819B8) :OFFSET 0 :COUNT NIL :MAX-CHARS 536870908 :ENCODING NIL)


any help will be appreciated.

Jose