コード例 #1
0
ファイル: tree.cpp プロジェクト: kopoden/Common-Storage
//================================================================================
node* grow_from_file (FILE* base, FILE* logs) {

    node* leaf = NULL;
    node* tree = NULL;

    char ch = 0;
    ch = getc(base);

    switch (ch) {

        case '(':

            create_new_leaf(&tree, NULL);
            tree->info = (char*) calloc (MAX_STRING_LENG, sizeof(char));

            fscanf(base, "'%[^']'", tree->info);
            fprintf(logs, "IN FUNCTION = %s\n", tree->info);

            leaf = grow_from_file(base, logs);

            if (leaf == NULL)
                return tree;

            fprintf(logs, "NEW LEFT LEAF %s OF %s\n", leaf->info, tree->info);
            add_left(tree, leaf);

            leaf = grow_from_file(base, logs);

            if (leaf == NULL)
                return tree;

            fprintf(logs, "NEW RIGHT LEAF %s OF %s\n", leaf->info, tree->info);
            add_rght(tree, leaf);

            ch = getc(base);

            if (ch == '(') {
                fprintf(logs, "ERROR, THIRD LEAF OF BINARY NODE\n");
                return NULL;
            }

            ungetc(ch, base);

            break;

        case ')':
            fprintf(logs, "DEADLOCK\n");
            return NULL;

        default:
            return NULL;
    }

    fprintf(logs, "EXIT FROM %s\n", tree->info);
    ch = getc(base);

    return tree;

}
コード例 #2
0
ファイル: blacklist.c プロジェクト: ibrdtn/dtndht
void blacklist_blacklist_node(const struct sockaddr *sa, unsigned char * md) {
	if (!enabled)
		return;
	struct sockaddr_in * ip4addr;
	struct sockaddr_in6 * ip6addr;
	struct blacklist_entry * prev;
	int i = 0, maxlevel = 0;
	u_int16_t port = 0;
	unsigned char addr[16];
	unsigned char pos = 0;
	//	printf("BLACKLIST ");
	//	printf_addr(sa);
	switch (sa->sa_family) {
	case AF_INET:
		maxlevel = 4;
		ip4addr = (struct sockaddr_in*) sa;
		if (IPv4_blacklist == NULL) {
			IPv4_blacklist = create_new_entry(0);
		}
		prev = IPv4_blacklist;
		memcpy(addr, &(ip4addr->sin_addr.s_addr), maxlevel);
		port = ip4addr->sin_port;
		//		printf(" Port %d", ntohs(ip4addr->sin_port));
		break;
	case AF_INET6:
		maxlevel = 16;
		ip6addr = (struct sockaddr_in6*) sa;
		memcpy(addr, &(ip6addr->sin6_addr.s6_addr), maxlevel);
		if (IPv6_blacklist == NULL) {
			IPv6_blacklist = create_new_entry(0);
		}
		prev = IPv6_blacklist;
		port = ip6addr->sin6_port;
		//		printf(" Port %d", ntohs(ip6addr->sin6_port));
		break;
	default:
		return;
	}
	//	printf("\n");
	for (i = 1; i <= maxlevel; i++) {
		if (i < maxlevel) {
			if (prev->children[addr[i - 1]] == NULL) {
				prev->children[addr[i - 1]] = create_new_entry(i + 1);
			}
		} else {
			if (prev->children[addr[i - 1]] == NULL) {
				switch (sa->sa_family) {
				case AF_INET:
					number_of_entries_ipv4++;
					break;
				case AF_INET6:
					number_of_entries_ipv6++;
					break;
				}
			}
			prev->children[addr[i - 1]] = create_new_leaf(port, md);
		}
		prev = prev->children[addr[i - 1]];
	}
	//	printf_blacklist();
}