return true;
}
+
+static void fill_ids_array(fr_packet_socket_t *ps)
+{
+ int i;
+
+ ps->ids_index = 0;
+
+ /*
+ * initialize the array with 256 IDs
+ */
+ for (i = 0; i < 256; i++) {
+ ps->ids[i] = i;
+ }
+
+ /*
+ * Swap this one with a random other one from later in
+ * the list.
+ */
+ for (i = 0; i < 256; i++) {
+ int tmp;
+ int k = fr_rand() % (256 - i);
+
+ tmp = ps->ids[i];
+ ps->ids[i] = ps->ids[i + k];
+ ps->ids[i + k] = tmp;
+ }
+
+ printf("\n");
+}
+
bool fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
fr_ipaddr_t *dst_ipaddr, int dst_port,
void *ctx)
/*
* Populate the ID array with a random list of IDs.
*/
- ps->ids_index = 0;
-
- for (i = 0; i < 256; i++) {
- ps->ids[fr_rand() & 0xff] = i;
- }
+ fill_ids_array(ps);
return true;
}
* Refill the ID array with random IDs.
*/
if (ps->ids_index == 256) {
- for (i = 0; i < 256; i++) {
- ps->ids[fr_rand() & 0xff] = i;
- }
- ps->ids_index = 0;
+ fill_ids_array(ps);
}
return true;