1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
static char genereip (int nombreip, char const *s)
{
int i;
for (i = 0; i < nombreip; i++)
{
int max = 254;
int min = 2;
int nb = min + (rand () % (max + 1 - min));
char ip[sizeof "192.168.1.255"];
sprintf (ip, "192.168.1.%d", nb);
printf ("%s : ip : %s\n", s, ip);
Sleep(1);
}
}
static void *task (void *p_data)
{
char const *s = p_data;
srand (time (NULL) + s[0]);
genereip (100, s);
return NULL;
}
int main (void)
{
pthread_t ta, tb;
pthread_create (&ta, NULL, task, (void *) "alphonse");
pthread_create (&tb, NULL, task, (void *) "beatrice");
pthread_join (ta, NULL);
pthread_join (tb, NULL);
system ("PAUSE");
return 0;
} |