I assume client_sock is defined as "int client_sock". In this case you should write the following:
if (pthread_create(&newthread , NULL, (void * ) accept_request, &client_sock) != 0) {
Then in accept_request (which, btw, should be a function taking a pointer) you will do like:
void *accept_request( void *client_sock_addr ) {
int client_sock = *((int*) client_sock_addr);
}
Converting an int to an (void*) might not be portable (as data sizes of int and void* are not necessarily the same). Of course, it might work on your current compiler...
Thanks jiles for pointing this: Depending on the rest of the code, the value at that address might change (for example if you have a loop around the accept construct and 2 accepts arrive before one thread is created). The nicest way to do it is indeed allocate memory with malloc like
int *client_sock_addr=malloc(sizeof(int));
*client_sock_addr = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);
if (pthread_create(&newthread , NULL, (void * ) accept_request, client_sock_addr) != 0) {
perror("pthread_create");
}
And then in the function do:
void *accept_request( void *param ) {
int *client_sock_addr = (int*) client_sock_addr;
int client_sock = *client_sock_addr;
// Before exiting the thread
free(client_sock_addr);
}