예제 #1
0
파일: predict.c 프로젝트: abedzadeh/gstat
static DPOINT *next_location(DPOINT *loc, PRED_AT what, int random_path,
		unsigned int *row, unsigned int *col, DATA **data) {

	double xc, yc;
	static unsigned int nr = 0;

	switch (what) {
		case AT_POINTS:
			if (DEBUG_TRACE) {
				nr++;
				printlog("\rbusy with loc: %3u", nr);
			}
			return get_point_location(random_path);
		case AT_GRIDMAP:
			if (get_map_location(loc, random_path, row, col)) {
				if (loc->u.stratum >= 0) { /* i.e., non-missing valued cell */
					if (DEBUG_TRACE)
						printlog("\rbusy with row: %3u col: %3u loc: %3u",
							*row + 1, *col + 1, nr + 1);
					map_rowcol2xy(masks[0], *row, *col, &xc, &yc);
					loc->x = xc;
					loc->y = yc;
					if (!is_mv_double(&gl_zmap))
						loc->z = gl_zmap;
					else
						loc->z = 0.0;
					loc->X = get_maskX(data, loc, *row, *col);
					nr++;
				}
				return loc;
			} 
			break;
	}
	return NULL;
} /* next_location() */ 
예제 #2
0
파일: irc.c 프로젝트: rdgout/ircbot
int irc_connect(char *hostname, int port) {
    struct sockaddr_in  saddr;
    struct in_addr     *peer;
    struct hostent     *hent;
    
    printlog("Attempting to connect to %s:%d", hostname, port);

    if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
        printlog("Failed to open socket.");
        exit(1);
    }

    if (!(hent = gethostbyname(hostname))) {
        printlog("Failed to resolve hostname.");
        return 0;
    }

    saddr.sin_family = PF_INET;
    saddr.sin_port = htons(port);

    peer = (struct in_addr *)hent->h_addr_list[0];

    saddr.sin_addr.s_addr = peer->s_addr;

    if (connect(sock, (struct sockaddr*)&saddr, sizeof(saddr)) == -1) {
        printlog("Failed to connect to %s:%d.", inet_ntoa(saddr.sin_addr), port);
        return 0;
    }

    return 1;
}
예제 #3
0
static int
try_receive_packet(unsigned char* buf, size_t len)
{
	struct net_header *nh = (struct net_header *)buf;

	if (nh->version != PROTO_VERSION) {
		printlog("ERROR: protocol version %x", nh->version);
		return 0;
	}

	switch (nh->type) {
	case PROTO_PKT_INFO:
		len = net_receive_packet(buf, len);
		break;
	case PROTO_CHAN_LIST:
		len = net_receive_chan_list(buf, len);
		break;
	case PROTO_CONF_CHAN:
		len = net_receive_conf_chan(buf, len);
		break;
	case PROTO_CONF_FILTER:
		len = net_receive_conf_filter(buf, len);
		break;
	default:
		printlog("ERROR: unknown net packet type");
		len = 0;
	}

	return len; /* the number of bytes we have consumed */
}
예제 #4
0
void* wait_thread(void* args)
{
	int status;

	while(running_flag) {
		//Start server
		pthread_mutex_lock(&fd_mutex);
		server_pid = run_server();

		if(server_pid == -1) {
			pthread_mutex_unlock(&fd_mutex);
			printlog(LOG_SERVER, "Failed to run server!\n");
			continue;
		}

		pthread_mutex_unlock(&fd_mutex);
		printlog(LOG_SERVER, "Server started.\n");

		//Wait
		waitpid(server_pid, &status, 0);
	}

	UNREFERRED_PARAMETER(args);
	return NULL;
}
예제 #5
0
파일: hdapsd.c 프로젝트: t-8ch/hdapsd
/*
 * write_protect() - park/unpark
 */
static int write_protect (const char *path, int val)
{
	int fd, ret;
	char buf[BUF_LEN];

	if (dry_run)
		return 0;

	snprintf(buf, sizeof(buf), "%d", val);

	fd = open (path, O_WRONLY);
	if (fd < 0) {
		printlog (stderr, "Could not open %s", path);
		return fd;
	}	

	ret = write (fd, buf, strlen(buf));

	if (ret < 0) {
		printlog (stderr, "Could not write to %s.\nDoes your kernel/drive support IDLE_IMMEDIATE with UNLOAD?", path);
		goto out;
	}
	ret = 0;

out:
	if (close (fd))
		printlog (stderr, "Could not close %s", path);

	return ret;
}
예제 #6
0
//destroys an object
Object::~Object()
{
	//lets just hope the given pointer is ok...
	printlog(1, "freeing Object");

	//1: remove it from the list
	if (prev == NULL) //first link
	{
		printlog(2, "(object is head)");
		head = next;
	}
	else
		prev->next = next;

	if (next) //not last link
		next->prev = prev;
	else
		printlog(2, "(object is last)");


	//remove components
	while (components)
		delete components; //just removes the one in top each time

	//make sure no events for this object is left
	Object_Event_List::Remove(this);
}
예제 #7
0
파일: nsearch.c 프로젝트: BenGraeler/gstat
static void logprint_qtree(QTREE_NODE *node, int depth) {
	BBOX b;
	int i;

	if (node == NULL)
		return;
	b = node->bb;
	if (!is_leaf(node)) {
		printlog("newline linethickness 0.3 pts %g %g %g %g %g %g %g %g %g %g\n",
			b.x, b.y, b.x+b.size, b.y, b.x+b.size,
			b.y+b.size, b.x, b.y+b.size, b.x, b.y);
		for (i = 0; i < N_NODES(node); i++)
			logprint_qtree(node->u.node[i], depth+1);
	} else {
		printlog("newline pts %g %g %g %g %g %g %g %g %g %g\n",
			b.x, b.y, b.x+b.size, b.y, b.x+b.size,
			b.y+b.size, b.x, b.y+b.size, b.x, b.y);
		/*
		if (node == NULL)
			printlog("newcurve marktype circle fill 1 pts %g %g\n",
				b.x+0.5*b.size, b.y+0.5*b.size);
		*/
		if (node->n_node > 0) {
			printlog("newcurve marktype cross pts");
			for (i = 0; i < node->n_node; i++)
				printlog(" %g %g",	node->u.list[i]->x, node->u.list[i]->y);
			printlog("\n");
		}
	}
}
예제 #8
0
파일: telnet.c 프로젝트: aissat/vde2
void telnet_init(int vdefd)
{
	int sockfd;
	struct sockaddr_in  serv_addr;
	vdehist_termread=lwip_read;
	vdehist_termwrite=lwip_write;
	vdehist_logincmd=telnet_logincmd;
	sockfd=lwip_socket(AF_INET, SOCK_STREAM, 0);

	if (!sockfd) {
		printlog(LOG_ERR,"telnet socket err: %s",strerror(errno));
	}

	bzero((char *) &serv_addr, sizeof(serv_addr));
	serv_addr.sin_family      = AF_INET;
	serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	serv_addr.sin_port        = htons(TELNET_TCP_PORT);

	if (lwip_bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printlog(LOG_ERR,"telnet bind err: %s",strerror(errno));
	}

	lwip_listen(sockfd, 5);

	addpfd(sockfd,telnetaccept);
}
예제 #9
0
void alchemyalmostoff(ALCHEMY_LIST list_)
{	
	switch(list_)
	{
	case ALCT_NONE:
	default:
		break;
	case ALCT_STONE_FIST:		
		break;
	case ALCT_DIAMOND_HARDNESS:
		break;
	case ALCT_POISON_BODY:
		break;
	case ALCT_HASTE:
		if(you.s_haste < 10)
			printlog("속도가 돌아오고 있다.",false,false,false,CL_blue);
		break;
	case ALCT_STONE_FORM:
		printlog("무념무상의 경지가 끝나간다.",false,false,false,CL_blue);
		break;
	case ALCT_AUTUMN_BLADE:
		printlog("손에 감긴 연금술의 힘이 약해지고있다.",false,false,false,CL_blue);
		break;
	case ALCT_PHILOSOPHERS_STONE:
		printlog("현자의 돌은 거의 사라져가고있다.",false,false,false,CL_blue);
		break;
	}
}
예제 #10
0
파일: hdapsd.c 프로젝트: zdzichu/hdapsd
/*
 * autodetect_devices()
 */
int autodetect_devices ()
{
	int num_devices = 0;
	DIR *dp;
	struct dirent *ep;
	dp = opendir(SYSFS_BLOCK);
	if (dp != NULL) {
		while ((ep = readdir(dp))) {
			char path[FILENAME_MAX];
			char removable[FILENAME_MAX];
			char rotational[FILENAME_MAX];
			snprintf(removable, sizeof(removable), REMOVABLE_FMT, ep->d_name);
			snprintf(rotational, sizeof(rotational), ROTATIONAL_FMT, ep->d_name);

			if (kernel_interface == UNLOAD_HEADS)
				snprintf(path, sizeof(path), UNLOAD_HEADS_FMT, ep->d_name);
			else
				snprintf(path, sizeof(path), QUEUE_PROTECT_FMT, ep->d_name);

			if (access(path, F_OK) == 0 && read_int(removable) == 0 && read_int(path) >= 0) {
				if (read_int(rotational) == 1 || forcerotational) {
					printlog(stdout, "Adding autodetected device: %s", ep->d_name);
					add_disk(ep->d_name);
					num_devices++;
				}
				else {
					printlog(stdout, "Not adding autodetected device \"%s\", it seems not to be a rotational drive.", ep->d_name);
				}
			}
		}
		(void)closedir(dp);
	}
	return num_devices;
}
uint16_t insert_hash(uint16_t chunk_length, uint16_t *packed_upto,
        unsigned char *payload,
        uint16_t last_marker,
        bool *dedup_flag,
        time_t current_timestamp) {
    uint16_t local_packed_upto = (*packed_upto);
    uint32_t left = 0, right = 0;
    hashlittle2((void*)(payload + last_marker), chunk_length, &right, &left);
    printlog(logfile, system_loglevel, LOG_DEBUG, "Hashing chunk"
            " from %d to %d\n", local_packed_upto, local_packed_upto +
            chunk_length);
    uint64_t hash_value = right + (((uint64_t)left)<<32);
    uint16_t advance_by = 0;
    if(regular_cache.find(hash_value) != regular_cache.end()) {
        printlog(logfile, system_loglevel, LOG_DEBUG, "Putting regular hash %llx for chunk length  %d\n", hash_value, chunk_length);
        advance_by += pack_hash_value(new_packet + local_packed_upto, left, right);
        *dedup_flag = true;
        printlog(logfile, system_loglevel, LOG_DEBUG, "Normal hit: "
                "%.llx\n", (unsigned long long)hash_value);
    } else if (feedback_cache.find(hash_value) !=
            feedback_cache.end()) {
        printlog(logfile, system_loglevel, LOG_DEBUG, "Putting feedback hash %llx for chunk length  %d\n", hash_value, chunk_length);
        advance_by += pack_hash_value(new_packet + local_packed_upto, left, right);
        *dedup_flag = true;
        printlog(logfile, system_loglevel, LOG_DEBUG, "Advert hit\
                %.llx\n", (unsigned long long)hash_value);
        feedback_cache.erase(hash_value);
    } else {
예제 #12
0
/************************* main *******************************/
int main() {
    new_packet = (unsigned char *)malloc(MTU);
    if(new_packet == NULL) {
        printf("Malloc failed\n");
        exit(EXIT_FAILURE);
    }

    struct nfq_handle *h = get_handle();
    fd_set rfds;

    // start the downstream code, later move to a thread
    initializeRabin(powers);
    int max_fd = 0;
    int down_fd = createQueue(h, DOWN_MOBILE_QUEUE, &cbDown);
    if(down_fd > max_fd)
        max_fd = down_fd;
    int up_fd = createQueue(h, UP_MOBILE_QUEUE, &cbUp);
    if(up_fd > max_fd)
        max_fd = up_fd;

    printlog(logfile, system_loglevel, LOG_DEBUG, 
            "Queue packet descriptors, down_fd: %d, up_fd: %d\n",
            down_fd, up_fd);

    int n = 0, rv = 0;
    char buf[4096] __attribute__ ((aligned));
    nfnl_rcvbufsiz(nfq_nfnlh(h), 4096 * 4096);
    while(true) {
        FD_ZERO(&rfds);
        FD_SET(down_fd, &rfds);
        FD_SET(up_fd, &rfds);
        n = select(max_fd + 1, &rfds, NULL, NULL, NULL);
        if(n == -1) {
            printlog(logfile, system_loglevel, LOG_CRITICAL, 
                    "Select returned error: %s\n", strerror(errno));
        } 
        if(FD_ISSET(down_fd, &rfds)) {
            rv = recv(down_fd, buf, sizeof(buf), 0);
            if(rv < 0) {
                printlog(logfile, system_loglevel, LOG_CRITICAL, 
                        "recv call failed: %s\n", strerror(errno));
            } else {
                nfq_handle_packet(h, buf, rv);
            }
        } 
        if(FD_ISSET(up_fd, &rfds)) {
            rv = recv(up_fd, buf, sizeof(buf), 0);
            if(rv < 0) {
                printlog(logfile, system_loglevel, LOG_CRITICAL, 
                        "recv call failed: %s\n", strerror(errno));
            } else {
                nfq_handle_packet(h, buf, rv);
            }
        }
    }

    // start the upstream code, later move to a thread
    return 0;
}
예제 #13
0
unsigned long openvme(void *vmeaddr,size_t vme_len, bool verbose)
{
  printlog("opening device", true, verbose);

  //** Fill the upper 3 bits
  //    const int vme_regA32_fd = open("/dev/mem", O_RDWR);
  int vme_regA32_fd = open("/dev/mem", O_RDWR);
  if( vme_regA32_fd == -1 ) {
    printf("error: open #1 /dev/mem failed, exiting ...\n");
    exit(-1);
  }

  // ... and map the part starting at offset 0xaa000000 to memory (with
  // VME seg.size as minimal size, even if it's only one register to access).
  //
  // definition:
  // void * mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
  // See: http://www.freebsd.org/cgi/man.cgi?query=mmap
  volatile void *const reg_A32_mmap
  = mmap(NULL, VME_SegSize, (PROT_READ | PROT_WRITE), MAP_SHARED, vme_regA32_fd, 0xaa000000);

  if( reg_A32_mmap == MAP_FAILED ) {
    printf("error: mmap #1 failed, exiting ...\n");
    exit(-1);
  }

  // Now write the upper three bits of the hardware base address into
  // this special register.
  unsigned long NewAddr, UpperAddr, LowerAddr;
  NewAddr = (unsigned long)vmeaddr;
  UpperAddr = NewAddr & 0xe0000000;
  LowerAddr= NewAddr & 0x1fffffff;
  *((unsigned long *)reg_A32_mmap) = UpperAddr ;

  //** Fill the upper 3 bits End




  vme_fd = open("/dev/mem", O_RDWR);
  if( vme_fd == -1 ) {
    printlog("Error opening vme device, aborting", true, verbose);
    closeLog(verbose);
    exit(1);
  }
  //  vmevirtbase  = mmap(NULL, VME_LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, vme_fd, 0x10000000 | VMEBUSPC_EXTOFFSET); //(off_t) vmeaddr
  //  vmevirtbase  = mmap(NULL, VME_LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, vme_fd, ((unsigned long) vmeaddr) | VMEBUSPC_EXTOFFSET); //(off_t) vmeaddr
  vmevirtbase  = mmap(NULL, VME_LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, vme_fd, LowerAddr | VMEBUSPC_EXTOFFSET); //(off_t) vmeaddr
  if (vmevirtbase==MAP_FAILED) {
    printlog("memory mapping failed, aborting", true, verbose);
    closeLog(verbose);
    exit(1);
  }
  printlog("vme virtual base is located at: ", true, verbose);
  printlogInt((unsigned long) vmevirtbase, verbose);
  printlog("device open", true, verbose);
  return (unsigned long) vmevirtbase;
}
예제 #14
0
파일: data.c 프로젝트: BenGraeler/gstat
DATA *get_area_centre(DATA *area, DATA *d) {
	int i, j;
	DPOINT p;

	d->n_list = d->n_max = 0; 
	d->variable = area->variable;
	d->x_coord = area->x_coord;
	d->y_coord = area->y_coord;
	d->z_coord = area->z_coord;
	d->type = data_types[area->type.type];
	d->fname = "";

	p.x = p.y = p.z = 0.0;
	p.u.stratum = 0;
	d->n_X = area->n_X;
	if (area->n_X > 0) {
		p.X = (double *) emalloc(area->n_X * sizeof(double));
		d->colX = (int *) emalloc(area->n_X * sizeof(int));
		for (j = 0; j < area->n_X; j++) {
			p.X[j] = 0.0;
			d->colX[j] = area->colX[j];
		}
	} else {
		p.X = NULL;
		d->colX = NULL;
	}
	for (i = 0; i < area->n_list; i++) {
		p.x += area->list[i]->x;
		p.y += area->list[i]->y;
		p.z += area->list[i]->z;
		for (j = 0; j < area->n_X; j++)
			p.X[j] += area->list[i]->X[j]; 
	}
	p.x /= area->n_list;
	p.y /= area->n_list;
	p.z /= area->n_list;
	for (j = 0; j < area->n_X; j++)
		p.X[j] /= area->n_list;
	p.attr = 0.0;

	printlog("prediction centre at x=%g, y=%g, z=%g",p.x,p.y,p.z);
	if (d->n_X) {
		printlog(" where x0 averages [");
		for (j = 0; j < area->n_X; j++)
			printlog("%g%s", p.X[j], j<area->n_X-1?",":"");
		printlog("]\n");
	} else
		printlog("\n");
	push_point(d, &p);
	d->minX = d->maxX = p.x;
	d->minY = d->maxY = p.y;
	d->minZ = d->maxZ = p.z;
	d->mode = area->mode;
	d->n_X = area->n_X;
	calc_data_mean_std(d);
	return d;
}
예제 #15
0
void  Singledata::save(vector<string> liBigEntries)
{

     printlog( "Save Data = " ,ID ) ;
     readEntries();
     printlog( "Save Data = ", ID ) ;
     saveValues();

}
예제 #16
0
void Singledata::loadEntryField(string sName)
{

     printlog(".....................................loadEntry..............................................");
     
     setOfEntries _entries = glx.loadEntries(sName);
     setDicEntries(_entries);
     printlog(".....................................End loadEntry..............................................");

}
예제 #17
0
파일: main.c 프로젝트: spontificus/rcx
//if something goes wrong (after initing physics and graphics)
void emergency_quit (void)
{
	printlog(0, "ERROR REQUIRES GAME TO STOP:\n");
	free_all();
	graphics_quit();
	physics_quit();

	exit (-1);
	printlog(0, "WTF?!\n");
}
예제 #18
0
void Singledata::fillEntries(int i)
{
     load(i);
     printlog("fill Entries for " + toString(i) );
     clearAllFields();
     Gtk::TreeIter _newIter ;
     iter = _newIter ;

     typedef map<string,dataEntry>::const_iterator iM ;
     dataEntries = oEntries.Entries;

     for(iM i = dataEntries.begin(); i != dataEntries.end(); i++) {
          _entry = i->second ;
          printlog( "_entry " +  _entry.get_nameOfEntry() + " verify_type = " + _entry.get_verifyTypeOfEntry() +" type = " + _entry.get_typeOfEntry() ) ;
          // cout << "entry Value = " <<  firstRecord.row_string[_entry.get_nameOfSql()] << endl ;
          if(_entry.get_verifyTypeOfEntry() == "string") {
               string _Value = firstRecord.row_string[_entry.get_nameOfSql()];

               if(_Value == "NONE") _Value = "";
               //cout << "stringValue = " << _Value << endl ;
               glx.setText(_entry,_Value);

          }
         
          else if (_entry.get_verifyTypeOfEntry() == "int") {
               int _Value = firstRecord.row_int[_entry.get_nameOfSql()];
               //cout << "intValue = " << _Value << endl ;
              
               
                    glx.setText(_entry,_Value);
               
          }
          else if (_entry.get_verifyTypeOfEntry() == "float") {
               float _Value = firstRecord.row_float[_entry.get_nameOfSql()];
               //cout << "floatValue = " << _Value << endl ;
              
               
               glx.setText(_entry,toString(_Value) );
               
          }
          else if (_entry.get_verifyTypeOfEntry() == "datetime") {
               string _Value = firstRecord.row_string[_entry.get_nameOfSql()];
               //cout << "datetime Value = " << _Value << endl ;
              
               
                    glx.setText(_entry,_Value);
               
          }


     }
     // printlog("now fill other and extra entries");
     fillOtherEntries();
     fillExtraEntries();
}
예제 #19
0
파일: nsearch.c 프로젝트: BenGraeler/gstat
void qtree_print(DATA *d) {
/*
 * plot the full tree (2D), in a format that can be read by jgraph, found
 * at netlib or at http://kenner.cs.utk.edu/~plank/plank/jgraph/jgraph.html
 */
	printlog("newgraph\nxaxis size 3\nyaxis size 3\n");
	printlog("title : %s [n = %d]\n",
		name_identifier(d->id), d->n_list);
	logprint_qtree(d->qtree_root, 0);
	return;
}
예제 #20
0
void discard(list<item>::iterator it, int number)
{
	item *temp2 = env[current_level].AddItem(you.position,&(*it),number);	
	temp2->drop = true;
	printlog("당신은 ",false,false,false,CL_normal);					
	printlog(temp2->GetName(number),false,false,false,temp2->item_color());				
	printlog(temp2->GetNameInfor().name_to(true),false,false,false,CL_normal);					
	printlog("내려놓았다.",true,false,false,CL_normal);	
	you.DeleteItem(it,number);
	changedisplay(DT_GAME);
	you.time_delay+=you.GetNormalDelay();
	you.TurnEnd();
}
예제 #21
0
string SingleContact::getAddress(int _id)
{
     string s1 = "";


     x1.callRP("Address.getAddressField",x1.add(_id), s1);
     printlog ("load Addressfield = " );

     printlog("load Addressfield = " , s1);



     return s1;
}
예제 #22
0
void Equip_Weapon()
{
	if(you.s_lunatic)
	{
		printlog("광기에 휩싸인 상태로 무기를 바꿀 수 없다!",true,false,false,CL_danger);
		return;
	}

	view_item(IVT_EQ_WEAPON,"무슨 무기를 장착하시겠습니까?");
	while(1)
	{
		int key_ = waitkeyinput();
		if( (key_ >= 'a' && key_ <= 'z') || (key_ >= 'A' && key_ <= 'Z') )
		{
			changedisplay(DT_GAME);
			you.equip(key_,ET_WEAPON);
			break;
		}
		else if(key_ == VK_DOWN)//-----이동키-------
		{
			changemove(32);  //위
		}
		else if(key_ == VK_UP)
		{
			changemove(-32); //아래
		}
		else if(key_ == VK_PRIOR)
		{
			changemove(-WindowHeight);
		}
		else if(key_ == VK_NEXT)
		{
			changemove(WindowHeight);
		}						//-----이동키끝-------
		else if(key_ == '*')
			view_item(IVT_SELECT,"무슨 무기를 장착하시겠습니까?");
		else if(key_ == '-')
		{
			if(!you.unequip(ET_WEAPON))
			{				
				printlog("저주에 걸려 있어서 장비를 벗을 수 없다.",true,false,false,CL_normal);
			}
			break;
		}
		else if(key_ == VK_ESCAPE)
			break;
	}
	changedisplay(DT_GAME);

}
예제 #23
0
void TestCameraProjection( Vec3f p, CamExtr *extr, CamIntr *intr )
{
    printlog( "Testing projection of p = %f %f %f", p[0], p[1], p[2]);

    // transform from world frame to camera frame
    Vec3f cp = extr->Transform( p  );      

    printlog( "In camera frame: %f %f %f", cp[0], cp[1], cp[2]);

    // project onto the camera plane
    Vec2f pp = intr->ProjectToPixels( cp );

    printlog( "On camera plane: %f %f", pp[0], pp[1]);
}
예제 #24
0
void  Singledata::load(int _id)
{
     // liRecords, self.firstRecord,  self.ID = self.rpc.callRP('Database.loadData', self.sNameOfTable, record, self.dicInternetUser, dicDetail)
     if(_id>0){
          vector<Record> oResultSet ;
          x1.callRP("Database.loadOneData",x1.add(sNameOfTable, _id), oResultSet);
          printlog ("load new data id 0 = " + toString(_id) );
          firstRecord = oResultSet.at(0);
          ID = firstRecord.row_int["id"];
          printlog("load new data id = " ,ID );
     }
     

}
예제 #25
0
파일: network.c 프로젝트: cvelazquez/horst
int
net_open_client_socket(char* serveraddr, int rport)
{
	struct addrinfo saddr;
	struct addrinfo *result, *rp;
	char rport_str[20];
	int ret;

	snprintf(rport_str, 20, "%d", rport);

	printlog("Connecting to server %s port %s", serveraddr, rport_str);

	/* Obtain address(es) matching host/port */
	memset(&saddr, 0, sizeof(struct addrinfo));
	saddr.ai_family = AF_INET;
	saddr.ai_socktype = SOCK_STREAM;
	saddr.ai_flags = 0;
	saddr.ai_protocol = 0;

	ret = getaddrinfo(serveraddr, rport_str, &saddr, &result);
	if (ret != 0) {
		fprintf(stderr, "Could not resolve: %s\n", gai_strerror(ret));
		exit(EXIT_FAILURE);
	}

	/* getaddrinfo() returns a list of address structures.
	 * Try each address until we successfully connect. */
	for (rp = result; rp != NULL; rp = rp->ai_next) {
		netmon_fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
		if (netmon_fd == -1)
			continue;

		if (connect(netmon_fd, rp->ai_addr, rp->ai_addrlen) != -1)
			break; /* Success */

		close(netmon_fd);
	}

	if (rp == NULL) {
		/* No address succeeded */
		freeaddrinfo(result);
		err(1, "Could not connect");
	}

	freeaddrinfo(result);

	printlog("Connected to server %s", serveraddr);
	return netmon_fd;
}
예제 #26
0
static int wext_get_channels(int fd, const char* devname,
		      struct channel_list* channels)
{
	struct iwreq iwr;
	struct iw_range range;
	int i;
	int band0cnt = 0;
	int band1cnt = 0;

	memset(&iwr, 0, sizeof(iwr));
	memset(&range, 0, sizeof(range));

	strncpy(iwr.ifr_name, devname, IFNAMSIZ - 1);
	iwr.ifr_name[IFNAMSIZ - 1] = '\0';
	iwr.u.data.pointer = (caddr_t) &range;
	iwr.u.data.length = sizeof(range);
	iwr.u.data.flags = 0;

	if (ioctl(fd, SIOCGIWRANGE, &iwr) < 0) {
		printlog("ERROR: wext get channel list");
		return 0;
	}

	if (range.we_version_compiled < 16) {
		printlog("ERROR: wext version %d too old to get channels",
			 range.we_version_compiled);
		return 0;
	}

	for (i = 0; i < range.num_frequency && i < MAX_CHANNELS; i++) {
		DEBUG("  Channel %.2d: %dMHz\n", range.freq[i].i, range.freq[i].m);
		channels->chan[i].chan = range.freq[i].i;
		/* different drivers return different frequencies
		 * (e.g. ipw2200 vs mac80211) try to fix them up here */
		if (range.freq[i].m > 100000000)
			channels->chan[i].freq = range.freq[i].m / 100000;
		else
			channels->chan[i].freq = range.freq[i].m;
		if (channels->chan[i].freq <= 2500)
			band0cnt++;
		else
			band1cnt++;
	}
	channels->num_channels = i;
	channels->num_bands = band1cnt > 0 ? 2 : 1;
	channels->band[0].num_channels = band0cnt;
	channels->band[1].num_channels = band1cnt;
	return i;
}
예제 #27
0
uint16_t recreate_original_payload(unsigned char* payload, uint16_t payload_len, struct ip* ip_hdr) {
    /* new_packet is already initialized */
    assert(ip_hdr->ip_p == DEDUP_MIXED);
    memset(new_packet, 0, sizeof(unsigned char) * MTU);
    /* packet is mixed content */
    /* iterate over it, read every 2B header and hash/unhash accordingly*/
    uint16_t new_packed_upto = 0, unpacked_upto = 0, shim_header = 0, chunk_length=0;
    uint32_t hash_left = 0, hash_right = 0;
    uint64_t dedup_hash = 0;
    while(unpacked_upto < payload_len) {
        shim_header = ntohs(unpack_buffer(uint16_t, payload,
                    unpacked_upto));
        unpacked_upto += 2;
        if((shim_header & HASH_HDR) == HASH_HDR){
            hash_left = ntohl(unpack_buffer(uint32_t, payload,
                        unpacked_upto));
            unpacked_upto += 4;
            hash_right = ntohl(unpack_buffer(uint32_t, payload,
                        unpacked_upto));
            unpacked_upto += 4;
            dedup_hash = hash_right + (((uint64_t)hash_left)<<32);
            /* unhash this value */
            if(hash_memory.find(dedup_hash) == hash_memory.end()){
                printlog(logfile, system_loglevel, LOG_CRITICAL,
                        "** Hash not present: %llx\n", dedup_hash);
                continue;
            } else{
                printlog(logfile, system_loglevel, LOG_CRITICAL,
                        "** Hash hit: %llx\n", dedup_hash);
                memcpy(new_packet + new_packed_upto,
                        hash_memory[dedup_hash]->chunk,
                        hash_memory[dedup_hash]->chunk_length);
                new_packed_upto +=
                    hash_memory[dedup_hash]->chunk_length;
            }
        } else {
            /* it's a chunk in original text */
            /* calculated length from shim_header and read the chunk*/
            chunk_length = shim_header; 
            memcpy(new_packet + new_packed_upto, payload +
                    unpacked_upto, chunk_length);
            unpacked_upto += chunk_length;
            new_packed_upto += chunk_length;
        }
    }
    assert(unpacked_upto == payload_len);
    return new_packed_upto;
}
예제 #28
0
파일: channel.c 프로젝트: JiantaoFu/horst
/* Note: ht40plus is only used for HT40 channel width, to distinguish between
 * HT40+ and HT40- */
bool
channel_change(int idx, enum chan_width width, bool ht40plus)
{
	unsigned int center1 = 0;

	if (width == CHAN_WIDTH_UNSPEC)
		width = channel_get_band_from_idx(idx).max_chan_width;

	switch (width) {
		case CHAN_WIDTH_20_NOHT:
		case CHAN_WIDTH_20:
			break;
		case CHAN_WIDTH_40:
			center1 = get_center_freq_ht40(channels.chan[idx].freq, ht40plus);
			break;
		case CHAN_WIDTH_80:
		case CHAN_WIDTH_160:
			center1 = get_center_freq_vht(channels.chan[idx].freq, width);
			break;
		default:
			printlog("%s not implemented", channel_width_string(width, -1));
			break;
	}

	/* only 20 MHz channels don't need additional center freq, otherwise we fail here
	 * quietly because the scanning code sometimes tries invalid HT40+/- channels */
	if (center1 == 0 && !(width == CHAN_WIDTH_20_NOHT || width == CHAN_WIDTH_20))
		return false;

	if (!ifctrl_iwset_freq(conf.ifname, channels.chan[idx].freq, width, center1)) {
		printlog("ERROR: Failed to set CH %d (%d MHz) %s center %d",
			channels.chan[idx].chan, channels.chan[idx].freq,
			channel_width_string(width, ht40plus),
			center1);
		return false;
	}

	printlog("Set CH %d (%d MHz) %s center %d",
		channels.chan[idx].chan, channels.chan[idx].freq,
		channel_width_string(width, ht40plus),
		center1);

	conf.channel_idx = idx;
	conf.channel_width = width;
	conf.channel_ht40plus = ht40plus;
	last_channelchange = the_time;
	return true;
}
예제 #29
0
void PickUp()
{		
	if(you.s_lunatic)
	{
		printlog("광기에 휩싸인 상태로 무언가를 주울 수 없다!",true,false,false,CL_danger);
		return;
	}
	int num=0;
	list<item>::iterator it, first_it;
	for(it = env[current_level].item_list.begin();it != env[current_level].item_list.end();)
	{
		list<item>::iterator temp = it++;
		if((*temp).position.x == you.position.x && (*temp).position.y == you.position.y)
		{
			if(isPick(&(*temp)))
			{
				if(!num++)
					first_it = temp;
			}
		}
		else if(num)
			break;
	}
	if(num)
	{
		if(num==1)
			PickUpNum(first_it,1,false);
		else
			PickUpSelect(first_it,num);

	}
}
예제 #30
0
파일: network.c 프로젝트: ocakgun/horst
void
net_init_server_socket(char* rport)
{
	struct sockaddr_in sock_in;
	int reuse = 1;

	printlog("Initializing server port %s", rport);

	memset(&sock_in, 0, sizeof(struct sockaddr_in));
	sock_in.sin_family = AF_INET;
	sock_in.sin_addr.s_addr = htonl(INADDR_ANY);
	sock_in.sin_port = htons(atoi(rport));

	if ((srv_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
		err(1, "Could not open server socket");

	if (setsockopt(srv_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0)
		err(1, "setsockopt SO_REUSEADDR");

	if (bind(srv_fd, (struct sockaddr*)&sock_in, sizeof(sock_in)) < 0)
		err(1, "bind");

	if (listen(srv_fd, 0) < 0)
		err(1, "listen");
}