Advertisement
saramata

client.c

Sep 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>  
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5. #include <sys/un.h>
  6. #include <inttypes.h>
  7. #include <arpa/inet.h>
  8. #include <errno.h>  
  9.  
  10. #include "common.h"
  11.  
  12. int p;
  13. int skt;
  14. /*funzione che genera un numero esadecimale di 32 bit*/
  15. uint32_t rand_id(){
  16.     uint32_t x=rand() & 0xff;
  17.     x|=(rand() & 0xff) <<8;
  18.     x|=(rand() & 0xff) <<16;
  19.     x|=(rand() & 0xff) <<24;
  20.     return x;
  21. }
  22. int main(int argc, char *argv[]){
  23.     int k, w, secret;
  24.     uint32_t ID;
  25.     if(argc!=4){
  26.         printf("Numero di argomenti diverso da 4 \n");
  27.         exit(EXIT_FAILURE);
  28.     }
  29.     p = strtol(argv[1], NULL, 10);
  30.     k = strtol(argv[2], NULL, 10);
  31.     w = strtol(argv[3], NULL, 10);
  32.     if((p<1 || p>=k) || w<=(3*p)){
  33.         printf("Vincoli violati");
  34.         exit(EXIT_FAILURE);
  35.     }
  36.     sa.sun_family = AF_UNIX;
  37.     srand(time(NULL)+getpid()); //uso anche getpid per fornire maggiore sicurezza
  38.     secret = (rand()%3000)+1; //genero secret compreso tra 1 e 3000
  39.     ID = rand_id();
  40.     printf("CLIENT %"PRIX32" SECRET %d\n", ID, secret);
  41.  
  42.    
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement