Random addresses

2011-10-26
2012-09-17
  • Hello.

    I had a necessity at each connection to product casual pair

    localip-remoteip. Unfortunately, the choice of the free pair (slot)

    addresses in pptpd in conducted linearly. I have made some changes to the

    code and at me all has earned as I want.

    Changes have concerned only to function slot_find_empty().

    int slot_find_empty()
     {
        int i;
        int count=0;
        int *index=NULL;
        for(i=0; i<slot_count; i++) {
            struct slot *slot = &slots[i];
            if (slot->pid == 0) {
                count++;
                index = (int*) realloc(index, count * sizeof(int));
                index[count-1] = i;
             }
        }
        if (count == 0) return -1;
        srand(count);
        i = index[rand()];
        free(index);
        return i;
     }
    

    It, of course, not the best variant. But if the given functionak is

    interesting to you, I can be engaged in finishing of this functional.

     
  • There was an error at code transfer. I am sorry.

    srand(time(NULL));

    i=index;

     
  • :( I am sorry.

    i-index[rand()%count];
    
     
  • :'(

    i=index[rand()%count];