示例#1
0
double modify_test(OSyncEngine *engine, OSyncMember *member, int num, const char *objtype)
{
	printf("Test \"Modify %i\" starting", num);
	fflush(stdout);

	empty_all(engine);

	printf(".");
	fflush(stdout);
	int i = 0;
	for (i = 0; i < num; i++)
		add_data(member, objtype);
	printf(".");
	fflush(stdout);

	check_sync(engine, "None", num);

	printf(".");
	fflush(stdout);
	modify_data(member, objtype);
	printf(".");
	fflush(stdout);

	return check_sync(engine, "Modify", num);
}
示例#2
0
int main(void)
{
	//创建有序二叉树,并且进行初始化
	Tree tree;
	tree.root = NULL;
	tree.cnt = 0;

	insert_data(&tree,50);
	travel_data(&tree);//50
	insert_data(&tree,70);
	travel_data(&tree);//50 70
	insert_data(&tree,20);
	travel_data(&tree);//20 50 70
	insert_data(&tree,60);
	travel_data(&tree);//20 50 60 70

	printf("------------------------\n");
	printf("%s\n",empty(&tree)?"有序二叉树已经空了":"有序二叉树没有空");//没有空
	printf("%s\n",full(&tree)?"有序二叉树已经满了":"有序二叉树没有满");//没有满
	printf("有序二叉树中根节点的元素值是:%d\n",get_root(&tree));//50
	printf("有序二叉树中节点元素的个数是:%d\n",size(&tree));//4

	printf("----------------------\n");
	delete_data(&tree,50);
	travel_data(&tree); //20 60 70

	modify_data(&tree,50,200);//修改失败
	modify_data(&tree,20,200);//修改成功
	travel_data(&tree);//60 70 200
	
	printf("-----------------------\n");
	clear_data(&tree);
	travel_data(&tree); //啥也没有
	printf("有序二叉树中节点元素的个数是:%d\n",size(&tree));//0
	return 0;
}
示例#3
0
int main()
{
 Link *Head =NULL;
 insert_data(&Head,10);  //삽입
 insert_data(&Head,20);  //삽입
 insert_data(&Head,30);  //삽입
 insert_data(&Head,40);  //삽입
 modify_data(Head,20,22);  //수정  20을22로변경
 delete_data(&Head,20);  //삭제//20이라는 데이터를 삭제해라
 search_data(Head,22);  //검색  //22라는데이터를검색(출력값은 데이터와 노드의 주소)
 print_data(Head);  //출력 현재존재하는 노트의 데이터가 모두 출력
 add_data(Head,22,26);  //추가 //22뒤에 26을 추가
 print_data(Head);
 return 0;
}
示例#4
0
/*---------------------------------------------------------------------------*                                            
 * NAME: update_hash
 * DESC: update each hash value.
 *---------------------------------------------------------------------------*/
void update_hash(config *conf) {
  
  struct struct_hash *hash;
  struct struct_block  *block;
  unsigned int int_big_endian;
  unsigned int int_little_endian;
  unsigned int crc = 0;

  /* debug */
  debug(1, "<-----------------------[enter]\n");

  /* verbose */
  verbose__("[*] computing the block's hash.\n");

  /* for each entry, find the block and fill the size */
  for(hash=conf->hash;hash;hash=hash->next) {
    for(block=conf->block;block;block=block->next) {
      if (block->id == hash->id) {
	hash->block = block;
	debug(3, "hash (%d) and block[%d] connected\n", block->size, hash->id);

	switch(hash->type) {

	case HF_BLOCK_CRC32_B : /* CRC32 big-endian 32bits */

	  /* compute the CRC32 of the block */
	  crc = hash_crc32(conf->buf_fuzz + block->offset, block->size);

	  /* convert in big endian */
	  int_big_endian = htonl(crc);

          /* write the hash value */
          modify_data(conf, (unsigned char *) &int_big_endian, sizeof(int), hash->offset);
	  
	  debug(3, "big-endian-32b CRC32 hash: 0x%02x%02x%02x%02x\n",
		*(conf->buf_fuzz + hash->offset),
		*(conf->buf_fuzz + hash->offset+1),
		*(conf->buf_fuzz + hash->offset+2),
		*(conf->buf_fuzz + hash->offset+3)); 

	  break;

	case HF_BLOCK_CRC32_L : /* CRC32 big-endian 32bits */

	  /* compute the CRC32 of the block */
	  crc = hash_crc32(conf->buf_fuzz + block->offset, block->size);

	  /* convert in big endian */
	  int_big_endian = htonl(crc);

	  /* convert in little-endian */
	  memcpy((unsigned char*) &int_little_endian    , (unsigned char *) &int_big_endian + 3, sizeof(char));
	  memcpy((unsigned char*) &int_little_endian + 1, (unsigned char *) &int_big_endian + 2, sizeof(char));
	  memcpy((unsigned char*) &int_little_endian + 2, (unsigned char *) &int_big_endian + 1, sizeof(char));
	  memcpy((unsigned char*) &int_little_endian + 3, (unsigned char *) &int_big_endian, sizeof(char));


          /* write the hash value */
          modify_data(conf, (unsigned char *) &int_little_endian, sizeof(int), hash->offset);

	  debug(3, "little-endian-32b CRC32 hash: 0x%02x%02x%02x%02x\n",
		*(conf->buf_fuzz + hash->offset),
		*(conf->buf_fuzz + hash->offset+1),
		*(conf->buf_fuzz + hash->offset+2),
		*(conf->buf_fuzz + hash->offset+3)); 
	  break;

	default: /* should never happen */ 
	  break;
	  
	}
	break; /* optimization 8^) */
      }
    }
  }

  /* debug */
  debug(1, "<-----------------------[quit]\n");

}
示例#5
0
/*---------------------------------------------------------------------------*                                            
 * NAME: update_length
 * DESC: update each length value, even string length (tricky!)
 *---------------------------------------------------------------------------*/
void update_length(config *conf) {
  
  struct struct_length *length;
  struct struct_block  *block;
  unsigned int int_big_endian;
  unsigned int int_little_endian;

  /* debug */
  debug(1, "<-----------------------[enter]\n");

  /* verbose */
  verbose__("[*] computing the block's length.\n");

  /* for each entry, find the block and fill the size */
  for(length=conf->length;length;length=length->next) {
    for(block=conf->block;block;block=block->next) {
      if (block->id == length->id) {
	length->block = block;
	debug(3, "length (%d) and block[%d] connected\n", block->size, length->id);

	/* size in big-endian */
	int_big_endian = htonl(block->size);

	/* convert in little-endian */
	memcpy((unsigned char*) &int_little_endian    , (unsigned char *) &int_big_endian + 3, sizeof(char));
	memcpy((unsigned char*) &int_little_endian + 1, (unsigned char *) &int_big_endian + 2, sizeof(char));
	memcpy((unsigned char*) &int_little_endian + 2, (unsigned char *) &int_big_endian + 1, sizeof(char));
	memcpy((unsigned char*) &int_little_endian + 3, (unsigned char *) &int_big_endian, sizeof(char));
	
	switch(length->type) {

	case HF_BLOCK_SIZE_B_32 : /* big-endian 32bits */
	  modify_data(conf, (unsigned char *) &int_big_endian, sizeof(int), length->offset);
	  debug(3, "big-endian-32b length: 0x%02x%02x%02x%02x\n",
		*(conf->buf_fuzz + length->offset),
		*(conf->buf_fuzz + length->offset+1),
		*(conf->buf_fuzz + length->offset+2),
		*(conf->buf_fuzz + length->offset+3)); 
	  break;
	case HF_BLOCK_SIZE_L_32 : /* little-endian 32bits */
	  modify_data(conf, (unsigned char *) &int_little_endian, sizeof(int), length->offset);
	  debug(3, "little-endian-32b length: 0x%02x%02x%02x%02x\n",
		*(conf->buf_fuzz + length->offset),
		*(conf->buf_fuzz + length->offset+1),
		*(conf->buf_fuzz + length->offset+2),
		*(conf->buf_fuzz + length->offset+3)); 

	  break; 
	case HF_BLOCK_SIZE_B_16 : /* big-endian 16bits */
	  modify_data(conf, (unsigned char *) &int_big_endian + 2, sizeof(short), length->offset);
	  debug(3, "big-endian-16b length: 0x%02x%02x\n",
		*(conf->buf_fuzz + length->offset),
		*(conf->buf_fuzz + length->offset+1)); 

	  break; 
	case HF_BLOCK_SIZE_L_16 : /* little-endian 16bits */
	  modify_data(conf, (unsigned char *) &int_little_endian + 2, sizeof(short), length->offset);
	  debug(3, "big-endian-16b length: 0x%02x%02x\n",
		*(conf->buf_fuzz + length->offset),
		*(conf->buf_fuzz + length->offset+1)); 
	  break; 
	case HF_BLOCK_SIZE_8 :    /* 8bits */
	  modify_data(conf, (unsigned char *) &int_big_endian + 3, sizeof(char), length->offset);
	  debug(3, "8b length : 0x%02x\n", *(conf->buf_fuzz + length->offset));
	  break; 
	case HF_BLOCK_SIZE_S_16 : /* string in hexadecimal */

	  /* TODOXXXFIXMEXXX */
	  break;
	case HF_BLOCK_SIZE_S_10 : /* string in decimal */
	  
	  /* TODOXXXFIXMEXXX */
	  break;
	default: /* should never happen */ 
	  break;
	  
	}
	break; /* optimization 8^) */
      }
    }
  }

  /* debug */
  debug(1, "<-----------------------[quit]\n");

}
void func(type x)
{

  	int sockfd, portno, n=0,length;
      struct sockaddr_in serv_addr,cli_addr;
      struct hostent *server;
	char s[80];
	int temp, i=10;
      char buffer[256],buff[50],buff2[4];

	printf("\nThe message: %d and %c and %f",x.a, x.b, x.c);

	x=modify_data(x);


	portno =3700;
	length=sizeof(struct sockaddr_in); 

   
     sockfd = socket(AF_INET, SOCK_DGRAM, 0);
     if (sockfd < 0) 
        error("ERROR opening socket");
     bzero((char *) &serv_addr, sizeof(serv_addr));
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_addr.s_addr = INADDR_ANY;
      serv_addr.sin_port = htons(portno);
     if (bind(sockfd, (struct sockaddr *) &serv_addr,
              sizeof(serv_addr)) < 0) 
              error("ERROR on binding");
    


	bzero(buff2,4);
	bzero(buffer,256);
	bzero(buff, 50);


	printf("\nwaiting for rohan.sdsu.edu...\n",buff2);
	for(i=0;i<200;i++)
	{
	
n = recvfrom(sockfd,buff2,sizeof(buff2),0,(struct sockaddr *)&cli_addr,(socklen_t *)&length);
	if(n!=0 || n!=-1 && strcmp(buff2,"Ok\n"))
	{
	
	printf("\nConnected!!\n");
	
	printf("\nSending modified data %d, %c and %f\n",x.a,x.b,x.c);
 	n = sendto(sockfd,&x,sizeof(type),0,(struct sockaddr *)&cli_addr,length);
	

	sprintf(buff,"%f",x.c);

	 n = sendto(sockfd,buff,sizeof(buff),0,(struct sockaddr *)&cli_addr,length);
	    if (n < 0) 
          error("ERROR writing to socket");



	n = recvfrom(sockfd,buffer,sizeof(buff),0,(struct sockaddr *)&cli_addr,(socklen_t *)&length);

	    if (n < 0) 
         error("ERROR reading from socket");
	    printf("\nMessage from rohan.sdsu.edu : %s\n",buffer);
	break;
	}
	}
	    close(sockfd);

}