コード例 #1
0
int main()
{
	filelist("tnolist.txt","T");
	filelist("tnofcorrectfilelist.txt","fileT$$$$$$$$$$c");
	filelist("tnoferrorfilelist.txt","fileT$$$$$$$$$$e");
	filelist("tnoscorrectfilelist.txt","sT$$$$$$$$$$c");
	filelist("tnoserrorfilelist.txt","sT$$$$$$$$$$e");
}
コード例 #2
0
ファイル: collector.c プロジェクト: gomes310/sactools
// New station list from a glob structure
stations *newStationList(glob_t *glb)
{
	stations *ss;
	int j, file;

	ss = malloc(sizeof(stations));
	ss->n = 0;
	ss->slist = NULL;

	/* Prepare stations table */
	for (j = 0; j < glb->gl_pathc; j++) {
		glob_t *glbs = filelist(glb->gl_pathv[j], "*Z.SAC");

		for (file = 0; file < glbs->gl_pathc; file++) {
			station *s = loadStation(glbs->gl_pathv[file]);
			int Id = getStationId(ss, s->name, s->net);
			if (Id == -1) {
				addss(ss, s);
			} else {
				killStation(s);
			}
		}
		glbs = killGlob(glbs);
	}

	qsort(&ss->slist[0], ss->n, sizeof(ss->slist[0]), cmpstation);
	return ss;
}
コード例 #3
0
ファイル: plotChain.C プロジェクト: lacaprara/usercode
void loadChain() {
  if (ch) return;
  ch=new TChain("Tree2HDM");
  std::ifstream filelist("list_ty1_afs.txt");

  char line[100];
  while (!(filelist.eof())) {
    filelist.getline(line, sizeof(line));
    if (strcmp(line, "") == 0) continue;
    ch->Add(line);
  }
}
コード例 #4
0
ファイル: collector.c プロジェクト: gomes310/sactools
// New event list from a glob
events *newEventList(glob_t *glb, stations * ss)
{
	events *evs;
	int j, file;

	evs = malloc(sizeof(events));
	evs->n = 0;
	evs->elist = NULL;

	/* Make event list */
	for (j = 0; j < glb->gl_pathc; j++) {
		glob_t *glbs = filelist(glb->gl_pathv[j],"*Z.SAC");

		if (collectorVerbose)
			fprintf(stdout, "%s: [ ] [   ] ", glb->gl_pathv[j]);
		
		event *ev = NULL;
		for (file = 0; file < glbs->gl_pathc; file++) {
			if (file == 0) {
				ev = loadEvent(glbs->gl_pathv[file]);
				if (ev == NULL) {
					fprintf(stderr, "Could not get event.\n");
					exit(-1);
				}
			}

			pick *p = loadPick(glbs->gl_pathv[file], ss);
			if (p != NULL) {
				addpick(ev, p);
				if (collectorVerbose) fprintf(stdout, ".");
			} else {
				if (collectorVerbose) fprintf(stdout, "x");
			}

		}


		if (ev->n != 0) {
			addev(evs, ev);
			if (collectorVerbose) fprintf(stdout, "\r%s: [A] [%03d] \n", glb->gl_pathv[j], ev->n);
		} else {
			killEvent(ev);
			if (collectorVerbose) fprintf(stdout, "\r%s: [D] [%03d] \n", glb->gl_pathv[j], ev->n);
		}
		
		glbs = killGlob(glbs);
	}

	calculateEventMean(evs);
	calculateResiduals(evs);

	return evs;
}
コード例 #5
0
ファイル: filelist_test.c プロジェクト: testfarm/testfarm
int main(int argc, char *argv[])
{
  GList *list;
  GList *l;

  if ( argc != 2 ) {
    fprintf(stderr, "Usage: filelist_test <regex>\n");
    exit(1);
  }

  list = filelist(argv[1]);

  l = list;
  while ( l != NULL ) {
    printf("%s\n", (char *) l->data);
    l = l->next;
  }

  filelist_free(list);

  return 0;
}
コード例 #6
0
ファイル: client.c プロジェクト: LZ-SecurityTeam/clamav-devel
int client(const struct optstruct *opts, int *infected, int *err)
{
	int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec, flags = 0;
	const char *fname;

    scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !optget(opts, "file-list")->enabled && !opts->filename[1]);
    remote = isremote(opts) | optget(opts, "stream")->enabled;
#ifdef HAVE_FD_PASSING
    if(!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
	scantype = FILDES;
	session = optget(opts, "multiscan")->enabled;
    } else 
#endif
    if(remote || scandash) {
	scantype = STREAM;
	session = optget(opts, "multiscan")->enabled;
    } 
    else if(optget(opts, "multiscan")->enabled) scantype = MULTI;
    else if(optget(opts, "allmatch")->enabled) scantype = ALLMATCH;
    else scantype = CONT;

    maxrec = optget(clamdopts, "MaxDirectoryRecursion")->numarg;
    maxstream = optget(clamdopts, "StreamMaxLength")->numarg;
    if (optget(clamdopts, "FollowDirectorySymlinks")->enabled)
	flags |= CLI_FTW_FOLLOW_DIR_SYMLINK;
    if (optget(clamdopts, "FollowFileSymlinks")->enabled)
	flags |= CLI_FTW_FOLLOW_FILE_SYMLINK;
    flags |= CLI_FTW_TRIM_SLASHES;

    *infected = 0;

    if(scandash) {
	int sockd, ret;
	STATBUF sb;
	if(FSTAT(0, &sb) < 0) {
	    logg("client.c: fstat failed for file name \"%s\", with %s\n.", 
		 opts->filename[0], strerror(errno));
	    return 2;
	}
	if((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM;
	if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret, NULL)) >= 0)
	    *infected = ret;
	else
	    errors = 1;
	if(sockd >= 0) closesocket(sockd);
    } else if(opts->filename || optget(opts, "file-list")->enabled) {
	if(opts->filename && optget(opts, "file-list")->enabled)
	    logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");

	while((fname = filelist(opts, NULL))) {
	    if(!strcmp(fname, "-")) {
		logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
		continue;
	    }
	    errors += client_scan(fname, scantype, infected, err, maxrec, session, flags);
	    /* this may be too strict
	    if(errors >= 10) {
		logg("!Too many errors\n");
		break;
	    }
	    */
	}
    } else {
	errors = client_scan("", scantype, infected, err, maxrec, session, flags);
    }
    return *infected ? 1 : (errors ? 2 : 0);
}
コード例 #7
0
int main(int argc, char * argv[])
{
  // usage 
  // > HBBAnalysisMacro [filelist]
  // example filelist is Analysis/HbbMSSMAnalysis/test/Run2011A_PR4

  // Enable Sumw2 for all histograms so we can access the correct errors
  // from the histograms as well.
  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();

  

  // requires as a parameter the name of the filelist

  std::ifstream inputfile(argv[1]);

  std::string filelist(argv[1]); 
  TString FileName(filelist);

  bool isData = false;

  if (FileName.Contains("Run2011")) 
    isData = true;

  TString ChainName("hbbanalysis/HBBTo4B");
  TString SVMassFileName("/afs/naf.desy.de/user/r/rasp/public/Hbb4b/TTJets_svMass.root");
  TString SVMassOnlineFileName("/afs/naf.desy.de/user/r/rasp/public/Hbb4b/TTJets_BTagHLTmatched_svMass.root");

  svMass * sv = new svMass(SVMassFileName);
  svMass * svOnline = new svMass(SVMassOnlineFileName);

  TString OutputFileName = TString(filelist) + TString(".root");

  float weight = 1;
  int numberOfFiles = 0;
  inputfile >> numberOfFiles;

  if (!isData) {

    int nGenEvents = 0;
    float internalXsec = 0;
    float externalXsecLO = 0;
    float externalXsecNLO = 0;
    float filterEfficiency = 0;
    for (int iFile=0; iFile<numberOfFiles; ++iFile) {
      TString filename;
      inputfile >> filename;
      std::cout << "File " << filename ;
      TFile * file = new TFile(filename);
      if (file->IsZombie()) {
	std::cout << " does not exist... quitting... " << std::endl;
      }
      std::cout << std::endl;
      TH1F * events = (TH1F*)file->Get("InputEvents/EventCount");
      nGenEvents += events->GetEntries(); 
      TTree * genInfo = (TTree*)file->Get("hbbanalysis/GenInfo");
      float internalX;
      float externalXLO;
      float externalXNLO;
      float filterEff; 
      genInfo->SetBranchAddress("internalXsec",&internalX);
      genInfo->SetBranchAddress("externalXsecLO",&externalXLO);
      genInfo->SetBranchAddress("externalXsecNLO",&externalXNLO);
      genInfo->SetBranchAddress("filterEfficiency",&filterEff);
      genInfo->GetEntry(0);
      internalXsec += internalX;
      externalXsecLO += externalXLO;
      externalXsecNLO += externalXNLO;
      filterEfficiency += filterEff; 
    }

    internalXsec /= float(numberOfFiles);
    externalXsecLO /= float(numberOfFiles);
    externalXsecNLO /= float(numberOfFiles);
    filterEfficiency /= float(numberOfFiles);

    std::cout << std::endl;
    std::cout << "   Total number of generated events = " << nGenEvents << std::endl;
    std::cout << "   InternalXsec      = " << internalXsec << std::endl;
    std::cout << "   ExternalXsecLO    = " << externalXsecLO << std::endl;
    std::cout << "   ExternalXsecNLO   = " << externalXsecNLO << std::endl;
    std::cout << "   Filter efficiency = " << filterEfficiency << std::endl;
    std::cout << std::endl;
    
    weight = internalXsec*fabs(filterEfficiency)/float(nGenEvents);

    // float weight = externalXsecLO*filterEfficiency/float(nGenEvents);
    // float weight = externalXsecNLO*filterEfficiency/float(nGenEvents);
    //  weight = 1;

  }
コード例 #8
0
int parse (int socketfd)
{
  // char message[] = "GetFile\n\rName: x.tmp\n\rStartByte: 0\n\rEndByte: 11\n\r";
  const char *delimiter = "\n\r";
  char *command, *name_str, *startbytes_str, *endbytes_str,
    *filter_str, *name, *filter, *fullsize_str, *md5_str, *md5, *token,
    *startbytes, *endbytes;
  unsigned long fullsize, ret;
  char message[200], *ps;

  ret = read (socketfd, message, BUFFERSIZE);

  // Si leemos un numero de bytes menor al tamano del buffer, pongo el caracter de terminacion
  if (ret > 0 && ret < BUFFERSIZE) {
    message[ret] = '\0';
  } else {
    message[0] = '\0';
  }

  command = strtok (message, delimiter);
  if (command == NULL)
    return 0;

  if (strcmp (command, "GetFile") == 0) {
    name_str = strtok (NULL, delimiter);
    startbytes_str = strtok (NULL, delimiter);
    endbytes_str = strtok (NULL, delimiter);

    strtok (name_str, " ");
    name = strtok (NULL, " ");
    if (name == NULL)
      return 0;
    // printf ("%s %s\n", command, name);

    strtok (startbytes_str, " ");
    startbytes = strtok (NULL, " ");
    if (startbytes == NULL)
      return 0;
    // startbytes = strtol (token, NULL, 0);
    // printf ("%s\n", startbytes);

    strtok (endbytes_str, " ");
    endbytes = strtok (NULL, " ");
    if (endbytes == NULL)
      return 0;
    // endbytes = strtol (token, NULL, 0);
    // printf ("%s\n", endbytes);

    file (socketfd, name, startbytes, endbytes);


  } else if (strcmp (command, "GetFileList") == 0) {
    filter_str = strtok (NULL, delimiter);

    strtok (filter_str, " ");
    filter = strtok (NULL, " ");
    if (filter == NULL)
      return 0;

    filelist (socketfd);
  } else if (strcmp (command, "GetFileInfo") == 0) {
    name_str = strtok (NULL, delimiter);
    strtok (name_str, " ");
    name = strtok (NULL, " ");
    if (name == NULL)
      return 0;
    printf ("%s %s\n", command, name);

    fileinfo (socketfd, name);
  }

  /*if (strcmp (command, "FileList") == 0) {
    filecount_str = strtok (NULL, delimiter);
    sizedatos_str = strtok (NULL, delimiter);
    datos = strtok (NULL, delimiter);

    strtok (filecount_str, " ");
    filecount = strtol (strtok (NULL, " "), NULL, 0);

    strtok (sizedatos_str, " ");
    sizedatos = strtol (strtok (NULL, " "), NULL, 0);
    } else if (strcmp (command, "File") == 0) {*/
  return 1;
}
コード例 #9
0
ファイル: io.c プロジェクト: marcelobianchi/sactools
glob_t * io_loadEv(defs *d) {
	// If data is loaded free it up
	if (d->nfiles != 0) {
		tffree(d->files, d->nfiles);
		d->files = NULL;
		d->nfiles = 0;
		d->has3 = 0;
	}

	// Prepare the pathname for the current event
	char *path = d->glb->gl_pathv[d->currentdir];

	// Prepare a new glob
	glob_t *glb = filelist(path, getConfigAsString(config, NAME_Z, DEFAULT_Z));
	glob_t *glbt =filelist(path, getConfigAsString(config, NAME_T, DEFAULT_T));

	// Set HAS to 0
	d->has = findHas(glb);

	// Load the Z components
	int nfiles = 0;
	tf *files = io_loadZ(glb, &nfiles);

	if (getConfigAsBoolean(config, NAME_LOAD, DEFAULT_LOAD)) {
		// Load N components
		glob_t *glbn = filelist(path, getConfigAsString(config, NAME_N, DEFAULT_N));
		io_loadN(glbn, files, nfiles);
		killGlob(glbn);
		
		// Load E
		glob_t *glbe = filelist(path, getConfigAsString(config, NAME_E, DEFAULT_E));
		io_loadE(glbe, files, nfiles);
		killGlob(glbe);

		// Load R components
		glob_t *glbr = filelist(path, getConfigAsString(config, NAME_R, DEFAULT_R));
		io_loadR(glbr, files, nfiles);
		killGlob(glbr);
			
		// Load T
		glob_t *glbt = filelist(path, getConfigAsString(config, NAME_T, DEFAULT_T));
		io_loadT(glbt, files, nfiles);
		
		d->has3 = 1;
	}

	// Find the filters in use for this event
	if (getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK) == P) 
		d->filter = findFilters(glb, &d->lp, &d->hp);

	else if (getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK) == S)
		d->filter = findFilters(glbt, &d->lp, &d->hp);

	else {
		sprintf(message, " filters used couldn't be loaded ");
		alert(WARNING);
	}

	//kill globs
	killGlob(glb);
	killGlob(glbt);


	// Check the files
	if (nfiles != 0) {
		// Check that we have picks
		checkTREF(files, nfiles);
		
		// Sort the files 
		qsort(files, nfiles, sizeof(tf), sortDist);
		
		// Synch Time
		synch(files, nfiles);
	}

	// Set Aligmenmode
	d->alig = (d->has) ? ALIGF : ALIGA;

	// Set the filterneed if needed
	if (d->filter)
		d->needfilter = 1;

	// Set offset to 0
	d->offset = 0;

	// Prepare to return
	d->files  = files;
	d->nfiles = nfiles;

	// Adjust the curent pointer
	io_AdjustCurrent(d);

	// Done
	return NULL;
}
コード例 #10
0
ファイル: manager.c プロジェクト: lattera/clamav-devel
int scanmanager(const struct optstruct *opts)
{
    int ret = 0, i;
    unsigned int options = 0, dboptions = 0, dirlnk = 1, filelnk = 1;
    struct cl_engine *engine;
    STATBUF sb;
    char *file, cwd[1024], *pua_cats = NULL;
    const char *filename;
    const struct optstruct *opt;
#ifndef _WIN32
    struct rlimit rlim;
#endif

    dirlnk = optget(opts, "follow-dir-symlinks")->numarg;
    if(dirlnk > 2) {
        logg("!--follow-dir-symlinks: Invalid argument\n");
        return 2;
    }

    filelnk = optget(opts, "follow-file-symlinks")->numarg;
    if(filelnk > 2) {
        logg("!--follow-file-symlinks: Invalid argument\n");
        return 2;
    }

    if(optget(opts, "yara-rules")->enabled) {
	char *p = optget(opts, "yara-rules")->strarg;
	if(strcmp(p, "yes")) {
	    if(!strcmp(p, "only"))
		dboptions |= CL_DB_YARA_ONLY;
	    else if (!strcmp(p, "no"))
		dboptions |= CL_DB_YARA_EXCLUDE;
	}

    }

    if(optget(opts, "phishing-sigs")->enabled)
        dboptions |= CL_DB_PHISHING;

    if(optget(opts, "official-db-only")->enabled)
        dboptions |= CL_DB_OFFICIAL_ONLY;

    if(optget(opts,"phishing-scan-urls")->enabled)
        dboptions |= CL_DB_PHISHING_URLS;

    if(optget(opts,"bytecode")->enabled)
        dboptions |= CL_DB_BYTECODE;

    if((ret = cl_init(CL_INIT_DEFAULT))) {
        logg("!Can't initialize libclamav: %s\n", cl_strerror(ret));
        return 2;
    }

    if(!(engine = cl_engine_new())) {
        logg("!Can't initialize antivirus engine\n");
        return 2;
    }

    cl_engine_set_clcb_virus_found(engine, clamscan_virus_found_cb);
    
    if (optget(opts, "disable-cache")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_DISABLE_CACHE, 1);

    if (optget(opts, "disable-pe-stats")->enabled) {
        cl_engine_set_num(engine, CL_ENGINE_DISABLE_PE_STATS, 1);
    }

    if (optget(opts, "enable-stats")->enabled) {
        cl_engine_stats_enable(engine);
    }

    if (optget(opts, "stats-timeout")->enabled) {
        cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg);
    }

    if (optget(opts, "stats-host-id")->enabled) {
        char *p = optget(opts, "stats-host-id")->strarg;

        if (strcmp(p, "default")) {
            if (!strcmp(p, "none")) {
                cl_engine_set_clcb_stats_get_hostid(engine, NULL);
            } else if (!strcmp(p, "anonymous")) {
                strcpy(hostid, STATS_ANON_UUID);
            } else {
                if (strlen(p) > 36) {
                    logg("!Invalid HostID\n");

                    cl_engine_set_clcb_stats_submit(engine, NULL);
                    cl_engine_free(engine);
                    return 2;
                }

                strcpy(hostid, p);
            }

            cl_engine_set_clcb_stats_get_hostid(engine, get_hostid);
        }
    }

    if(optget(opts, "detect-pua")->enabled) {
        dboptions |= CL_DB_PUA;
        if((opt = optget(opts, "exclude-pua"))->enabled) {
            dboptions |= CL_DB_PUA_EXCLUDE;
            i = 0;
            while(opt) {
                if(!(pua_cats = realloc(pua_cats, i + strlen(opt->strarg) + 3))) {
                    logg("!Can't allocate memory for pua_cats\n");

                    cl_engine_free(engine);
                    return 2;
                }

                sprintf(pua_cats + i, ".%s", opt->strarg);
                i += strlen(opt->strarg) + 1;
                pua_cats[i] = 0;

                opt = opt->nextarg;
            }
            pua_cats[i] = '.';
            pua_cats[i + 1] = 0;
        }

        if((opt = optget(opts, "include-pua"))->enabled) {
            if(pua_cats) {
                logg("!--exclude-pua and --include-pua cannot be used at the same time\n");

                cl_engine_free(engine);
                free(pua_cats);
                return 2;
            }

            dboptions |= CL_DB_PUA_INCLUDE;
            i = 0;
            while(opt) {
                if(!(pua_cats = realloc(pua_cats, i + strlen(opt->strarg) + 3))) {
                    logg("!Can't allocate memory for pua_cats\n");
                    cl_engine_free(engine);
                    return 2;
                }

                sprintf(pua_cats + i, ".%s", opt->strarg);
                i += strlen(opt->strarg) + 1;
                pua_cats[i] = 0;

                opt = opt->nextarg;
            }

            pua_cats[i] = '.';
            pua_cats[i + 1] = 0;
        }

        if(pua_cats) {
            if((ret = cl_engine_set_str(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) {
                logg("!cli_engine_set_str(CL_ENGINE_PUA_CATEGORIES) failed: %s\n", cl_strerror(ret));

                free(pua_cats);
                cl_engine_free(engine);
                return 2;
            }

            free(pua_cats);
        }
    }

    if(optget(opts, "dev-ac-only")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_AC_ONLY, 1);

    if(optget(opts, "dev-ac-depth")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_AC_MAXDEPTH, optget(opts, "dev-ac-depth")->numarg);

    if(optget(opts, "leave-temps")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_KEEPTMP, 1);

    if(optget(opts, "force-to-disk")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_FORCETODISK, 1);

    if(optget(opts, "bytecode-unsigned")->enabled)
        dboptions |= CL_DB_BYTECODE_UNSIGNED;

    if((opt = optget(opts,"bytecode-timeout"))->enabled)
        cl_engine_set_num(engine, CL_ENGINE_BYTECODE_TIMEOUT, opt->numarg);

    if (optget(opts, "nocerts")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_DISABLE_PE_CERTS, 1);

    if (optget(opts, "dumpcerts")->enabled)
        cl_engine_set_num(engine, CL_ENGINE_PE_DUMPCERTS, 1);

    if((opt = optget(opts,"bytecode-mode"))->enabled) {
        enum bytecode_mode mode;

        if (!strcmp(opt->strarg, "ForceJIT"))
            mode = CL_BYTECODE_MODE_JIT;
        else if(!strcmp(opt->strarg, "ForceInterpreter"))
            mode = CL_BYTECODE_MODE_INTERPRETER;
        else if(!strcmp(opt->strarg, "Test"))
            mode = CL_BYTECODE_MODE_TEST;
        else
            mode = CL_BYTECODE_MODE_AUTO;

        cl_engine_set_num(engine, CL_ENGINE_BYTECODE_MODE, mode);
    }

    if((opt = optget(opts, "statistics"))->enabled) {
	while(opt) {
	    if (!strcasecmp(opt->strarg, "bytecode")) {
		dboptions |= CL_DB_BYTECODE_STATS;
	    }
	    else if (!strcasecmp(opt->strarg, "pcre")) {
		dboptions |= CL_DB_PCRE_STATS;
	    }
	    opt = opt->nextarg;
        }
    }

    if((opt = optget(opts, "tempdir"))->enabled) {
        if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) {
            logg("!cli_engine_set_str(CL_ENGINE_TMPDIR) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "database"))->active) {
        while(opt) {
            if((ret = cl_load(opt->strarg, engine, &info.sigs, dboptions))) {
                logg("!%s\n", cl_strerror(ret));

                cl_engine_free(engine);
                return 2;
            }

            opt = opt->nextarg;
        }
    } else {
        char *dbdir = freshdbdir();

        if((ret = cl_load(dbdir, engine, &info.sigs, dboptions))) {
            logg("!%s\n", cl_strerror(ret));

            free(dbdir);
            cl_engine_free(engine);
            return 2;
        }

        free(dbdir);
    }

    /* pcre engine limits - required for cl_engine_compile */
    if ((opt = optget(opts, "pcre-match-limit"))->active) {
        if ((ret = cl_engine_set_num(engine, CL_ENGINE_PCRE_MATCH_LIMIT, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_PCRE_MATCH_LIMIT) failed: %s\n", cl_strerror(ret));
            cl_engine_free(engine);
            return 2;
        }
    }

    if ((opt = optget(opts, "pcre-recmatch-limit"))->active) {
        if ((ret = cl_engine_set_num(engine, CL_ENGINE_PCRE_RECMATCH_LIMIT, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_PCRE_RECMATCH_LIMIT) failed: %s\n", cl_strerror(ret));
            cl_engine_free(engine);
            return 2;
        }
    }

    if((ret = cl_engine_compile(engine)) != 0) {
        logg("!Database initialization error: %s\n", cl_strerror(ret));;

        cl_engine_free(engine);
        return 2;
    }

    if(optget(opts, "archive-verbose")->enabled) {
        cl_engine_set_clcb_meta(engine, meta);
        cl_engine_set_clcb_pre_cache(engine, pre);
        cl_engine_set_clcb_post_scan(engine, post);
    }

    /* set limits */

    if((opt = optget(opts, "max-scansize"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_SCANSIZE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_SCANSIZE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-filesize"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILESIZE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

#ifndef _WIN32
    if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) {
        if(rlim.rlim_cur < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL))
            logg("^System limit for file size is lower than engine->maxfilesize\n");
        if(rlim.rlim_cur < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL))
            logg("^System limit for file size is lower than engine->maxscansize\n");
    } else {
        logg("^Cannot obtain resource limits for file size\n");
    }
#endif

    if((opt = optget(opts, "max-files"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_FILES, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_FILES) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-recursion"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    /* Engine max sizes */

    if((opt = optget(opts, "max-embeddedpe"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_EMBEDDEDPE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_EMBEDDEDPE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-htmlnormalize"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_HTMLNORMALIZE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_HTMLNORMALIZE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-htmlnotags"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_HTMLNOTAGS, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_HTMLNOTAGS) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-scriptnormalize"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_SCRIPTNORMALIZE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_SCRIPTNORMALIZE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-ziptypercg"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_ZIPTYPERCG, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_ZIPTYPERCG) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-partitions"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_PARTITIONS, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_PARTITIONS) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-iconspe"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_ICONSPE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_ICONSPE) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if((opt = optget(opts, "max-rechwp3"))->active) {
        if((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECHWP3, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_MAX_RECHWP3) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if ((opt = optget(opts, "timelimit"))->active) {
        if ((ret = cl_engine_set_num(engine, CL_ENGINE_TIME_LIMIT, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_TIME_LIMIT) failed: %s\n", cl_strerror(ret));

            cl_engine_free(engine);
            return 2;
        }
    }

    if ((opt = optget(opts, "pcre-max-filesize"))->active) {
        if ((ret = cl_engine_set_num(engine, CL_ENGINE_PCRE_MAX_FILESIZE, opt->numarg))) {
            logg("!cli_engine_set_num(CL_ENGINE_PCRE_MAX_FILESIZE) failed: %s\n", cl_strerror(ret));
            cl_engine_free(engine);
            return 2;
        }
    }

    /* set scan options */
    if(optget(opts, "allmatch")->enabled) {
        options |= CL_SCAN_ALLMATCHES;
    }

    if(optget(opts,"phishing-ssl")->enabled)
        options |= CL_SCAN_PHISHING_BLOCKSSL;

    if(optget(opts,"phishing-cloak")->enabled)
        options |= CL_SCAN_PHISHING_BLOCKCLOAK;

    if(optget(opts,"partition-intersection")->enabled)
        options |= CL_SCAN_PARTITION_INTXN;

    if(optget(opts,"heuristic-scan-precedence")->enabled)
        options |= CL_SCAN_HEURISTIC_PRECEDENCE;

    if(optget(opts, "scan-archive")->enabled)
        options |= CL_SCAN_ARCHIVE;

    if(optget(opts, "detect-broken")->enabled)
        options |= CL_SCAN_BLOCKBROKEN;

    if(optget(opts, "block-encrypted")->enabled)
        options |= CL_SCAN_BLOCKENCRYPTED;

    if(optget(opts, "block-macros")->enabled)
        options |= CL_SCAN_BLOCKMACROS;

    if(optget(opts, "scan-pe")->enabled)
        options |= CL_SCAN_PE;

    if(optget(opts, "scan-elf")->enabled)
        options |= CL_SCAN_ELF;

    if(optget(opts, "scan-ole2")->enabled)
        options |= CL_SCAN_OLE2;

    if(optget(opts, "scan-pdf")->enabled)
        options |= CL_SCAN_PDF;

    if(optget(opts, "scan-swf")->enabled)
        options |= CL_SCAN_SWF;

    if(optget(opts, "scan-html")->enabled && optget(opts, "normalize")->enabled)
        options |= CL_SCAN_HTML;

    if(optget(opts, "scan-mail")->enabled)
        options |= CL_SCAN_MAIL;

    if(optget(opts, "scan-xmldocs")->enabled)
        options |= CL_SCAN_XMLDOCS;

    if(optget(opts, "scan-hwp3")->enabled)
        options |= CL_SCAN_HWP3;

    if(optget(opts, "algorithmic-detection")->enabled)
        options |= CL_SCAN_ALGORITHMIC;

    if(optget(opts, "block-max")->enabled) {
        options |= CL_SCAN_BLOCKMAX;
    }

#ifdef HAVE__INTERNAL__SHA_COLLECT
    if(optget(opts, "dev-collect-hashes")->enabled)
        options |= CL_SCAN_INTERNAL_COLLECT_SHA;
#endif

    if(optget(opts, "dev-performance")->enabled)
        options |= CL_SCAN_PERFORMANCE_INFO;

    if(optget(opts, "detect-structured")->enabled) {
        options |= CL_SCAN_STRUCTURED;

        if((opt = optget(opts, "structured-ssn-format"))->enabled) {
            switch(opt->numarg) {
            case 0:
                options |= CL_SCAN_STRUCTURED_SSN_NORMAL;
                break;
            case 1:
                options |= CL_SCAN_STRUCTURED_SSN_STRIPPED;
                break;
            case 2:
                options |= (CL_SCAN_STRUCTURED_SSN_NORMAL | CL_SCAN_STRUCTURED_SSN_STRIPPED);
                break;
            default:
                logg("!Invalid argument for --structured-ssn-format\n");
                return 2;
            }
        } else {
            options |= CL_SCAN_STRUCTURED_SSN_NORMAL;
        }

        if((opt = optget(opts, "structured-ssn-count"))->active) {
            if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_SSN_COUNT, opt->numarg))) {
                logg("!cli_engine_set_num(CL_ENGINE_MIN_SSN_COUNT) failed: %s\n", cl_strerror(ret));

                cl_engine_free(engine);
                return 2;
            }
        }

        if((opt = optget(opts, "structured-cc-count"))->active) {
            if((ret = cl_engine_set_num(engine, CL_ENGINE_MIN_CC_COUNT, opt->numarg))) {
                logg("!cli_engine_set_num(CL_ENGINE_MIN_CC_COUNT) failed: %s\n", cl_strerror(ret));
                cl_engine_free(engine);
                return 2;
            }
        }
    } else {
        options &= ~CL_SCAN_STRUCTURED;
    }

#ifdef C_LINUX
    procdev = (dev_t) 0;
    if(CLAMSTAT("/proc", &sb) != -1 && !sb.st_size)
        procdev = sb.st_dev;
#endif

#if HAVE_JSON
    if (optget(opts, "gen-json")->enabled)
        options |= CL_SCAN_FILE_PROPERTIES;
#endif

    /* check filetype */
    if(!opts->filename && !optget(opts, "file-list")->enabled) {
        /* we need full path for some reasons (eg. archive handling) */
        if(!getcwd(cwd, sizeof(cwd))) {
            logg("!Can't get absolute pathname of current working directory\n");
            ret = 2;
        } else {
            CLAMSTAT(cwd, &sb);
            scandirs(cwd, engine, opts, options, 1, sb.st_dev);
        }

    } else if(opts->filename && !optget(opts, "file-list")->enabled && !strcmp(opts->filename[0], "-")) { /* read data from stdin */
        ret = scanstdin(engine, opts, options);
    } else {
        if(opts->filename && optget(opts, "file-list")->enabled)
            logg("^Only scanning files from --file-list (files passed at cmdline are ignored)\n");

        while((filename = filelist(opts, &ret)) && (file = strdup(filename))) {
            if(LSTAT(file, &sb) == -1) {
                perror(file);
                logg("^%s: Can't access file\n", file);
                ret = 2;
            } else {
                for(i = strlen(file) - 1; i > 0; i--) {
                    if(file[i] == *PATHSEP)
                        file[i] = 0;
                    else
                        break;
                }

                if(S_ISLNK(sb.st_mode)) {
                    if(dirlnk == 0 && filelnk == 0) {
                        if(!printinfected)
                            logg("%s: Symbolic link\n", file);
                    } else if(CLAMSTAT(file, &sb) != -1) {
                        if(S_ISREG(sb.st_mode) && filelnk) {
                            scanfile(file, engine, opts, options);
                        } else if(S_ISDIR(sb.st_mode) && dirlnk) {
                            scandirs(file, engine, opts, options, 1, sb.st_dev);
                        } else {
                            if(!printinfected)
                                logg("%s: Symbolic link\n", file);
                        }
                    }
                } else if(S_ISREG(sb.st_mode)) {
                    scanfile(file, engine, opts, options);
                } else if(S_ISDIR(sb.st_mode)) {
                    scandirs(file, engine, opts, options, 1, sb.st_dev);
                } else {
                    logg("^%s: Not supported file type\n", file);
                    ret = 2;
                }
            }

            free(file);
        }
    }

    if((opt = optget(opts, "statistics"))->enabled) {
	while(opt) {
	    if (!strcasecmp(opt->strarg, "bytecode")) {
		cli_sigperf_print();
		cli_sigperf_events_destroy();
	    }
#if HAVE_PCRE
	    else if (!strcasecmp(opt->strarg, "pcre")) {
		cli_pcre_perf_print();
		cli_pcre_perf_events_destroy();
	    }
#endif
	    opt = opt->nextarg;
        }
    }

    /* free the engine */
    cl_engine_free(engine);

    /* overwrite return code - infection takes priority */
    if(info.ifiles)
        ret = 1;
    else if(info.errors)
        ret = 2;

    return ret;
}
コード例 #11
0
void ResourceListBuilder::BuildPakResourceList(const std::string &pakfilename)
{
	// open the pak file in binary read mode
	File pakfile(pakfilename, "rb");

	if (pakfile == NULL)
	{
		// error opening pakfile!
		printf("Could not find pakfile \"%s\".\n", pakfilename.c_str());
		return;
	}

	// Check a pakfile for resources
	// get the header
	size_t pakheadersize = sizeof(pakheader_s);
	pakheader_s pakheader;
	size_t retval = fread(&pakheader, 1, pakheadersize, pakfile);

	if (retval != pakheadersize)
	{
		// unexpected size.
		if (verbal)
		{
			printf("Reading pakfile header failed. Wrong size (" SIZE_T_SPECIFIER " read, " SIZE_T_SPECIFIER " expected).\n", retval, pakheadersize);
			printf("Is \"%s\" a valid pakfile?\n", pakfilename.c_str());
		}
		return;
	}

	// verify pak identity
	if (pakheader.pakid != 1262698832)
	{
		if (verbal)
		{
			printf("Pakfile \"%s\" does not appear to be a Half-Life pakfile (ID mismatch).\n", pakfilename.c_str());
		}
		return;
	}

	// count the number of files in the pak
	size_t fileinfosize = sizeof(fileinfo_s);
	size_t filecount = pakheader.dirsize / fileinfosize;

	// re-verify integrity of header
	if (pakheader.dirsize % fileinfosize != 0 || filecount == 0)
	{
		if (verbal)
		{
			printf("Pakfile \"%s\" does not appear to be a Half-Life pakfile (invalid dirsize).\n", pakfilename.c_str());
		}
		return;
	}

	// load file list to memory
	if(fseek(pakfile, pakheader.diroffset, SEEK_SET))
	{
		if (verbal)
		{
			printf("Error seeking for file list.\nPakfile \"%s\" is not a pakfile, or is corrupted.\n", pakfilename.c_str());
		}
		return;
	}

	std::vector<fileinfo_s> filelist(filecount);
	retval = fread(filelist.data(), 1, pakheader.dirsize, pakfile);
	if (retval != pakheader.dirsize)
	{
		if (verbal)
		{
			printf("Error seeking for file list.\nPakfile \"%s\" is not a pakfile, or is corrupted.\n", pakfilename.c_str());
		}
		return;
	}

	if (verbal)
	{
		printf("Scanning pak file \"%s\" for resources (" SIZE_T_SPECIFIER " files in pak)\n", pakfilename.c_str(), filecount);
	}

	// Read filelist for possible resources
	for (size_t i = 0; i < filecount; i++)
	{
		const std::string fileLower = strToLowerCopy(filelist[i].name);

		const size_t dotIndex = fileLower.find_last_of('.');

		if(dotIndex != std::string::npos)
		{
			const std::string extension = fileLower.substr(dotIndex + 1);

			if (
				extension == "mdl" ||
				extension == "wav" ||
				extension == "spr" ||
				extension == "bmp" ||
				extension == "tga" ||
				extension == "txt" ||
				extension == "wad"
			)
			{
				// resource, add to list
				std::string resStr = replaceCharAllCopy(filelist[i].name, '\\', '/');

				resources[strToLowerCopy(resStr)] = resStr;

				if (resourcedisp)
				{
					printf("Added \"%s\" to resource list\n", resStr.c_str());
				}
			}
		}
	}
}
コード例 #12
0
ファイル: split.C プロジェクト: XuQiao/phenix
void split(char *inFileList= "Run15pAl200MBPro104.Lst"){
  //split file to different run #
  char cc[100];
  ofstream lstfile[10000];
  int tmprun[10000];
  
  for(int irun=0;irun<10000;irun++){
    tmprun[irun]=0;
  }

  //get the list of run
  ofstream runlist("run15pAl200MBPro104.Lst");

  ifstream filelist(inFileList);
  char cntfile[1000];

  int nrun=0;
  int ifile=0;
  while (filelist.getline(cntfile, 1000)) {    
    int run=0;
    ifile++;
    //if(ifile>10) continue;

    cout<<cntfile<<endl;

    int index=0;
    //get run number
    for(int i=0; i<200; i++){
      if(cntfile[i]=='r'&&cntfile[i+1]=='o'&&cntfile[i+2]=='o'&&cntfile[i+3]=='t'){
	cout<<"i= "<<i<<endl;
	index=9-9;
      }
    }

    //int index=104-12;

    for(int j=index;j<index+6;j++){
      run=run*10+(int)cntfile[j]-48;
    }
    //}
    //}
    cout<<run<<endl;

    bool runflag=true;
    for(int irun=0;irun<nrun;irun++){
      if(run==tmprun[irun]) {
	runflag=false;
	lstfile[irun]<<cntfile<<endl;
      }
    }
    if(runflag) {
      //split
      tmprun[nrun]=run;
      sprintf(cc,"%s%s%d%s","lst/run2","_",run,".lst");
      cout<<cc<<endl;
      lstfile[nrun].open(cc);
      lstfile[nrun]<<cntfile<<endl;
      //store the run #
      runlist<<run<<endl;
      nrun++;
    }

  }//end of while
  runlist.close();
}
コード例 #13
0
ファイル: client.c プロジェクト: suiy/PA3
int main(int argc, char *argv[])
{
	
	//Read Command Line and set values
    if (argc != 5) {
        printf("usage: %s <client name> <server ip> <server port #> <list of files from “shared files directory”>\n", argv[0]);
        exit(1);
    }

    c_name = argv[1];
    server_ip = argv[2];
    server_port = atoi(argv[3]);
    file_list=argv[4];

 	// 1. Create socket and connect to server
 	
	int sock,csock,clientsock;
    int clientAddrSize = sizeof(struct sockaddr_in);
    struct sockaddr_in clientAddr;

    sock = tcp_connect(server_ip,server_port);
    srand((unsigned)time(0));
    int ran_num=rand() % 2000;
    client_port=5000+ran_num;
    csock = tcp_listen(client_port);

    //2.send client name and file list to server 
    char buffer[MAXBUFSIZE];
    bzero(buffer,MAXBUFSIZE);
    filelist(c_name,file_list,buffer,client_port);
    printf("client %s is sending file_list\n",c_name);
    send(sock,buffer,sizeof(buffer),0);
    bzero(buffer,MAXBUFSIZE);
    recv(sock,buffer,MAXBUFSIZE,0);
    printf("%s\n",buffer);

    char buf[MAXBUFSIZE];
    char recvbuf[MAXBUFSIZE];
    while (1) {
fd_set rfds;
        struct timeval tv;
        FD_ZERO(&rfds);
        FD_SET(csock, &rfds);
        tv.tv_sec = 0;
        tv.tv_usec = 100000;
        //printf("loop\n");
        if (select(csock + 1, &rfds, NULL, NULL, &tv)) {
            printf("in select 1\n");
            /* if someone is trying to connect, accept() the connection */
            clientsock = accept(csock,
                (struct sockaddr*) &clientAddr,
                (socklen_t*) &clientAddrSize);
            FD_ZERO(&rfds);
            FD_SET(clientsock, &rfds);
            tv.tv_sec = 0;
            tv.tv_usec = 100000;
            if (select(clientsock + 1, &rfds, NULL, NULL, &tv)) {
            bzero(buffer,MAXBUFSIZE);
            bzero(buf,MAXBUFSIZE);
             printf("in select 2\n");
            recv(clientsock,buffer,MAXBUFSIZE,0);
            strncpy(buf,buffer,3);
            if(!strcmp(buf,"Get")){
                send_file(buffer+4,clientsock);
            }
            }
            close(clientsock);
        }
        /* Read command line and store in buffer*/
        bzero(buf,MAXBUFSIZE);
        bzero(buffer,MAXBUFSIZE);
       // printf("> ");
        fd_set fds;
        struct timeval ttv;
        int ioflag = 0;
        ttv.tv_sec = 5; 
        ttv.tv_usec = 0;
        FD_ZERO(&fds);
        FD_SET(0,&fds); //stdin
        select(0+1,&fds,NULL,NULL,&ttv);
        if(FD_ISSET(0,&fds)){
            
            fgets(buf, MAXBUFSIZE, stdin);
            ioflag = 1;
            
            
        }
        if(!ioflag){ //bounce back to start of loop on user io timeout
            continue;
        }
        
        if (strlen(buf) > 0) {
            buf[strlen(buf) - 1] = '\0';
        if(!strcmp(buf,"Exit")){
        	sprintf(buffer,"%s.%s.",c_name,buf);
        	send(sock,buffer,sizeof(buffer),0);
        	close(sock);
        	exit(EXIT_SUCCESS);
        }
        else if(!strcmp(buf,"List")){
        	sprintf(buffer,"%s.%s.",c_name,buf);
        	send(sock,buffer,sizeof(buffer),0);
        }
        else if(!strcmp(buf,"SendMyFilesList")){
		bzero(buffer,MAXBUFSIZE);
    	filelist(c_name,file_list,buffer,client_port);
    	send(sock,buffer,sizeof(buffer),0);
        }
        else if(!strcmp(buf,"")){
            continue;
        }
        else{
        	strncpy(buffer,buf,3);
        	if(!strcmp(buffer,"Get")){
        		bzero(buffer,MAXBUFSIZE);
        		sprintf(buffer,"%s.Get.%s",c_name,buf+4);
        		send(sock,buffer,sizeof(buffer),0);
			}
			else{
				printf("Invalid Command: Exit/List/SendMyFilesList/Get <file>\n");
				continue;
			}
        }
    }
    

        bzero(recvbuf,MAXBUFSIZE);
        bzero(buf,MAXBUFSIZE);
        recv(sock,recvbuf,MAXBUFSIZE,0);
        
        int fdot = strcspn(recvbuf, ".");
		strncpy(buf, recvbuf, fdot);
		if(!strcmp(buf,"Server: receive file_list successfully")){
			printf("%s\n",recvbuf);
		}
		else if(!strcmp(buf,"filelist")){
			printf("Received list of files from server\nFile name || File size KB || File owner\n%s",recvbuf+fdot+1);
		}
		else if(!strcmp(buf,"ip")){
            int sdot = strcspn(recvbuf+fdot+1,"|");
            
            char client_ip[MAXBUFSIZE];
            char filename[MAXBUFSIZE];
            char file_buf[MAXBUFSIZE];
            char cport[MAXBUFSIZE];
            int cp;
            bzero(filename,MAXBUFSIZE);
            strncpy(filename,recvbuf+fdot+1,sdot);
            if(!strcmp(recvbuf+fdot+sdot+2,"File requested is not available")){
                printf("Server: File requested is not available\n");
                continue;
            }

            int adot = strcspn(recvbuf+fdot+sdot+2,".");
            bzero(cport,MAXBUFSIZE);
            strncpy(cport,recvbuf+fdot+sdot+2,adot);
            cp=atoi(cport);
            bzero(client_ip,MAXBUFSIZE);
			strcpy(client_ip,recvbuf+fdot+sdot+adot+3);
            
            
            int currentsock = tcp_connect(client_ip,cp);
            sprintf(file_buf,"Get %s",filename);
            send(currentsock,file_buf,sizeof(file_buf),0);
            receive_file(filename,currentsock);
            close(currentsock);

		}

    }
close(sock);
}