Example #1
0
static bool
add_user_into_multicast_group( struct in_addr maddr, unsigned int *n_users ) {
  assert( multicast_groups != NULL );
  assert( n_users != NULL );

  if ( !IN_MULTICAST( ntohl( maddr.s_addr ) ) ) {
    return false;
  }

  lock_multicast_group_table();

  unsigned int *in_use = search_hash( &multicast_groups->groups, &maddr );
  if ( in_use == NULL ) {
    in_use = malloc( sizeof( unsigned int ) );
    assert( in_use != NULL );
    *in_use = 0;
    insert_hash( &multicast_groups->groups, in_use, &maddr );
  }
  ( *in_use )++;

  *n_users = *in_use;

  unlock_multicast_group_table();

  return true;
}
Example #2
0
int main()
{
    int initial_num, query_num;
    unsigned int roll_number = 0;
    char name[26];
    int i = 0;
    node_p *hash_arry = malloc(MAX_LIMIT*sizeof(node_p *));
    memset(hash_arry, 0, MAX_LIMIT*sizeof(node_p *));

    scanf("%d", &initial_num);

    for (i = 0; i < initial_num; i++) {
        scanf("%u", &roll_number);
        scanf("%s", name);
        insert_hash(hash_arry, roll_number, name);
    }

    scanf("%d", &query_num);
    for (i = 0; i < query_num; i++) {
        scanf("%u", &roll_number);
        search_hash(hash_arry, roll_number);
    }

    return 0;
}
Example #3
0
static bool
delete_user_from_multicast_group( struct in_addr maddr, unsigned int *n_users ) {
  assert( multicast_groups != NULL );
  assert( n_users != NULL );

  if ( !IN_MULTICAST( ntohl( maddr.s_addr ) ) ) {
    return false;
  }

  lock_multicast_group_table();

  unsigned int *in_use = search_hash( &multicast_groups->groups, &maddr );
  if ( in_use == NULL ) {
    *n_users = 0;
    unlock_multicast_group_table();
    return false;
  }

  ( *in_use )--;
  *n_users = *in_use;
  if ( *in_use == 0 ) {
    in_use = delete_hash( &multicast_groups->groups, &maddr );
    if ( in_use != NULL ) {
      free( in_use );
      in_use = NULL;
    }
  }

  unlock_multicast_group_table();

  return true;
}
Example #4
0
int main ()
{
    int n, num0[6];
    while(~scanf("%d", &n))
    {
        cur = 0;
        init_hash();
        int temp, twins = 0;
        for(int i = 0; i < n;  i ++)
        {
            for(int j = 0; j < 6; j ++)
            {
                scanf("%d", &temp);
                num0[j] = temp;
            }
            if(twins)
                continue;
            twins = search_hash(num0);
        }
        if(twins)
            printf("Twin snowflakes found.\n");
        else
            printf("No two snowflakes are alike.\n");
    }
    return 0;
}
Example #5
0
void
exec_command_vni_destroy (char * str, int sock)
{
	u_int8_t vnibuf[3];
	char cmd[CONTROL_CMD_BUF_LEN];
	char vni[CONTROL_CMD_BUF_LEN];
	struct vxlan_instance * vins;
	
	if (sscanf (str, "%s %s", cmd, vni) < 2) {
		write (sock, CONTROL_ERRMSG, sizeof (CONTROL_ERRMSG));
		return;
	}
	
	strtovni (vni, vnibuf);
	if ((vins = search_hash (&vxlan.vins_tuple, vnibuf)) == NULL) {
		char errbuf[] = "this vxlan instance does not exists\n";
		write (sock, errbuf, strlen (errbuf));
		return;
	}
	
	if (destroy_vxlan_instance (vins) < 0) {
		char errbuf[] = "Delete vxlan instance failed\n";
		write (sock, errbuf, strlen (errbuf));

	} else {
		char errbuf[] = "Deleted\n";
		write (sock, errbuf, strlen (errbuf));
	}

	return;	
}
Example #6
0
void
exec_command_vni_create (char * str, int sock)
{
	u_int8_t vnibuf[3];
	char cmd[CONTROL_CMD_BUF_LEN];
	char vni[CONTROL_CMD_BUF_LEN];
	struct vxlan_instance * vins;
	
	if (sscanf (str, "%s %s", cmd, vni) < 2) {
		write (sock, CONTROL_ERRMSG, sizeof (CONTROL_ERRMSG));
		return;
	}
	
	strtovni (vni, vnibuf);

	if ((vins = search_hash (&vxlan.vins_tuple, vnibuf)) != NULL) {
		char errbuf[] = "this vxlan instance exists\n";
		write (sock, errbuf, strlen (errbuf));
		return;
	}
	
	vins = create_vxlan_instance (vnibuf);
	insert_hash (&vxlan.vins_tuple, vins, vnibuf);
	init_vxlan_instance (vins);
	vxlan.vins_num++;

	char msgbuf[] = "created\n";
	write (sock, msgbuf, strlen (msgbuf));
	return;
}
Example #7
0
void loopcase(char op){
   
   clock_t start_time, end_time;
   char word[50] = { 0 };

   if (op == 'y') {
      while (1){
         printf("검색 원하는 단어 입력 : ");
         scanf("%s", word);
         if(strlen(word)<3){
            printf("3글자 단어부터 검색됩니다.");
            continue;
         }
         start_time = clock();
         search_hash(word);
         end_time = clock();
         printf("Time : %lf\n",
            ((double)(end_time - start_time)) / CLOCKS_PER_SEC);
         printf("\n");
      }
   }
   else if (op == 'n'){
      while (1){
         printf("검색 원하는 단어 입력 : ");
         scanf("%s", word);
         if(strlen(word)<3){
            printf("3글자 단어부터 검색됩니다.");
            continue;
         }
         start_time = clock();
         search_hash(strlwr(word));
         end_time = clock();
         printf("Time : %lf\n",
            ((double)(end_time - start_time)) / CLOCKS_PER_SEC);
         printf("\n");
      }
   }
   else{
      printf("ERR!\n");
      system("pause");
      exit(1);
   }

}
Example #8
0
struct sockaddr *
fdb_search_vtep_addr (struct hash * fdb, u_int8_t * mac)
{
	struct fdb_entry * entry;
	
	if ((entry = search_hash (fdb, mac)) == NULL)
		return NULL;
	
	return &entry->vtep_addr;
}
Example #9
0
void
exec_command_acl (char * str, int sock)
{

	int n;
	struct acl_entry ae;

	struct vxlan_instance * vins;
	
	if ((n = strtoaclentry (str + 4, &ae)) < 0) {
		char errbuf[] = "inavlid acl entry\n";
		write (sock, errbuf, strlen (errbuf));
		return;
	}
		
	if ((vins = search_hash (&vxlan.vins_tuple, ae.vni)) == NULL) {
		char errbuf[] = "this vni instance does not exist\n";
		write (sock, errbuf, strlen (errbuf));
		return;
	}

	if (n == STRTOACLENTRY_INSTALL) {
		if (install_acl_entry (vins, ae) < 0) {
			char errbuf[] = "install access list failed\n";
			write (sock, errbuf, strlen (errbuf));
			return;
		} else {
			char errbuf[] = "access list installed\n";
			write (sock, errbuf, strlen (errbuf));
			return;
		}
	}

	if (n == STRTOACLENTRY_UNINSTALL) {
		if (uninstall_acl_entry (vins, ae) < 0) {
			char errbuf[] = "uninstall access list failed\n";
			write (sock, errbuf, strlen (errbuf));
			return;
		} else {
			char errbuf[] = "access list uninstalled\n";
			write (sock, errbuf, strlen (errbuf));
			return;
		}
	}

	return;
}
Example #10
0
struct fdb_entry *
fdb_search_entry (struct hash * fdb, u_int8_t * mac)
{
	return search_hash (fdb, mac);
}