Is it possible to send and recieve a structure with SSL_write and SSL_read?
Client
typedef struct{
unsigned int userid;
unsigned int name;
} sendInfo;
sendInfo infofile;
SSL_write(ssl, infofile, sizeof(struct infofile));
Server
bytes = SSL_read(ssl, struct(infofile), sizeof(struct infofile) );
Is there other methods to send a structure?
Cheers.
You should not do this in general. C data structures do not have a mandatory, universal memory layout that’s the same on all architectures and platforms. When you serialize data, you always have to break it down into individual parts (integers and byte sequences), and moreover you will have to specify the size and ordering (endianness) of all multibyte fields like integers.
Imagine that you find a block of bytes on the street. How would you know what it means? When you serialize, you have to publish a specification of the format, something which you could apply to your found bytes and say, “this is the first integer”, “this is a sequence of bytes, counted by the previously read integer”, etc. With this information, the corresponding deserializing code can rebuild the internal data structure.
A typical serialization field would be something like “unsigned 32-bit integer, little-endian”. That means you have to write out bytes
n & 0xFF,(n >> 8) & 0xFF,(n >> 16) 0xFF,(n >> 24) & 0xFF, and you read back inbuf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24). Note that you’ll never have to know anything about your platform, but only about the wire format.