Segmentation fault on TCP recv
Hi everyone,
I have run into an issue where I need to transmit a custom struct I created to a program using TCP sockets and threads.
I believe that I am allocating memory correctly but I receive a seg fault every time the recv() call is reached. So I am not really sure what is going on.
Code:
//struct definition
typedef struct
{
char *header;
char data[256];
}Message;
void * respond(void * incomingSocketFD)
{
printf("in respond\n");
char buffer[32];
int newFD;
nt retval;
//copy socket
memcpy(&newFD, &incomingSocketFD, sizeof(incomingSocketFD));
//allocate space for message
message = malloc(sizeof(Message *));
message->header = (char *)malloc(sizeof(char));
while(retval != 0)
{
printf("inside while in respond\n");
/* Receive data from the client */
retval = recv(newFD, message, sizeof(Message), 0); //!!!!!SEG FAULT HERE
if(retval < 0)//error check
{
perror("NATbox:recv()");
exit(1);
}
}//end while
}//end respond
Any help/pointers would be great,
Thanks,
Hunter