void hash_add(int key, long payload, int *id_ctr){ record_t *s; HASH_FIND(hh, records, &key, sizeof(int),s); //When true, no record with same key exists if(s==NULL) { record_t *r = (record_t*)malloc( sizeof(record_t) ); memset(r, 0, sizeof(record_t)); r->key=key; r->payload=payload; r->id=(*id_ctr)++; r->count=1; HASH_ADD(hh, records, key, sizeof(int), r); ll_add(r->id); } else { //record with same key exists. need to find out if it's the same payload if (s->payload == payload) { s->count++; ll_add(s->id); } else { //key collision for different payloads...what to do? //kinda want to linear probe. maybe chaining } } }
EXPORT void knl_timer_insert_reltim( TMEB *event, RELTIM tmout, CBACK callback, VP arg ) { event->callback = callback; event->arg = arg; /* To guarantee longer wait time specified by 'tmout', add TIMER_PERIOD on wait time */ event->time = ll_add( ll_add(knl_current_time, ultoll(tmout)), uitoll(CFN_TIMER_PERIOD) ); knl_enqueue_tmeb(event); }
/* * Set timeout event * Register the timer event 'event' onto the timer queue to * start after the timeout 'tmout'. At timeout, start with the * argument 'arg' on the callback function 'callback'. * When 'tmout' is TMO_FEVR, do not register onto the timer * queue, but initialize queue area in case 'timer_delete' * is called later. * * "include/tk/typedef.h" * typedef W TMO; * typedef UW RELTIM; * #define TMO_FEVR (-1) */ EXPORT void knl_timer_insert( TMEB *event, TMO tmout, CBACK callback, VP arg ) { event->callback = callback; event->arg = arg; if ( tmout == TMO_FEVR ) { QueInit(&event->queue); } else { /* To guarantee longer wait time specified by 'tmout', add TIMER_PERIOD on wait time */ event->time = ll_add( ll_add(knl_current_time, ltoll(tmout)), uitoll(CFN_TIMER_PERIOD) ); knl_enqueue_tmeb(event); } }
/* * * Simple hooking into system calls. Calls are passed by name to keep them * platform independent. * * * XXX: This is not true^, we can just use SYS_foo too. (Although SYS_clone does * not exist on say, BSD) * */ int tracy_set_hook(struct tracy *t, char *syscall, long abi, tracy_hook_func func) { struct tracy_ll_item *item; int hash; union { void *pvoid; tracy_hook_func pfunc; } _hax; /* XXX: Do this for each abi in abi_mask */ hash = hash_syscall(syscall, abi); item = ll_find(t->hooks, hash); _hax.pfunc = func; if (!item) { if (ll_add(t->hooks, hash, _hax.pvoid)) { /* XXX: Add debug/print here */ return -1; } } else { /* XXX: Add debug/print here */ return -1; } return 0; }
/* Le o arquivo de entrada. */ int read_file(char *path) { FILE *f; char t; int k, flag, dist = 0; f = fopen(path, "r"); if (f == NULL) { return -1; } fscanf(f, "%d", &m); fscanf(f, "%d", &n); fscanf(f, "%c", &v); /* Ler o '\n'. */ fscanf(f, "%c", &v); fscanf(f, "%d", &d); fscanf(f, "%c", &t); /* '\n'... */ ll_init(); while (dist < d) { fscanf(f, "%c", &t); fscanf(f, "%d", &k); dist += k; flag = ll_add(t, k); if (flag != 0) { ll_clean(); return -1; } fscanf(f, "%c", &t); } fclose(f); return 0; }
static int proxy_set(struct tracy_event *e, int fd, proxy_t *proxy) { if(proxy == NULL) { return ll_del(cproxy(e->child->custom)->ll, fd); } else { return ll_add(cproxy(e->child->custom)->ll, fd, proxy); } }
void add_int(int num) { printf(1, "Attempting to add %d to linked list\n", num); lock_acquire(&add); ll_add(&start, num); lock_release(&add); printf(1, "Added %d to linked list\n", num); }
int main(void) { struct llist *list = ll_create(1.7); ll_add(&list, 2.8); ll_print(list); }
int add_cronjob(p_cronjob job) { job->timestamp += get_timestamp() + 1; log_message(INFO,"Adding job for timestamp %d, cronlist %d", job->timestamp, cronlist); p_linkedlist item = ll_create(job, sizeof(t_cronjob)); log_message(DEBUG, "."); cronlist = ll_add(cronlist,item, LL_BACK, 0); log_message(DEBUG, ".."); }
static int processDirectory(char *dirname, LinkedList *ll, int verbose) { DIR *dd; struct dirent *dent; char *sp; int len, status = 1; char d[4096]; /* * eliminate trailing slash, if there */ strcpy(d, dirname); len = strlen(d); if (len > 1 && d[len-1] == '/') d[len-1] = '\0'; /* * open the directory */ if ((dd = opendir(d)) == NULL) { if (verbose) fprintf(stderr, "Error opening directory `%s'\n", d); return 1; } /* * duplicate directory name to insert into linked list */ sp = strdup(d); if (sp == NULL) { fprintf(stderr, "Error adding `%s' to linked list\n", d); status = 0; goto cleanup; } if (!ll_add(ll, sp)) { fprintf(stderr, "Error adding `%s' to linked list\n", sp); free(sp); status = 0; goto cleanup; } if (len == 1 && d[0] == '/') d[0] = '\0'; /* * read entries from the directory */ while (status && (dent = readdir(dd)) != NULL) { if (strcmp(".", dent->d_name) == 0 || strcmp("..", dent->d_name) == 0) continue; if (dent->d_type & DT_DIR) { char b[4096]; sprintf(b, "%s/%s", d, dent->d_name); status = processDirectory(b, ll, 0); } } cleanup: (void) closedir(dd); return status; }
int main(int argc, char **argv) { int i; link_head_t list[] = { /* some lists to operate on */ LINK_HEAD_INIT(0), { DEADINT, DEADINT, DEADPTR, DEADPTR, 0 } /* list[1] is a bad list */ }; link_elem_t elem[] = { /* some elements to operate on */ LINK_ELEM_INIT(OBJECT0), LINK_ELEM_INIT(OBJECT1), LINK_ELEM_INIT(OBJECT2), LINK_ELEM_INIT(OBJECT3), LINK_ELEM_INIT(OBJECT4), LINK_ELEM_INIT(OBJECT5), }; struct itercheck itcheck = { 0, 0 }; /* First, build the lists */ for (i = 0; i < 5; i++) if (ll_add(&list[0], &elem[i], LINK_LOC_TAIL, 0)) return -1; /* failed to initialize test */ /* Baseline checks */ check_list(&list[0], 5, &elem[0], &elem[4], "ll_iter_baseline", "Verify baseline list"); /* Check to see if ll_iter() verifies its arguments correctly */ check_result(ll_iter(0, 0, 0), DB_ERR_BADARGS, "ll_iter_noargs", "ll_iter() with no arguments", 0); check_result(ll_iter(&list[1], check_iter, &itcheck), DB_ERR_BADARGS, "ll_iter_badlist", "ll_iter() with bad list", 0); check_result(ll_iter(&list[0], 0, &itcheck), DB_ERR_BADARGS, "ll_iter_badfunc", "ll_iter() with bad function", 0); /* Now check to see if ll_iter() returns what the iter function returns */ check_result(ll_iter(&list[0], check_iter, &itcheck), EINVAL, "ll_iter_funcreturn", "ll_iter() returning iteration function return value", 0); /* Now iterate through the list */ itcheck.elem_array = elem; itcheck.elem_idx = 0; check_result(ll_iter(&list[0], check_iter, &itcheck), 0, "ll_iter_function", "ll_iter() iteration", 0); /* Did it check them all? */ if (itcheck.elem_idx == 5) printf("PASS/ll_iter_func_count:ll_iter() visited all items\n"); else printf("FAIL/ll_iter_func_count:ll_iter() visited only %d items\n", itcheck.elem_idx); return 0; }
int top_subscribe(char *name, unsigned long id) { Topic *st; if (tshm_get(topicTable, name, (void **)&st)) { pthread_mutex_lock(&(st->lock)); (void)ll_add(st->regAUs, (void *)id); pthread_mutex_unlock(&(st->lock)); return 1; } return 0; }
void recursive_add_to_array(ll_node *array, const char *path) { DIR *d; struct dirent *entry; struct stat s; #ifdef _WIN32 stat(path, &s); #else lstat(path, &s); #endif if(path[strlen(path) - 1] == '.') return; if(s.st_mode & S_IFDIR) { // Directory ll_add(array, path); d = opendir(path); if(d == NULL) { fprintf(stderr, "Warning: Could not open %s\n", path); return; } while((entry = readdir(d)) != NULL) { if(entry->d_name[0] == '.') continue; char *newpath = malloc(255); if(newpath == NULL) { fprintf(stderr, "Not enough memory available!\n"); continue; } memset(newpath, 0, 255); strncat(newpath, path, 254); strncat(newpath, "/", 254 - strlen(newpath)); strncat(newpath, entry->d_name, 254 - strlen(newpath)); recursive_add_to_array(array, newpath); } closedir(d); } else if(s.st_mode & S_IFREG) // File ll_add(array, path); #ifndef _WIN32 else if(s.st_mode & S_IFLNK) // Symlink ll_add(array, path); #endif else { fprintf(stderr, "Warning: cannot archive %s\n", path); } }
/** * @return: * < 0 : success. * < E_VOS_PARAM : fail. */ static int vos_init(int argc, char **argv) { int s; char *env; if (argc < 2 || argc > 2) return E_VOS_PARAM; pthread_mutex_init(&_vos.proc_tmp_dir_lock, 0); /* get Vos variable value from system environment */ sys_getenv_num((unsigned long *) &_vos.debug, VOS_ENV_DEBUG, VOS_DEF_DEBUG_VALUE); sys_getenv_num(&_vos.file_buf_size, VOS_ENV_FILE_BUF_SIZE, VOS_DEF_FILE_BUF_SIZE); sys_getenv_num((unsigned long *) &_vos.proc_cmp_case, VOS_ENV_PROC_CMP_CASE, VOS_DEF_PROC_CMP_CASE); sys_getenv_num((unsigned long *) &_vos.proc_max, VOS_ENV_PROC_MAX, VOS_DEF_PROC_MAX); sys_getenv_num(&_vos.proc_max_row, VOS_ENV_PROC_MAX_ROW, VOS_DEF_PROC_MAX_ROW); /* get temporary dir from system environment */ env = getenv(VOS_ENV_TMP_DIR); if (env) set_proc_tmp_dir_value(env); else { s = ll_add(&_vos.proc_tmp_dir, 1, VOS_DEF_PROC_TMP_DIR); if (s) return s; } _vos.p_proc_tmp_dir = _vos.proc_tmp_dir; _vos.script = argv[1]; srand(time((void *) 0)); if (_vos.debug) vos_print(); return 0; }
/* * Functionality for pthread_cond_wait() */ int mypthread_cond_wait(mypthread_cond_t *cond, mypthread_mutex_t *mutex) { sem_wait(&cond_sem); //Unblock all threads locked by mutex mypthread_mutex_unlock(mutex); //Make the current thread wait for the signal mykthread_t* current_kthread = mykthread_get(gettid()); current_kthread->th->state = PS_BLOCKED; ll_add(current_kthread->th, &(cond->cond_q_head), &(cond->cond_q_tail)); sem_wait(&mypthread_sem); mypthread_enqueue(current_kthread->th); sem_post(&mypthread_sem); sem_post(&cond_sem); mythread_scheduler(current_kthread, 1); mypthread_mutex_lock(mutex); return 0; }
struct tracy_child * tracy_add_child(struct tracy *t, int pid) { struct tracy_child * child; child = malloc_tracy_child(t, pid); if (!child) { perror("Cannot allocate structure for new child"); return NULL; /* TODO Kill the child ? */ } ll_add(t->childs, pid, child); if (t->se.child_create) (t->se.child_create)(child); return child; }
static int hook_dup(struct tracy_event *e) { int rc = TRACY_HOOK_CONTINUE; struct multiboot_child_data *mbc = e->child->custom; if (e->child->pre_syscall) { int fd = (int)e->args.a0; struct tracy_ll_item *item = ll_find(mbc->files, fd); if (item) { struct fd_info *fdi = item->data; mbc->tmp = strdup(fdi->filename); } } else { // we need to handle write for this fd if (mbc->tmp) { int fd = (int)e->args.return_code; DEBUG("dup(%s) = %d\n", mbc->tmp, fd); if (fd >= 0) { struct fd_info *fdi = make_fdinfo(e->child, fd, mbc->tmp); if (fdi) ll_add(mbc->files, fd, make_fdinfo(e->child, fd, mbc->tmp)); else { ERROR("Couldn't make fdinfo for %s!\n", mbc->tmp); free(mbc->tmp); } } // dup failed else free(mbc->tmp); mbc->tmp = NULL; } } return rc; }
/** * @brief Default constructor. */ CRPG_FileVar::CRPG_FileVar(char *n, char *dv, char *p): path(NULL), key(NULL), pathlen(0) { unsigned int dvlen, i; memset(&value, 0, sizeof(value)); WARN_IF((n == NULL) || (p == NULL) || !strlen(p), return); name = (char*)calloc(strlen(n)+1, sizeof(char)); strcpy(name, n); /* Set the default value for this file variable */ if((dv != NULL) && (dvlen = strlen(dv))) { set_value(dv); } else { set_value(NULL); } pathlen = strlen(p); /* Scan backwards for the first '/', everything after it is the key name */ i = pathlen; while(i--) { if(p[i] == '/') break; } i++; WARN_IF(i <= 1, return); key = (char*)calloc(pathlen-i+1, sizeof(char)); strcpy(key, p+i); pathlen = i-1; path = (char*)calloc(pathlen+1, sizeof(char)); strncpy(path, p, pathlen); /* break up the path so it can be parsed */ for(i = 0; i < pathlen; i++) { if(path[i] == '/') path[i] = '\0'; } ll_add(); }
int all(struct tracy_event *e) { struct tracy_ll_item *i; long syscall; if(e->child->pre_syscall) return TRACY_HOOK_CONTINUE; syscall = e->syscall_num; i = ll_find(ll, syscall); if (i) { i->data = (void*)((long)(i->data) + 1); } else { ll_add(ll, syscall, (void*)1); } return TRACY_HOOK_CONTINUE; }
int parser_EmployeeFromBinary(FILE* pFile , LinkedList* pArrayListEmployee) { Employee* pEmpleado = NULL; int retorno = -1; if(pFile != NULL) { while(!feof(pFile)) { pEmpleado = Employee_new(); fread(pEmpleado, sizeof(Employee), 1, pFile); ll_add(pArrayListEmployee, pEmpleado); } retorno = 0; } return retorno; }
/** \ingroup dbprim_hash * \brief Move an entry in the hash table. * * This function moves an existing entry in the hash table to * correspond to the new key. * * \param table A pointer to a #hash_table_t. * \param entry A pointer to a #hash_entry_t to be moved. It must * already be in the hash table. * \param key A pointer to a #db_key_t describing the new key for * the entry. * * \retval DB_ERR_BADARGS An invalid argument was given. * \retval DB_ERR_UNUSED Entry is not in a hash table. * \retval DB_ERR_WRONGTABLE Entry is not in this hash table. * \retval DB_ERR_FROZEN Hash table is frozen. * \retval DB_ERR_DUPLICATE New key is a duplicate of an existing * key. * \retval DB_ERR_READDFAILED Unable to re-add entry to table. */ unsigned long ht_move(hash_table_t *table, hash_entry_t *entry, db_key_t *key) { unsigned long retval; initialize_dbpr_error_table(); /* initialize error table */ if (!ht_verify(table) || !he_verify(entry) || !key) /* verify arguments */ return DB_ERR_BADARGS; if (!entry->he_table) /* it's not in a table */ return DB_ERR_UNUSED; if (entry->he_table != table) /* it's in the wrong table */ return DB_ERR_WRONGTABLE; if (table->ht_flags & HASH_FLAG_FREEZE) /* don't mess with frozen tables */ return DB_ERR_FROZEN; if (!ht_find(table, 0, key)) /* don't permit duplicates */ return DB_ERR_DUPLICATE; /* remove the entry from the table */ if ((retval = ll_remove(&table->ht_table[entry->he_hash], &entry->he_elem))) return retval; /* rekey the entry */ entry->he_key = *key; /* thank goodness for structure copy! */ /* get the new hash value for the entry */ entry->he_hash = (*table->ht_func)(table, &entry->he_key) % table->ht_modulus; /* Now re-add it to the table */ if ((retval = ll_add(&table->ht_table[entry->he_hash], &entry->he_elem, LINK_LOC_HEAD, 0))) { table->ht_count--; /* decrement the count--don't worry about shrinking */ entry->he_table = 0; /* zero the table pointer */ return DB_ERR_READDFAILED; } return 0; }
Llist *ll_clone(Llist *list, ...){ ll_secuList(list); Llist *copy = ll_initialisation(); ll_secuList(copy); va_list ap; va_start(ap, list); int start = va_arg(ap, int); int end = va_arg(ap, int); if(end == 0 || end > ll_size(list)) end = ll_size(list); va_end(ap); Element *res = ll_containt(list, start); ll_addStart(copy, res->valeur); start++; for(int a = start; a < end && res != NULL; a++){ res = res->nxt; ll_add(copy, 1, res->valeur); } return copy; }
EXPORT void knl_timer_handler( void ) { TMEB *event; knl_clear_hw_timer_interrupt(); /* Clear timer interrupt */ BEGIN_CRITICAL_SECTION; knl_current_time = ll_add(knl_current_time, uitoll(CFN_TIMER_PERIOD)); #if USE_DBGSPT && defined(USE_FUNC_TD_INF_TSK) if ( knl_ctxtsk != NULL ) { /* Task at execution */ if ( knl_ctxtsk->sysmode > 0 ) { knl_ctxtsk->stime += CFN_TIMER_PERIOD; } else { knl_ctxtsk->utime += CFN_TIMER_PERIOD; } } #endif /* Execute event that passed occurring time. */ while ( !isQueEmpty(&knl_timer_queue) ) { event = (TMEB*)knl_timer_queue.next; if ( ll_cmp(event->time, knl_current_time) > 0 ) { break; } QueRemove(&event->queue); if ( event->callback != NULL ) { (*event->callback)(event->arg); } } END_CRITICAL_SECTION; knl_end_of_hw_timer_interrupt(); /* Clear timer interrupt */ }
/* * Functionality for pthread_mutex_lock() */ int mypthread_mutex_lock(mypthread_mutex_t *mutex) { sem_wait(&mutex_sem); if (!(mutex->lock)) { mutex->lock = true; sem_post(&mutex_sem); } else { mykthread_t* current_kthread = mykthread_get(gettid()); //No need to acquire mypthread_lock as the mypthread_t are not in the run queue current_kthread->th->state = PS_BLOCKED; ll_add(current_kthread->th, &(mutex->blocked_q_head), &(mutex->blocked_q_tail)); //This will ensure that when the blocked thread becomes runnable, it executes the mutex lock logic again makecontext(current_kthread->th->ctx, (void (*)()) mypthread_mutex_lock, 1, mutex); sem_wait(&mypthread_sem); mypthread_enqueue(current_kthread->th); sem_post(&mypthread_sem); sem_post(&mutex_sem); //Set context to the next active thread mythread_scheduler(current_kthread, 0); } return 0; }
/** \brief Parsea los datos los datos de los empleados desde el archivo data.csv (modo texto). * * \param path char* * \param pArrayListEmployee LinkedList* * \return int * */ int parser_EmployeeFromText(FILE* pFile , LinkedList* pArrayListEmployee) { //validaciones acá! o al contructor con parametros ya que deberia validar desde ahí! Employee* pEmpleado; char bufferInt[1024]; char bufferNombre[1024]; char bufferHorasTrabajadas[1024]; char bufferSueldo[1024]; int flagOnce = 1; int retorno = -1; if(pFile != NULL) { while(!feof(pFile)) { if(flagOnce) { flagOnce = 0; fscanf(pFile, "%[^,],%[^,],%[^,],%[^\n]\n", bufferInt, bufferNombre, bufferHorasTrabajadas, bufferSueldo); //Descarta primer linea } fscanf(pFile, "%[^,],%[^,],%[^,],%[^\n]\n", bufferInt, bufferNombre, bufferHorasTrabajadas, bufferSueldo); printf("%s - %s - %s - %s\n", bufferInt, bufferNombre, bufferHorasTrabajadas, bufferSueldo); pEmpleado = Employee_newConParametros(bufferInt, bufferNombre, bufferHorasTrabajadas, bufferSueldo); if(pEmpleado != NULL) { ll_add(pArrayListEmployee, pEmpleado); retorno = 0; } } } return retorno; }
/** * add a client into our array of clients */ t_client *add_client(TCPsocket sock, p_rocsmq_clientdata info) { char *tok; char filter[ROCS_IDSIZE]; p_client client = 0; // resize list clients = (p_client) realloc(clients, (num_clients + 1) * sizeof(t_client)); client = &clients[num_clients]; // copy name strcpy((void *) client->name, info->name); // copy socket client->sock = sock; // create filter list client->filters = 0; tok = strtok(info->filter, MESSAGE_SEPARATOR); memset(filter,'\0',ROCS_IDSIZE); while(tok) { // add filter log_message(DEBUG, "Adding filter %s [%d] to client %s.", tok, strlen(tok)+1, client->name); strcpy(filter,tok); p_linkedlist item = ll_create(filter, ROCS_IDSIZE); client->filters = ll_add(client->filters,item,LL_BACK, 0); // get next filter tok = strtok(0,MESSAGE_SEPARATOR); } // add client number num_clients++; // return client return client; }
void ll_insert(LinkedList *root, int val, size_t index) { for(size_t i = 0; i<index;i++) root = root->next; ll_add(root,val); }
int main(int argc, char *argv[]) { /* Define the options specific to the DNS protocol. */ struct option long_options[] = { /* General options */ {"help", no_argument, 0, 0}, /* Help */ {"h", no_argument, 0, 0}, {"version", no_argument, 0, 0}, /* Version */ #if 0 {"name", required_argument, 0, 0}, /* Name */ {"n", required_argument, 0, 0}, {"download",required_argument, 0, 0}, /* Download */ {"n", required_argument, 0, 0}, {"chunk", required_argument, 0, 0}, /* Download chunk */ {"isn", required_argument, 0, 0}, /* Initial sequence number */ #endif {"delay", required_argument, 0, 0}, /* Retransmit delay */ {"steady", no_argument, 0, 0}, /* Don't transmit immediately after getting a response. */ {"max-retransmits", required_argument, 0, 0}, /* Set the max retransmissions */ {"retransmit-forever", no_argument, 0, 0}, /* Retransmit forever if needed */ #ifndef NO_ENCRYPTION {"secret", required_argument, 0, 0}, /* Pre-shared secret */ {"no-encryption", no_argument, 0, 0}, /* Disable encryption */ #endif /* i/o options. */ {"console", no_argument, 0, 0}, /* Enable console */ {"exec", required_argument, 0, 0}, /* Enable execute */ {"e", required_argument, 0, 0}, {"command", no_argument, 0, 0}, /* Enable command (default) */ {"ping", no_argument, 0, 0}, /* Ping */ /* Tunnel drivers */ {"dns", required_argument, 0, 0}, /* Enable DNS */ #if 0 {"tcp", optional_argument, 0, 0}, /* Enable TCP */ #endif /* Debug options */ {"d", no_argument, 0, 0}, /* More debug */ {"q", no_argument, 0, 0}, /* Less debug */ {"packet-trace", no_argument, 0, 0}, /* Trace packets */ /* Sentry */ {0, 0, 0, 0} /* End */ }; int c; int option_index; const char *option_name; NBBOOL tunnel_driver_created = FALSE; ll_t *drivers_to_create = ll_create(NULL); uint32_t drivers_created = 0; log_level_t min_log_level = LOG_LEVEL_WARNING; group = select_group_create(); system_dns = dns_get_system(); /* Seed with the current time; not great, but it'll suit our purposes. */ srand((unsigned int)time(NULL)); /* This is required for win32 support. */ winsock_initialize(); #ifndef WIN32 /* set the SIGCHLD handler to SIG_IGN causing zombie child processes to be reaped automatically */ if(signal(SIGCHLD, SIG_IGN) == SIG_ERR) { perror("Couldn't set SIGCHLD handler to SIG_IGN"); exit(1); } #endif /* Set the default log level */ log_set_min_console_level(min_log_level); /* Parse the command line options. */ opterr = 0; while((c = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch(c) { case 0: option_name = long_options[option_index].name; /* General options */ if(!strcmp(option_name, "help") || !strcmp(option_name, "h")) { usage(argv[0], "--help requested"); } if(!strcmp(option_name, "version")) { printf(NAME" "VERSION" (client)\n"); exit(0); } else if(!strcmp(option_name, "isn")) { uint16_t isn = (uint16_t) (atoi(optarg) & 0xFFFF); debug_set_isn(isn); } else if(!strcmp(option_name, "delay")) { int delay = (int) atoi(optarg); session_set_delay(delay); LOG_INFO("Setting delay between packets to %dms", delay); } else if(!strcmp(option_name, "steady")) { session_set_transmit_immediately(FALSE); } else if(!strcmp(option_name, "max-retransmits")) { controller_set_max_retransmits(atoi(optarg)); } else if(!strcmp(option_name, "retransmit-forever")) { controller_set_max_retransmits(-1); } #ifndef NO_ENCRYPTION else if(!strcmp(option_name, "secret")) { session_set_preshared_secret(optarg); } else if(!strcmp(option_name, "no-encryption")) { session_set_encryption(FALSE); } #endif /* i/o drivers */ else if(!strcmp(option_name, "console")) { ll_add(drivers_to_create, ll_32(drivers_created++), make_console()); /* session = session_create_console(group, "console"); controller_add_session(session); */ } else if(!strcmp(option_name, "exec") || !strcmp(option_name, "e")) { ll_add(drivers_to_create, ll_32(drivers_created++), make_exec(optarg)); /* session = session_create_exec(group, optarg, optarg); controller_add_session(session); */ } else if(!strcmp(option_name, "command")) { ll_add(drivers_to_create, ll_32(drivers_created++), make_command()); /* session = session_create_command(group, "command"); controller_add_session(session); */ } else if(!strcmp(option_name, "ping")) { ll_add(drivers_to_create, ll_32(drivers_created++), make_ping()); /* session = session_create_ping(group, "ping"); controller_add_session(session); */ } /* Tunnel driver options */ else if(!strcmp(option_name, "dns")) { tunnel_driver_created = TRUE; tunnel_driver = create_dns_driver(group, optarg); } else if(!strcmp(option_name, "tcp")) { tunnel_driver_created = TRUE; create_tcp_driver(optarg); } /* Debug options */ else if(!strcmp(option_name, "d")) { if(min_log_level > 0) { min_log_level--; log_set_min_console_level(min_log_level); } } else if(!strcmp(option_name, "q")) { min_log_level++; log_set_min_console_level(min_log_level); } else if(!strcmp(option_name, "packet-trace")) { session_enable_packet_trace(); } else { usage(argv[0], "Unknown option"); } break; case '?': default: usage(argv[0], "Unrecognized argument"); break; } } create_drivers(drivers_to_create); ll_destroy(drivers_to_create); if(tunnel_driver_created && argv[optind]) { printf("It looks like you used --dns and also passed a domain on the commandline.\n"); printf("That's not allowed! Either use '--dns domain=xxx' or don't use a --dns\n"); printf("argument!\n"); exit(1); } /* If no output was set, use the domain, and use the last option as the * domain. */ if(!tunnel_driver_created) { /* Make sure they gave a domain. */ if(optind >= argc) { printf("Starting DNS driver without a domain! This will only work if you\n"); printf("are directly connecting to the dnscat2 server.\n"); printf("\n"); printf("You'll need to use --dns server=<server> if you aren't.\n"); tunnel_driver = create_dns_driver_internal(group, NULL, "0.0.0.0", 53, DEFAULT_TYPES, NULL); } else { tunnel_driver = create_dns_driver_internal(group, argv[optind], "0.0.0.0", 53, DEFAULT_TYPES, NULL); } } /* Be sure we clean up at exit. */ atexit(cleanup); /* Start the driver! */ driver_dns_go(tunnel_driver); return 0; }
int main () { printf("Tester for ll\n"); ll * l1 = ll_create(2); printf("Head is %d\n",l1->head); ll_add(l1,"AAAAAAAAAAAAA",5,1); ll_add(l1,"AAAAAAAAAAAAA",5,1); ll_add(l1,"AAAAAAAAAAAAA",5,1); ll_add(l1,"AAAAAAAAAAAAA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"AAAAAAAAAAACCA",5,1); ll_add(l1,"ACAAAAAAAAACCA",5,1); ll_add(l1,"ACAAAAAAAAACCA",5,1); ll_add(l1,"ACAAAAAAAAACCA",5,1); ll_add(l1,"ACAAAAAAAAACCA",5,1); ll_print(l1); int hw; ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); ll_max(l1,300,&hw,5); printf("There are %d max's\n",hw); ll_max(l1,3,&hw,5); printf("There are %d max's\n",hw); ll_max(l1,3,&hw,5); printf("There are %d max's\n",hw); ll_max(l1,3,&hw,5); printf("There are %d max's\n",hw); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_max(l1,3,&hw,5); ll_print(l1); return 0; }
/* * This function creates a fdinfo entry if the device needs format detection */ static int hook_open(struct tracy_event *e, int argpos, bool resolve_symlinks) { int rc = TRACY_HOOK_CONTINUE; struct fstab_rec *fstabrec; struct multiboot_child_data *mbc = e->child->custom; char *path = NULL; long *argptr = NULL; if (e->child->pre_syscall) { argptr = &e->args.a0; // we don't need to handle readonly access int flags = (int)argptr[argpos + 1]; if ((flags & O_ACCMODE) == O_RDONLY) goto out; // get path path = get_patharg(e->child, argptr[argpos], resolve_symlinks); if (!path) { rc = TRACY_HOOK_ABORT; goto out; } // check if we need to redirect this partition fstabrec = get_fstab_rec(path); if (!fstabrec) { goto out; } // losetup's can be formatted already if (!fstabrec->replacement_bind) { ERROR("%s: no bind for %s\n", __func__, path); goto out; } // check fs now // to update the last_checked timestamp check_fs_nomount(fstabrec->stub_device); mbc->handled_by_open = 1; // store path for post_syscall mbc->tmp = path; } else if (mbc->handled_by_open) { // we need to handle format for this fd if (mbc->tmp) { int fd = (int)e->args.return_code; ERROR("open(%s) = %d\n", mbc->tmp, fd); // add to fd list if (fd >= 0) { struct fd_info *fdi = make_fdinfo(e->child, fd, mbc->tmp); if (fdi) ll_add(mbc->files, fd, fdi); else { ERROR("Couldn't make fdinfo for %s!\n", mbc->tmp); free(mbc->tmp); } } // open failed else free(mbc->tmp); mbc->tmp = NULL; } } out: if (rc && path) free(path); if (!e->child->pre_syscall) mbc->handled_by_open = 0; return rc; }