Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1.     /* TEST TEST TEST */
  2.     static plist covert = NULL; // lista che contiene tutti i bit covert
  3.     static int length_covert=0; // lunghezza lista covert
  4.     int len;
  5.     int exitCond = 0;
  6.     int i = 0;
  7.     int j = 0;
  8.     struct timespec now,after;
  9.     double difference = 0;
  10.     double timing_interval = 1;
  11.     char* covert_message;
  12.  
  13.     clock_gettime(CLOCK_MONOTONIC, &now);
  14.     int fail_or_len = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
  15.     clock_gettime(CLOCK_MONOTONIC, &after);
  16.     difference = ( ((double)after.tv_sec + 1.0e-9*after.tv_nsec) - ((double)now.tv_sec + 1.0e-9*now.tv_nsec) ) * 100 * 1000;
  17.     //printf("D: %4f\n", difference);
  18.     if(fail_or_len > 800) {
  19.        
  20.         difference = difference-timing_interval/2;
  21.         printf("Difference: %4f\n", difference);
  22.         int zeros=(int)(difference/timing_interval);
  23.         if(difference < 0) // sto ancora inviando in covert mode
  24.             insertCovert(&covert,zeros,&length_covert);
  25.  
  26.         covert_message = list_to_array(covert,length_covert+1);
  27.         printf("covert_message[0]: %4d\n", covert_message[0]);
  28.         covert_message = decodeCovert(covert_message);
  29.     }
  30.  
  31.     if(covert_message)
  32.        if(strcmp(covert_message, "") != 0)
  33.           printf("Messaggio covert: %s\n",covert_message);
  34.  
  35.     /**/
  36.  
  37.  
  38.  
  39. /***** insertCovert ********/
  40. void insertCovert(plist* l, int zeros, int* length) {
  41.     int i;
  42.     plist x = *l;
  43.     /*
  44.     if(x!=NULL) {
  45.         while(x->next != NULL)
  46.             x = x->next;
  47.     } else {
  48.         x = (plist)malloc(sizeof(list));
  49.         x->next = (plist)malloc(sizeof(list));
  50.         *l = x->next;
  51.     }
  52.  
  53.     for (i = 0; i < zeros; i++) {
  54.         if(x->next==NULL)
  55.             x->next = (plist)malloc(sizeof(list));
  56.         x = x->next;
  57.         x->value = 0;
  58.         x->next = NULL;
  59.     }
  60.     */
  61.     if (x == NULL) {
  62.         x = (plist)malloc(sizeof(list));
  63.         x->value=0;
  64.         x->next=NULL;  
  65.         zeros--;
  66.         *l = x;
  67.     }
  68.  
  69.     while(x->next != NULL)
  70.         x = x->next;
  71.  
  72.     for (i = 0; i < zeros; i++) {
  73.         x->next = (plist)malloc(sizeof(list));
  74.         x = x->next;
  75.         x->value = 0;
  76.         x->next = NULL;
  77.     }
  78.  
  79.     x->next=(plist)malloc(sizeof(list));
  80.     x = x->next;
  81.     x->value = 1;
  82.     x->next = NULL;
  83.  
  84.     *length = *length + zeros + 1;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement