I want to allocate memory dinamically in netfilter programming, but some problems came out.
These are structures what I want to make new dynamic memory. (Source : http://git.netfilter.org/libnetfilter_queue/tree/src/libnetfilter_queue.c)
struct nfq_q_handle
{
struct nfq_q_handle *next;
struct nfq_handle *h;
uint16_t id;
nfq_callback *cb;
void *data;
};
struct nfq_data {
struct nfattr **data;
};
And this is a function what I am making now.
NODE* create_node(struct nfq_q_handle* qh_data, struct nfgenmsg* nfmsg_data, struct nfq_data* nfa_data, void* data_data)
{
NODE* node = (NODE*)malloc(sizeof(NODE));
struct nfq_q_handle* temp_qh = (struct nfq_q_handle*)malloc(sizeof(struct nfq_q_handle));
struct nfgenmsg* temp_nfmsg = (struct nfgenmsg*)malloc(sizeof(struct nfgenmsg));
struct nfq_data* temp_nfa = (struct nfq_data*)malloc(sizeof(struct nfq_data));
void* temp_data = (void*)malloc(malloc_usable_size(data_data));
memcpy(temp_qh, qh_data, sizeof(struct nfq_q_handle));
node->node_qh = temp_qh;
memcpy(temp_nfmsg, nfmsg_data, sizeof(struct nfgenmsg));
node->node_nfmsg = temp_nfmsg;
memcpy(temp_nfa, nfa_data, sizeof(struct nfq_data);
node->node_nfa = temp_nfa;
memcpy(temp_data, data_data, malloc_usable_size(data_data));
node->node_data = temp_data;
return node;
}
When I use malloc in function and compile it, Error messages come out. "error: invalid application of `sizeof' to incomplete type 'struct..' Actually struct nfgenmsg is working fine, but struct nfq_q_handle and struct nfa_data are not working and show error message.
Is there any solutions? Please help me.
And also, I used 'malloc_usable_size', but I don't know how to use it correctly. If you have an idea with 'malloc_usable_size', please talk to me. Thanks.
Plus: I notified struct is declared in header file only "struct nfq_q_handle". But in c file, it has its parameters. Like, struct nfq_q_handle { .... }