I am using Python and CFFI to write some unit tests for a library that I have written in C, this library involves socket programming on Linux. The .c
file is compiled into a shared library and then loaded using ffi.dlopen()
.
Naturally the struct sockaddr_in
structure is used which is defined in netinet/in.h
, and in my case it is used within another structure.
typedef struct sDeviceSockAddr
{
int sockfd;
struct sockaddr_in deviceAddr;
} tDeviceSockAddr;
I am using ffi.cdef()
to define this structure. Running the unit test returns the (kind of expected) following error :
TypeError: field 'tDeviceSockAddr.DeviceAddr' has ctype 'struct sockaddr_in' of unknown size
My first thought was how do I load the whole netinet/in.h
, but being new to CFFI, I am not sure that this is the way to go.
Is it possible to load netinet/in.h
correctly? if so, how?
If not, what is the way to do this?