In response to your question Salem, yes this is a thread function, I have included the portion of code where I create the thread and start the function, including the argument I pass the function.
I changed the struct as you suggested to have the header field be a fixed array of size 1, which along with your suggested changes to my malloc call have resolved my segmentation fault issue.
* Recv the data from the sender
/* accept a connection from a client program */
newFD = accept( socketFD, (struct sockaddr *)&srcAddr, (socklen_t *)&fromlen );
if ( newFD < 0 )
perror( "NATbox:accept()" );
int threadError = pthread_create(&tid, NULL, respond, (void *) newFD);
if(threadError < 0)
int i = 0;
while( i != -1 )
i = wait( &status );
printf( "Finished pid = %d\n", i );
* Return a 0 to say it worked correctly from this end
void * respond(void * incomingSocketFD)
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);
if(retval < 0)//error check
The header field of the Message struct is just a single character which indicates what service the client program wants, "A", "M", or "C".
Thanks for the help.