I have seen a lot of answers that are related to my question, but I really cannot use it under my condition.
I am building a network module using socket programming with C language under Linux domain. I have to implement a function that could send a struct that consists of int, char, char * and some other structures (nested struct).
struct EnQuery
{
char type[6]; // insert, select , update , delete
char * columns; //note here, it's an array of big, {name, age, sex, position, email} not in string
struct Values * values; //an array of values(another struct), {tom, 23, male, student, [email protected]} is represented by the second struct values, not in string
struct condition * enCondition; // array of condition, "name=tom and age>30" is represnted by the third struct condition
short len;
short rn;
};
struct Values
{
char * doc;
char key[2];
char s;
};
struct condition
{
short k;
struct condition * children;
};
Above is the structure that I am trying to send. I am declaring the variables and sending over through socket using send() function.
How would I have to send char * through the socket? Or would there be a way to resize the char array length conveniently?
P.S I can't use external libraries
*
) needs to be serialized, not only thechar
s. If you didn't have any pointers you could just send the struct as is (assuming receiver have the same endianness and memory padding etc). – Soren