int main(int argc, char **argv) { test_t *test; test_result_t result; unsigned int n_failed; unsigned int testno; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); printf("S:%s:%s\n", SUITENAME, gettime()); n_failed = 0; for (testno = 0; testno < NTESTS; testno++) { test = &tests[testno]; printf("T:%s:%u:A\n", test->tag, testno + 1); printf("A:%s\n", test->description); result = test->func(); printf("R:%s\n", test_result_totext(result)); if (result != PASSED) n_failed++; } printf("E:%s:%s\n", SUITENAME, gettime()); if (n_failed > 0) exit(1); return (0); }
int main() { isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); return (func1()); }
static void do_register(void) { RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS); RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS); RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS); RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS); RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS); }
int main(int argc, char *argv[]) { isc_interval_t linterval; int i; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); isc_app_start(); isc_interval_set(&linterval, 1, 0); RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_taskmgr_create(mctx, 3, 0, &taskmgr) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_create(taskmgr, 0, &g_task) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_ratelimiter_create(mctx, timermgr, g_task, &rlim) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_ratelimiter_setinterval(rlim, &linterval) == ISC_R_SUCCESS); for (i = 0; i < NEVENTS; i++) { isc_interval_t uinterval; int ms = schedule[i].milliseconds; isc_interval_set(&uinterval, ms / 1000, (ms % 1000) * 1000000); timers[i] = NULL; RUNTIME_CHECK(isc_timer_create(timermgr, isc_timertype_once, NULL, &uinterval, g_task, schedule[i].fun, NULL, &timers[i]) == ISC_R_SUCCESS); } isc_app_run(); isc_task_destroy(&g_task); isc_ratelimiter_detach(&rlim); isc_timermgr_destroy(&timermgr); isc_taskmgr_destroy(&taskmgr); isc_mem_stats(mctx, stdout); isc_app_finish(); return (0); }
int main(int argc, char *argv[]) { lwres_context_t *ctx; const char *file = "/etc/resolv.conf"; int ret; #ifdef USE_ISC_MEM isc_mem_t *mem; isc_result_t result; #endif isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); if (argc > 1) { file = argv[1]; } #ifdef USE_ISC_MEM mem = NULL; result = isc_mem_create(0, 0, &mem); INSIST(result == ISC_R_SUCCESS); #endif ctx = NULL; #ifdef USE_ISC_MEM ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0); #else ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0); #endif CHECK(ret, "lwres_context_create"); lwres_conf_init(ctx); if (lwres_conf_parse(ctx, file) == 0) { lwres_conf_print(ctx, stderr); } else { perror("lwres_conf_parse"); } lwres_conf_clear(ctx); lwres_context_destroy(&ctx); #ifdef USE_ISC_MEM isc_mem_stats(mem, stdout); isc_mem_destroy(&mem); #endif return (0); }
int main(int argc, char *argv[]) { dns_name_t name1; dns_name_t name2; dns_name_t name3; isc_region_t region; int c; isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); while ((c = isc_commandline_parse(argc, argv, "rv")) != -1) { switch (c) { case 'r': raw++; break; case 'v': verbose++; break; } } dns_name_init(&name1, NULL); region.base = plain1; region.length = sizeof(plain1); dns_name_fromregion(&name1, ®ion); dns_name_init(&name2, NULL); region.base = plain2; region.length = sizeof(plain2); dns_name_fromregion(&name2, ®ion); dns_name_init(&name3, NULL); region.base = plain3; region.length = sizeof(plain3); dns_name_fromregion(&name3, ®ion); test(DNS_COMPRESS_NONE, &name1, &name2, &name3, plain, sizeof(plain)); test(DNS_COMPRESS_GLOBAL14, &name1, &name2, &name3, plain, sizeof(plain)); test(DNS_COMPRESS_ALL, &name1, &name2, &name3, plain, sizeof(plain)); return (0); }
int main(int argc, char **argv) { isc_keyboard_t kbd; unsigned char c; isc_result_t res; unsigned int count; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); printf("Type Q to exit.\n"); res = isc_keyboard_open(&kbd); CHECK("isc_keyboard_open()", res); c = 'x'; count = 0; while (res == ISC_R_SUCCESS && c != 'Q') { res = isc_keyboard_getchar(&kbd, &c); printf("."); fflush(stdout); count++; if (count % 64 == 0) printf("\r\n"); } printf("\r\n"); if (res != ISC_R_SUCCESS) { printf("FAILURE: keyboard getchar failed: %s\r\n", isc_result_totext(res)); goto errout; } errout: res = isc_keyboard_close(&kbd, 3); CHECK("isc_keyboard_close()", res); return (0); }
int main(int argc, char *argv[]) { void *items1[50]; void *items2[50]; void *tmp; isc_mempool_t *mp1, *mp2; unsigned int i, j; isc_mutex_t lock; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); isc_mem_debugging = ISC_MEM_DEBUGRECORD; RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS); mctx = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); mp1 = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, 24, &mp1) == ISC_R_SUCCESS); mp2 = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, 31, &mp2) == ISC_R_SUCCESS); isc_mempool_associatelock(mp1, &lock); isc_mempool_associatelock(mp2, &lock); isc_mem_stats(mctx, stderr); isc_mempool_setfreemax(mp1, 10); isc_mempool_setfillcount(mp1, 10); isc_mempool_setmaxalloc(mp1, 30); /* * Allocate 30 items from the pool. This is our max. */ for (i = 0; i < 30; i++) { items1[i] = isc_mempool_get(mp1); RUNTIME_CHECK(items1[i] != NULL); } /* * Try to allocate one more. This should fail. */ tmp = isc_mempool_get(mp1); RUNTIME_CHECK(tmp == NULL); /* * Free the first 11 items. Verify that there are 10 free items on * the free list (which is our max). */ for (i = 0; i < 11; i++) { isc_mempool_put(mp1, items1[i]); items1[i] = NULL; } RUNTIME_CHECK(isc_mempool_getfreecount(mp1) == 10); RUNTIME_CHECK(isc_mempool_getallocated(mp1) == 19); isc_mem_stats(mctx, stderr); /* * Now, beat up on mp2 for a while. Allocate 50 items, then free * them, then allocate 50 more, etc. */ isc_mempool_setfreemax(mp2, 25); isc_mempool_setfillcount(mp2, 25); for (j = 0; j < 5000; j++) { for (i = 0; i < 50; i++) { items2[i] = isc_mempool_get(mp2); RUNTIME_CHECK(items2[i] != NULL); } for (i = 0; i < 50; i++) { isc_mempool_put(mp2, items2[i]); items2[i] = NULL; } } /* * Free all the other items and blow away this pool. */ for (i = 11; i < 30; i++) { isc_mempool_put(mp1, items1[i]); items1[i] = NULL; } isc_mempool_destroy(&mp1); isc_mem_stats(mctx, stderr); isc_mempool_destroy(&mp2); isc_mem_stats(mctx, stderr); isc_mem_destroy(&mctx); DESTROYLOCK(&lock); return (0); }
int main(int argc, char **argv) { isc_mem_t *mctx = NULL; isc_interfaceiter_t *iter = NULL; isc_interface_t ifdata; isc_result_t result; const char * res; char buf[128]; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); result = isc_interfaceiter_create(mctx, &iter); if (result != ISC_R_SUCCESS) goto cleanup; result = isc_interfaceiter_first(iter); while (result == ISC_R_SUCCESS) { result = isc_interfaceiter_current(iter, &ifdata); if (result != ISC_R_SUCCESS) { fprintf(stdout, "isc_interfaceiter_current: %s", isc_result_totext(result)); continue; } fprintf(stdout, "%s %d %x\n", ifdata.name, ifdata.af, ifdata.flags); INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6); res = inet_ntop(ifdata.af, &ifdata.address.type, buf, sizeof(buf)); if (ifdata.address.zone != 0) fprintf(stdout, "address = %s (zone %u)\n", res == NULL ? "BAD" : res, ifdata.address.zone); else fprintf(stdout, "address = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.address.family == ifdata.af); res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf, sizeof(buf)); fprintf(stdout, "netmask = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.netmask.family == ifdata.af); if ((ifdata.flags & INTERFACE_F_POINTTOPOINT) != 0) { res = inet_ntop(ifdata.af, &ifdata.dstaddress.type, buf, sizeof(buf)); fprintf(stdout, "dstaddress = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.dstaddress.family == ifdata.af); } result = isc_interfaceiter_next(iter); if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) { fprintf(stdout, "isc_interfaceiter_next: %s", isc_result_totext(result)); continue; } } isc_interfaceiter_destroy(&iter); fprintf(stdout, "\nPass 2\n\n"); result = isc_interfaceiter_create(mctx, &iter); if (result != ISC_R_SUCCESS) goto cleanup; result = isc_interfaceiter_first(iter); while (result == ISC_R_SUCCESS) { result = isc_interfaceiter_current(iter, &ifdata); if (result != ISC_R_SUCCESS) { fprintf(stdout, "isc_interfaceiter_current: %s", isc_result_totext(result)); continue; } fprintf(stdout, "%s %d %x\n", ifdata.name, ifdata.af, ifdata.flags); INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6); res = inet_ntop(ifdata.af, &ifdata.address.type, buf, sizeof(buf)); if (ifdata.address.zone != 0) fprintf(stdout, "address = %s (zone %u)\n", res == NULL ? "BAD" : res, ifdata.address.zone); else fprintf(stdout, "address = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.address.family == ifdata.af); res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf, sizeof(buf)); fprintf(stdout, "netmask = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.netmask.family == ifdata.af); if ((ifdata.flags & INTERFACE_F_POINTTOPOINT) != 0) { res = inet_ntop(ifdata.af, &ifdata.dstaddress.type, buf, sizeof(buf)); fprintf(stdout, "dstaddress = %s\n", res == NULL ? "BAD" : res); INSIST(ifdata.dstaddress.family == ifdata.af); } result = isc_interfaceiter_next(iter); if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) { fprintf(stdout, "isc_interfaceiter_next: %s", isc_result_totext(result)); continue; } } isc_interfaceiter_destroy(&iter); cleanup: isc_mem_destroy(&mctx); return (0); }
int main(int argc, char **argv) { unsigned int bytes; unsigned int k; char *endp; int c, i, n = 1; size_t len; char *name; isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); isc_commandline_errprint = ISC_FALSE; while ((c = isc_commandline_parse(argc, argv, "hn:")) != EOF) { switch (c) { case 'n': n = strtol(isc_commandline_argument, &endp, 10); if ((*endp != 0) || (n <= 1) || (n > 9)) usage(); break; case '?': if (isc_commandline_option != '?') fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); case 'h': usage(); default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); exit(1); } } if (isc_commandline_index + 2 != argc) usage(); k = strtoul(argv[isc_commandline_index++], &endp, 10); if (*endp != 0) usage(); bytes = k << 10; #ifndef HAVE_ARC4RANDOM srand(0x12345678); #endif if (n == 1) { generate(argv[isc_commandline_index], bytes); return (0); } len = strlen(argv[isc_commandline_index]) + 2; name = (char *) malloc(len); if (name == NULL) { perror("malloc"); exit(1); } for (i = 1; i <= n; i++) { snprintf(name, len, "%s%d", argv[isc_commandline_index], i); generate(name, bytes); } free(name); return (0); }
int main(int argc, char *argv[]) { isc_taskmgr_t *manager = NULL; isc_task_t *t1 = NULL, *t2 = NULL; isc_task_t *t3 = NULL, *t4 = NULL; isc_event_t *event; unsigned int workers; isc_timermgr_t *timgr; isc_timer_t *ti1, *ti2; struct isc_interval interval; isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); if (argc > 1) workers = atoi(argv[1]); else workers = 2; printf("%d workers\n", workers); RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_create(manager, 0, &t1) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_create(manager, 0, &t2) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_create(manager, 0, &t3) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_create(manager, 0, &t4) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t1, my_shutdown, "1") == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t2, my_shutdown, "2") == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t3, my_shutdown, "3") == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t4, my_shutdown, "4") == ISC_R_SUCCESS); timgr = NULL; RUNTIME_CHECK(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); ti1 = NULL; isc_interval_set(&interval, 1, 0); RUNTIME_CHECK(isc_timer_create(timgr, isc_timertype_ticker, NULL, &interval, t1, my_tick, "foo", &ti1) == ISC_R_SUCCESS); ti2 = NULL; isc_interval_set(&interval, 1, 0); RUNTIME_CHECK(isc_timer_create(timgr, isc_timertype_ticker, NULL, &interval, t2, my_tick, "bar", &ti2) == ISC_R_SUCCESS); printf("task 1 = %p\n", t1); printf("task 2 = %p\n", t2); sleep(2); /* * Note: (void *)1 is used as a sender here, since some compilers * don't like casting a function pointer to a (void *). * * In a real use, it is more likely the sender would be a * structure (socket, timer, task, etc) but this is just a test * program. */ event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "1", sizeof(*event)); isc_task_send(t1, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "2", sizeof(*event)); isc_task_send(t2, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "3", sizeof(*event)); isc_task_send(t3, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "4", sizeof(*event)); isc_task_send(t4, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "2", sizeof(*event)); isc_task_send(t2, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "3", sizeof(*event)); isc_task_send(t3, &event); event = isc_event_allocate(mctx, (void *)1, 1, my_callback, "4", sizeof(*event)); isc_task_send(t4, &event); isc_task_purgerange(t3, NULL, ISC_EVENTTYPE_FIRSTEVENT, ISC_EVENTTYPE_LASTEVENT, NULL); isc_task_detach(&t1); isc_task_detach(&t2); isc_task_detach(&t3); isc_task_detach(&t4); sleep(10); printf("destroy\n"); isc_timer_detach(&ti1); isc_timer_detach(&ti2); isc_timermgr_destroy(&timgr); isc_taskmgr_destroy(&manager); printf("destroyed\n"); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); return (0); }
int main(int argc, char *argv[]) { isc_task_t *t1, *t2; isc_timermgr_t *timgr; isc_time_t expires; isc_interval_t interval; isc_timer_t *ti1; unsigned int workers; isc_socketmgr_t *socketmgr; isc_socket_t *so1, *so2; isc_sockaddr_t sockaddr; struct in_addr ina; struct in6_addr in6a; isc_result_t result; int pf; isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); if (argc > 1) { workers = atoi(argv[1]); if (workers < 1) workers = 1; if (workers > 8192) workers = 8192; } else workers = 2; printf("%d workers\n", workers); if (isc_net_probeipv6() == ISC_R_SUCCESS) pf = PF_INET6; else pf = PF_INET; /* * EVERYTHING needs a memory context. */ mctx = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); /* * The task manager is independent (other than memory context) */ manager = NULL; RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) == ISC_R_SUCCESS); /* * Timer manager depends only on the memory context as well. */ timgr = NULL; RUNTIME_CHECK(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); t1 = NULL; RUNTIME_CHECK(isc_task_create(manager, 0, &t1) == ISC_R_SUCCESS); t2 = NULL; RUNTIME_CHECK(isc_task_create(manager, 0, &t2) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t1, my_shutdown, "1") == ISC_R_SUCCESS); RUNTIME_CHECK(isc_task_onshutdown(t2, my_shutdown, "2") == ISC_R_SUCCESS); printf("task 1 = %p\n", t1); printf("task 2 = %p\n", t2); socketmgr = NULL; RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS); /* * Open up a listener socket. */ so1 = NULL; if (pf == PF_INET6) { in6a = in6addr_any; isc_sockaddr_fromin6(&sockaddr, &in6a, 5544); } else { ina.s_addr = INADDR_ANY; isc_sockaddr_fromin(&sockaddr, &ina, 5544); } RUNTIME_CHECK(isc_socket_create(socketmgr, pf, isc_sockettype_tcp, &so1) == ISC_R_SUCCESS); result = isc_socket_bind(so1, &sockaddr, ISC_SOCKET_REUSEADDRESS); RUNTIME_CHECK(result == ISC_R_SUCCESS); RUNTIME_CHECK(isc_socket_listen(so1, 0) == ISC_R_SUCCESS); /* * Queue up the first accept event. */ RUNTIME_CHECK(isc_socket_accept(so1, t1, my_listen, "so1") == ISC_R_SUCCESS); isc_time_settoepoch(&expires); isc_interval_set(&interval, 10, 0); ti1 = NULL; RUNTIME_CHECK(isc_timer_create(timgr, isc_timertype_once, &expires, &interval, t1, timeout, so1, &ti1) == ISC_R_SUCCESS); /* * Open up a socket that will connect to www.flame.org, port 80. * Why not. :) */ so2 = NULL; ina.s_addr = inet_addr("204.152.184.97"); if (0 && pf == PF_INET6) isc_sockaddr_v6fromin(&sockaddr, &ina, 80); else isc_sockaddr_fromin(&sockaddr, &ina, 80); RUNTIME_CHECK(isc_socket_create(socketmgr, isc_sockaddr_pf(&sockaddr), isc_sockettype_tcp, &so2) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_socket_connect(so2, &sockaddr, t2, my_connect, "so2") == ISC_R_SUCCESS); /* * Detaching these is safe, since the socket will attach to the * task for any outstanding requests. */ isc_task_detach(&t1); isc_task_detach(&t2); /* * Wait a short while. */ sleep(10); fprintf(stderr, "Destroying socket manager\n"); isc_socketmgr_destroy(&socketmgr); fprintf(stderr, "Destroying timer manager\n"); isc_timermgr_destroy(&timgr); fprintf(stderr, "Destroying task manager\n"); isc_taskmgr_destroy(&manager); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); return (0); }
int main(int argc, char *argv[]) { char s[1000]; isc_result_t result; dns_fixedname_t wname, wname2, oname, compname, downname; isc_buffer_t source; isc_region_t r; dns_name_t *name, *origin, *comp, *down; unsigned int downcase = 0; size_t len; isc_boolean_t quiet = ISC_FALSE; isc_boolean_t concatenate = ISC_FALSE; isc_boolean_t got_name = ISC_FALSE; isc_boolean_t check_absolute = ISC_FALSE; isc_boolean_t check_wildcard = ISC_FALSE; isc_boolean_t test_downcase = ISC_FALSE; isc_boolean_t inplace = ISC_FALSE; isc_boolean_t want_split = ISC_FALSE; unsigned int labels, split_label = 0; dns_fixedname_t fprefix, fsuffix; dns_name_t *prefix, *suffix; int ch; isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); while ((ch = isc_commandline_parse(argc, argv, "acdiqs:w")) != -1) { switch (ch) { case 'a': check_absolute = ISC_TRUE; break; case 'c': concatenate = ISC_TRUE; break; case 'd': test_downcase = ISC_TRUE; break; case 'i': inplace = ISC_TRUE; break; case 'q': quiet = ISC_TRUE; break; case 's': want_split = ISC_TRUE; split_label = atoi(isc_commandline_argument); break; case 'w': check_wildcard = ISC_TRUE; break; } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc > 0) { if (strcasecmp("none", argv[0]) == 0) origin = NULL; else { len = strlen(argv[0]); isc_buffer_init(&source, argv[0], len); isc_buffer_add(&source, len); dns_fixedname_init(&oname); origin = &oname.name; result = dns_name_fromtext(origin, &source, dns_rootname, 0, NULL); if (result != 0) { fprintf(stderr, "dns_name_fromtext() failed: %d\n", result); exit(1); } } } else if (concatenate) origin = NULL; else origin = dns_rootname; if (argc >= 1) { if (strcasecmp("none", argv[1]) == 0) comp = NULL; else { len = strlen(argv[1]); isc_buffer_init(&source, argv[1], len); isc_buffer_add(&source, len); dns_fixedname_init(&compname); comp = &compname.name; result = dns_name_fromtext(comp, &source, origin, 0, NULL); if (result != 0) { fprintf(stderr, "dns_name_fromtext() failed: %d\n", result); exit(1); } } } else comp = NULL; dns_fixedname_init(&wname); name = dns_fixedname_name(&wname); dns_fixedname_init(&wname2); while (fgets(s, sizeof(s), stdin) != NULL) { len = strlen(s); if (len > 0U && s[len - 1] == '\n') { s[len - 1] = '\0'; len--; } isc_buffer_init(&source, s, len); isc_buffer_add(&source, len); if (len > 0U) result = dns_name_fromtext(name, &source, origin, downcase, NULL); else { if (name == dns_fixedname_name(&wname)) dns_fixedname_init(&wname); else dns_fixedname_init(&wname2); result = ISC_R_SUCCESS; } if (result != ISC_R_SUCCESS) { printf("%s\n", dns_result_totext(result)); if (name == dns_fixedname_name(&wname)) dns_fixedname_init(&wname); else dns_fixedname_init(&wname2); continue; } if (check_absolute && dns_name_countlabels(name) > 0) { if (dns_name_isabsolute(name)) printf("absolute\n"); else printf("relative\n"); } if (check_wildcard && dns_name_countlabels(name) > 0) { if (dns_name_iswildcard(name)) printf("wildcard\n"); else printf("not wildcard\n"); } dns_name_toregion(name, &r); if (!quiet) { print_wirename(&r); printf("%u labels, %u bytes.\n", dns_name_countlabels(name), r.length); } if (concatenate) { if (got_name) { printf("Concatenating.\n"); result = dns_name_concatenate(&wname.name, &wname2.name, &wname2.name, NULL); name = &wname2.name; if (result == ISC_R_SUCCESS) { if (check_absolute && dns_name_countlabels(name) > 0) { if (dns_name_isabsolute(name)) printf("absolute\n"); else printf("relative\n"); } if (check_wildcard && dns_name_countlabels(name) > 0) { if (dns_name_iswildcard(name)) printf("wildcard\n"); else printf("not " "wildcard\n"); } dns_name_toregion(name, &r); if (!quiet) { print_wirename(&r); printf("%u labels, " "%u bytes.\n", dns_name_countlabels(name), r.length); } } else printf("%s\n", dns_result_totext(result)); got_name = ISC_FALSE; } else got_name = ISC_TRUE; } isc_buffer_init(&source, s, sizeof(s)); if (dns_name_countlabels(name) > 0) result = dns_name_totext(name, ISC_FALSE, &source); else result = ISC_R_SUCCESS; if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&source, &r); if (r.length > 0) printf("%.*s\n", (int)r.length, r.base); else printf("<empty text name>\n"); if (!quiet) { printf("%u bytes.\n", source.used); } } else printf("%s\n", dns_result_totext(result)); if (test_downcase) { if (inplace) { down = name; } else { dns_fixedname_init(&downname); down = dns_fixedname_name(&downname); } result = dns_name_downcase(name, down, NULL); INSIST(result == ISC_R_SUCCESS); if (!quiet) { dns_name_toregion(down, &r); print_wirename(&r); printf("%u labels, %u bytes.\n", dns_name_countlabels(down), r.length); } isc_buffer_init(&source, s, sizeof(s)); print_name(down); } if (comp != NULL && dns_name_countlabels(name) > 0) { int order; unsigned int nlabels; dns_namereln_t namereln; namereln = dns_name_fullcompare(name, comp, &order, &nlabels); if (!quiet) { if (order < 0) printf("<"); else if (order > 0) printf(">"); else printf("="); switch (namereln) { case dns_namereln_contains: printf(", contains"); break; case dns_namereln_subdomain: printf(", subdomain"); break; case dns_namereln_commonancestor: printf(", common ancestor"); break; default: break; } if (namereln != dns_namereln_none && namereln != dns_namereln_equal) printf(", nlabels = %u", nlabels); printf("\n"); } printf("dns_name_equal() returns %s\n", dns_name_equal(name, comp) ? "TRUE" : "FALSE"); } labels = dns_name_countlabels(name); if (want_split && split_label < labels) { dns_fixedname_init(&fprefix); prefix = dns_fixedname_name(&fprefix); dns_fixedname_init(&fsuffix); suffix = dns_fixedname_name(&fsuffix); printf("splitting at label %u: ", split_label); dns_name_split(name, split_label, prefix, suffix); printf("\n prefix = "); print_name(prefix); printf(" suffix = "); print_name(suffix); } if (concatenate) { if (got_name) name = &wname2.name; else name = &wname.name; } } return (0); }
int main(int argc, char **argv) { isc_lfsr_t lfsr1, lfsr2; int i; isc_uint32_t temp; UNUSED(argc); UNUSED(argv); isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); /* * Verify that returned values are reproducable. */ isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr1, &state[i], 4); printf("lfsr1: state[%2d] = %08x\n", i, state[i]); } isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr1, &temp, 4); if (state[i] != temp) printf("lfsr1: state[%2d] = %08x, " "but new state is %08x\n", i, state[i], temp); } /* * Now do the same with skipping. */ isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr1, &state[i], 4); isc_lfsr_skip(&lfsr1, 32); printf("lfsr1: state[%2d] = %08x\n", i, state[i]); } isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr1, &temp, 4); isc_lfsr_skip(&lfsr1, 32); if (state[i] != temp) printf("lfsr1: state[%2d] = %08x, " "but new state is %08x\n", i, state[i], temp); } /* * Try to find the period of the LFSR. * * x^16 + x^5 + x^3 + x^2 + 1 */ isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr2, &state[i], 4); printf("lfsr2: state[%2d] = %08x\n", i, state[i]); } isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL); for (i = 0; i < 32; i++) { isc_lfsr_generate(&lfsr2, &temp, 4); if (state[i] != temp) printf("lfsr2: state[%2d] = %08x, " "but new state is %08x\n", i, state[i], temp); } return (0); }