예제 #1
0
파일: main.c 프로젝트: Nurb432/plan9front
static void
fsstat(Req *r)
{
	int rc;
	FInfo fi;
	Aux *a = r->fid->aux;

	if(ptype(r->fid->qid.path) == Proot)
		V2D(&r->d, r->fid->qid, "");
	else if(ptype(r->fid->qid.path) == Pinfo)
		dirgeninfo(pindex(r->fid->qid.path), &r->d);
	else if(ptype(r->fid->qid.path) == Pshare)
		V2D(&r->d, r->fid->qid, a->path +1);
	else{
		memset(&fi, 0, sizeof fi);
		if(Sess->caps & CAP_NT_SMBS)
			rc = T2queryall(Sess, a->sp, mapfile(a->path), &fi);
		else
			rc = T2querystandard(Sess, a->sp, mapfile(a->path), &fi);
		if(rc == -1){
			responderrstr(r);
			return;
		}
		I2D(&r->d, a->sp, a->path, &fi);
		if(Billtrog == 0)
			upd_names(Sess, a->sp, mapfile(a->path), &r->d);
	}
	respond(r, nil);
}
예제 #2
0
파일: main.c 프로젝트: Nurb432/plan9front
static void
fsopen(Req *r)
{
	int rc;
	FInfo fi;
	Aux *a = r->fid->aux;

	a->end = a->off = 0;
	a->cache = emalloc9p(max(Sess->mtu, MTU));

	if(ptype(r->fid->qid.path) == Pinfo){
		if(makeinfo(pindex(r->fid->qid.path)) != -1)
			respond(r, nil);
		else
			respond(r, "cannot generate info");
		return;
	}

	if(r->fid->qid.type & QTDIR){
		respond(r, nil);
		return;
	}

	if(Sess->caps & CAP_NT_SMBS)
		rc = ntcreateopen(a, mapfile(a->path), r->ifcall.mode, 0777,
			0, 0, &fi);
	else
		rc = smbcreateopen(a, mapfile(a->path), r->ifcall.mode, 0777,
			0, 0, &fi);
	if(rc == -1){
		responderrstr(r);
		return;
	}
	respond(r, nil);
}
예제 #3
0
파일: main.c 프로젝트: Nurb432/plan9front
static void
fscreate(Req *r)
{
	FInfo fi;
	int rc, is_dir;
	char *npath;
	Aux *a = r->fid->aux;

	a->end = a->off = 0;
	a->cache = emalloc9p(max(Sess->mtu, MTU));

	is_dir = (r->ifcall.perm & DMDIR) == DMDIR;
	npath = smprint("%s/%s", a->path, r->ifcall.name);

	if(Sess->caps & CAP_NT_SMBS)
		rc = ntcreateopen(a, mapfile(npath), r->ifcall.mode,
			r->ifcall.perm, 1, is_dir, &fi);
	else
		rc = smbcreateopen(a, mapfile(npath), r->ifcall.mode,
			r->ifcall.perm, 1, is_dir, &fi);
	if(rc == -1){
		free(npath);
		responderrstr(r);
		return;
	}

	r->fid->qid = mkqid(npath, fi.attribs & ATTR_DIRECTORY, fi.changed, 0, 0);

	r->ofcall.qid = r->fid->qid;
	free(a->path);
	a->path = npath;

	respond(r, nil);
}
예제 #4
0
int main(int argc, char **argv) {

  if (argc != 6) {
    usage(argv[0]);
    exit(1);
  }

  double res = atof(argv[1]);
  double left = atof(argv[2]);
  double top = atof(argv[3]);

  std::string jpegfile(argv[4]);
  std::string mapfile(argv[5]);

  std::ofstream out(mapfile.c_str(), std::ofstream::out);

  out << jpegfile << std::endl;
  out << res << std::endl;
  out << left << std::endl;
  out << top << std::endl;

  out.close();

  return 0;
}
예제 #5
0
int main(int ac, char **av)
{
	int failed = 0, verbose = 0;
	struct snappy_env env;
	snappy_init_env(&env);

	if (av[1] && !strcmp(av[1], "-v")) {
		verbose++;
		av++;
	}

	while (*++av) { 
		size_t size;
		char *map = mapfile(*av, O_RDONLY, &size);
		if (!map) {
			if (size > 0) {
				perror(*av);
				failed = 1;
			}
			continue;
		}

		size_t outlen;
		int err;       
		char *out = xmalloc(snappy_max_compressed_length(size));
		char *buf2 = xmalloc(size);

		err = snappy_compress(&env, map, size, out, &outlen);		
		if (err) {
			failed = 1;
			printf("compression of %s failed: %d\n", *av, err);
			goto next;
		}
		err = snappy_uncompress(out, outlen, buf2);

		if (err) {
			failed = 1;
			printf("uncompression of %s failed: %d\n", *av, err);
			goto next;
		}
		if (memcmp(buf2, map, size)) {
			int o = compare(buf2, map, size);			
			if (o >= 0) {
				failed = 1;
				printf("final comparision of %s failed at %d of %lu\n", 
				       *av, o, (unsigned long)size);
			}
		} else {
			if (verbose)
				printf("%s OK!\n", *av);
		}

	next:
		unmap_file(map, size);
		free(out);
		free(buf2);
	}
	return failed;
}
예제 #6
0
파일: nile.c 프로젝트: Gottox/nile
int
nileDiff(FILE *oldfile, FILE *newfile, FILE *output, enum Options options) {
	int rv = 1;
	off_t oldoff = 0, newoff = 0, lastSkip = 0;
	size_t oldsize, newsize;
	char *olddata = NULL, *newdata = NULL, md5sum[MD5_DIGEST_LENGTH] = { 0 }, header[8];

	if((oldsize = mapfile(oldfile, &olddata)) == -1)
		rv = 1;
	else if((newsize = mapfile(newfile, &newdata)) == -1)
		rv = 1;

	fputs(MAGIC, output);

	// newfile: uncompress and build md5sum
	if((newfile = uncompress(newfile, output, options)) == NULL)
		goto diff_cleanup;
	buildhash(md5sum, newfile);
	fwrite(md5sum, sizeof(md5sum), 1, output);

	// oldfile: uncompress and build md5sum
	if((oldfile = uncompress(oldfile, NULL, options)) == NULL)
		goto diff_cleanup;
	buildhash(md5sum, oldfile);
	fwrite(md5sum, sizeof(md5sum), 1, output);

	// Building Diff
	for(oldoff = newoff = 0; oldoff < oldsize && newoff < newsize;) {
		if(lcs(olddata, &oldoff, oldsize, newdata, &newoff, newsize, &lastSkip, output)) break;
	}
	// write trailing diff
	offtout(lastSkip, header);
	fwrite(header, sizeof(header), 1, output);
	offtout(oldsize - oldoff, header);
	fwrite(header, sizeof(header), 1, output);
	offtout(newsize - newoff, header);
	fwrite(header, sizeof(header), 1, output);
	fwrite(&newdata[newoff], newsize - newoff, 1, output);

diff_cleanup:
	if(oldsize >= 0)
		munmap(olddata, oldsize);
	if(newsize >= 0)
		munmap(newdata, newsize);
	return rv;
}
예제 #7
0
void GameShell::loadMap()
{
    SDL_Rect srctile, destile;
    std::ifstream mapfile("map.txt");
    int nr, id = 1;
    mapfile >> layerNumber;
    std::vector<Tile*> layer;

    for(unsigned int i = 0; i < layerNumber; i++)
    {
        destile.x = -TILE_WIDTH;
        destile.y = 0;
        layer.clear();
        for(int j = 0; j < MAXTILES; j++)
        {
            mapfile >> nr;
            if(nr == 1)
            {
                int posx = j % (SCREEN_WIDTH / TILE_WIDTH);
                int posy = j / (SCREEN_WIDTH / TILE_WIDTH);
                exit.x = posx * TILE_WIDTH;
                exit.y = posy * TILE_HEIGHT;
                std::cout<<"XEXIT = " <<exit.x <<" "<<"YEXIT = " << exit.y<<"\n";
            }

            srctile = bkgtiles[nr];
            destile.x += TILE_WIDTH;

            Tile* tile = new Tile(destile.x, destile.y);
            tile->id = id++;
            tile->type = nr;

            if(nr == TRANSPARENCY)
            {
                tile->setTransparency(true);
            }

            if(isItem(nr) == true)
            {
                tile->setItem(true);
            }

            layer.push_back(tile);

            SDL_BlitSurface(tileset, &srctile, screen, &destile);
            if(destile.x >= SCREEN_WIDTH - TILE_WIDTH)
            {
                destile.y += TILE_WIDTH;
                destile.x = -TILE_WIDTH;
            }
        }
        tiles.push_back(layer);
    }
    mapfile.close();
    SDL_UpdateWindowSurface(window);
}
예제 #8
0
파일: bench.c 프로젝트: PrismTech/snappy-c
int main(int ac, char **av)
{
	int snappy_only = 0;

	if (av[1] && !strcmp(av[1], "-s")) {
		snappy_only = 1;
		av++;
	}

#ifdef SIMPLE_PMU
	pin_cpu(NULL);
	if(perfmon_available() == 0) {
		printf("no perfmon support\n");
		exit(1);
	}
#endif

	while (*++av) { 
		size_t size;
		char *map = mapfile(*av, O_RDONLY, &size);
		if (!map)
			err(*av);
		
		int i, v;
		for (i = 0; i < size; i += 4096)
			v = ((volatile char *)map)[i];

#ifdef COMP
		test_lz4(map, size, *av);
#endif

		test_snappy(map, size, *av);

		if (snappy_only)
			goto unmap;

#ifdef COMP		
		test_lzo(map, size, *av);
		test_zlib(map, size, *av, 1);
		test_zlib(map, size, *av, 3);
		//test_zlib(map, size, *av, 5);
		test_lzf(map, size, *av);
		test_quicklz(map, size, *av);
		test_fastlz(map, size, *av);
#endif		

#ifdef SNAPREF
		test_snapref(map, size, *av);
#endif

unmap:
		unmap_file(map, size);
		
	}
	return 0;
}
예제 #9
0
파일: client.c 프로젝트: zhan849/cs558
int main(int argc, char *argv[])
{
    if (argc < 4) {
       fprintf(stderr,"%s", USAGE);
       exit(0);
    }
    server_t = gethostbyname(argv[2]);
    server = gethostbyname(argv[2]);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    if (server_t == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    filename = (char *) malloc(FILENAME_SIZE);
    strcpy(filename,argv[1]);
    portno = atoi(argv[3]);
    makesocket();
    mapfile();
    //send_file_info();
    send_file_info_tcp();
    if((error=pthread_create(&resend_thread,NULL,resend_packet,NULL))){
        fprintf(stderr, "error in creating pthread: %s\n",strerror(error));
        exit(1);
    }
    packet packet1;
    memset(packet1.payload,'\0',PAYLOAD_SIZE+1);
    if((filesize % PAYLOAD_SIZE) != 0)
        no_of_packets = (filesize/PAYLOAD_SIZE)+1;
    else
        no_of_packets = (filesize/PAYLOAD_SIZE);
	if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { perror( "clock gettime" );}
    while(seqNum < no_of_packets){
        packet1.seq_num = seqNum;
        if((seqNum == (no_of_packets-1)) && ((filesize % PAYLOAD_SIZE) != 0)){
        	memcpy(packet1.payload,data+off,(filesize % PAYLOAD_SIZE));
        	}
        else{
        	memcpy(packet1.payload,data+off,PAYLOAD_SIZE);
        	}
        seqNum++;
        memcpy(packet1.payload,data+off,PAYLOAD_SIZE);
        off = off + PAYLOAD_SIZE;
        send_packets(packet1);
    }
    pthread_join(resend_thread,NULL);
    munmap(data, filesize);
    close(fp);
	return 1;
}
예제 #10
0
파일: zson.c 프로젝트: fvdsn/ZSON
zson_t *zson_decode_file(FILE *f){
    zson_t *z = zson_new();
    // *f; crash if file is NULL ?
    if(!f){
        zson_set_error(z, ZSON_ERROR_NULL_ARG, "cannot decode NULL file");
        return z;
    }
    z->path = NULL;
    z->file = f;
    mapfile(f,&(z->mem),&(z->mem_size));
    if(!zson_next(z) && !zson_has_error(z)){
        zson_set_error(z, ZSON_ERROR_EMPTY, "the file to decode has no content");
    }
    return z;
}
예제 #11
0
파일: s_hash.cpp 프로젝트: giser/fastwiki
int SHash::sh_extern_shm()
{
    size_t size;

    struct shm_hash_head *head = sh_get_head();

    size = head->data * (value_len + key_len + sizeof(int)) / 10;

    if (size < 8192)
        size = 8192 - 8192 % (value_len + key_len + sizeof(int));

    debug_log(("extern shm start: add size=%llu ...\n", (unsigned long long)size));

    if (shm_flag & _SHASH_MEM_FLAG) {
        old_size += size;
        if ((mem = realloc(mem, old_size)) == NULL) {
            debug_log(("extern memory: realloc error: +size=%llu, %s\n",
                       (unsigned long long)size, strerror(errno)));
            return -1;
        }
        memset((char *)mem + old_size - size, 0, size);
    } else if (shm_flag & _SHASH_FILE_FLAG) {
#ifndef WIN32
        if (munmap(mem, old_size) == -1)
            return -1;
#endif
        if (ftruncate(fd, old_size + size) == -1) {
            debug_log(("ftruncate fd=%d size=%llu: %s\n", fd,
                       (unsigned long long)(old_size + size), strerror(errno)));
            return -1;
        }
#ifndef WIN32
        if ((mem = mapfile(fd, &old_size, 1)) == NULL) {
            debug_log(("extern memory: realloc error: +size=%llu, %s\n",
                       (unsigned long long)size, strerror(errno)));
            return -1;
        }
#endif
        memset((char *)mem + old_size - size, 0, size);
    }

    if (sh_init_head(1) == -1)
        return -1;

    debug_log(("extern shm done.\n"));

    return 0;
}
예제 #12
0
void loadMap( GameModel & game, PathGraph & pathgraph, GameView & view, GameViewSound & sound, std::map< std::string, float > & globalVariables, const std::string & filename ) {
	std::ifstream mapfile( filename.c_str( ) );
	while( !mapfile.eof( ) ) {
		char c = Map::Consume( mapfile, "{" );
		if( !mapfile.eof( ) ) {
			mapfile.putback( c );
			Map::Entity entity;
			mapfile >> entity;

			if( entity.values[ "classname" ] == "worldspawn" ) {
				addWorldspawn( game, view, entity );
			} else if( entity.values[ "classname" ] == "info_player_start" ) {
				std::istringstream originstream( entity.values[ "origin" ] );
				float x, y, z;
				originstream >> x >> z >> y;
				game.addSpawnPoint( Vector3( x, y, -z ) );
			} else if( entity.values[ "classname" ] == "light" ) {
예제 #13
0
/*!
* \fn Map* MapBuilderStd::createMap(std::string filename)
* \brief Cree une map a partir du fichier de description de map
* \return Map* pointeur sur la map creee a partir du fichier passe en parametre
*/
Map* MapBuilderStd::createMap(std::string filename){
	this->initializeCheckers();
	//creation d'une Map
	MapStd* map = new MapStd();

	//ouverture du flux
	std::ifstream mapfile(filename, std::ios::in);

	if(!mapfile.fail()){
		//std::cout << "File " << filename << " successfully opened." << std::endl;

		std::string tmp_str; //string qui sera lu
		std::string square; //type de la case a construire
		int x = 0; //abcisse de la case a construire
		int y = 0; //ordonnee de la case a construire
		int longueur = 0;
		int hauteur = 0;
		std::vector<int> coordVector; //vector de coordonnees pour les asteroides

 		while(mapfile.good())
		{
			mapfile>>tmp_str;

			if(tmp_str=="P" ||tmp_str=="\'P\'" ){
				square = tmp_str;
				mapfile>>tmp_str;
				x = this->stringToInt(tmp_str);
				mapfile>>tmp_str;
				y = this->stringToInt(tmp_str);
				
				if(x>=0 && y >=0){
					map->setLongueur(x);
					longueur = x;
					map->setHauteur(y);
					hauteur = y;
					map->initialize(longueur,hauteur);
				}
				else{
					//std::cout << "Impossible to build the map" << std::endl;
					map->setValidMap(false);
					return map;
				}

			}
			else if(tmp_str=="O"||tmp_str=="\'O\'"){
예제 #14
0
파일: library.c 프로젝트: UIKit0/fsex
int map_lib_file(char *filename, struct fsex_libdata *lib)
{
	char *idstr;
	struct fsex_id *id;

	lib->data = mapfile(filename);
	if (lib->data == NULL) {
		perror(filename);
		exit(1);
	}

	lib->model = MODEL_NONE;
	lib->filename = filename;
	printf("* %s: ", filename);

	id = find_id_by_libid(lib->data);
	if (id == NULL) {
		printf("unknown\n");
		exit(1);
	}

	idstr = id->name;
	lib->model = id->model;

	lib->data += 32;
	lib->num_patch = val32_be(lib->data);
	lib->data += 128;

	if (check_lib(lib) < 0) {
		fprintf(stderr, "data seems to be corrupted\n");
		exit(1);
	}

	printf("%s library file (%d patches)\n", idstr, lib->num_patch);

	lib->patch = malloc(lib->num_patch * sizeof(struct fsex_patch));
	if (lib->patch == NULL) {
		perror("error");
		exit(1);
	}

	load_patches(lib);

	return 0;
}
예제 #15
0
void MapBuilder::convert() {
    char c;
    int x = 0;
    int y = 0;
    int maxX = 0;
    int maxY = 0;
    string mapName, terrainType;
    
    // Declares an Input filestream
    ifstream datafile(readFile.c_str());
    // Declares an Output filestream.
    ofstream mapfile(saveFile.c_str());
    if (datafile.is_open()) {
        cout << "Output open!" << endl;
    }
    
    if (datafile.is_open())
    {
        while (! datafile.eof() )
        {
            datafile >> c;
            if (c == '/') {
                x = 0;
                y++;
            }
            else {
                mapfile << x << " " << y << " " << getType( c ) << " 0" << "\n";
                x++;
            }
            
            if (x > maxX) {
                maxX = x;
            }
            if (y > maxY) {
                maxY = y;
            }
        }
        cout << "Map Width: " << maxX << endl;
        cout << "Map Height: " << maxY - 1 << endl;
        
        datafile.close();
        datafile.clear();
    }   
    else cout << "Unable to open file"; 
예제 #16
0
int
fbsd_nat_target::find_memory_regions (find_memory_region_ftype func,
				      void *obfd)
{
  pid_t pid = inferior_ptid.pid ();
  unsigned long start, end, size;
  char protection[4];
  int read, write, exec;

  std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid);
  gdb_file_up mapfile (fopen (mapfilename.c_str (), "r"));
  if (mapfile == NULL)
    error (_("Couldn't open %s."), mapfilename.c_str ());

  if (info_verbose)
    fprintf_filtered (gdb_stdout, 
		      "Reading memory regions from %s\n", mapfilename.c_str ());

  /* Now iterate until end-of-file.  */
  while (fbsd_read_mapping (mapfile.get (), &start, &end, &protection[0]))
    {
      size = end - start;

      read = (strchr (protection, 'r') != 0);
      write = (strchr (protection, 'w') != 0);
      exec = (strchr (protection, 'x') != 0);

      if (info_verbose)
	{
	  fprintf_filtered (gdb_stdout, 
			    "Save segment, %ld bytes at %s (%c%c%c)\n",
			    size, paddress (target_gdbarch (), start),
			    read ? 'r' : '-',
			    write ? 'w' : '-',
			    exec ? 'x' : '-');
	}

      /* Invoke the callback function to create the corefile segment.
	 Pass MODIFIED as true, we do not know the real modification state.  */
      func (start, size, read, write, exec, 1, obfd);
    }

  return 0;
}
예제 #17
0
파일: cpel.c 프로젝트: Venkattk/vpp
/*
 * read_cpel_file
 */
int read_cpel_file(char *cpel_file)
{
    int verbose = 0;
    int rv;
    static u8 *cpel;
    static unsigned long size;
    static FILE *ofp;

    if (cpel) {
        unmapfile((char *)cpel, size);
        hash_free(the_strtab_hash);
        the_strtab_hash = 0;
        hash_free(the_evtdef_hash);
        the_evtdef_hash = 0;
        hash_free(the_trackdef_hash);
        the_trackdef_hash = 0;
    }

    cpel = (u8 *)mapfile((char *)cpel_file, &size);
    if (cpel == 0) {
        fprintf(stderr, "Couldn't map %s...\n", cpel_file);
        exit(1);
    }

    if (ofp == NULL) {
        ofp = fdopen(2, "w");
        if (ofp == NULL) {
            fprintf(stderr, "Couldn't fdopen(2)?\n");
            exit(1);
        }
    }

    the_strtab_hash = hash_create_string (0, sizeof (uword));
    the_evtdef_hash = hash_create (0, sizeof (uword));
    the_trackdef_hash = hash_create (0, sizeof (uword));

    rv = cpel_process(cpel, verbose, ofp);

    set_pid_ax_width(8*widest_track_format);

    return(rv);
}
예제 #18
0
파일: zson.c 프로젝트: fvdsn/ZSON
zson_t *zson_decode_path(const char *path){
    zson_t *z = zson_new();
    if(!path){
        zson_set_error(z, ZSON_ERROR_NULL_ARG, "cannot read NULL path");
        return z;
    }
    FILE *f = fopen(path,"r");

    if(!f){
        zson_set_error(z, ZSON_ERROR_FILE_READ, "could not read input file");
        return z;
    }
    z->path = path;
    z->file = f;
    z->private_file = true;
    mapfile(f, &(z->mem), &(z->mem_size));
    if(!zson_next(z) && !zson_has_error(z)){
        zson_set_error(z, ZSON_ERROR_EMPTY, "the file to decode has no content");
    }
    return z;
}
예제 #19
0
bool Map::_loadMapStr(std::string filepath) {
    std::ifstream mapfile(filepath);

    if (mapfile.is_open()) {
        std::stringstream mapstream;
        std::string line;

        while(std::getline(mapfile, line)) {
            mapstream << line << std::endl;
        }

        mapfile.close();

        Map::_mapstr = mapstream.str();
    } else {
        // unable to open file
        return false;
    }

    // map was opened and loaded successfully, but now we have to validade it
    return Map::_sanityCheck();
}
예제 #20
0
bool World::processLevelData(std::string pathToMapFile)
{
    //File object
    std::ifstream mapfile(pathToMapFile);

    //Store our character.
    char inputChar;

    //Store our working data
    int data;

    //Loop get single characters.
    if (mapfile.is_open()) {
        while (mapfile)
        {
            //Grab the character
            inputChar = mapfile.get();

            //If we have a number
            if (inputChar >= '0' && inputChar <= '9') {
                //Convert to ASCII int
                data = inputChar - 48;
            } else if (isalpha(inputChar) && isupper(inputChar)) {
                //If we  have an uppercase character...
                //...convert to ASCII int too
                data = inputChar - 55;
            } else { //We must have junk
                continue; // Discard it
            }
            //Update our level vector.
            currentLevel.push_back(data);
        }
    } else {
        return false; //No mapfile found.
    }
    mapfile.close(); //Remember to cleanup!
    return true; //Successfully loaded level
}
예제 #21
0
int main (int argc, char * argv[])
{
  try {
    std::ifstream doc("test.xqm", std::ios_base::binary);
    if(argc == 2 && std::string(argv[1]) == "-t") {
      std::ifstream mapfile("test.xqa", std::ios_base::binary);
      std::ofstream output("test.xml");
      std::cerr<<"Parsing with translation enabled... ";
      output<<"<?xml version=\"1.0\"?>\n";
      xqML::Parser myparser(mapfile, doc, output);
      myparser.parseDocument();
      std::cerr<<"done\n\tSee file \"test.xml\" for an xml-like output (viewable in Mozilla/IE)\n";
    }
    else if (argc == 1) {
      std::ofstream output("test.dat");
      std::cerr<<"Parsing with translation disabled... ";
      xqML::Parser myparser(doc, output);
      myparser.parseDocument();
      std::cerr<<"done\n\tSee file \"test.dat\" for an xml-like output with numbers instead of identifiers\n";
    }
    else {
      std::cerr<<"Usage: parser_test [-t]\n";
      std::cerr<<"       Options:\n";
      std::cerr<<"       -t\tenable translation\n";
    }
  }
  catch (xqML::IllegalIdentifier exception) {
    std::cerr<<"Illegal Identifier "<<exception.identifier<<" of type "<<exception.type<<"\n";
  }
  catch (xqML::IllegalContext exception) {
    std::cerr<<"Illegal Context \""<<exception.context<<"\" while writing \""<<exception.identifier<<"\" of type "<<exception.type<<'\n';
  }
  catch (...) {
    std::cerr<<"Caught unknown exception, aborting :-(\n";
    std::abort();
  }
  return 0;
}
예제 #22
0
파일: test.c 프로젝트: agiz/spooky-c
int main(int ac, char **av)
{
	while (*++av) {
		unsigned long start, end;
		uint64_t h1, h2;
		struct spooky_state state;
		size_t size;
		char *map = mapfile(*av, O_RDONLY, &size);
		if (!map) {
			perror(*av);
			continue;
		}
		
		int i;
		for (i = 0; i < size; i += 64)
			use_value(((volatile char *)map)[i]);

		spooky_init(&state, 0x123456789abcdef, 0xfedcba987654321);
		spooky_update(&state, map, size);
		spooky_final(&state, &h1, &h2);

		start = __builtin_ia32_rdtsc();
		for (i = 0; i < ITER; i++) {
			spooky_init(&state, 0x123456789abcdef, 0xfedcba987654321);
			spooky_update(&state, map, size);
			spooky_final(&state, &h1, &h2);
		}
		end = __builtin_ia32_rdtsc();

		printf("%s: %016llx%016llx [%f c/b]\n", *av, 
		        (unsigned long long)h1, 
		        (unsigned long long)h2,
			((end - start) / ITER) / (double)size);

		unmap_file(map, size);
	}
	return 0;
}
예제 #23
0
파일: main.c 프로젝트: Nurb432/plan9front
static int
smbcreateopen(Aux *a, char *path, int mode, int perm, int is_create,
	int is_dir, FInfo *fip)
{
	int rc, action, attrs, access, result;

	if(is_create && is_dir){
		if(CIFScreatedirectory(Sess, a->sp, path) == -1)
			return -1;
		return 0;
	}

	if(mode & DMAPPEND) {
		werrstr("filesystem does not support DMAPPEND");
		return -1;
	}

	if(is_create)
		action = 0x12;
	else if(mode & OTRUNC)
		action = 0x02;
	else
		action = 0x01;

	if(perm & 0222)
		attrs = ATTR_NORMAL;
	else
		attrs = ATTR_NORMAL|ATTR_READONLY;

	switch (mode & OMASK){
	case OREAD:
		access = 0;
		break;
	case OWRITE:
		access = 1;
		break;
	case ORDWR:
		access = 2;
		break;
	case OEXEC:
		access = 3;
		break;
	default:
		werrstr("%d bad open mode", mode & OMASK);
		return -1;
		break;
	}

	if(mode & DMEXCL == 0)
		access |= 0x10;
	else
		access |= 0x40;

	if((a->fh = CIFS_SMB_opencreate(Sess, a->sp, path, access, attrs,
	    action, &result)) == -1)
		return -1;

	if(Sess->caps & CAP_NT_SMBS)
		rc = T2queryall(Sess, a->sp, mapfile(a->path), fip);
	else
		rc = T2querystandard(Sess, a->sp, mapfile(a->path), fip);
	if(rc == -1){
		fprint(2, "internal error: stat of newly open/created file failed\n");
		return -1;
	}

	if((mode & OEXCL) && (result & 0x8000) == 0){
		werrstr("%d bad open mode", mode & OMASK);
		return -1;
	}
	return 0;
}
예제 #24
0
파일: main.c 프로젝트: Nurb432/plan9front
static char*
fswalk1(Fid *fid, char *name, Qid *qid)
{
	FInfo fi;
	int rc, n, i;
	Aux *a = fid->aux;
	static char e[ERRMAX];
	char *p, *npath, *winpath;

	*e = 0;
	npath = newpath(a->path, name);
	if(strcmp(npath, "/") == 0){			/* root dir */
		*qid = mkqid("/", 1, 1, Proot, 0);
		free(a->path);
		a->path = npath;
		fid->qid = *qid;
		return nil;
	}

	if(strrchr(npath, '/') == npath){		/* top level dir */
		if((n = walkinfo(name)) != -1){		/* info file */
			*qid = mkqid(npath, 0, 1, Pinfo, n);
		}
		else {					/* volume name */
			for(i = 0; i < Nshares; i++){
				n = strlen(Shares[i].name);
				if(cistrncmp(npath+1, Shares[i].name, n) != 0)
					continue;
				if(Checkcase && strncmp(npath+1, Shares[i].name, n) != 0)
					continue;
				if(npath[n+1] != 0 && npath[n+1] != '/')
					continue;
				break;
			}
			if(i >= Nshares){
				free(npath);
				return "not found";
			}
			a->sp = Shares+i;
			*qid = mkqid(npath, 1, 1, Pshare, i);
		}
		free(a->path);
		a->path = npath;
		fid->qid = *qid;
		return nil;
	}

	/* must be a vanilla file or directory */
again:
	if(mapshare(npath, &a->sp) == -1){
		rerrstr(e, sizeof(e));
		free(npath);
		return e;
	}

	winpath = mapfile(npath);
	memset(&fi, 0, sizeof fi);
	if(Sess->caps & CAP_NT_SMBS)
		rc = T2queryall(Sess, a->sp, winpath, &fi);
	else
		rc = T2querystandard(Sess, a->sp, winpath, &fi);

	if(rc == -1){
		rerrstr(e, sizeof(e));
		free(npath);
		return e;
	}

	if((a->sp->options & SMB_SHARE_IS_IN_DFS) != 0 &&
	    (fi.attribs & ATTR_REPARSE) != 0){
		if(redirect(Sess, a->sp, npath) != -1)
			goto again;
	}

	if((p = strrchr(fi.name, '/')) == nil && (p = strrchr(fi.name, '\\')) == nil)
		p = fi.name;
	else
		p++;

	if(! validfile(p, name, winpath, a->sp)){
		free(npath);
		return "not found";

	}
	*qid = mkqid(npath, fi.attribs & ATTR_DIRECTORY, fi.changed, 0, 0);

	free(a->path);
	a->path = npath;
	fid->qid = *qid;
	return nil;
}
예제 #25
0
파일: main.c 프로젝트: Nurb432/plan9front
static int
dirgen(int slot, Dir *d, void *aux)
{
	long off;
	FInfo *fi;
	int rc, got;
	Aux *a = aux;
	char *npath;
	int numinf = numinfo();
	int slots;

	slots = 128;		/* number of dir entries to fetch at one time */

	if(strcmp(a->path, "/") == 0){
		if(slot < numinf){
			dirgeninfo(slot, d);
			return 0;
		} else
			slot -= numinf;

		if(slot >= Nshares)
			return -1;
		V2D(d, mkqid(Shares[slot].name, 1, 1, Pshare, slot),
			Shares[slot].name);
		return 0;
	}

	off = slot * sizeof(FInfo);
	if(off >= a->off && off < a->end && time(nil) < a->expire)
		goto from_cache;

	if(off == 0){
		fi = (FInfo *)a->cache;
		npath = smprint("%s/*", mapfile(a->path));
		a->sh = T2findfirst(Sess, a->sp, slots, npath, &got, &a->srch,
			(FInfo *)a->cache);
		free(npath);
		if(a->sh == -1)
			return -1;

		a->off = 0;
		a->end = got * sizeof(FInfo);

		if(got >= 2 && strcmp(fi[0].name, ".") == 0 &&
		    strcmp(fi[1].name, "..") == 0){
			a->end = (got - 2) * sizeof(FInfo);
			memmove(a->cache, a->cache + sizeof(FInfo)*2,
				a->end - a->off);
		}
	}

	while(off >= a->end && a->sh != -1){
		fi = (FInfo *)(a->cache + (a->end - a->off) - sizeof(FInfo));
		a->off = a->end;
		npath = smprint("%s/%s", mapfile(a->path), fi->name);
		rc = T2findnext(Sess, a->sp, slots, npath,
			&got, &a->srch, (FInfo *)a->cache, a->sh);
		free(npath);
		if(rc == -1 || got == 0)
			break;
		a->end = a->off + got * sizeof(FInfo);
	}
	a->expire = time(nil) + CACHETIME;

	if(got < slots){
		if(a->sh != -1)
			CIFSfindclose2(Sess, a->sp, a->sh);
		a->sh = -1;
	}

	if(off >= a->end)
		return -1;

from_cache:
	fi = (FInfo *)(a->cache + (off - a->off));
	npath = smprint("%s/%s", mapfile(a->path), fi->name);
	I2D(d, a->sp, npath, fi);
	if(Billtrog == 0)
		upd_names(Sess, a->sp, npath, d);
	free(npath);
	return 0;
}
예제 #26
0
int main(int argc, char *argv[])
{
    pcap_if_t *device_list = NULL;		// Linked list of all devices discovered
	pcap_if_t *device_ptr = NULL;		// Pointer to a single device


	char err[128];						// Holds the error

	//char devices[10][64];				// For holding all available
	int count = 0;
	int ret = 0;
	int n = 0;

	srand(time(NULL));

	//printf("Scanning available devices ... ");
	if ( (ret = pcap_findalldevs(&device_list, err)) != 0 ) {
		fprintf(stderr, "Error scanning devices, with error code %d, and error message %s\n", ret, err);
		exit(1);
	}
	//printf("DONE\n");

	//printf("Here are the available devices:\n");
	for (device_ptr = device_list; device_ptr != NULL; device_ptr = device_ptr->next) {
		if (device_ptr->name != NULL && !strncmp(device_ptr->name, "eth", 3)){
			char ipaddr[20];
			if ((ret = getIPfromIface(device_ptr->name, ipaddr)) != 0) {
				fprintf(stderr, "ERROR getting IP from Iface for device %s\n", device_ptr->name);
			}
			if (strncmp(ipaddr, "10.", 3) == 0) {
				strcpy(device_name, device_ptr->name);
				fprintf(stdout, "Find iface %s, ip %s\n", device_name, ipaddr);
				break;
			}
		}
	}

	printf("Trying to open device %s to send ... ", device_name);
	if ( (handle_sniffed = pcap_open_live(device_name, BUFSIZ, 1, 100, err)) == NULL ) {
		fprintf(stderr, "Error opening device %s, with error message %s\n", device_name, err);
		exit(1);
	}
	fprintf(stdout, "OPEN DONE \n");
	//printTime();
	//if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { perror( "clock gettime" );}

	//printf("generating packets...\n");

//	Create thread to handle resend
	if((pthread_create(&resend_thread, NULL, resend_packet, NULL)) != 0){
        fprintf(stderr, "error in creating pthread. n");
        exit(1);
    }

    u_char packet[PACKET_BUF_SIZE];
    char payload[PAYLOAD_SIZE];

    int payload_size;
    long offset = 0;
    init();
    mapfile(argv[1]);
//    fp_read = fopen(argv[1], "r");
//    if(fp_read == NULL){
//        fprintf(stderr, "File open failed");
//        exit(1);
//    }
//    fseek(fp_read, 0L, SEEK_END);
//    filesize = ftell(fp_read);
    if((filesize % PAYLOAD_SIZE) != 0)
        no_of_packets = (filesize/PAYLOAD_SIZE) + 1;
    else
        no_of_packets = (filesize/PAYLOAD_SIZE);
    //fseek(fp_read, 0L, SEEK_SET);

    if(strcmp(argv[2], "node1") == 0)
        dest_addr = 0x0011;
    else if(strcmp(argv[2], "node2") == 0)
        dest_addr = 0x0021;
    else if(strcmp(argv[2], "node3") == 0)
        dest_addr = 0x0031;

    port = atoi(argv[3]);
    int seqNum = 0;
    //printf("My Ip: %02x, dest IP : %02x, port no: %d, FS: %d, Packet #: %d\n", my_addr, dest_addr, port, filesize, no_of_packets );
    //printf("Sending RELIABLE packets \n");
    if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { perror( "clock gettime" );}
    while (seqNum < no_of_packets) {
        //fseek(fp_read, offset, SEEK_SET);
        if((seqNum == (no_of_packets-1)) && ((filesize % PAYLOAD_SIZE) != 0))
            payload_size = filesize % PAYLOAD_SIZE;
        else
            payload_size = PAYLOAD_SIZE;
        memcpy(payload, data + offset, payload_size);
        //fread(payload, 1, payload_size, fp_read);
        offset = offset + payload_size;
        //change for RELIABLE/UNRELIABLE
        //int pktlen = generate_route_on_file_packet(packet, payload, payload_size + UR_HEADER_SIZE, ROUTE_ON_UNRELIABLE );
        int pktlen = generate_route_on_file_packet(packet, payload, payload_size + RE_HEADER_SIZE, ROUTE_ON_RELIABLE, seqNum );
        //fprintf(stdout, "%d, ", seqNum);
        if ((ret = pcap_inject(handle_sniffed, packet, pktlen)) < 0){
            fprintf(stderr, "Fail to inject packet\n");
		// exit(1);
        }
        seqNum++;
    }

    printf("\n");


    pthread_join(resend_thread, NULL);
    pcap_close(handle_sniffed);
    pcap_close(handle_sniffed_nack);
    munmap(data, filesize);
    close(fp);
    printf( "ALL DONE\n");
    return 1;
}
예제 #27
0
파일: scmd.c 프로젝트: thekvs/snappy-c
int main(int ac, char **av)
{
	int opt;
	int to_stdout = 0;

	while ((opt = getopt(ac, av, "dcs")) != -1) {
		switch (opt) { 
		case 'd':
			mode = uncompress;
			break;
		case 'c':
			mode = compress;
			break;
		case 's':
			to_stdout = 1;
			break;
		default:
			usage();
		}
	}

	char *map;
	size_t size;
	if (!av[optind])
		usage();

	if (mode == undef && match_suffix(av[optind], ".snp"))
		mode = uncompress;
	else
		mode = compress;

	map = mapfile(av[optind], O_RDONLY, &size);
	if (!map) { 
		fprintf(stderr, "Cannot open %s: %s\n", av[1], strerror(errno));
		exit(1);
	}
		
	int err;
	char *out;	
	size_t outlen;
	if (mode == uncompress) {
		if (!snappy_uncompressed_length(map, size, &outlen)) {
			fprintf(stderr, "Cannot read length in %s\n", 
				av[optind]);
			exit(1);
		}
	} else {	
		outlen = snappy_max_compressed_length(size);
	}
	
	out = xmalloc(outlen);

	if (mode == compress) {
		struct snappy_env env;
		snappy_init_env(&env);
		err = snappy_compress(&env, map, size, out, &outlen);
	} else
		err = snappy_uncompress(map, size, out);

	if (err) {
		fprintf(stderr, "Cannot process %s: %s\n", av[optind], 
			strerror(-err));
		exit(1);
	}

	char *file;
	int fd;
	if (to_stdout) {
		if(av[optind + 1])
			usage();
		fd = 1;
		file = "<stdout>";
	} else {
		if (av[optind + 1] && av[optind + 2])
			usage();
		fd = open_output(av[optind], av[optind + 1], &file);
	}

	err = 0;
	if (write(fd, out, outlen) != outlen) {
		fprintf(stderr, "Cannot write to %s: %s\n", 
			file,
			strerror(errno));
		err = 1;
	}

	return err;
}
예제 #28
0
파일: main.c 프로젝트: leffmann/vlink
int main(int argc,char *argv[])
{
  struct GlobalVars *gv = &gvars;
  int i,j;
  char *buf;
  struct LibPath *libp;
  struct InputFile *ifn;
  bool stdlib = TRUE;
  int so_version = 0;   /* minum version for shared objects */
  uint16_t flags = 0;   /* input file flags */

  /* initialize and set default values */
  memset(gv,0,sizeof(struct GlobalVars));
  initlist(&gv->libpaths);
  initlist(&gv->rpaths);
  gv->dynamic = TRUE;  /* link with dynamic libraries first */
  gv->interp_path = DEFAULT_INTERP_PATH;
  gv->soname = NULL;
  gv->endianess = -1;  /* endianess is unknown */

  /* initialize targets */
  for (j=0; fff[j]; j++) {
    if (fff[j]->init)
      fff[j]->init(gv);
  }
#ifdef DEFTARGET
  for (j=0; fff[j]; j++) {
    if (!strcmp(fff[j]->tname,DEFTARGET)) {
      gv->dest_format = (uint8_t)j;
      break;
    }
  }
  if (fff[j] == NULL) {
    fprintf(stderr,"Configuration warning: Selected default target "
            "\"%s\" is not included.\nThe current default target "
            "is \"%s\".\n",DEFTARGET,fff[gv->dest_format]->tname);
    printf("\n");
  }
#endif

  initlist(&gv->inputlist);
  initlist(&gv->lnksec);
  gv->dest_name = "a.out";
  gv->maxerrors = DEF_MAXERRORS;
  gv->reloctab_format = RTAB_UNDEF;
  gv->osec_base_name = NULL;

  if (argc<2 || (argc==2 && *argv[1]=='?')) {
    show_usage();
    exit(EXIT_SUCCESS);
  }

  for (i=1; i<argc; i++) {

    if (*argv[i] == '-') {  /* option detected */
      switch (argv[i][1]) {

        case 'b':  
          if (!strcmp(&argv[i][2],"aseoff")) {  /* set base-relative offset */
            long bo;

            sscanf(get_arg(argc,argv,&i),"%li",&bo);
            fff[gv->dest_format]->baseoff = bo;
          }
          else {  /* select target format */
            if (buf = get_option_arg(argc,argv,&i)) {
              /* for compatibility with older vlink versions,
                 elf32amiga is automatically converted into elf32powerup
                 and amigaos into amigahunk */
              if (!strcmp(buf,"elf32amiga"))
                buf = "elf32powerup";
              else if (!strcmp(buf,"amigaos"))
                buf = "amigahunk";
              for (j=0; fff[j]; j++) {
                if (!strcmp(fff[j]->tname,buf))
                  break;
              }
              if (fff[j])
                gv->dest_format = (uint8_t)j;
              else
                error(9,buf);  /* invalid target format */
            }
          }
          break;

        case 'c':
          if (!strncmp(&argv[i][2],"lr-",3))
            flags &= ~(chk_flags(argv[i]));   /* -clr-flags */
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'd':
          if (!argv[i][2] || argv[i][2]=='c' || argv[i][2]=='p')
            gv->alloc_common = TRUE;  /* force alloc. of common syms. */
          else if (argv[i][2] == 'a')
            gv->alloc_addr = TRUE;  /* force alloc. of address syms. */
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'e':
          if (!strcmp(&argv[i][2],"xport-dynamic"))
            gv->dyn_exp_all = TRUE;  /* export all globals as dynamic */
          else  /* defines entry point */
            gv->entry_name = get_option_arg(argc,argv,&i);
          break;

        case 'f':
          if (!strcmp(&argv[i][2],"ixunnamed")) {
            gv->fix_unnamed = TRUE;  /* assign a name to unnamed sections */
          }
          else {  /* set a flavour */
            char *name,**fl;

            if (name = get_option_arg(argc,argv,&i)) {
              if (fl = gv->flavours.flavours) {
                char **tmp = alloc((gv->flavours.n_flavours+1)*sizeof(char *));

                memcpy(tmp,fl,gv->flavours.n_flavours*sizeof(char *));
                free(fl);
                fl = tmp;
              }
              else
                fl = alloc(sizeof(char *));
              fl[gv->flavours.n_flavours++] = name;
              gv->flavours.flavours = fl;
              gv->flavours.flavours_len += strlen(name) + 1;
            }
          }
          break;

        case 'g':
          if (!strcmp(&argv[i][2],"c-empty"))
            gv->gc_sects = GCS_EMPTY;
          else if (!strcmp(&argv[i][2],"c-all"))
            gv->gc_sects = GCS_ALL;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'h':
          if (!strcmp(&argv[i][2],"unkattr")) {
            struct SecAttrOvr *sao;
            char secname[64];
            lword val;

            val = get_assign_arg(argc,argv,&i,secname,64);
            sao = addsecattrovr(gv,secname,SAO_MEMFLAGS);
            sao->memflags = (uint32_t)val;
          }
          else {
            if (argv[i][2] == '\0') {
              show_usage();      /* help text */
              exit(EXIT_SUCCESS);
            }
            else
              error(2,argv[i]);  /* unrecognized option */
          }
          break;

        case 'i':
          if (!strcmp(&argv[i][2],"nterp"))
            gv->interp_path = get_arg(argc,argv,&i);
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'k':
          gv->keep_sect_order = TRUE;
          break;

        case 'l':  /* library specifier */
          if (buf = get_option_arg(argc,argv,&i)) {
            ifn = alloc(sizeof(struct InputFile));
            ifn->name = buf;
            ifn->lib = TRUE;
            ifn->dynamic = gv->dynamic;
            ifn->so_ver = so_version;
            so_version = 0;
            ifn->flags = flags;
            addtail(&gv->inputlist,&ifn->n);
          }
          break;

        case 'm':
          if (!strcmp(&argv[i][2],"inalign")) {
            long a;

            sscanf(get_arg(argc,argv,&i),"%li",&a);
            gv->min_alignment = (uint8_t)a;
          }
          else if (!strcmp(&argv[i][2],"rel"))
            gv->auto_merge = TRUE;
          else if (!strcmp(&argv[i][2],"type"))
            gv->merge_same_type = TRUE;
          else if (!strcmp(&argv[i][2],"ultibase"))
            gv->multibase = TRUE;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'n':
          if (!argv[i][2])
            gv->no_page_align = TRUE;
          else if (!strcmp(&argv[i][2],"ostdlib"))
            stdlib = FALSE;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'o':  /* set output file name */
          if (!strncmp(&argv[i][2],"sec=",4) && argv[i][6]!='\0') {
            /* defines a base name of the sections to output */
            gv->osec_base_name = &argv[i][6];
            gv->output_sections = TRUE;  /* output each section as a file */
          }
          else if (!strcmp(&argv[i][2],"sec"))
            gv->output_sections = TRUE;  /* output each section as a file */
          else
            gv->dest_name = get_option_arg(argc,argv,&i);
          break;

        case 'q':  /* force relocations into final executable */
          gv->keep_relocs = TRUE;
          break;

        case 'r':  /* output is an relocatable object again */
          if (!argv[i][2]) {
            gv->dest_object = TRUE;
          }
          else if (!strcmp(&argv[i][2],"path")) {
            if (buf = get_arg(argc,argv,&i)) {
              libp = alloc(sizeof(struct LibPath));
              libp->path = buf;
              addtail(&gv->rpaths,&libp->n);
            }
          }
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 's':
          switch (argv[i][2]) {
            case '\0':  /* strip all symbols */
              gv->strip_symbols = STRIP_ALL;
              break;
            case 'c':   /* -sc force small code */
              gv->small_code = TRUE;
              break;
            case 'd':   /* -d force small data */
              gv->small_data = TRUE;
              break;
            case 'e':
              if (!strncmp(&argv[i][3],"t-",2))  /* -set-flags */
                flags |= chk_flags(argv[i]);
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 'h':   /* -shared */
              if (!strcmp(&argv[i][3],"ared"))
                gv->dest_sharedobj = TRUE;
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 'o':   /* -soname <real name> */
              if (!strcmp(&argv[i][3],"name"))
                gv->soname = get_arg(argc,argv,&i);
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            case 't':   /* -static */
              if (!strcmp(&argv[i][3],"atic"))
                gv->dynamic = FALSE;
              else
                error(2,argv[i]);  /* unrecognized option */
              break;
            default:
              error(2,argv[i]);  /* unrecognized option */
              break;
          }
          break;

        case 't':  /* trace file accesses */
          if (!strcmp(&argv[i][2],"extbaserel"))
            gv->textbaserel = TRUE;
          else if (!strncmp(&argv[i][2],"os-",3)) {
            /* -tos-options for targets ataritos and aoutmint */
            if (!strcmp(&argv[i][5],"flags")) {
              long fl;

              sscanf(get_arg(argc,argv,&i),"%li",&fl);
              gv->tosflags = fl;
            }
            else if (!strcmp(&argv[i][5],"fastload"))
              gv->tosflags |= 1;
            else if (!strcmp(&argv[i][5],"fastram"))
              gv->tosflags |= 2;
            else if (!strcmp(&argv[i][5],"fastalloc"))
              gv->tosflags |= 4;
            else if (!strcmp(&argv[i][5],"private"))
              gv->tosflags &= ~0x30;
            else if (!strcmp(&argv[i][5],"global"))
              gv->tosflags |= 0x10;
            else if (!strcmp(&argv[i][5],"super"))
              gv->tosflags |= 0x20;
            else if (!strcmp(&argv[i][5],"readable"))
              gv->tosflags |= 0x30;
            else if (!strcmp(&argv[i][5],"textbased"))
              gv->textbasedsyms = 1;
            else
              error(2,argv[i]);  /* unrecognized option */
          }
          else if (!argv[i][2])
            gv->trace_file = stderr;
          else
            error(2,argv[i]);  /* unrecognized option */
          break;

        case 'u':  /* mark symbol as undefined */
          if (buf = get_option_arg(argc,argv,&i))
            add_symnames(&gv->undef_syms,buf);
          break;

        case 'v':  /* show version and target info */
          show_version();
          printf("Standard library path: "
#ifdef LIBPATH
                 LIBPATH
#endif
                 "\nDefault target: %s\n"
                 "Supported targets:",fff[gv->dest_format]->tname);
          for (j=0; fff[j]; j++)
            printf(" %s",fff[j]->tname);
          printf("\n");
          exit(EXIT_SUCCESS);

        case 'w':  /* suppress warnings */
          gv->dontwarn = TRUE;
          break;

        case 'x':  /* discard all local symbols */
          gv->discard_local = DISLOC_ALL;
          break;

        case 'y':  /* trace all accesses on a specific symbol */
          if (gv->trace_syms == NULL)
            gv->trace_syms = alloc_hashtable(TRSYMHTABSIZE);
          if (buf = get_option_arg(argc,argv,&i)) {
            struct SymNames **chain = 
                            &gv->trace_syms[elf_hash(buf)%TRSYMHTABSIZE];
            while (*chain)
              chain = &(*chain)->next;
            *chain = alloczero(sizeof(struct SymNames));
            (*chain)->name = buf;
          }
          break;

        case 'B':  /* set link mode */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"static")) {
              gv->dynamic = FALSE;
            }
            else if (!strcmp(buf,"dynamic")) {
              gv->dynamic = TRUE;
            }
            else if (!strcmp(buf,"shareable")) {
              gv->dest_sharedobj = TRUE;
            }
            else if (!strcmp(buf,"forcearchive")) {
              gv->whole_archive = TRUE;
            }
            else if (!strcmp(buf,"symbolic")) {
              ;  /* don't know, what this means... */
            }
            else {
              error(3,buf);  /* unknown link mode */
            }
          }
          break;

        case 'C':  /* select con-/destructor type */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"gnu")) {
              gv->collect_ctors_type = CCDT_GNU;
            }
            else if (!strcmp(buf,"vbcc")) {
              gv->collect_ctors_type = CCDT_VBCC;
            }
            else if (!strcmp(buf,"vbccelf")) {
              gv->collect_ctors_type = CCDT_VBCC_ELF;
            }
            else if (!strcmp(buf,"sasc")) {
              gv->collect_ctors_type = CCDT_SASC;
            }
            else  /* @@@ print error message */
              gv->collect_ctors_type = CCDT_NONE;
          }
          break;

        case 'E':  /* set endianess */
          switch (argv[i][2]) {
            case 'B':
              gv->endianess = _BIG_ENDIAN_;
              break;
            case 'L':
              gv->endianess = _LITTLE_ENDIAN_;
              break;
            default:
              error(2,argv[i]);  /* unrecognized option */
              break;
          }
          break;

        case 'F':  /* read a file with object file names */
          if (buf = get_option_arg(argc,argv,&i))
            ReadListFile(gv,buf,flags);
          break;

        case 'L':  /* new library search path */
          if (buf = get_option_arg(argc,argv,&i)) {
            libp = alloc(sizeof(struct LibPath));
            libp->path = buf;
            addtail(&gv->libpaths,&libp->n);
          }
          break;

        case 'M':  /* mapping output */
          gv->map_file = stdout;
          break;

        case 'P':  /* protect symbol against stripping */
          if (buf = get_option_arg(argc,argv,&i))
            add_symnames(&gv->prot_syms,buf);
          break;

        case 'R':  /* use short form for relocations */
          if (buf = get_option_arg(argc,argv,&i)) {
            if (!strcmp(buf,"std"))
              gv->reloctab_format = RTAB_STANDARD;
            else if (!strcmp(buf,"add"))
              gv->reloctab_format = RTAB_ADDEND;
            else if (!strcmp(buf,"short"))
              gv->reloctab_format = RTAB_SHORTOFF;
            else
              error(123,buf);  /* unknown reloc table format ignored */
          }
          break;

        case 'S':  /* strip debugger symbols */
          gv->strip_symbols = STRIP_DEBUG;
          break;

        case 'T':  /* read linker script file or set text address */
          if (!strcmp(&argv[i][2],"text")) {
            if (i+1 < argc)
              sscanf(argv[++i],"%lli",&gv->start_addr);
            else
              error(5,'T');  /* option requires argument */
          }
          else if (buf = get_option_arg(argc,argv,&i)) {
            if (gv->ldscript = mapfile(buf))
              gv->scriptname = buf;
            else
              error(8,buf);
          }
          break;

        case 'V':  /* set minimum version for next shared object */
          if (buf = get_option_arg(argc,argv,&i))
            so_version = atoi(buf);
          break;

        case 'X':  /* discard temporary local symbols only */
          gv->discard_local = DISLOC_TMP;
          break;

        case 'Z':  /* keep trailing zero-bytes at end of section */
          gv->keep_trailing_zeros = TRUE;
          break;

        default:
          error(2,argv[i]);  /* unrecognized option */
          break;
      }
    }

    else {  /* normal input file name */
      ifn = alloc(sizeof(struct InputFile));
      ifn->name = argv[i];
      ifn->lib = FALSE;
      ifn->flags = flags;
      addtail(&gv->inputlist,&ifn->n);
    }
  }

  /* add default library search path at the end of the list */
  if (stdlib) {
#ifdef LIBPATH
    libp = alloc(sizeof(struct LibPath));
    libp->path = LIBPATH;  /* default search path */
    addtail(&gv->libpaths,&libp->n);
#endif
  }

  /* allocate flavour path buffer and sort flavours */
  gv->flavours.flavour_dir = alloc(gv->flavours.flavours_len + 1);
  if (gv->flavours.n_flavours > 1) {
    qsort((void *)gv->flavours.flavours, gv->flavours.n_flavours,
          sizeof(char **), flavours_cmp);
  }

  /* link them... */
  linker_init(gv);
  linker_load(gv);     /* load all objects and libraries and their symbols */
  linker_resolve(gv);  /* resolve symbol references */
  linker_relrefs(gv);  /* find all relative references between sections */
  linker_dynprep(gv);  /* prepare for dynamic linking */
  linker_sectrefs(gv); /* find all referenced sections from the start */
  linker_gcsects(gv);  /* section garbage collection (gc_sects) */
  linker_join(gv);     /* join sections with same name and type */
  linker_mapfile(gv);  /* mapfile output */
  linker_copy(gv);     /* copy section contents and fix symbol offsets */
  linker_delunused(gv);/* delete empty/unused sects. without relocs/symbols */
  linker_relocate(gv); /* relocate addresses in joined sections */
  linker_write(gv);    /* write output file in selected target format */
  linker_cleanup(gv);

  cleanup(gv);
  return 0;
}
예제 #29
0
파일: cli.c 프로젝트: 0x0mar/netsniff-ng
// Read in configuration file
int cli_read_cfg(char *str)
{
	char filename[256];
	char line[256];
	char path[256];
	char *ampfile;
	char dev[256];
	FILE *fd;
	int i, j=0, len, found=0, nonspc=0;
	int user=0, pass=0, ena=0, amp=0, mgmt_only=0, cli=0, port=0, addr=0;
	
	strncpy(filename, str, 255);
	 
	if (getfullpath_cfg(filename)) return 1;

	if (verbose) {
		fprintf(stderr, "Opening config file %s...\n", filename);
	}
	
	fd = fopen (filename, "r");
	if (fd==NULL) return 1;
	
	while (fgets(line, 255, fd) != NULL) {
		len=strnlen(line, 255);
		// Take string left side of # (comments)
		if (len) for(i=0;i<len;i++) if (line[i]=='#') line[i]='\0'; // cut off
		len=strnlen(line, 255); 
		if (len) for(i=0;i<len;i++) if (!isspace(line[i])) nonspc++;
		if (nonspc==0) continue; else nonspc=0;
		if (!user) user = sscanf(line, " user = %s ", mz_username);
		if (!pass) pass = sscanf(line, " password = %s ", mz_password);
		if (!ena)  ena  = sscanf(line, " enable = %s ", mz_enable);
		if (!port) port = sscanf(line, " port = %i ", &mz_port);
		if (!addr) addr = sscanf(line, " listen-addr = %s ", mz_listen_addr);
		if (!cli)  cli  = sscanf(line, " cli-device = %s ", dev);
		if (cli==1) {
			for (i=0; i<device_list_entries; i++) {
				if (strncmp(device_list[i].dev, dev, 16)==0) {
					device_list[i].cli=1;
					found=1;
					break;
				}
			}
			if (!found) { 
				fprintf(stderr, " Warning: [%s] cli device '%s' does not exist!\n", filename, dev);
			 	cli=0; // try again
			}
			found=0;
			cli=0;
		}
		
		if (!mgmt_only) mgmt_only  = sscanf(line, " management-only  = %s ", dev);
		if (mgmt_only==1) {
			for (i=0; i<device_list_entries; i++) {
				if (strncmp(device_list[i].dev, dev, 16)==0) {
					device_list[i].mgmt_only=1;
					found=1;
					break;
				}
			}
			if (!found) fprintf(stderr, " Warning: [%s] management device '%s' does not exist!\n", filename, dev);
			mgmt_only=0;
			found=0;
		}
		
		if (AUTOMOPS_ENABLED) {
			// read-in all protocol definitions
			amp = sscanf(line, " automops = %s ", path);
			if (amp) {
				ampfile = mapfile(path);
				if (ampfile==NULL) fprintf(stderr, " Warning: Cannot read %s\n", path);
				else {
					j = 0;
					j = parse_protocol (ampfile);
					if (j) {
						if (verbose) {
							fprintf(stderr, "  Warning: invalid protocol definitions in %s\n", path);
						}
					}
					free(ampfile);
					amp=0;
				}
			}
		}
	}
	fclose(fd);

	if (verbose) {
		if (user!=1)
			fprintf(stderr, "%s: No user name specified - will use default.\n", filename);
		
		if (pass!=1) 
			fprintf(stderr, "%s: No password specified - will use default.\n", filename);
		
		if (ena!=1) 
			fprintf(stderr, "%s: No enable password specified - will use default.\n", filename);

		if (port!=1)
			fprintf(stderr, "%s: No port specified - will use default.\n", filename);

		if (addr!=1)
			fprintf(stderr, "%s: No listen address specified - will use default.\n", filename);
	}
	
	cli_debug = 0;
	return 0;
}
예제 #30
0
int main (int argc, char** argv) {
	if (argc < 3) {
		printf("Usage: sudo ./fsender filepath source dest1 dest2\n");
		exit(1);
	}
	int src, dest1, dest2;
	pcap_if_t *device_list = NULL;		// Linked list of all devices discovered
	pcap_if_t *device_ptr = NULL;		// Pointer to a single device
	//pcap_t *handle_sniffed = NULL;

	char err[128];						// Holds the error
	char *device_name = NULL;
	char devices[10][64];				// For holding all available
	int count = 0;
	int ret = 0;
	int n = 0;

	srand(time(NULL));

	printf("Scanning available devices ... ");
	if ( (ret = pcap_findalldevs(&device_list, err)) != 0 ) {
		fprintf(stderr, "Error scanning devices, with error code %d, and error message %s\n", ret, err);
		exit(1);
	}
	printf("DONE\n");

	printf("Here are the available devices:\n");
	for (device_ptr = device_list; device_ptr != NULL; device_ptr = device_ptr->next) {
		printf("%d. %s\t-\t%s\n", count, device_ptr->name, device_ptr->description);
		if (device_ptr->name != NULL) {
			strcpy(devices[count], device_ptr->name);
		}
		count++;
	}

	printf("Which device do you want to sniff? Enter the number:\n");
	scanf("%d", &n);
	device_name = devices[n];

	printf("Trying to open device %s to send ... ", device_name);
	if ( (handle_sniffed = pcap_open_live(device_name, BUFSIZ, 1, 100, err)) == NULL ) {
		fprintf(stderr, "Error opening device %s, with error message %s\n", device_name, err);
		exit(1);
	}
	printf( "DONE\n");


    //	unsigned char key_p[4];
//    key_p[0] = 0x33; key_p[1] = 0x13; key_p[2]= 0x3f; key_p[3] = 0xe4;
//	initDes(key_p, &schedule_p);

    u_char payload[PAYLOAD_SIZE];
    char node_name[8];
    int payload_size;
    long offset = 0;
    mapfile(argv[1]);

    switch(atoi(argv[2])){
    case 1:
        src = NODE1_RTR1;
        strcpy(node_name, "node1");
//        key_h[0] = 0x99; key_h[1] = 0xa1; key_h[2]= 0x10; key_h[3] = 0x7b;
//        key_h[4] = 0xeb; key_h[5] = 0x17; key_h[6]= 0x6a; key_h[7] = 0x2a;
        break;
    case 2:
        src = NODE2_RTR1;
        strcpy(node_name, "node2");
//        key_h[0] = 0x13; key_h[1] = 0x33; key_h[2]= 0xe4; key_h[3] = 0x3f;
//        key_h[4] = 0x13; key_h[5] = 0x33; key_h[6]= 0xe4; key_h[7] = 0x3f;
        break;
    case 3:
        src = NODE3_RTR1;
        strcpy(node_name, "node3");
//        key_h[0] = 0xe4; key_h[1] = 0x3f; key_h[2]= 0x13; key_h[3] = 0x33;
//        key_h[4] = 0xe4; key_h[5] = 0x3f; key_h[6]= 0x13; key_h[7] = 0x33;
        break;
    default:
        break;
    }

    switch(atoi(argv[3])){
    case 1:
        dest1 = NODE1_RTR1;
        break;
    case 2:
        dest1 = NODE2_RTR1;
        break;
    case 3:
        dest1 = NODE3_RTR1;
        break;
    default:
        break;
    }

    switch(atoi(argv[4])){
    case 1:
        dest2 = NODE1_RTR1;
        break;
    case 2:
        dest2 = NODE2_RTR1;
        break;
    case 3:
        dest2 = NODE3_RTR1;
        break;
    default:
        break;
    }

    //printKey(key_h, 8);
    if((ret = initDes(node_name, &schedule_h)) < 0){
        printf("Failed with %d \n", ret);
        }

    //printKey(&schedule_h, 8);
//    fp_read = fopen(argv[1], "r");
//    if(fp_read == NULL){
//        fprintf(stderr, "File open failed");
//        exit(1);
//    }
//    fseek(fp_read, 0L, SEEK_END);
//    filesize = ftell(fp_read);
    if((filesize % PAYLOAD_SIZE) != 0)
        no_of_packets = (filesize/PAYLOAD_SIZE) + 1;
    else
        no_of_packets = (filesize/PAYLOAD_SIZE);

    //initialize keys

    int seqNum = 0; int i;

    char str[20];
    fprintf(stdout, "Please enter Y/y to start \n");
    scanf("%s", &str);

    if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { perror( "clock gettime" );}
    printTime();
    printf("Sending ... \n");
    for(i = 0; i < 1; i++){
        seqNum = 0;
        offset = 0;
        while (seqNum < no_of_packets) {
            //printf("Seq : %d\n", seqNum);
            //fseek(fp_read, offset, SEEK_SET);
            if((seqNum == (no_of_packets-1)) && ((filesize % PAYLOAD_SIZE) != 0))
                payload_size = filesize % PAYLOAD_SIZE;
            else
                payload_size = PAYLOAD_SIZE;
            memcpy(payload, data + offset, payload_size);
            //fread(payload, 1, payload_size, fp_read);
            offset = offset + payload_size;
            // send to 1 destination
            send_file_packet(payload, payload_size, src, dest1, 11, seqNum);
            usleep(200);
            // send to 2nd destination
            send_file_packet(payload, payload_size, src, dest2, 12, seqNum);
            usleep(100);
            seqNum++;
        }
    }
    printf("\n");
    //pthread_join(resend_thread, NULL);
    pcap_close(handle_sniffed);
    //pcap_close(handle_sniffed_nack);
    munmap(data, filesize);
    close(fp);
    printf( "ALL DONE\n");
    return 1;
}