I am trying to send and receive a following struct via send() and recv(). Following are the struct that I am trying to send/recv, my client.c, and server.c codes. It seems like my server is unable to deserialize the struct received. When I run the following server code, I am getting segfaults and the print statements after recv() aren't printing anything. Any advice on how to properly send and receive a struct?
typedef struct {
char* path;
int flags;
} OpenStruct;
client.c
OpenStruct *os = malloc(sizeof(OpenStruct));
char* pathname = "overflow.txt"
os -> path = pathname;
os -> flags = 1;
int ret = send(socket_fd, &os, sizeof(OpenStruct), 0);
server.c
int openSize = sizeof(OpenStruct);
OpenStruct *os = (OpenStruct*)malloc(openSize);
char* buf1 = malloc(openSize);
while ((rv = recv(sessfd, (void *)buf1, openSize, 0))>0) {
memcpy(&os, buf1, intBuf);
char* path = os -> pathname;
fprintf(stderr, "content of path %s\n", path);
}