Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <time.h>
- #include <sys/un.h>
- #include <inttypes.h>
- #include <arpa/inet.h>
- #include <errno.h>
- #include "common.h"
- int p;
- int skt;
- /*funzione che genera un numero esadecimale di 32 bit*/
- uint32_t rand_id(){
- uint32_t x=rand() & 0xff;
- x|=(rand() & 0xff) <<8;
- x|=(rand() & 0xff) <<16;
- x|=(rand() & 0xff) <<24;
- return x;
- }
- int main(int argc, char *argv[]){
- int k, w, secret;
- uint32_t ID;
- if(argc!=4){
- printf("Numero di argomenti diverso da 4 \n");
- exit(EXIT_FAILURE);
- }
- p = strtol(argv[1], NULL, 10);
- k = strtol(argv[2], NULL, 10);
- w = strtol(argv[3], NULL, 10);
- if((p<1 || p>=k) || w<=(3*p)){
- printf("Vincoli violati");
- exit(EXIT_FAILURE);
- }
- sa.sun_family = AF_UNIX;
- srand(time(NULL)+getpid()); //uso anche getpid per fornire maggiore sicurezza
- secret = (rand()%3000)+1; //genero secret compreso tra 1 e 3000
- ID = rand_id();
- printf("CLIENT %"PRIX32" SECRET %d\n", ID, secret);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement