int main(int argc, char *argv[]) { int fds; int fdc; int fdf; struct sockaddr_in srvAddr; struct sockaddr_in cliAddr; unsigned int srvAddrLen; unsigned int cliAddrLen; char wrkBuf[4096]; ssize_t nRead; if(argc != 4) { fprintf(stderr, "usage: minitcpsrvr ip-addr port outfile\n"); exit(1); } if(!strcmp(argv[3], "-")) { fdf = 1; } else { fdf = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR); if(fdf == -1) errout(argv[3]); } fds = socket(AF_INET, SOCK_STREAM, 0); srvAddr.sin_family = AF_INET; srvAddr.sin_addr.s_addr = inet_addr(argv[1]); srvAddr.sin_port = htons(atoi(argv[2])); srvAddrLen = sizeof(srvAddr); if(bind(fds, (struct sockaddr *)&srvAddr, srvAddrLen) != 0) errout("bind"); if(listen(fds, 20) != 0) errout("listen"); cliAddrLen = sizeof(cliAddr); fdc = accept(fds, (struct sockaddr *)&cliAddr, &cliAddrLen); while(1) { nRead = read(fdc, wrkBuf, sizeof(wrkBuf)); if(nRead == 0) break; if(write(fdf, wrkBuf, nRead) != nRead) errout("write"); } /* let the OS do the cleanup */ return 0; }
int main ( int argc, char *argv[] ) { Param params; FlowCom *comPtr = NULL; char line [ LINE_LEN ]; while ( argc > 1 ) { if ( !strcmp( argv[1], "-D" ) ) { setDebugFlag(); } else if ( !strcmp( argv[1], "-V" ) ) { printf ( "%s\n", VERSION ); exit ( 0 ); } else { break; } argv++; argc--; } open_tempfile(); open_infile ( ( argc > 1 ) ? argv[ 1 ] : NULL ); tprintf ( "%% picture environment flowchart generated by flow " ); tprintf ( "%s\n", VERSION ); while ( readline_infile ( line, LINE_LEN ) != NULL ) { if ( ( comPtr = getCommand ( line, params ) ) != NULL ) { switch ( comPtr -> command ) { case MACRO: if ( doMacro ( params ) ) { errout ( E_NO_END_MACRO ); } break; case EXPAND: doExpand ( params ); break; default: if ( !doCommand ( comPtr, params ) ) { return 10; } } } else { break; } } close_infile(); close_tempfile(); apply_tempfile ( getPic(), ( argc > 2 ) ? argv[ 2 ] : NULL ); remove_tempfile(); // dumpFigure(); return 0; /* just to suppress the warning */ }
void DataPipe::ScanFiles() { FILE* f; char fn[MAXPATHLEN]; SDataPlacement cp; SChunkFileRec rec; //scan world files to map known chunks for (chsavelast = 0; ; chsavelast++) { //get the save file name and open it snprintf(fn,sizeof(fn),CHUNKSAVEFILE,root,chsavelast); f = fopen(fn,"rb"); if (!f) break; //if new game, delete this file if (settings.new_game) { fclose(f); unlink(fn); #ifdef DPDEBUG dbg_print("[DP] Deleted file '%s'",fn); #endif continue; } //scan chunks contained in file while (!feof(f)) { cp.offset = (ulli)ftell(f); cp.filenum = chsavelast; //read chunk sub-header if (fread(&rec,sizeof(rec),1,f) < 1) { if (feof(f)) break; //EOF will be set only after the next read beyond the EOF :) errout("Unable to read chunk sub-header at %llu in file '%s'\n",cp.offset,fn); break; } //fill placement data cp.pos = rec.pos; cp.length = rec.length; //append position information and advance through file placetab.insert(std::make_pair(GetChunkLinearOffset(cp.pos),cp)); fseek(f,cp.length,SEEK_CUR); #ifdef DPDEBUG dbg_print("[DP] Detected data for chunk at [%d %d %d]; file #%llu",cp.pos.X,cp.pos.Y,cp.pos.Z,chsavelast); #endif } //close the file fclose(f); } //reset file numbering for new game if (settings.new_game) chsavelast = 0; }
void *xcalloc(size_t num, size_t size) { void *c = calloc(num, size); if (NULL == c) { errout("Not enough memory.\n"); return NULL; } return c; }
/*! * Read a sequence from a file "fnin" of format "format". If "format" is 0 * (ANY_FORMAT), we automatically determine the correct format. * Returns: * Read * for success * NULLRead for failure */ Read *read_reading(char *fn, int format) { Read *read; mFILE *fp; #ifdef USE_BIOLIMS if( !strncmp(fn,BIOLIMS_TAG,strlen(BIOLIMS_TAG))){ return spReadBiolimsReading(fn); } #endif /* * If we're asking for an Experiment file, read it. * If the format is ANY then attempt EXP first following by trace. * Otherwise use the trace search mechanism. * * Note this is purely for locating files and not for forcing the file * format. It's here so that experiment files and trace files may be * given identical names but accessed through different search paths * (as is the case with the trace server). */ if (format == TT_EXP) { if (NULL == (fp = open_exp_mfile(fn, NULL))) { errout("'%s': couldn't open\n", fn); return NULL; } } else { fp = NULL; if (format == TT_ANY) fp = open_exp_mfile(fn, NULL); if (!fp && NULL == (fp = open_trace_mfile(fn, NULL))) { errout("'%s': couldn't open\n", fn); return NULL; } } read = mfread_reading(fp, fn, format); mfclose(fp); return read; }
void tprintf ( char *fmt, ... ) { va_list ap; if ( outFile == NULL ) { errout ( E_TEMPFILE_NOT_OPENED ); } else { va_start ( ap, fmt ); vfprintf ( outFile, fmt, ap ); va_end( ap ); } }
void tdprintf ( char *fmt, ... ) { va_list ap; if ( outFile == NULL ) { errout ( E_TEMPFILE_NOT_OPENED ); } else if ( debugFlag == 1 ) { fprintf ( outFile, "%%DEBUG: " ); va_start ( ap, fmt ); vfprintf ( outFile, fmt, ap ); va_end( ap ); } }
UCHAR *readfile(UCHAR *name, UCHAR *b0, UCHAR *b1) { FILE *fp; int bytes, len = b1 - b0; fp = fopen(name, "rb"); if (fp == NULL) errout_s_NL("can't open file: ", name); bytes = fread(b0, 1, len, fp); fclose(fp); if (len == bytes) errout("input filebuf over!" NL); return b0 + bytes; }
void apply_tempfile ( BoundingBox pic, char *outName ) { FILE *ifp; FILE *ofp; if ( ( ifp = fopen ( tmpfileName, "r" ) ) == NULL ) { errout ( E_OPEN_TEMPFILE, tmpfileName ); } if ( outName == NULL ) { ofp = stdout; } else if ( ( ofp = fopen ( outName, "w" ) ) == NULL ) { errout ( E_OPEN_OUTPUT, outName ); } applyPicWrapper ( ifp, ofp, pic ); if ( ofp != stdout ) { fclose ( ofp ); } fclose ( ifp ); }
int main(int argc, UCHAR **argv) { struct stack_alloc *pwork; UCHAR *p0, *filename, *src1, i = 0; struct STR_FLAGS flags; pwork = (struct stack_alloc *) malloc(sizeof (struct stack_alloc)); flags.opt[FLAG_E] = flags.opt[FLAG_S] = 0; while (--argc) { p0 = *++argv; if (*p0 == '-') { do { p0++; if (*p0 == 's') flags.opt[FLAG_S] = 1; } while (*p0 > ' '); } else { filename = p0; if (i == 0) src1 = readfile(filename, pwork->ibuf, pwork->ibuf + sizeof (pwork->ibuf)); i++; } }; if (i != 2) { errout("\"sjisconv\" Copyright(C) 2003 H.Kawai" NL "usage : >sjisconv [-e] [-s] input-file output-file" NL ); } src1 = convmain(pwork->ibuf, src1, pwork->obuf, pwork->obuf + sizeof (pwork->obuf), flags); if (src1 == NULL) errout("output filebuf over!" NL); if (GOLD_write_t(filename, src1 - pwork->obuf, pwork->obuf)) errout_s_NL("can't write file: ", filename); return 0; }
void VL_MungePic (unsigned char far *source, unsigned width, unsigned height) { unsigned x,y,plane,size,pwidth; unsigned char far *temp, far *dest, far *srcline; size = width*height; if (width&3) errout ("VL_MungePic: Not divisable by 4!\n"); // // copy the pic to a temp buffer // temp = (unsigned char far *)farmalloc (size); if (!temp) errout ("Non enough memory for munge buffer!\n"); _fmemcpy (temp,source,size); // // munge it back into the original buffer // dest = source; pwidth = width/4; for (plane=0;plane<4;plane++) { srcline = temp; for (y=0;y<height;y++) { for (x=0;x<pwidth;x++) *dest++ = *(srcline+x*4+plane); srcline+=width; } } free (temp); }
UCHAR *readfile(UCHAR *name, UCHAR *b0, UCHAR *b1) { HANDLE h; int bytes, len = b1 - b0; h = CreateFileA((char *) name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (h == INVALID_HANDLE_VALUE) errout_s_NL("can't open file: ", name); if (ReadFile(h, b0, len, &bytes, NULL)) CloseHandle(h); if (len == bytes) errout("input filebuf over!" NL); return b0 + bytes; }
void test_mpow(void) { int i, j, mem, x; unsigned int *a, *b, *c; logout("testing mpow\n"); mem = mtotal; // small numbers for (i = -10; i < 10; i++) { a = mint(i); x = 1; for (j = 0; j < 10; j++) { b = mpow(a, j); c = mint(x); if (mcmp(b, c) != 0) { sprintf(logbuf, "failed a=%d b=%d c=%d\n", a[0], b[0], c[0]); logout(logbuf); errout(); } mfree(b); mfree(c); x *= i; } mfree(a); } if (mem != mtotal) { logout("memory leak\n"); errout(); } logout("ok\n"); }
void open_tempfile ( void ) { #ifdef KURINO mkstemp ( tmpfileName ); #else tmpnam ( tmpfileName ); #endif #ifdef DEBUG_PRINT fprintf ( stderr, "tmepfile=(%s)\n", tmpfileName ); #endif if ( ( outFile = fopen ( tmpfileName, "w" ) ) == NULL ) { errout ( E_OPEN_TEMPFILE, tmpfileName ); } }
void *xrealloc(void *ptr, size_t size) { void *c; /* * realloc _should_ allocate memory for us when ptr is NULL. * Unfortunately this is not the case with the non-ANSI conformant * C library provided with SunOS4.1 */ if (ptr) c = realloc(ptr, size); else c = malloc(size); if (NULL == c) { errout("Not enough memory.\n"); return NULL; } return c; }
/* * Read a sequence from a file "fnin" of format "format". If "format" is 0 * (ANY_FORMAT), we automatically determine the correct format. * Returns: * Read * for success * NULLRead for failure */ Read *read_reading(char *fn, int format) { Read *read; mFILE *fp; #ifdef USE_BIOLIMS if( !strncmp(fn,BIOLIMS_TAG,strlen(BIOLIMS_TAG))){ return spReadBiolimsReading(fn); } #endif if (NULL == (fp = open_trace_mfile(fn, NULL))) { errout("'%s': couldn't open\n", fn); return NULL; } read = mfread_reading(fp, fn, format); mfclose(fp); return read; }
void test_low_level(void) { run("clear"); // to initialize stack and memory if (setjmp(stop_return)) { errout(); return; } test_madd(); test_msub(); test_mmul(); test_mdiv(); test_mmod(); test_mprime(); test_mgcd(); test_mpow(); test_mroot(); test_quickfactor(); }
void test_msqrt(void) { int i; unsigned int *n, *x, *y; logout("testing msqrt\n"); for (i = 0; i < 1000000; i++) { n = mint(i); x = msqrt(n); y = mint((int) (sqrt((double) i) + 1e-10)); if (mcmp(x, y) != 0) { sprintf(logbuf, "failed for %d got %u\n", i, x[0]); logout(logbuf); errout(); } mfree(n); mfree(x); mfree(y); } logout("ok\n"); }
void establish_contexts(gss_OID imech, gss_cred_id_t icred, gss_cred_id_t acred, gss_name_t tname, OM_uint32 flags, gss_ctx_id_t *ictx, gss_ctx_id_t *actx, gss_name_t *src_name, gss_OID *amech, gss_cred_id_t *deleg_cred) { OM_uint32 minor, imaj, amaj; gss_buffer_desc itok, atok; *ictx = *actx = GSS_C_NO_CONTEXT; imaj = amaj = GSS_S_CONTINUE_NEEDED; itok.value = atok.value = NULL; itok.length = atok.length = 0; for (;;) { (void)gss_release_buffer(&minor, &itok); imaj = gss_init_sec_context(&minor, icred, ictx, tname, imech, flags, GSS_C_INDEFINITE, GSS_C_NO_CHANNEL_BINDINGS, &atok, NULL, &itok, NULL, NULL); check_gsserr("gss_init_sec_context", imaj, minor); if (amaj == GSS_S_COMPLETE) break; (void)gss_release_buffer(&minor, &atok); amaj = gss_accept_sec_context(&minor, actx, acred, &itok, GSS_C_NO_CHANNEL_BINDINGS, src_name, amech, &atok, NULL, NULL, deleg_cred); check_gsserr("gss_accept_sec_context", amaj, minor); (void)gss_release_buffer(&minor, &itok); if (imaj == GSS_S_COMPLETE) break; } if (imaj != GSS_S_COMPLETE || amaj != GSS_S_COMPLETE) errout("One side wants to continue after the other is done"); (void)gss_release_buffer(&minor, &itok); (void)gss_release_buffer(&minor, &atok); }
gss_name_t import_name(const char *str) { OM_uint32 major, minor; gss_name_t name; gss_buffer_desc buf; gss_OID nametype = NULL; if (*str == 'u') nametype = GSS_C_NT_USER_NAME; else if (*str == 'p') nametype = (gss_OID)GSS_KRB5_NT_PRINCIPAL_NAME; else if (*str == 'e') nametype = (gss_OID)GSS_KRB5_NT_ENTERPRISE_NAME; else if (*str == 'h') nametype = GSS_C_NT_HOSTBASED_SERVICE; if (nametype == NULL || str[1] != ':') errout("names must begin with u: or p: or e: or h:"); buf.value = (char *)str + 2; buf.length = strlen(str) - 2; major = gss_import_name(&minor, &buf, nametype, &name); check_gsserr("gss_import_name", major, minor); return name; }
void test(char *file, char **s, int n) { int i; char *t; test_flag = 1; run("clear"); run("e=quote(e)"); for (i = 0; i < n; i++) { logout(s[i]); logout("\n"); if (s[i][0] == '#') continue; out_count = 0; run(s[i]); out_buf[out_count] = 0; t = out_buf; // skip leading newlines while (*t == '\n') t++; // remove trailing newlines while (out_count && out_buf[out_count - 1] == '\n') out_buf[--out_count] = 0; i++; if (strcmp(t, s[i]) == 0) continue; // make copy because logout clobbers out_buf t = strdup(t); logout("expected to get the following result:\n"); logout(s[i]); logout("\n"); logout("got this result instead:\n"); logout(t); logout("\n"); logout(file); logout("\n"); free(t); errout(); } test_flag = 0; }
void DataPipe::SaveChunk(const unsigned l) { FILE* sav; SDataPlacement plc; char fn[MAXPATHLEN]; vector3di pos; SChunkFileRec rec; bool fnd = false; //check if this chunk should be saved if ((!chstat[l].changed) || (settings.dryrun)) return; pos = vector3di(chstat[l].pos); #ifdef DPDEBUG dbg_print("[DP] Saving chunk %u at [%d %d %d]",l,pos.X,pos.Y,pos.Z); #endif //if there's a file containing our chunk, use its number if (!FindChunk(pos,&plc)) plc.filenum = chsavelast; //or just use the next number else fnd = true; //get the save file name and open it snprintf(fn,sizeof(fn),CHUNKSAVEFILE,root,plc.filenum); sav = fopen(fn,"wb"); if (!sav) { errout("[DP] SaveChunk(): unable to open the file '%s'\n",fn); return; } //if our file isn't new, seek to the position needed if (fnd) { fseek(sav,plc.offset,SEEK_SET); } else { fseek(sav,0,SEEK_END); plc.offset = (ulli)ftell(sav); //check the size of the resulting file (in advance) if ( (plc.offset + ((sizeof(SChunkFileRec) + sizeof(VChunk)) * 2)) >= settings.maxchfile) { //next time, we'll open the new file chsavelast++; } } //fill in placement info remaining plc.length = sizeof(VChunk); rec.pos = chstat[l].pos; rec.length = plc.length; //write to file fwrite(&rec,sizeof(rec),1,sav); fwrite(chunks[l],sizeof(VChunk),1,sav); //append data placement information if (!fnd) { plc.pos = pos; placetab.insert(std::make_pair(GetChunkLinearOffset(pos),plc)); } //and we're done fclose(sav); chstat[l].changed = false; //remove 'changed' flag }
int main(int argc, char *argv[]) { krb5_error_code ret; krb5_context kctx = NULL; krb5_enctype *ienc = NULL, *aenc = NULL, zero = 0; OM_uint32 minor, major, flags; gss_name_t tname; gss_cred_id_t icred = GSS_C_NO_CREDENTIAL, acred = GSS_C_NO_CREDENTIAL; gss_ctx_id_t ictx, actx; gss_krb5_lucid_context_v1_t *ilucid, *alucid; gss_krb5_rfc1964_keydata_t *i1964, *a1964; gss_krb5_cfx_keydata_t *icfx, *acfx; size_t count; void *lptr; int c; ret = krb5_init_context(&kctx); check_k5err(kctx, "krb5_init_context", ret); /* Parse arguments. */ while ((c = getopt(argc, argv, "i:a:")) != -1) { switch (c) { case 'i': ret = krb5int_parse_enctype_list(kctx, "", optarg, &zero, &ienc); check_k5err(kctx, "krb5_parse_enctype_list(initiator)", ret); break; case 'a': ret = krb5int_parse_enctype_list(kctx, "", optarg, &zero, &aenc); check_k5err(kctx, "krb5_parse_enctype_list(acceptor)", ret); break; default: usage(); } } argc -= optind; argv += optind; if (argc != 1) usage(); tname = import_name(*argv); if (ienc != NULL) { major = gss_acquire_cred(&minor, GSS_C_NO_NAME, GSS_C_INDEFINITE, &mechset_krb5, GSS_C_INITIATE, &icred, NULL, NULL); check_gsserr("gss_acquire_cred(initiator)", major, minor); for (count = 0; ienc[count]; count++); major = gss_krb5_set_allowable_enctypes(&minor, icred, count, ienc); check_gsserr("gss_krb5_set_allowable_enctypes(init)", major, minor); } if (aenc != NULL) { major = gss_acquire_cred(&minor, GSS_C_NO_NAME, GSS_C_INDEFINITE, &mechset_krb5, GSS_C_ACCEPT, &acred, NULL, NULL); check_gsserr("gss_acquire_cred(acceptor)", major, minor); for (count = 0; aenc[count]; count++); major = gss_krb5_set_allowable_enctypes(&minor, acred, count, aenc); check_gsserr("gss_krb5_set_allowable_enctypes(acc)", major, minor); } flags = GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG | GSS_C_MUTUAL_FLAG; establish_contexts(&mech_krb5, icred, acred, tname, flags, &ictx, &actx, NULL, NULL, NULL); /* Export to lucid contexts. */ major = gss_krb5_export_lucid_sec_context(&minor, &ictx, 1, &lptr); check_gsserr("gss_export_lucid_sec_context(initiator)", major, minor); ilucid = lptr; major = gss_krb5_export_lucid_sec_context(&minor, &actx, 1, &lptr); check_gsserr("gss_export_lucid_sec_context(acceptor)", major, minor); alucid = lptr; /* Grab the session keys and make sure they match. */ if (ilucid->protocol != alucid->protocol) errout("Initiator/acceptor protocol mismatch"); if (ilucid->protocol) { icfx = &ilucid->cfx_kd; acfx = &alucid->cfx_kd; if (icfx->have_acceptor_subkey != acfx->have_acceptor_subkey) errout("Initiator/acceptor have_acceptor_subkey mismatch"); check_key_match(&icfx->ctx_key, &acfx->ctx_key); if (icfx->have_acceptor_subkey) check_key_match(&icfx->acceptor_subkey, &acfx->acceptor_subkey); fputs("cfx ", stdout); display_enctype(icfx->ctx_key.type); if (icfx->have_acceptor_subkey) { fputs(" ", stdout); display_enctype(icfx->acceptor_subkey.type); } fputs("\n", stdout); } else { i1964 = &ilucid->rfc1964_kd; a1964 = &alucid->rfc1964_kd; if (i1964->sign_alg != a1964->sign_alg || i1964->seal_alg != a1964->seal_alg) errout("Initiator/acceptor sign or seal alg mismatch"); check_key_match(&i1964->ctx_key, &a1964->ctx_key); fputs("rfc1964 ", stdout); display_enctype(i1964->ctx_key.type); fputs("\n", stdout); } krb5_free_context(kctx); free(ienc); free(aenc); (void)gss_release_name(&minor, &tname); (void)gss_release_cred(&minor, &icred); (void)gss_release_cred(&minor, &acred); (void)gss_delete_sec_context(&minor, &ictx, NULL); (void)gss_delete_sec_context(&minor, &actx, NULL); (void)gss_krb5_free_lucid_sec_context(&minor, ilucid); (void)gss_krb5_free_lucid_sec_context(&minor, alucid); return 0; }
static void usage() { errout("Usage: t_enctypes [-i initenctypes] [-a accenctypes] " "targetname"); }
int gas2nask_main(struct STR_GAS2NASK *params) { UCHAR *p0, *f, *src0, i = 0; static UCHAR filename[1000]; struct STR_FLAGS flags; int j, size; errflag = 0; DRVOSA_errcode = 0; msgptr = params->err0; msgptr1 = params->err1; params->outname = NULL; for (j = 0; j < 8; j++) flags.opt[j] = 0; if (setjmp(setjmp_env)) { params->err0 = msgptr; params->errcode = DRVOSA_errcode; return GOL_abortcode; } p0 = params->cmdlin; while (*p0 > ' ') p0++; for (;;) { while (*p0 != '\0' && *p0 <= ' ') p0++; if (*p0 == '\0') break; if (*p0 == '-') { do { p0++; if (*p0 == 'a') flags.opt[FLAG_a] = 1; if (*p0 == 'e') flags.opt[FLAG_e] = 1; if (*p0 == 'd') { j = FLAG_d; getparam: do { p0++; } while (*p0 != '\0' && *p0 <= ' '); param_p[j] = p0; while ('0' <= *p0 && *p0 <= '9') p0++; flags.opt[j] = p0 - param_p[j]; p0--; /* 次のループのため */ } if (*p0 == 'b') { j = FLAG_b; goto getparam; } if (*p0 == 't') { j = FLAG_t; goto getparam; } if (*p0 == 'D') { j = FLAG_D; goto getparam; } if (*p0 == 'B') { j = FLAG_B; goto getparam; } if (*p0 == 'T') { j = FLAG_T; goto getparam; } } while (*p0 > ' '); continue; } f = filename; do { *f++ = *p0++; } while (*p0 > ' '); *f = '\0'; if (i == 0) { src0 = osain(filename, &size); if (src0 == NULL) errout_s_NL("can't open file: ", filename); } i++; } if (i != 2) { errout("\"gas2nask\" Copyright(C) 2004 H.Kawai" NL "usage : >gas2nask [-a] [-e] input-file output-file" NL ); } src0 = convmain(src0, src0 + size, params->dest0, params->dest1, flags); if (src0 == NULL) GOL_sysabort(GO_TERM_OUTOVER); params->outname = filename; params->dest0 = src0; GOLD_exit(errflag); }
void help() { usage(); errout(gettext("\t" "-d <flags> Specifies the statistics to be displayed\n\n")); errout(gettext("\t" " For 'cache' mode\n")); errout(gettext("\t" " Valid <flags> are 'rwfsdc', default <flags> are 'sf'\n")); errout(gettext("\t" " r=read, w=write, f=flags, s=summary,\n")); errout(gettext("\t" " only available for cache mode, need to combine with '-m'\n")); errout(gettext("\t" " d=destaged, c=write cancellations\n\n")); errout(gettext("\t" " For 'ii' mode;\n")); errout(gettext("\t" " Valid <flags> are 'rwtfps', default <flags> are 'sf'\n")); errout(gettext("\t" " r=read, w=write, t=timing, f=flags, p=percentages,\n")); errout(gettext("\t" " s=summary\n\n")); errout(gettext("\t" " For 'sndr' mode;\n")); errout(gettext("\t" " Valid <flags> are'rwtfpsq', default <flags> are 'spf'\n")); errout(gettext("\t" " r=read, w=write, t=timing, f=flags, p=percentages,\n")); errout(gettext("\t" " s=summary\n")); errout(gettext("\t" " only available for sndr mode, need to combine with '-m'\n")); errout(gettext("\t" " q=queue\n\n")); errout(gettext("\t" "-f prints field headers once for each iteration\n\n")); errout(gettext("\t" "-F prints field headers once, at the start of reporting\n\n")); errout(gettext("\t" "-h prints detailed usage message\n\n")); errout(gettext("\t" "-m <mode>[,<mode>] where mode is, 'cache', 'ii', or 'sndr'\n\n")); errout(gettext("\t" " Multiple modes may be specified as a comma separated list,\n")); errout(gettext("\t" " or multiple -m switches may be used.\n\n")); errout(gettext("\t" "-r <flags> specifies components to be reported\n\n")); errout(gettext("\t" " For 'cache' mode, this option is not used.\n\n")); errout(gettext("\t" " For 'ii' mode;\n")); errout(gettext("\t" " Valid <flags> are 'msbo', default <flags> are 'msbo'\n")); errout(gettext("\t" " m=master, s=shadow, b=bitmap, o=overflow\n\n")); errout(gettext("\t" " For 'sndr' mode;\n")); errout(gettext("\t" " Valid <flags> are 'nb', default <flags> are 'nb'\n")); errout(gettext("\t" " n=network, b=bitmap\n\n")); errout(gettext("\t" "-s <sets> outputs specified sets\n")); errout(gettext("\t" " Where <sets> is a comma delimited list of set names\n\n")); errout(gettext("\t" "-z suppress reports with zero value (no activity)\n\n")); errout(gettext("\t" "<interval> is the number of seconds between reports\n\n")); errout(gettext("\t" "<count> is the number of reports to be generated\n\n")); }
/* * Read a sequence from a FILE *fp of format "format". If "format" is 0 * (ANY_FORMAT), we automatically determine the correct format. * We still pass a filename 'fn' although this isn't used other than for * filling in the read->trace_name field. * * NB this function should NOT be used when Biolims support is required * (as biolims readings are not stored in a file) * * Returns: * Read * for success * NULLRead for failure */ Read *mfread_reading(mFILE *fp, char *fn, int format) { Read *read; mFILE *newfp; if (!fn) fn = "(unknown)"; newfp = freopen_compressed(fp, NULL); if (newfp != fp) { fp = newfp; } else { newfp = NULL; } #ifdef _WIN32 /* * jkb 16/05/00 comment below * * On windows "prog < file.abi" will work wrongly (compared to * "prog file.abi") because windows is rather stupid. It treats ascii * and binary streams differently, it considers stdin to be ascii unless * told otherwise, and it can only be told otherwise by using non-ansi * windows-specific function calls. */ if (format != TT_EXP && format != TT_PLN && fp->fp) _setmode(_fileno(fp->fp), _O_BINARY); #endif if (format == TT_ANY) { format = fdetermine_trace_type(fp); mrewind(fp); } switch (format) { case TT_UNK: case TT_ERR: errout("File '%s' has unknown trace type\n", fn); read = NULLRead; break; #ifdef IOLIB_SCF case TT_SCF: { Scf *scf; scf = mfread_scf(fp); if (scf) { read = scf2read(scf); scf_deallocate(scf); } else read = NULLRead; break; } #endif #ifdef IOLIB_CTF case TT_CTF: read = mfread_ctf(fp); break; #endif #ifdef IOLIB_ZTR case TT_ZTR: case TT_ZTR1: case TT_ZTR2: case TT_ZTR3: { ztr_t *ztr; if ((ztr = mfread_ztr(fp))) { uncompress_ztr(ztr); read = ztr2read(ztr); delete_ztr(ztr); } else { read = NULLRead; } break; } #endif #ifdef IOLIB_ABI case TT_ABI: read = mfread_abi(fp); break; #endif #ifdef IOLIB_ALF case TT_ALF: read = mfread_alf(fp); break; #endif #ifdef IOLIB_EXP case TT_EXP: { /* FIXME: we shouldn't redirect like this */ Exp_info *e = exp_mfread_info(fp); read = e ? exp2read(e,fn) : NULLRead; break; } #endif #ifdef IOLIB_PLN case TT_PLN: read = mfread_pln(fp); break; #endif default: errout("Unknown format %d specified to read_reading()\n", format); read = NULLRead; } if (read != NULLRead && (read->trace_name = (char *)xmalloc(strlen(fn)+1))) strcpy(read->trace_name, fn); if (newfp) mfclose(newfp); return read; }
int main(int argc,char **argv) { struct taia stamp; struct taia deadline; int opt; unsigned long u; int i; int j; int r; while ((opt = getopt(argc,argv,"c:l:")) != opteof) switch(opt) { case 'c': scan_ulong(optarg,&u); if (u < 1) u = 1; if (u > 1000) u = 1000; maxactive = u; break; case 'l': scan_ulong(optarg,&u); if (u < 1) u = 1; if (u > 1000000) u = 1000000; xmax = u; break; default: strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ]"); } x = (struct line *) alloc(xmax * sizeof(struct line)); if (!x) nomem(); byte_zero(x,xmax * sizeof(struct line)); io = (iopause_fd *) alloc((xmax + 1) * sizeof(iopause_fd)); if (!io) nomem(); if (!stralloc_copys(&partial,"")) nomem(); while (flag0 || inbuflen || partial.len || xnum) { taia_now(&stamp); taia_uint(&deadline,120); taia_add(&deadline,&deadline,&stamp); iolen = 0; if (flag0) if (inbuflen < sizeof inbuf) { inio = io + iolen++; inio->fd = 0; inio->events = IOPAUSE_READ; } for (i = 0;i < xnum;++i) if (x[i].flagactive) { x[i].io = io + iolen++; dns_transmit_io(&x[i].dt,x[i].io,&deadline); } iopause(io,iolen,&deadline,&stamp); if (flag0) if (inbuflen < sizeof inbuf) if (inio->revents) { r = read(0,inbuf + inbuflen,(sizeof inbuf) - inbuflen); if (r <= 0) flag0 = 0; else inbuflen += r; } for (i = 0;i < xnum;++i) if (x[i].flagactive) { r = dns_transmit_get(&x[i].dt,x[i].io,&stamp); if (r == -1) { errout(i); x[i].flagactive = 0; --numactive; } else if (r == 1) { if (dns_name_packet(&x[i].middle,x[i].dt.packet,x[i].dt.packetlen) == -1) errout(i); if (x[i].middle.len) if (!stralloc_cats(&x[i].left,"=")) nomem(); x[i].flagactive = 0; --numactive; } } for (;;) { if (xnum && !x[0].flagactive) { buffer_put(buffer_1,x[0].left.s,x[0].left.len); buffer_put(buffer_1,x[0].middle.s,x[0].middle.len); buffer_put(buffer_1,x[0].right.s,x[0].right.len); buffer_flush(buffer_1); --xnum; tmp = x[0]; for (i = 0;i < xnum;++i) x[i] = x[i + 1]; x[xnum] = tmp; continue; } if ((xnum < xmax) && (numactive < maxactive)) { i = byte_chr(inbuf,inbuflen,'\n'); if (inbuflen && (i == inbuflen)) { if (!stralloc_catb(&partial,inbuf,inbuflen)) nomem(); inbuflen = 0; continue; } if ((i < inbuflen) || (!flag0 && partial.len)) { if (i < inbuflen) ++i; if (!stralloc_catb(&partial,inbuf,i)) nomem(); inbuflen -= i; for (j = 0;j < inbuflen;++j) inbuf[j] = inbuf[j + i]; if (partial.len) { i = byte_chr(partial.s,partial.len,'\n'); i = byte_chr(partial.s,i,'\t'); i = byte_chr(partial.s,i,' '); if (!stralloc_copyb(&x[xnum].left,partial.s,i)) nomem(); if (!stralloc_copys(&x[xnum].middle,"")) nomem(); if (!stralloc_copyb(&x[xnum].right,partial.s + i,partial.len - i)) nomem(); x[xnum].flagactive = 0; partial.len = i; if (!stralloc_0(&partial)) nomem(); if (ip4_scan(partial.s,ip)) { dns_name4_domain(name,ip); if (dns_resolvconfip(servers) == -1) strerr_die2sys(111,FATAL,"unable to read /etc/resolv.conf: "); if (dns_transmit_start(&x[xnum].dt,servers,1,name,DNS_T_PTR,"\0\0\0\0") == -1) errout(xnum); else { x[xnum].flagactive = 1; ++numactive; } } ++xnum; } partial.len = 0; continue; } } break; } } _exit(0); }
static int pass1(void) { signed char o[MAXLINE]; int l,er,temp_er,al; memode=0; xmode=0; tlen=0; ner=0; temp_er = 0; /*FIXIT*/ while(!(er=xa_getline(s))) { er=t_p1((signed char*)s,o,&l,&al); switch(segment) { case SEG_ABS: case SEG_TEXT: tlen += al; break; case SEG_DATA: dlen += al; break; case SEG_BSS : blen += al; break; case SEG_ZERO: zlen += al; break; } /*printf(": er= %d, l=%d, tmpz=%d\n",er,l,tmpz); */ if(l) { if(er) { if(er==E_OKDEF) { if(!(er=puttmp(l))) er=puttmps(o,l); } else if(er==E_NOLINE) er=E_OK; } else { if(!(er=puttmp(-l))) er=puttmps(o,l); } } if(er) { lineout(); errout(er); } /* printf("tmpz =%d\n",afile->mn.tmpz); */ } if(er!=E_EOF) { fprintf(stderr, "foul through\n"); errout(er); } /* { int i; printf("Pass 1 \n"); for(i=0;i<afile->mn.tmpz;i++) fprintf(stderr, " %02x",255 & afile->mn.tmp[i]); getchar();} */ return(ner); }
static int pass2(void) { int c,er,l,ll,i,al; Datei datei; signed char *dataseg=NULL; signed char *datap=NULL; memode=0; xmode=0; if((dataseg=malloc(dlen))) { if(!dataseg) { fprintf(stderr, "Couldn't alloc dataseg memory...\n"); exit(1); } datap=dataseg; } filep=&datei; afile->mn.tmpe=0L; while(ner<20 && afile->mn.tmpe<afile->mn.tmpz) { l=afile->mn.tmp[afile->mn.tmpe++]; ll=l; if(!l) { if(afile->mn.tmp[afile->mn.tmpe]==T_LINE) { datei.fline=(afile->mn.tmp[afile->mn.tmpe+1]&255)+(afile->mn.tmp[afile->mn.tmpe+2]<<8); afile->mn.tmpe+=3; } else if(afile->mn.tmp[afile->mn.tmpe]==T_FILE) { datei.fline=(afile->mn.tmp[afile->mn.tmpe+1]&255)+(afile->mn.tmp[afile->mn.tmpe+2]<<8); memcpy(&datei.fname, afile->mn.tmp+afile->mn.tmpe+3, sizeof(datei.fname)); afile->mn.tmpe+=3+sizeof(datei.fname); /* datei.fname = malloc(strlen((char*) afile->mn.tmp+afile->mn.tmpe+3)+1); if(!datei.fname) { fprintf(stderr,"Oops, no more memory\n"); exit(1); } strcpy(datei.fname,(char*) afile->mn.tmp+afile->mn.tmpe+3); afile->mn.tmpe+=3+strlen(datei.fname); */ } } else { /* do not attempt address mode optimization on pass 2 */ er=t_p2(afile->mn.tmp+afile->mn.tmpe,&ll,1,&al); if(er==E_NOLINE) { } else if(er==E_OK) { if(segment<SEG_DATA) { for(i=0;i<ll;i++) chrput(afile->mn.tmp[afile->mn.tmpe+i]); } else if (segment==SEG_DATA && datap) { memcpy(datap,afile->mn.tmp+afile->mn.tmpe,ll); datap+=ll; } } else if(er==E_DSB) { c=afile->mn.tmp[afile->mn.tmpe]; if(segment<SEG_DATA) { /*printf("E_DSB, ll=%d, l=%d, c=%c\n",ll,l,afile->mn.tmp[afile->mn.tmpe]);*/ for(i=0;i<ll;i++) chrput(c); } else if (segment==SEG_DATA && datap) { memset(datap, c, ll); datap+=ll; } } else if (er == E_BIN) { int i; int j; int flen; int offset; int fstart; FILE *foo; char binfnam[256]; i = afile->mn.tmpe; /* fprintf(stderr, "ok, ready to insert\n"); for (i=0; i<ll; i++) { fprintf(stderr, "%i: %02x\n", i, afile->mn.tmp[afile->mn.tmpe+i]); } */ offset = afile->mn.tmp[i] + (afile->mn.tmp[i+1] << 8) + (afile->mn.tmp[i+2] << 16); fstart = afile->mn.tmp[i+3] + 1 + (afile->mn.tmp[i+4] << 8); /* usually redundant but here for single-char names that get interpreted as chars */ flen = afile->mn.tmp[i+5]; if (flen > 1) fstart++; /* now fstart points either to string past quote and length mark, OR, single char byte */ /* fprintf(stderr, "offset = %i length = %i fstart = %i flen = %i charo = %c\n", offset, ll, fstart, flen, afile->mn.tmp[afile->mn.tmpe+fstart]); */ /* there is a race condition here where altering the file between validation in t_p2 (xat.c) and here will cause problems. I'm not going to worry about this right now. */ for(j=0; j<flen; j++) { binfnam[j] = afile->mn.tmp[i+fstart+j]; } binfnam[flen] = '\0'; /* fprintf(stderr, "fnam = %s\n", binfnam); */ /* primitive insurance */ if (!(foo = fopen(binfnam, "r"))) { errout(E_FNF); ner++; } else { fseek(foo, offset, SEEK_SET); for(j=0; j<ll; j++) { /* damn you Andre ;-) */ i = fgetc(foo); if (segment<SEG_DATA) { chrput(i); } if (segment==SEG_DATA && datap) { memset(datap++, i, 1); } } fclose(foo); } } else { errout(er); } } afile->mn.tmpe+=abs(l); } if(relmode) { if((ll=fwrite(dataseg, 1, dlen, fpout))<dlen) { fprintf(stderr, "Problems writing %d bytes, return gives %d\n",dlen,ll); } } return(ner); }