diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/b-scan/tmp/src/test_garage.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/b-scan/tmp/src/test_garage.c')
| -rw-r--r-- | other/b-scan/tmp/src/test_garage.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/other/b-scan/tmp/src/test_garage.c b/other/b-scan/tmp/src/test_garage.c new file mode 100644 index 0000000..06acf61 --- /dev/null +++ b/other/b-scan/tmp/src/test_garage.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* test_garage.c - test program for the garage module | ||
| 2 | * | ||
| 3 | * by scut / teso | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <time.h> | ||
| 10 | #include <garage.h> | ||
| 11 | |||
| 12 | |||
| 13 | void | ||
| 14 | cleaner_t (ip_list *il); | ||
| 15 | |||
| 16 | int | ||
| 17 | main (int argc, char *argv[]) | ||
| 18 | { | ||
| 19 | int data_len; | ||
| 20 | unsigned char * data; | ||
| 21 | unsigned long int ip, | ||
| 22 | gip = 0; | ||
| 23 | unsigned long int ips; | ||
| 24 | garage_hdlr * hdl; | ||
| 25 | unsigned long int maxkeep; | ||
| 26 | |||
| 27 | printf ("mg_cidr_getmask (20) = 0x%08lx\n", mg_cidr_getmask (20)); | ||
| 28 | printf ("mg_cidr_getmask (0xffffffc0) = 0x%08lx\n", mg_cidr_getmask (0xffffffc0)); | ||
| 29 | |||
| 30 | if (argc < 2 || sscanf (argv[1], "%lu", &ips) != 1) { | ||
| 31 | printf ("usage: %s <number-of-ips> [maxkeep]\n\n", argv[0]); | ||
| 32 | |||
| 33 | exit (EXIT_FAILURE); | ||
| 34 | } | ||
| 35 | if (argc == 3 && sscanf (argv[2], "%lu", &maxkeep) != 1) | ||
| 36 | exit (EXIT_FAILURE); | ||
| 37 | |||
| 38 | srand (time (NULL)); | ||
| 39 | hdl = mg_init ("footest", maxkeep, cleaner_t); | ||
| 40 | |||
| 41 | printf ("mg_cidr_getmask (0) = 0x%08lx\n", mg_cidr_getmask (0)); | ||
| 42 | |||
| 43 | mg_write (hdl, 2048, "foobar", 7, 0); | ||
| 44 | mg_write (hdl, 2050, "foobar", 7, 0); | ||
| 45 | mg_write (hdl, 101911, "foobar", 7, 0); | ||
| 46 | mg_write (hdl, 28914191, "foobar", 7, 0); | ||
| 47 | printf ("mg_cidr_count (hdl, 2048, 32) = %lu\n", mg_cidr_count (hdl, 2048, 32)); | ||
| 48 | printf ("mg_cidr_count (hdl, 2048, 31) = %lu\n", mg_cidr_count (hdl, 2048, 31)); | ||
| 49 | printf ("mg_cidr_count (hdl, 2048, 30) = %lu\n", mg_cidr_count (hdl, 2048, 30)); | ||
| 50 | printf ("mg_cidr_count (hdl, 2048, 13) = %lu\n", mg_cidr_count (hdl, 2048, 13)); | ||
| 51 | printf ("mg_cidr_count (hdl, 2048, 0) = %lu\n", mg_cidr_count (hdl, 2048, 0)); | ||
| 52 | |||
| 53 | |||
| 54 | ip = 123; | ||
| 55 | mg_write (hdl, ip, "foo", 4, 0); | ||
| 56 | mg_read (hdl, ip); | ||
| 57 | mg_clean (hdl, ip, NULL); | ||
| 58 | |||
| 59 | do { | ||
| 60 | ip = rand (); | ||
| 61 | |||
| 62 | data_len = rand () % 64; | ||
| 63 | data_len += 1; /* avoid allocating zero bytes */ | ||
| 64 | data = malloc (data_len); | ||
| 65 | memset (data, '\x73', data_len); | ||
| 66 | data[data_len - 1] = '\0'; | ||
| 67 | |||
| 68 | mg_write (hdl, ip, (void *) data, data_len, 1); | ||
| 69 | if (ips % 137 == 0) | ||
| 70 | gip = ip; | ||
| 71 | |||
| 72 | if (ips % 139 == 0) | ||
| 73 | (void) mg_read (hdl, gip); | ||
| 74 | |||
| 75 | ips -= 1; | ||
| 76 | if (ips % 5000 == 0) | ||
| 77 | mg_show (hdl); | ||
| 78 | |||
| 79 | } while (ips > 0); | ||
| 80 | |||
| 81 | mg_show (hdl); | ||
| 82 | mg_destroy (hdl, 0); | ||
| 83 | |||
| 84 | exit (EXIT_SUCCESS); | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | void | ||
| 89 | cleaner_t (ip_list *il) | ||
| 90 | { | ||
| 91 | if ((rand () % 20000) == 0) | ||
| 92 | printf ("cleaner_t: il = 0x%08lx IP = 0x%08lx\n", | ||
| 93 | (unsigned long int) il, | ||
| 94 | il->ip); | ||
| 95 | |||
| 96 | return; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
