I'm having a C function that returns a pointer to an struct:
struct iperf_test *
iperf_new_test()
{
struct iperf_test *test;
test = (struct iperf_test *) malloc(sizeof(struct iperf_test));
...
return test;
}
This function is called from Python in the following way:
self.lib = cdll.LoadLibrary("lib.so")
self._test = self.lib.iperf_new_test()
The struct has some values such as:
struct iperf_test
{
int server_port;
int bind_port;
};
The examples I see on the internet shows that I need to use a function that receives a pointer to alter the values, for example in python:
self.lib.iperf_set_test_server_port(self._test, int(port))
And in C:
void
iperf_set_test_server_port(struct iperf_test *ipt, int srv_port)
{
ipt->server_port = srv_port;
}
Is there a way to change the value bind_port directly without using a C function?
ctypes.Structure, create actypes.POINTERtype of this class and set this asrestypeof the function. Then you can change the value directly.