void build_scan_target_IP_list(int proto, int timeout, int* iplist, int size, int&
                               index, int local_peer) {
 
  int isUDP = proto != 6;
  u_long ipaddr;
  unsigned int v18;
  index = 0;
  EnterCriticalSection(off_9BAD92);

  if ( local_peer )  {
     unsigned int sum = 0;

     for (int i=0; i < 32; i++) {
         if ( global_9BEC1C[10 * i] && global_9BEC20[10*i]  && global_9BEC28[10*i] )
               sum = ~htonl_0(global_9BEC30[10*i]) + sum + 1;
     }
 
     if ( sum >= 2 ) {
         while ( size-- > 0 ) {
            unsigned int rand = critical_generate_random() % sum;
            ipaddr = 0;
            for ( i = 0; i < 32; ++i ) {
                if (global_9BEC1C[10 * i] && global_9BEC20[10*i]  &&
                    global_9BEC28[10*i] ) {
                    if (rand < ~htonl_0(global_9BEC30[10*i]) + 1 ) {
                        ipaddr = htonl_0(rand htonl_0(global_9BEC30[10*i]) &
                                 htonl_0(global_9BEC2C[10*i]));
                        if (ipaddr == global_9BEC2C[10*i] ||
                            global_9BEC30[10*i] != 0xFEFFFFFF &&
                            (ipaddr == (global_9BEC30[10*i] & global_9BEC2C[10*i]) ||
                             ipaddr == (global_9BEC2C[10*i] | ~global_9BEC30[10*i]) ||
                             !is_legit_ip_address(ipaddr)))
                           ipaddr = 0;
                    }
                    break;
                }
                rand -= ~htonl_0(global_9BEC30[10*i]) + 1;;
            }
         }
         if ( is_legit_ip_address(ipaddr) && !is_private_subnet(ipaddr) &&
             
call_check_IP_is_in_ranges(ipaddr) )
                 iplist[index++] = ipaddr;
     }
  }
  else {
      reg_set_two_values(isUDP, timeout);
      int j=2048;
      while (j > 0 && !global_9BCBC8[j--]);
      InterlockedExchange(off_9B9F99, j);

      while(size-- > 0) {
         /* with a small probability pick an existing peer */
         if (num_peers > 0 || critical_generate_random() % (unsigned int)(1000 -
             950 *
num_peers / 2048) == 0)
             ipaddr = peerlist[critical_generate_random() %
                     (unsigned int)num_peers];   
         else {
             do {
                global_counter[3 * isUDP]++;
                ipaddr = global_9BCBBC[3 * isUDP] ^ 0xE4B24259 * (global_9BCBB8[3 *
                         isUDP]
^ 0xADEFED73 * (global_9BCBBC[3 * isUDP] ^ 0x55E206F1
                         *
(global_9BCBB8[3 * isUDP] ^ global_counter[3 * isUDP])));
             } while ( !call_check_IP_is_in_ranges(ipaddr) );
         }
     
         if (is_legit_ip_address(ipaddr) && !is_private_subnet(ipaddr) &&
             call_check_IP_is_in_ranges(ipaddr) )
             iplist[index++] = ipaddr;
      }
  }
  LeaveCriticalSection(off_9BAD92);
}


SOURCE LISTING 8: IP address list generation



 


 







Acknowledements

  This material is based upon work supported through the U.S. Army Research Office under the Cyber-TA Research Grant No. W911NF-06-1- 0316 and by the National Science Foundation, Grant No. CNS-07-16 612. The views expressed in this document are those of the authors and do not necessarily represent the official position of the sponsors.