Deleted Added
full compact
unbound-anchor.c (266114) unbound-anchor.c (276605)
1/*
2 * unbound-anchor.c - update the root anchor if necessary.
3 *
4 * Copyright (c) 2010, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 653 unchanged lines hidden (view full) ---

662 int num = 0;
663 while(p) {
664 if(!p->used) num++;
665 p = p->next;
666 }
667 return num;
668}
669
1/*
2 * unbound-anchor.c - update the root anchor if necessary.
3 *
4 * Copyright (c) 2010, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 653 unchanged lines hidden (view full) ---

662 int num = 0;
663 while(p) {
664 if(!p->used) num++;
665 p = p->next;
666 }
667 return num;
668}
669
670static int get_random(void)
671{
672 int r;
673 if (RAND_bytes((unsigned char*)&r, (int)sizeof(r)) == 1) {
674 return r;
675 }
676 return (int)random();
677}
678
679/** pick random unused element from IP list */
680static struct ip_list*
681pick_random_ip(struct ip_list* list)
682{
683 struct ip_list* p = list;
684 int num = count_unused(list);
685 int sel;
686 if(num == 0) return NULL;
687 /* not perfect, but random enough */
670/** pick random unused element from IP list */
671static struct ip_list*
672pick_random_ip(struct ip_list* list)
673{
674 struct ip_list* p = list;
675 int num = count_unused(list);
676 int sel;
677 if(num == 0) return NULL;
678 /* not perfect, but random enough */
688 sel = get_random() % num;
679 sel = (int)arc4random_uniform((uint32_t)num);
689 /* skip over unused elements that we did not select */
690 while(sel > 0 && p) {
691 if(!p->used) sel--;
692 p = p->next;
693 }
694 /* find the next unused element */
695 while(p && p->used)
696 p = p->next;

--- 1616 unchanged lines hidden ---
680 /* skip over unused elements that we did not select */
681 while(sel > 0 && p) {
682 if(!p->used) sel--;
683 p = p->next;
684 }
685 /* find the next unused element */
686 while(p && p->used)
687 p = p->next;

--- 1616 unchanged lines hidden ---