void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void *), void *arg) { HANDLE hThread; struct QemuThreadData *data; qemu_thread_init(); data = g_malloc(sizeof *data); data->thread = thread; data->start_routine = start_routine; data->arg = arg; hThread = (HANDLE) _beginthreadex(NULL, 0, win32_start_routine, data, 0, NULL); if (!hThread) { error_exit(GetLastError(), __func__); } CloseHandle(hThread); }
int find_path_max(void) { #ifdef PATH_MAX int path_max = PATH_MAX; #else int path_max = pathconf("/", _PC_PATH_MAX); if (path_max <= 0) { if (errno) error_exit(TRUE, FALSE, "pathconf() failed\n"); path_max = 4096; } else path_max++; /* since its relative to root */ #endif if (path_max > 4096) path_max = 4096; return path_max; }
void panic(const char *msg, ...) { va_list va; boolean bug = FALSE; if (*msg == '*') { bug = TRUE; msg++; } fflush(stdout); fprintf(stderr, "Fatal error: "); va_start(va, msg); vfprintf(stderr, msg, va); va_end(va); fprintf(stderr, "\n"); if (bug) fprintf(stderr, "Please report bugs to %s\n", PACKAGE_BUGREPORT); fflush(stderr); error_exit(3); }
/*---------------------------------------------------------------------------*/ unsigned int wpcap_read(void) { struct pcap_pkthdr *packet_header; unsigned char *packet; switch(pcap_next_ex(pcap, &packet_header, &packet)) { case -1: error_exit("error on read\n"); case 0: return 0; } if(packet_header->caplen > UIP_BUFSIZE) { return 0; } CopyMemory(uip_buf, packet, packet_header->caplen); return packet_header->caplen; }
/* Call a stop function if a sequence is running in this REGION. No error * return, really. */ void im__call_stop( REGION *reg ) { IMAGE *im = reg->im; int res; /* Stop any running sequence. */ if( reg->seq && im->stop ) { g_mutex_lock( im->sslock ); res = im->stop( reg->seq, im->client1, im->client2 ); g_mutex_unlock( im->sslock ); if( res ) error_exit( "panic: user stop callback failed " "for image %s", im->filename ); reg->seq = NULL; } }
void *xmalloc(void *md, long unsigned size, const char *file, const int line) { void *memory; if ((long)size <= 0) core("xmalloc(%ld).", file, line, (long)size); memory = (void*)dmalloc(md, size, file, line); if (!memory) { if (reserve) { low_memory_warning = 1; FREE(reserve); reserve = NULL; memory = (void*)dmalloc(md, size, file, line); } if (!memory) error_exit("xmalloc(%ld): out of memory.", file, line, (long)size); } return memory; }
void *background_work(void *data) { pthread_attr_t t_attr; struct get_coords_data *cd; struct background_work_data *bgwd = (struct background_work_data*)data; while(work) { safe_sleep(bgwd->step, NULL); cd = malloc(sizeof(struct get_coords_data)); if(cd == NULL) error_exit("Allocating memory:"); cd->list = bgwd->list; start_detached_thread(&cd->mutex, &t_attr, &cd->thread, collect_coordinates, cd); } return NULL; }
int reconnect_tcp_server(struct sockaddr_in * servaddr) { int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) error_exit("tcp socket at reconnect_tcp_server: %s", strerror(errno)); while (-1 == connect(s, (struct sockaddr*)servaddr, sizeof(struct sockaddr))) { if (g_verbose > 1) fprintf(stdout, "THR: thread sleeping for %d ms before retrying connection\n", g_tcp_conn_retry); usleep(g_tcp_conn_retry * 1000); } if (g_verbose > 0) fprintf(stdout, "THR: connected with remote TCP server: %s:%d\n", g_tcp_ipv4_addr, g_tcp_port); return s; }
char *get_arg(char *buff) { char *arg; int k; int w; if (!(arg = malloc(sizeof(char) * (strlen(buff) - 3)))) { error_exit("ERROR: malloc failed.\n"); return (NULL); } k = 0; while (buff[k] && buff[k] != '\n' && buff[k] != '\r' && buff[k] != ' ') k++; k++; w = 0; while (buff[k] && buff[k] != '\n' && buff[k] != '\r') arg[w++] = buff[k++]; arg[w] = '\0'; return (arg); }
unsigned int wpcap_read(unsigned char *buf, unsigned int buflen) { struct pcap_pkthdr *packet_header; unsigned char *packet; switch (pcap_next_ex(pcap, &packet_header, &packet)) { case -1: error_exit("error on read\n"); case 0: return 0; } if (packet_header->caplen > buflen) { return 0; } memcpy(buf, packet, packet_header->caplen); return packet_header->caplen; }
void SendLeaveMessage(int id, int writesocket) { if (player[id].joinstatus >= 4) { int stringsize = 3; unsigned char *buffer = malloc(stringsize); if (buffer == NULL) error_exit("Memory error ( SendLeaveMessage() )\n"); int position = 0; buffer[position] = 253; position++; buffer[position] = id; position++; buffer[position] = 0; //u_strlen ACK position++; SendToAll(buffer, stringsize, 1, writesocket); free(buffer); } }
int mydup(int old_fd) { int new_fd = -1; for(;;) { new_fd = dup(old_fd); if (new_fd == -1) { if (errno == EINTR) continue; error_exit(TRUE, FALSE, "dup() failed\n"); } break; } return new_fd; }
void SendRotUpdate(int id, float rotation, int writesocket) { int stringsize = 6; unsigned char *buffer = malloc(stringsize); if (buffer == NULL) error_exit("Memory error ( SendRotUpdate() )\n"); int position = 0; //if(rotation > 180) rotation = (rotation - 360); buffer[position] = 12; position++; buffer[position] = id; position++; memcpy(buffer + position, &rotation, sizeof(float)); SendToAllOther(id, buffer, stringsize, 1, writesocket); free(buffer); }
/** r�ckgabe �ndern in bool?! **/ TSingleField CSpiel::is_valid_turn(CStone* stone, int playernumber, int startY, int startX)const{ #ifdef _DEBUG if (playernumber < 0 || playernumber >= PLAYER_MAX) error_exit("Falsche Spielerzahl", playernumber); //debug #endif TSingleField valid = FIELD_DENIED; TSingleField field_value; for (int y = 0; y < stone->get_stone_size(); y++){ for (int x = 0; x < stone->get_stone_size(); x++){ if (stone->get_stone_field(y,x) != STONE_FIELD_FREE) { if (!is_position_inside_field(y + startY, x + startX)) return FIELD_DENIED; /*TODO::: eventuell ein array �bergeben*/ field_value = CSpiel::get_game_field (playernumber, y + startY , x + startX); if (field_value == FIELD_DENIED) return FIELD_DENIED; if (field_value == FIELD_ALLOWED) valid = FIELD_ALLOWED; } } } return valid; }
static void echo(int client_socket) #endif { char echo_buffer[RCVBUFSIZE]; int recv_size; if ((recv_size = recv(client_socket, echo_buffer, RCVBUFSIZE, 0)) < 0) error_exit("Fehler bei recv()"); echo_buffer[recv_size] = '\0'; //printf("Nachrichten vom Client : %s ", // echo_buffer); std::chrono::system_clock::time_point p = std::chrono::system_clock::now(); std::time_t t = std::chrono::system_clock::to_time_t(p); std::cout << "Nachricht vom Client: " << echo_buffer << " " << std::ctime(&t) << std::endl; // for example : Tue Dec 16 14:21:13 2014 }
static int find_hist( REGION *reg, void *seq, void *a, void *b ) { Histogram *hist = (Histogram *) seq; Rect *r = ®->valid; IMAGE *im = reg->im; int le = r->left; int to = r->top; int bo = IM_RECT_BOTTOM(r); int nb = im->Bands; int max_val = im->BandFmt == IM_BANDFMT_UCHAR ? 256 : 65536; int scale = max_val / hist->bins; int x, y, z, i; int index[3]; /* Fill these with dimensions, backwards. */ index[0] = index[1] = index[2] = 0; /* Accumulate! */ for( y = to; y < bo; y++ ) { char *line = IM_REGION_ADDR( reg, le, y ); switch( im->BandFmt ) { case IM_BANDFMT_UCHAR: LOOP( unsigned char ); break; case IM_BANDFMT_USHORT: LOOP( unsigned char ); break; default: error_exit( "panic #34847563245" ); } } return( 0 ); }
void dopolygon(vert *basevert) { /* we now have a polygon contained within one source pixel if it's a triangle we call dotriangle() otherwise we recurse */ vert *thevert, *vert1, *vert2, *prev, *next; int nverts = 0; /* count the vertices */ thevert = basevert; while (1) { nverts++; if (thevert->next == basevert) { break; } thevert = thevert->next; } if (nverts < 3) { error_exit("dopolygon: dunno what to do with two-vertex polygon\n"); } if (nverts == 3) { dotriangle(basevert); } else { vert1 = allocvert(); vert2 = allocvert(); next = basevert->next; prev = basevert->prev; *vert1 = *next; *vert2 = *prev; (next->next)->prev = vert1; (prev->prev)->next = vert2; vert1->prev = vert2; vert2->next = vert1; next->next = prev; prev->prev = next; dotriangle(basevert); dopolygon(vert1); } return; }
int main() { int sockfd, connfd; struct sockaddr_un seraddr, cltaddr; socklen_t addrlen = sizeof(cltaddr); char buff[BUFF_SIZE]; int flag = 1; /* argument for setsockopt, SO_REUSEADDR */ if (-1 == (sockfd = socket(AF_LOCAL, SOCK_STREAM, 0))) error_exit("sockfd"); seraddr.sun_family = AF_LOCAL; strcpy(seraddr.sun_path, SERADDR); if (-1 == setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int))) error_exit("setsockopt"); if (-1 == bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr))) error_exit("bind"); if (-1 == listen(sockfd, 10)) error_exit("listen"); if (-1 == (connfd = accept(sockfd, (struct sockaddr *)&cltaddr, &addrlen))) error_exit("accept"); if (0 >= recv(connfd, buff, BUFF_SIZE, 0)) error_exit("recv"); printf("recv:%s\n", buff); strcat(buff, "------echo"); if (-1 == send(connfd, buff, strlen(buff)+1, 0)) error_exit("send"); close(connfd); close(sockfd); return 0; }
void SendTeamChangeMessage(int id, unsigned char team, unsigned char skin, int writesocket) { int stringsize = 4; unsigned char *buffer = malloc(stringsize); if (buffer == NULL) error_exit("Memory error ( SendJoinMessage() )\n"); int position = 0; buffer[position] = 20; position++; buffer[position] = id; position++; buffer[position] = team; position++; buffer[position] = skin; position++; SendToAll(buffer, stringsize, 1, writesocket); free(buffer); }
void SendWeaponChangeMessage(int id, int wpnid, int writesocket) { int stringsize = 4; unsigned char *buffer = malloc(stringsize); if (buffer == NULL) error_exit("Memory error ( SendWeaponChangeMessage() )\n"); int position = 0; buffer[position] = 9; position++; buffer[position] = id; position++; buffer[position] = wpnid; position++; buffer[position] = 0; position++; SendToAll(buffer, stringsize, 1, writesocket); free(buffer); }
// 28 - id - xx - yy - c void SendSprayMessage(char id, unsigned short xx, unsigned short yy, char c, int writesocket) { int stringsize = 8; unsigned char *buffer = malloc(stringsize * sizeof(char)); if (buffer == NULL) error_exit("Memory error ( SendReloadMessage() )\n"); int position = 0; buffer[position++] = 28; buffer[position++] = 0; buffer[position++] = id; memcpy(buffer + position, &xx, 2); position += 2; memcpy(buffer + position, &yy, 2); position += 2; buffer[position++] = c; // SendToAll(buffer, stringsize, 1, writesocket); -- Make sure that the spray-image send packet is crafted first. free(buffer); }
int pkt_asm_val_set_value_binary(pkt_asm_val_t val, int size, void *data) { int data_size; if (val->type != PKT_ASM_VAL_TYPE_BINARY) return -1; if (val->value.binary.data) free(val->value.binary.data); if (size > 0) { data_size = ((size / 16) + 2) * 16; val->value.binary.size = size; val->value.binary.data_size = data_size; val->value.binary.data = malloc(data_size); if (val->value.binary.data == NULL) error_exit("Out of memory.\n"); memcpy(val->value.binary.data, data, size); } else { val->value.binary.size = 0; val->value.binary.data_size = 0; val->value.binary.data = NULL; } return 0; }
// Multiplexer command, first argument is command to run, rest are args to that. // If first argument starts with - output list of command install paths. void toybox_main(void) { static char *toy_paths[]={"usr/","bin/","sbin/",0}; int i, len = 0; // fast path: try to exec immediately. // (Leave toys.which null to disable suid return logic.) if (toys.argv[1]) toy_exec(toys.argv+1); // For early error reporting toys.which = toy_list; if (toys.argv[1]) { if (!strcmp("--version", toys.argv[1])) { xputs(TOYBOX_VERSION); xexit(); } if (toys.argv[1][0] != '-') { toys.exitval = 127; error_exit("Unknown command %s", toys.argv[1]); } } // Output list of command. for (i=1; i<ARRAY_LEN(toy_list); i++) { int fl = toy_list[i].flags; if (fl & TOYMASK_LOCATION) { if (toys.argv[1]) { int j; for (j=0; toy_paths[j]; j++) if (fl & (1<<j)) len += printf("%s", toy_paths[j]); } len += printf("%s",toy_list[i].name); if (++len > 65) len = 0; xputc(len ? ' ' : '\n'); } } xputc('\n'); }
int arp_attack(atklist_st *atklist){ int sockfd; int index; struct in_addr sender; if (-1 == (sockfd = socket(AF_PACKET, SOCK_RAW, 0))) error_exit("socket"); inet_aton(GATEWAY, &sender); while (1) { for (index = 0; index < atklist->atk_num; index ++) { send_arp(sockfd, sender, atklist->atk_list[index]); printf("%s\n", inet_ntoa(atklist->atk_list[index])); usleep(50000); } // sleep(5); } close(sockfd); return 0; }
/* * This is the initialization routine for the random number generator. * NOTE: The seed variables can have values between: 0 <= iSeed1 <= 31328 * 0 <= iSeed2 <= 30081 * The random number sequences created by these two seeds are of sufficient * length to complete an entire calculation with. For example, if sveral * different groups are working on different parts of the same calculation, * each group could be assigned its own iSeed1 seed. This would leave each group * with 30000 choices for the second seed. That is to say, this random * number generator can create 900 million different subsequences -- with * each subsequence having a length of approximately 10^30. * * Use iSeed1 = 1802 & iSeed2 = 9373 to test the random number generator. The * subroutine RANMAR should be used to generate 20000 random numbers. * Then display the next six random numbers generated multiplied by 4096*4096 * If the random number generator is working properly, the random numbers * should be: * 6533892.0 14220222.0 7275067.0 * 6172232.0 8354498.0 10633180.0 */ static void randgen_init(int iSeed1, int iSeed2) { int i, j, k, l, ii, jj, m; float s, t; if (iSeed1<0 || iSeed1>31328 || iSeed2<0 || iSeed2>30081) error_exit("Seed value out of Range. function: randgen_init()"); i = (iSeed1/177)%177 + 2; j = iSeed1%177 + 2; k = (iSeed2/169)%178 + 1; l = iSeed2%169; for (ii=1; ii<=97; ii++) { s = 0.0; t = 0.5; for (jj=1; jj<=24; jj++) { m = (((i*j)%179)*k) % 179; i = j; j = k; k = m; l = (53*l + 1) % 169; if ((l*m)%64 >= 32) s += t; t *= 0.5; } u[ii] = s; } c = 362436.0 / 16777216.0; cd = 7654321.0 / 16777216.0; cm = 16777213.0 / 16777216.0; i97 = 97; j97 = 33; test = GENOCOP_TRUE; }
void gc_collect(struct RootSet *root) { LOG(";; gc_collect called\n"); memset(gc_to_space, 0xcd, gc_space_size); gc_scan = gc_free = gc_to_space; gc_walk_roots(root); while (gc_scan < gc_free) { Ptr *obj = OBJ(gc_scan); switch (OBJTAG(obj)) { case float_tag: error_exit("scan incorrect, unboxed type.\n"); break; case pair_tag: case symbol_tag: case vector_tag: case proc_tag: { unsigned int i, len = OBJLENGTH(obj); unsigned int offset = content_offset(obj); for (i=0; i<len; i++) gc_copy_forward(&obj[i+offset]); LOG("\n"); gc_scan += align(offset + len) * ws; break; } case number_tag: /* box */ case immed_tag: /* bytevector */ case string_tag: gc_scan += object_size(obj); break; } } LOG("switch roles of gc spaces\n"); char *temp = gc_to_space; gc_to_space = gc_cur_space; gc_cur_space = temp; heap_end = gc_cur_space + gc_space_size; memset(gc_to_space, 0xfd, gc_space_size); }
/* True if this IMAGE is a partial of some sort. */ int im_ispartial( IMAGE *im ) { switch( im->dtype ) { case IM_PARTIAL: return( 1 ); case IM_SETBUF: case IM_SETBUF_FOREIGN: case IM_MMAPIN: case IM_MMAPINRW: case IM_OPENIN: case IM_OPENOUT: case IM_NONE: return( 0 ); default: error_exit( "im_ispartial: corrupt IMAGE descriptor" ); /*NOTREACHED*/ return( -1 ); } }
//----------------------------------------------------------------------------- static void target_cm0p_select(void) { uint32_t dsu_did; // Stop the core dap_write_word(DHCSR, 0xa05f0003); dap_write_word(DEMCR, 0x00000001); dap_write_word(AIRCR, 0xfa050004); dsu_did = dap_read_word(DSU_DID); for (device = devices; device->dsu_did > 0; device++) { if (device->dsu_did == dsu_did) { verbose("Target: %s\n", device->name); return; } } error_exit("unknown target device (DSU_DID = 0x%08x)", dsu_did); }
/* * Create a new library */ int create_library(char *libname) { FILE *libfp; struct rdlm_hdr hdr; hdr.magic = RDLAMAG; hdr.hdrsize = 0; hdr.date = time(NULL); hdr.owner = getuid(); hdr.group = getgid(); hdr.mode = umask(022); hdr.size = 0; libfp = fopen(libname, "wb"); if (!libfp) error_exit(1, true, "could not open '%s'\n", libname); /* Write library header */ put_header(&hdr, libfp, NULL); fclose(libfp); return true; }
/*---------------------------------------------------------------------------* * data from keyboard available, read and process it *---------------------------------------------------------------------------*/ static void kbdrdhdl(void) { int ch = getch(); if(ch == ERR) { dolog(LL_ERR, "kbdrdhdl: ERROR, read error on controlling tty, errno = %d!", errno); error_exit(1, "kbdrdhdl: ERROR, read error on controlling tty, errno = %d!", errno); } switch(ch) { case 0x0c: /* control L */ wrefresh(curscr); break; case '\n': case '\r': do_menu(); break; } }