I want to send a character array over a tcp socket in unix.
My first idea was to use an ordinary char array for the struct that will be sent over the socket:
typedef struct __attribute__((packed))
{
uint8_t type;
uint8_t id_index;
char char_value[STR_MSG_MAX];
} a_msg;
Simply because a C char is always 8 bit long. However, after some googling I found out that even if a char is always 8 bit long the underlying representation could actually be a 32 bit integer. So my impression is that char is maybe not the best way of representing a string in a message that will be sent over a socket from FreeBSd to Linux (or input some other unixes if you want to =) ...).
stdint.h is present on all modern unixes to day (I hope) and my thoughts is that maybe a array of uint8_t or a int8_t could do the trick.
typedef struct __attribute__((packed))
{
uint8_t type;
uint8_t id_index;
uint8_t char_value[STR_MSG_MAX];
} a_msg;
or
typedef struct __attribute__((packed))
{
uint8_t type;
uint8_t id_index;
int8_t char_value[STR_MSG_MAX];
} a_msg;
However, uint8_t is a unsigned char and int8_t is a signed char. A standard C char is neither of that because the implementation is undefined as I understand it.
My questions is: What is the best way of representing a character array (string) in C that will be sent over tcp/ip in a *nix (Linux, FreeBSD etc.) platform independent way.