#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <strings.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#define NUM_THREADS 3
void* do_test(void *param)
{
char *host = (char*) param;
struct hostent *hp;
struct sockaddr_in addr;
if ((hp = gethostbyname(host)) ==NULL)
{
perror("gethostbyname");
return NULL;
}
memcpy(&addr.sin_addr,hp->h_addr, hp->h_length);
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t doRequests[NUM_THREADS];
char ip[24];
strcpy(ip, "127.0.0.1");
for (size_t i = 0; i <NUM_THREADS; i++)
{
pthread_create(&doRequests[i],NULL, do_test, ip);
}
for (size_t i = 0; i <NUM_THREADS; i++)
{
pthread_join(doRequests[i],NULL);
}
return 1;
}
Getting the Unix training click here !!
http://www.cetpainfotech.com/technology/unix-training